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