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 2007 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 java.math.BigDecimal;
 19  
 import java.math.BigInteger;
 20  
 import java.util.Enumeration;
 21  
 import java.util.HashMap;
 22  
 import java.util.Map;
 23  
 
 24  
 import javax.servlet.ServletConfig;
 25  
 import javax.servlet.ServletContext;
 26  
 import javax.servlet.ServletException;
 27  
 
 28  
 import org.apache.commons.beanutils.ConvertUtils;
 29  
 import org.apache.commons.beanutils.converters.BigDecimalConverter;
 30  
 import org.apache.commons.beanutils.converters.BigIntegerConverter;
 31  
 import org.apache.commons.beanutils.converters.BooleanConverter;
 32  
 import org.apache.commons.beanutils.converters.ByteConverter;
 33  
 import org.apache.commons.beanutils.converters.CharacterConverter;
 34  
 import org.apache.commons.beanutils.converters.DoubleConverter;
 35  
 import org.apache.commons.beanutils.converters.FloatConverter;
 36  
 import org.apache.commons.beanutils.converters.IntegerConverter;
 37  
 import org.apache.commons.beanutils.converters.LongConverter;
 38  
 import org.apache.commons.beanutils.converters.ShortConverter;
 39  
 import org.apache.commons.collections.iterators.IteratorEnumeration;
 40  
 import org.apache.log4j.Logger;
 41  
 import org.apache.struts.action.ActionServlet;
 42  
 import org.kuali.rice.core.config.ConfigContext;
 43  
 import org.kuali.rice.core.config.ModuleConfigurer;
 44  
 import org.kuali.rice.core.config.RiceConfigurer;
 45  
 import org.kuali.rice.core.util.RiceConstants;
 46  
 
 47  0
 public class KualiActionServlet extends ActionServlet {
 48  0
     private static final Logger LOG = Logger.getLogger(KualiActionServlet.class);
 49  
 
 50  
     /**
 51  
      * <p>Initialize other global characteristics of the controller servlet.</p>
 52  
      * Overridden to remove the ConvertUtils.deregister() command that caused problems
 53  
      * with the concurrent data dictionary load.  (KULRNE-4405)
 54  
      *
 55  
      * @exception ServletException if we cannot initialize these resources
 56  
      */
 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 config = super.getServletConfig();
 98  
 
 99  0
             if ( config == null ) {
 100  0
                 return null;
 101  
             } else {
 102  0
                 serverConfigOverride = new KualiActionServletConfig(config);
 103  
             }
 104  
         }
 105  0
         return serverConfigOverride;
 106  
     }
 107  
 
 108  
     /**
 109  
      * A custom ServletConfig implementation which dynamically includes web content based on the installed modules in the RiceConfigurer object.
 110  
      *   Accomplishes this by implementing custom
 111  
      * {@link #getInitParameter(String)} and {@link #getInitParameterNames()} methods.
 112  
      */
 113  0
     private class KualiActionServletConfig implements ServletConfig {
 114  
 
 115  
         private ServletConfig wrapped;
 116  0
         private Map<String,String> initParameters = new HashMap<String, String>();
 117  
 
 118  
         @SuppressWarnings("deprecation")
 119  0
         public KualiActionServletConfig(ServletConfig wrapped) {
 120  0
             this.wrapped = wrapped;
 121  
             // copy out all the init parameters so they can be augmented
 122  0
             Enumeration<String> initParameterNames = wrapped.getInitParameterNames();
 123  0
             while ( initParameterNames.hasMoreElements() ) {
 124  0
                 String paramName = initParameterNames.nextElement();
 125  0
                 initParameters.put( paramName, wrapped.getInitParameter(paramName) );
 126  0
             }
 127  
             // loop over the installed modules, adding their struts configuration to the servlet
 128  
             // if they have a web interface
 129  0
             RiceConfigurer rice = (RiceConfigurer)ConfigContext.getCurrentContextConfig().getObject( RiceConstants.RICE_CONFIGURER_CONFIG_NAME );
 130  0
             if ( LOG.isInfoEnabled() ) {
 131  0
                     LOG.info( "Configuring init parameters of the KualiActionServlet from RiceConfigurer: " + rice );
 132  
             }
 133  0
             for ( ModuleConfigurer module : rice.getModules() ) {
 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  
         public String getInitParameter(String name) {
 152  0
             return initParameters.get(name);
 153  
         }
 154  
 
 155  
         @SuppressWarnings("unchecked")
 156  
                 public Enumeration<String> getInitParameterNames() {
 157  0
             return new IteratorEnumeration( initParameters.keySet().iterator() );
 158  
         }
 159  
 
 160  
         public ServletContext getServletContext() {
 161  0
             return wrapped.getServletContext();
 162  
         }
 163  
         public String getServletName() {
 164  0
             return wrapped.getServletName();
 165  
         }
 166  
     }
 167  
 
 168  
 }