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.kfs.web.struts.action;
017:
018: import java.util.ArrayList;
019: import java.util.Enumeration;
020: import java.util.List;
021: import java.util.ResourceBundle;
022:
023: import javax.servlet.ServletConfig;
024: import javax.servlet.ServletContext;
025:
026: import org.apache.commons.collections.iterators.IteratorEnumeration;
027: import org.kuali.core.web.struts.action.KualiActionServlet;
028: import org.kuali.kfs.KFSConstants;
029: import org.kuali.kfs.context.PropertyLoadingFactoryBean;
030: import org.kuali.rice.core.Core;
031:
032: /**
033: * KFSActionServlet implementation which overrides {@link #getServletConfig()} to filter out the
034: * kew struts module from the init parameters in the case where KFS is running against a
035: * central workflow instance.
036: *
037: * @author Eric Westfall
038: */
039: public class KFSActionServlet extends KualiActionServlet {
040:
041: @Override
042: public ServletConfig getServletConfig() {
043: return new KualiActionServletConfig(super .getServletConfig());
044: }
045:
046: /**
047: * A custom ServletConfig implementation which doesn't return the config/en init param
048: * whenever KFS is running against a central KEW. Accomplishes this by implementing custom
049: * {@link #getInitParameter(String)} and {@link #getInitParameterNames()} methods.
050: */
051: private class KualiActionServletConfig implements ServletConfig {
052:
053: private static final String KEW_STRUTS_MODULE_PARAM = "config/en";
054:
055: private ServletConfig wrapped;
056:
057: public KualiActionServletConfig(ServletConfig wrapped) {
058: this .wrapped = wrapped;
059: }
060:
061: public String getInitParameter(String name) {
062: if (isUseStandaloneWorkflow()
063: && KEW_STRUTS_MODULE_PARAM.equals(name)) {
064: return null;
065: }
066: return this .wrapped.getInitParameter(name);
067: }
068:
069: public Enumeration getInitParameterNames() {
070: Enumeration initParameterNames = this .wrapped
071: .getInitParameterNames();
072: if (isUseStandaloneWorkflow()) {
073: List<String> paramNames = new ArrayList<String>();
074: while (initParameterNames.hasMoreElements()) {
075: String paramName = (String) initParameterNames
076: .nextElement();
077: if (!KEW_STRUTS_MODULE_PARAM.equals(paramName)) {
078: paramNames.add(paramName);
079: }
080: }
081: return new IteratorEnumeration(paramNames.iterator());
082: }
083: return initParameterNames;
084: }
085:
086: public ServletContext getServletContext() {
087: return this .wrapped.getServletContext();
088: }
089:
090: public String getServletName() {
091: return this .wrapped.getServletName();
092: }
093:
094: private boolean isUseStandaloneWorkflow() {
095: return Boolean
096: .valueOf(PropertyLoadingFactoryBean
097: .getBaseProperty(KFSConstants.USE_STANDALONE_WORKFLOW));
098: }
099: }
100:
101: }
|