1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
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 | |
|
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 | |
|
76 | |
|
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 | |
|
88 | 0 | configLocations.add("classpath:META-INF/workflow.xml"); |
89 | |
} |
90 | 0 | } |
91 | |
} |