Coverage Report - org.kuali.rice.kns.web.RiceConfigurationListener
 
Classes in this File Line Coverage Branch Coverage Complexity
RiceConfigurationListener
0%
0/29
0%
0/10
3.333
 
 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;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.servlet.ServletContext;
 22  
 import javax.servlet.ServletContextEvent;
 23  
 import javax.servlet.ServletContextListener;
 24  
 
 25  
 import org.apache.commons.lang.StringUtils;
 26  
 import org.kuali.rice.core.config.Config;
 27  
 import org.kuali.rice.core.config.ConfigContext;
 28  
 import org.kuali.rice.core.config.JAXBConfigImpl;
 29  
 import org.kuali.rice.core.config.SimpleConfig;
 30  
 import org.kuali.rice.core.util.JSTLConstants;
 31  
 import org.kuali.rice.kew.util.KEWConstants;
 32  
 
 33  
 
 34  0
 public class RiceConfigurationListener implements ServletContextListener {
 35  
 
 36  
     public void contextDestroyed(ServletContextEvent sce) {
 37  
 
 38  0
     }
 39  
 
 40  
     public void contextInitialized(ServletContextEvent sce) {
 41  0
         sce.getServletContext().setAttribute("Constants", new JSTLConstants(KEWConstants.class));
 42  
 
 43  0
         List<String> configLocations = new ArrayList<String>();
 44  
         // use the system prop as an override of the default packaged META-INF/workflow.xml
 45  0
         String altCoreConfigLocation = System.getProperty(KEWConstants.DEFAULT_CONFIG_LOCATION_PARAM);
 46  0
         if (altCoreConfigLocation != null) {
 47  0
             configLocations.add(altCoreConfigLocation);
 48  
         }
 49  
         else {
 50  0
             addDefaultConfigLocation(sce.getServletContext(), configLocations);
 51  
         }
 52  
 
 53  
         // use the system property to add additional configurations (useful for testing)
 54  0
         String additionalConfigLocations = System.getProperty(KEWConstants.ADDITIONAL_CONFIG_LOCATIONS_PARAM);
 55  0
         if (!StringUtils.isEmpty(additionalConfigLocations)) {
 56  0
             String[] additionalConfigLocationArray = additionalConfigLocations.split(",");
 57  0
             for (String additionalConfigLocation : additionalConfigLocationArray) {
 58  0
                 configLocations.add(additionalConfigLocation);
 59  
             }
 60  
         }
 61  
 
 62  
         try {
 63  0
             Config serverConfig = new JAXBConfigImpl(configLocations);
 64  0
             serverConfig.parseConfig();
 65  0
             ConfigContext.init(serverConfig);
 66  
         }
 67  0
         catch (Exception e) {
 68  0
             e.printStackTrace();
 69  0
             throw new RuntimeException("Workflow failed to start properly.  Exiting.", e);
 70  0
         }
 71  0
     }
 72  
 
 73  
 
 74  
     /**
 75  
      * Configures the default config location by first checking the init params for default locations and then falling back to the
 76  
      * standard default config location.
 77  
      */
 78  
     protected void addDefaultConfigLocation(ServletContext context, List<String> configLocations) {
 79  0
         String defaultConfigLocation = context.getInitParameter(KEWConstants.DEFAULT_CONFIG_LOCATION_PARAM);
 80  0
         if (!StringUtils.isEmpty(defaultConfigLocation)) {
 81  0
             String[] locations = defaultConfigLocation.split(",");
 82  0
             for (String location : locations) {
 83  0
                 configLocations.add(location);
 84  
             }
 85  0
         }
 86  
         else {
 87  
                 // TODO: say what? Why workflow.xml?
 88  0
             configLocations.add("classpath:META-INF/workflow.xml");
 89  
         }
 90  0
     }
 91  
 }