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.log4j.Logger;
31 import org.apache.struts.action.ActionServlet;
32 import org.kuali.rice.core.api.config.ConfigurationException;
33 import org.kuali.rice.core.api.config.property.ConfigContext;
34 import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
35 import org.kuali.rice.core.framework.config.module.WebModuleConfiguration;
36
37 import javax.servlet.ServletConfig;
38 import javax.servlet.ServletContext;
39 import javax.servlet.ServletException;
40 import java.math.BigDecimal;
41 import java.math.BigInteger;
42 import java.util.Collection;
43 import java.util.Enumeration;
44 import java.util.HashMap;
45 import java.util.Map;
46
47 public class KualiActionServlet extends ActionServlet {
48 private static final Logger LOG = Logger.getLogger(KualiActionServlet.class);
49
50
51
52
53
54
55
56
57 @Override
58 protected void initOther() throws ServletException {
59
60 String value = null;
61 value = getServletConfig().getInitParameter("config");
62 if (value != null) {
63 config = value;
64 }
65
66
67
68 value = getServletConfig().getInitParameter("convertNull");
69 if ("true".equalsIgnoreCase(value)
70 || "yes".equalsIgnoreCase(value)
71 || "on".equalsIgnoreCase(value)
72 || "y".equalsIgnoreCase(value)
73 || "1".equalsIgnoreCase(value)) {
74
75 convertNull = true;
76 }
77
78 if (convertNull) {
79 ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
80 ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
81 ConvertUtils.register(new BooleanConverter(null), Boolean.class);
82 ConvertUtils.register(new ByteConverter(null), Byte.class);
83 ConvertUtils.register(new CharacterConverter(null), Character.class);
84 ConvertUtils.register(new DoubleConverter(null), Double.class);
85 ConvertUtils.register(new FloatConverter(null), Float.class);
86 ConvertUtils.register(new IntegerConverter(null), Integer.class);
87 ConvertUtils.register(new LongConverter(null), Long.class);
88 ConvertUtils.register(new ShortConverter(null), Short.class);
89 }
90
91 }
92
93 KualiActionServletConfig serverConfigOverride = null;
94
95 @Override
96 public ServletConfig getServletConfig() {
97 if ( serverConfigOverride == null ) {
98 ServletConfig sConfig = super.getServletConfig();
99
100 if ( sConfig == null ) {
101 return null;
102 }
103 serverConfigOverride = new KualiActionServletConfig(sConfig);
104 }
105 return serverConfigOverride;
106 }
107
108
109
110
111
112
113 private class KualiActionServletConfig implements ServletConfig {
114
115 private ServletConfig wrapped;
116 private Map<String,String> initParameters = new HashMap<String, String>();
117
118 public KualiActionServletConfig(ServletConfig wrapped) {
119 this.wrapped = wrapped;
120
121 @SuppressWarnings("unchecked")
122 final Enumeration<String> initParameterNames = wrapped.getInitParameterNames();
123 while ( initParameterNames.hasMoreElements() ) {
124 String paramName = initParameterNames.nextElement();
125 initParameters.put( paramName, wrapped.getInitParameter(paramName) );
126 }
127
128
129 @SuppressWarnings("unchecked")
130 final Collection<ModuleConfigurer> riceModules = (Collection<ModuleConfigurer>) ConfigContext.getCurrentContextConfig().getObject("ModuleConfigurers");
131
132 if ( LOG.isInfoEnabled() ) {
133 LOG.info( "Configuring init parameters of the KualiActionServlet from riceModules: " + riceModules );
134 }
135 for ( ModuleConfigurer module : riceModules ) {
136
137
138
139 if ( module.shouldRenderWebInterface() ) {
140 WebModuleConfiguration webModuleConfiguration = module.getWebModuleConfiguration();
141 if (webModuleConfiguration == null) {
142 throw new ConfigurationException("Attempting to load WebModuleConfiguration for module '" + module.getModuleName() + "' but no configuration was provided!");
143 }
144 if ( LOG.isInfoEnabled() ) {
145 LOG.info( "Configuring Web Content for Module: " + webModuleConfiguration.getModuleName()
146 + " / " + webModuleConfiguration.getWebModuleStrutsConfigName()
147 + " / " + webModuleConfiguration.getWebModuleStrutsConfigurationFiles()
148 + " / Base URL: " + webModuleConfiguration.getWebModuleBaseUrl() );
149 }
150 if ( !initParameters.containsKey( webModuleConfiguration.getWebModuleStrutsConfigName() ) ) {
151 initParameters.put( webModuleConfiguration.getWebModuleStrutsConfigName(), webModuleConfiguration.getWebModuleStrutsConfigurationFiles() );
152 }
153 }
154 }
155 }
156
157 @Override
158 public String getInitParameter(String name) {
159 return initParameters.get(name);
160 }
161
162 @Override
163 @SuppressWarnings("unchecked")
164 public Enumeration<String> getInitParameterNames() {
165 return new IteratorEnumeration( initParameters.keySet().iterator() );
166 }
167
168 @Override
169 public ServletContext getServletContext() {
170 return wrapped.getServletContext();
171 }
172 @Override
173 public String getServletName() {
174 return wrapped.getServletName();
175 }
176 }
177
178 }