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