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 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 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 setSpringBasedConfigPath(new Boolean(config.getInitParameter("springpath")));
51 super.init(config);
52 }
53
54
55
56
57
58
59
60
61 @Override
62 public void configure(ServletConfig servletConfig, Configuration configuration) throws ServletException {
63 String classpathResourcePrefix = KNSServiceLocator.getKualiConfigurationService().getPropertyString(CLASSPATH_RESOURCE_PREFIX);
64 for (NamedOrderedListBean namedOrderedListBean : KNSServiceLocator.getNamedOrderedListBeans(KNSConstants.SCRIPT_CONFIGURATION_FILES_LIST_NAME)) {
65 for (String scriptConfigurationFilePath : namedOrderedListBean.getList()) {
66 if (getSpringBasedConfigPath()) {
67 DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader());
68 try {
69 InputStream is = resourceLoader.getResource(scriptConfigurationFilePath).getInputStream();
70 configuration.addConfig(is);
71 } catch (Exception e) {
72 throw new ServletException(e);
73 }
74 } else {
75 super.readFile(classpathResourcePrefix +
76 scriptConfigurationFilePath, configuration);
77 }
78 }
79 }
80 for (ModuleService moduleService : KNSServiceLocator.getKualiModuleService().getInstalledModuleServices()) {
81 for (String scriptConfigurationFilePath : moduleService.getModuleConfiguration().getScriptConfigurationFilePaths()) {
82 if (!StringUtils.isBlank(scriptConfigurationFilePath))
83 super.readFile(classpathResourcePrefix + scriptConfigurationFilePath, configuration);
84 }
85 }
86
87 for (String configFile : HACK_ADDITIONAL_FILES) {
88 super.readFile(classpathResourcePrefix + configFile, configuration);
89 }
90 }
91
92 public Boolean getSpringBasedConfigPath() {
93 return springBasedConfigPath;
94 }
95
96 public void setSpringBasedConfigPath(Boolean springBasedConfigPath) {
97 this.springBasedConfigPath = springBasedConfigPath;
98 }
99 }