Coverage Report - org.kuali.rice.kns.web.struts.action.KualiActionServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
KualiActionServlet
0%
0/29
0%
0/18
3.286
KualiActionServlet$KualiActionServletConfig
0%
0/22
0%
0/12
3.286
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
      * <p>Initialize other global characteristics of the controller servlet.</p>
 50  
      * Overridden to remove the ConvertUtils.deregister() command that caused problems
 51  
      * with the concurrent data dictionary load.  (KULRNE-4405)
 52  
      *
 53  
      * @exception ServletException if we cannot initialize these resources
 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  
         // Backwards compatibility for form beans of Java wrapper classes
 65  
         // Set to true for strict Struts 1.0 compatibility
 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  
      * A custom ServletConfig implementation which dynamically includes web content based on the installed modules in the RiceConfigurer object.
 108  
      *   Accomplishes this by implementing custom
 109  
      * {@link #getInitParameter(String)} and {@link #getInitParameterNames()} methods.
 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  
             // copy out all the init parameters so they can be augmented
 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  
             // loop over the installed modules, adding their struts configuration to the servlet
 126  
             // if they have a web interface
 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  
                 // only install the web configuration if the module has web content
 135  
                 // and it is running in a "local" mode
 136  
                 // in "embedded" or "remote" modes, the UIs are hosted on a central server
 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  
 }