001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.web.servlet;
017:
018: import java.io.InputStream;
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import javax.servlet.ServletConfig;
023: import javax.servlet.ServletException;
024:
025: import org.apache.commons.lang.StringUtils;
026: import org.kuali.RiceConstants;
027: import org.kuali.core.KualiModule;
028: import org.kuali.core.util.spring.NamedOrderedListBean;
029: import org.kuali.rice.KNSServiceLocator;
030: import org.springframework.core.io.DefaultResourceLoader;
031:
032: import uk.ltd.getahead.dwr.Configuration;
033: import uk.ltd.getahead.dwr.DWRServlet;
034: import edu.iu.uis.eden.util.ClassLoaderUtils;
035:
036: public class KualiDWRServlet extends DWRServlet {
037: /**
038: *
039: */
040: private static final long serialVersionUID = -3903455224197903186L;
041:
042: private static final String CLASSPATH_RESOURCE_PREFIX = "WEB-INF/classes/";
043:
044: public static List<String> HACK_ADDITIONAL_FILES = new ArrayList<String>();
045:
046: private Boolean springBasedConfigPath;
047:
048: @Override
049: public void init(ServletConfig config) throws ServletException {
050: setSpringBasedConfigPath(new Boolean(config
051: .getInitParameter("springpath")));
052: super .init(config);
053: }
054:
055: /**
056: * This method calls the super version then loads the dwr config file
057: * specified in the loaded module definitions.
058: *
059: * @see uk.ltd.getahead.dwr.DWRServlet#configure(javax.servlet.ServletConfig,
060: * uk.ltd.getahead.dwr.Configuration)
061: */
062: @Override
063: public void configure(ServletConfig servletConfig,
064: Configuration configuration) throws ServletException {
065: for (NamedOrderedListBean namedOrderedListBean : KNSServiceLocator
066: .getNamedOrderedListBeans(RiceConstants.SCRIPT_CONFIGURATION_FILES_LIST_NAME)) {
067: for (String scriptConfigurationFilePath : namedOrderedListBean
068: .getList()) {
069: if (getSpringBasedConfigPath()) {
070: DefaultResourceLoader resourceLoader = new DefaultResourceLoader(
071: ClassLoaderUtils.getDefaultClassLoader());
072: try {
073: InputStream is = resourceLoader.getResource(
074: scriptConfigurationFilePath)
075: .getInputStream();
076: configuration.addConfig(is);
077: } catch (Exception e) {
078: throw new ServletException(e);
079: }
080: } else {
081: super .readFile(CLASSPATH_RESOURCE_PREFIX
082: + scriptConfigurationFilePath,
083: configuration);
084: }
085: }
086: }
087: for (KualiModule module : KNSServiceLocator
088: .getKualiModuleService().getInstalledModules()) {
089: for (String scriptConfigurationFilePath : module
090: .getScriptConfigurationFilePaths()) {
091: if (!StringUtils.isBlank(scriptConfigurationFilePath))
092: super .readFile(CLASSPATH_RESOURCE_PREFIX
093: + scriptConfigurationFilePath,
094: configuration);
095: }
096: }
097:
098: for (String configFile : HACK_ADDITIONAL_FILES) {
099: super .readFile(CLASSPATH_RESOURCE_PREFIX + configFile,
100: configuration);
101: }
102: }
103:
104: public Boolean getSpringBasedConfigPath() {
105: return springBasedConfigPath;
106: }
107:
108: public void setSpringBasedConfigPath(Boolean springBasedConfigPath) {
109: this.springBasedConfigPath = springBasedConfigPath;
110: }
111: }
|