Coverage Report - org.kuali.rice.kns.web.servlet.KualiDWRServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiDWRServlet
0%
0/27
0%
0/14
3.25
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.web.servlet;
 17  
 
 18  
 import java.io.InputStream;
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.servlet.ServletConfig;
 23  
 import javax.servlet.ServletException;
 24  
 
 25  
 import org.apache.commons.lang.StringUtils;
 26  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 27  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 28  
 import org.kuali.rice.kns.service.ModuleService;
 29  
 import org.kuali.rice.kns.util.KNSConstants;
 30  
 import org.kuali.rice.kns.util.spring.NamedOrderedListBean;
 31  
 import org.springframework.core.io.DefaultResourceLoader;
 32  
 
 33  
 import uk.ltd.getahead.dwr.Configuration;
 34  
 import uk.ltd.getahead.dwr.DWRServlet;
 35  
 
 36  0
 public class KualiDWRServlet extends DWRServlet {
 37  
         /**
 38  
          * 
 39  
          */
 40  
         private static final long serialVersionUID = -3903455224197903186L;
 41  
 
 42  
         private static final String CLASSPATH_RESOURCE_PREFIX = "classpath.resource.prefix";
 43  
         
 44  0
         public static List<String> HACK_ADDITIONAL_FILES = new ArrayList<String>();
 45  
 
 46  
         private Boolean springBasedConfigPath;
 47  
 
 48  
         @Override
 49  
         public void init(ServletConfig config) throws ServletException {
 50  0
                 setSpringBasedConfigPath(new Boolean(config.getInitParameter("springpath")));
 51  0
                 super.init(config);
 52  0
         }
 53  
 
 54  
         /**
 55  
          * This method calls the super version then loads the dwr config file
 56  
          * specified in the loaded module definitions.
 57  
          * 
 58  
          * @see uk.ltd.getahead.dwr.DWRServlet#configure(javax.servlet.ServletConfig,
 59  
          *      uk.ltd.getahead.dwr.Configuration)
 60  
          */
 61  
         @Override
 62  
         public void configure(ServletConfig servletConfig, Configuration configuration) throws ServletException {
 63  0
                 String classpathResourcePrefix = KNSServiceLocator.getKualiConfigurationService().getPropertyString(CLASSPATH_RESOURCE_PREFIX);
 64  0
                 for (NamedOrderedListBean namedOrderedListBean : KNSServiceLocator.getNamedOrderedListBeans(KNSConstants.SCRIPT_CONFIGURATION_FILES_LIST_NAME)) {
 65  0
                         for (String scriptConfigurationFilePath : namedOrderedListBean.getList()) {
 66  0
                                 if (getSpringBasedConfigPath()) {
 67  0
                                         DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
 68  
                                         try {
 69  0
                                                 InputStream is = resourceLoader.getResource(scriptConfigurationFilePath).getInputStream();
 70  0
                                                 configuration.addConfig(is);
 71  0
                                         } catch (Exception e) {
 72  0
                                                 throw new ServletException(e);
 73  0
                                         }
 74  0
                                 } else {
 75  0
                                         super.readFile(classpathResourcePrefix + 
 76  
                                                         scriptConfigurationFilePath, configuration);
 77  
                                 }
 78  
                         }
 79  
                 }
 80  0
                 for (ModuleService moduleService : KNSServiceLocator.getKualiModuleService().getInstalledModuleServices()) {
 81  0
                         for (String scriptConfigurationFilePath : moduleService.getModuleConfiguration().getScriptConfigurationFilePaths()) {
 82  0
                                 if (!StringUtils.isBlank(scriptConfigurationFilePath))
 83  0
                                         super.readFile(classpathResourcePrefix + scriptConfigurationFilePath, configuration);
 84  
                         }        
 85  
                 }
 86  
                 
 87  0
                 for (String configFile : HACK_ADDITIONAL_FILES) {
 88  0
                         super.readFile(classpathResourcePrefix + configFile, configuration);
 89  
                 }
 90  0
         }
 91  
 
 92  
         public Boolean getSpringBasedConfigPath() {
 93  0
                 return springBasedConfigPath;
 94  
         }
 95  
 
 96  
         public void setSpringBasedConfigPath(Boolean springBasedConfigPath) {
 97  0
                 this.springBasedConfigPath = springBasedConfigPath;
 98  0
         }
 99  
 }