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