1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
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 | |
} |