Coverage Report - net.fckeditor.handlers.RequestCycleHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
RequestCycleHandler
0%
0/26
0%
0/10
0
 
 1  
 /*
 2  
  * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 3  
  * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 4  
  * 
 5  
  * == BEGIN LICENSE ==
 6  
  * 
 7  
  * Licensed under the terms of any of the following licenses at your
 8  
  * choice:
 9  
  * 
 10  
  *  - GNU General Public License Version 2 or later (the "GPL")
 11  
  *    http://www.gnu.org/licenses/gpl.html
 12  
  * 
 13  
  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 14  
  *    http://www.gnu.org/licenses/lgpl.html
 15  
  * 
 16  
  *  - Mozilla Public License Version 1.1 or later (the "MPL")
 17  
  *    http://www.mozilla.org/MPL/MPL-1.1.html
 18  
  * 
 19  
  * == END LICENSE ==
 20  
  */
 21  
 package net.fckeditor.handlers;
 22  
 
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 
 25  
 import net.fckeditor.requestcycle.UserAction;
 26  
 import net.fckeditor.requestcycle.UserPathBuilder;
 27  
 
 28  
 import org.slf4j.Logger;
 29  
 import org.slf4j.LoggerFactory;
 30  
 
 31  
 /**
 32  
  * Handler for classes which implement the interfaces from package
 33  
  * {@link net.fckeditor.requestcycle}.
 34  
  * 
 35  
  * @version $Id: RequestCycleHandler.java 2151 2008-07-02 22:03:15Z mosipov $
 36  
  */
 37  0
 public class RequestCycleHandler {
 38  0
         private static Logger logger = LoggerFactory.getLogger(RequestCycleHandler.class);
 39  0
         private static UserAction userAction = null;
 40  0
         private static UserPathBuilder userPathBuilder = null;
 41  
 
 42  
         static {
 43  
                 // If there are more objects to instantiate in future, we could solve the following by reflection!
 44  
                 
 45  
                 // 1. try to instantiate the UserAction object
 46  0
                 String fqcn = PropertiesLoader.getProperty("connector.userActionImpl");
 47  0
                 if (fqcn == null)
 48  0
                         logger.warn("No property found for UserAction implementation, any user action will be disabled!");
 49  
                 else {
 50  
                         try {
 51  0
                                 Class<?> clazz = Class.forName(fqcn);
 52  0
                                 userAction = (UserAction) clazz.newInstance();
 53  0
                                 logger.info("UserAction implementation successfully instantiated!");
 54  0
                         } catch (Exception e) {
 55  0
                                 logger.error("Couldn't instantiate class [".concat(fqcn).concat(
 56  
                                         "], any user action will disabled!"), e);
 57  0
                         }
 58  
                 }
 59  
 
 60  
                 // 2. try to instantiate the UserPathBuilder object
 61  0
                 fqcn = PropertiesLoader.getProperty("connector.userPathBuilderImpl");
 62  0
                 if (fqcn == null)
 63  0
                         logger.warn("No property found for UserPathBuilder implementation! "
 64  
                                         .concat("The 'DefaultUserFilesPath' will be used in the ConnectorServlet!"));
 65  
                 else {
 66  
                         try {
 67  0
                                 Class<?> clazz = Class.forName(fqcn);
 68  0
                                 userPathBuilder = (UserPathBuilder) clazz.newInstance();
 69  0
                                 logger.info("UserPathBuilder object successfully instantiated!");
 70  0
                         } catch (Exception e) {
 71  0
                                 logger.error("Couldn't instantiate class [".concat(fqcn)
 72  
                                         .concat("], The 'DefaultUserFilesPath' will be used in the ConnectorServlet!"), e);
 73  0
                         }
 74  
                 }
 75  0
         }
 76  
 
 77  
         /**
 78  
          * Just a wrapper to
 79  
          * {@link UserAction#isEnabledForFileBrowsing(HttpServletRequest)}.
 80  
          * 
 81  
          * @param request
 82  
          * @return {@link UserAction#isEnabledForFileBrowsing(HttpServletRequest)}
 83  
          *         or false if <code>userAction</code> isn't set.
 84  
          */
 85  
         public static boolean isEnabledForFileBrowsing(final HttpServletRequest request) {
 86  0
                 return (userAction != null && userAction.isEnabledForFileBrowsing(request));
 87  
         }
 88  
 
 89  
         /**
 90  
          * Just a wrapper to
 91  
          * {@link UserAction#isEnabledForFileUpload(HttpServletRequest)}.
 92  
          * 
 93  
          * @param request
 94  
          * @return {@link UserAction#isEnabledForFileUpload(HttpServletRequest)} or
 95  
          *         false if <code>userAction</code> isn't set.
 96  
          */
 97  
         public static boolean isEnabledForFileUpload(final HttpServletRequest request) {
 98  0
                 return (userAction != null && userAction.isEnabledForFileUpload(request));
 99  
         }
 100  
 
 101  
         /**
 102  
          * Getter for the <code>UserFilesPath</code>.<br />
 103  
          * Method is used by other handlers only!
 104  
          * 
 105  
          * @param request
 106  
          * @return {@link UserPathBuilder#getUserFilesPath(HttpServletRequest)} or
 107  
          *         <code>null</code> if <code>userPathBuilder</code> is
 108  
          *         <code>null</code>.
 109  
          */
 110  
         protected static String getUserFilePath(final HttpServletRequest request) {
 111  0
                 return (userPathBuilder != null) ? userPathBuilder.getUserFilesPath(request) : null;
 112  
         }
 113  
 }