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 2006-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  
 
 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  
      * <p>Initialize other global characteristics of the controller servlet.</p>
 51  
      * Overridden to remove the ConvertUtils.deregister() command that caused problems
 52  
      * with the concurrent data dictionary load.  (KULRNE-4405)
 53  
      *
 54  
      * @exception ServletException if we cannot initialize these resources
 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  
         // Backwards compatibility for form beans of Java wrapper classes
 66  
         // Set to true for strict Struts 1.0 compatibility
 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  
      * A custom ServletConfig implementation which dynamically includes web content based on the installed modules in the RiceConfigurer object.
 109  
      *   Accomplishes this by implementing custom
 110  
      * {@link #getInitParameter(String)} and {@link #getInitParameterNames()} methods.
 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  
             // copy out all the init parameters so they can be augmented
 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  
             // loop over the installed modules, adding their struts configuration to the servlet
 127  
             // if they have a web interface
 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  
                 // only install the web configuration if the module has web content
 136  
                 // and it is running in a "local" mode
 137  
                 // in "embedded" or "remote" modes, the UIs are hosted on a central server
 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  
 }