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