1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.action;
17
18 import org.apache.commons.beanutils.ConvertUtils;
19 import org.apache.commons.beanutils.converters.BigDecimalConverter;
20 import org.apache.commons.beanutils.converters.BigIntegerConverter;
21 import org.apache.commons.beanutils.converters.BooleanConverter;
22 import org.apache.commons.beanutils.converters.ByteConverter;
23 import org.apache.commons.beanutils.converters.CharacterConverter;
24 import org.apache.commons.beanutils.converters.DoubleConverter;
25 import org.apache.commons.beanutils.converters.FloatConverter;
26 import org.apache.commons.beanutils.converters.IntegerConverter;
27 import org.apache.commons.beanutils.converters.LongConverter;
28 import org.apache.commons.beanutils.converters.ShortConverter;
29 import org.apache.commons.collections.iterators.IteratorEnumeration;
30 import org.apache.commons.lang.StringUtils;
31 import org.apache.log4j.Logger;
32 import org.apache.struts.action.ActionServlet;
33 import org.kuali.rice.core.api.config.ConfigurationException;
34 import org.kuali.rice.core.api.config.property.ConfigContext;
35 import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
36 import org.kuali.rice.core.framework.config.module.WebModuleConfiguration;
37
38 import java.io.IOException;
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse;
41 import javax.servlet.ServletConfig;
42 import javax.servlet.ServletContext;
43 import javax.servlet.ServletException;
44 import java.math.BigDecimal;
45 import java.math.BigInteger;
46 import java.util.Collection;
47 import java.util.Enumeration;
48 import java.util.HashMap;
49 import java.util.Map;
50
51
52
53
54 @Deprecated
55 public class KualiActionServlet extends ActionServlet {
56 private static final Logger LOG = Logger.getLogger(KualiActionServlet.class);
57
58
59 private String parameterEncoding = "";
60
61
62
63
64
65
66
67
68 @Override
69 protected void initOther() throws ServletException {
70
71 String value = null;
72 value = getServletConfig().getInitParameter("config");
73 if (value != null) {
74 config = value;
75 }
76
77
78
79 value = getServletConfig().getInitParameter("convertNull");
80 if ("true".equalsIgnoreCase(value)
81 || "yes".equalsIgnoreCase(value)
82 || "on".equalsIgnoreCase(value)
83 || "y".equalsIgnoreCase(value)
84 || "1".equalsIgnoreCase(value)) {
85
86 convertNull = true;
87 }
88
89 if (convertNull) {
90 ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
91 ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
92 ConvertUtils.register(new BooleanConverter(null), Boolean.class);
93 ConvertUtils.register(new ByteConverter(null), Byte.class);
94 ConvertUtils.register(new CharacterConverter(null), Character.class);
95 ConvertUtils.register(new DoubleConverter(null), Double.class);
96 ConvertUtils.register(new FloatConverter(null), Float.class);
97 ConvertUtils.register(new IntegerConverter(null), Integer.class);
98 ConvertUtils.register(new LongConverter(null), Long.class);
99 ConvertUtils.register(new ShortConverter(null), Short.class);
100 }
101
102
103 parameterEncoding = getServletConfig().getInitParameter("PARAMETER_ENCODING");
104 }
105
106 KualiActionServletConfig serverConfigOverride = null;
107
108 @Override
109 public ServletConfig getServletConfig() {
110 if ( serverConfigOverride == null ) {
111 ServletConfig sConfig = super.getServletConfig();
112
113 if ( sConfig == null ) {
114 return null;
115 }
116 serverConfigOverride = new KualiActionServletConfig(sConfig);
117 }
118 return serverConfigOverride;
119 }
120
121
122
123
124
125
126 private class KualiActionServletConfig implements ServletConfig {
127
128 private ServletConfig wrapped;
129 private Map<String,String> initParameters = new HashMap<String, String>();
130
131 public KualiActionServletConfig(ServletConfig wrapped) {
132 this.wrapped = wrapped;
133
134 @SuppressWarnings("unchecked")
135 final Enumeration<String> initParameterNames = wrapped.getInitParameterNames();
136 while ( initParameterNames.hasMoreElements() ) {
137 String paramName = initParameterNames.nextElement();
138 initParameters.put( paramName, wrapped.getInitParameter(paramName) );
139 }
140
141
142 final Collection<ModuleConfigurer> riceModules = ModuleConfigurer.getCurrentContextConfigurers();
143
144 if ( LOG.isInfoEnabled() ) {
145 LOG.info( "Configuring init parameters of the KualiActionServlet from riceModules: " + riceModules );
146 }
147 for ( ModuleConfigurer module : riceModules ) {
148
149
150
151 if ( module.shouldRenderWebInterface() ) {
152 WebModuleConfiguration webModuleConfiguration = module.getWebModuleConfiguration();
153 if (webModuleConfiguration == null) {
154 throw new ConfigurationException("Attempting to load WebModuleConfiguration for module '" + module.getModuleName() + "' but no configuration was provided!");
155 }
156 if ( LOG.isInfoEnabled() ) {
157 LOG.info( "Configuring Web Content for Module: " + webModuleConfiguration.getModuleName()
158 + " / " + webModuleConfiguration.getWebModuleStrutsConfigName()
159 + " / " + webModuleConfiguration.getWebModuleStrutsConfigurationFiles()
160 + " / Base URL: " + webModuleConfiguration.getWebModuleBaseUrl() );
161 }
162 if ( !initParameters.containsKey( webModuleConfiguration.getWebModuleStrutsConfigName() ) ) {
163 initParameters.put( webModuleConfiguration.getWebModuleStrutsConfigName(), webModuleConfiguration.getWebModuleStrutsConfigurationFiles() );
164 }
165 }
166 }
167 }
168
169 @Override
170 public String getInitParameter(String name) {
171 return initParameters.get(name);
172 }
173
174 @Override
175 @SuppressWarnings("unchecked")
176 public Enumeration<String> getInitParameterNames() {
177 return new IteratorEnumeration( initParameters.keySet().iterator() );
178 }
179
180 @Override
181 public ServletContext getServletContext() {
182 return wrapped.getServletContext();
183 }
184 @Override
185 public String getServletName() {
186 return wrapped.getServletName();
187 }
188 }
189
190
191
192
193
194
195 @Override
196 protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
197 if (StringUtils.isNotBlank(parameterEncoding)) {
198 request.setCharacterEncoding(parameterEncoding);
199 response.setCharacterEncoding(parameterEncoding);
200 }
201
202 super.process(request, response);
203 }
204 }