Coverage Report - org.apache.turbine.modules.actions.InitContextsAction
 
Classes in this File Line Coverage Branch Coverage Complexity
InitContextsAction
0%
0/20
0%
0/6
4
 
 1  
 package org.apache.turbine.modules.actions;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.Hashtable;
 23  
 import java.util.Iterator;
 24  
 import java.util.Map.Entry;
 25  
 import java.util.Properties;
 26  
 
 27  
 import javax.naming.InitialContext;
 28  
 import javax.naming.NamingException;
 29  
 
 30  
 import org.apache.commons.configuration2.Configuration;
 31  
 import org.apache.turbine.annotation.TurbineConfiguration;
 32  
 import org.apache.turbine.modules.Action;
 33  
 import org.apache.turbine.pipeline.PipelineData;
 34  
 import org.apache.turbine.util.RunData;
 35  
 
 36  
 /**
 37  
  * Used to initialize JNDI contexts.
 38  
  *
 39  
  * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
 40  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 41  
  * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
 42  
  * @version $Id: InitContextsAction.java 1854797 2019-03-04 20:41:39Z tv $
 43  
  */
 44  0
 public class InitContextsAction implements Action
 45  
 {
 46  
     /** Injected configuration instance */
 47  
     @TurbineConfiguration
 48  
     private Configuration conf;
 49  
 
 50  
     /**
 51  
      * This action will place the contexts defined in the TurbineResources
 52  
      * instance (if any) into the data.contexts Hashtable.
 53  
      *
 54  
      * @param pipelineData
 55  
      *            The PipelineRunData object for the current request.
 56  
      * @throws NamingException
 57  
      *                could not create InitialContext
 58  
      */
 59  
     @Override
 60  
     public void doPerform(PipelineData pipelineData)
 61  
             throws NamingException
 62  
     {
 63  0
         RunData data = pipelineData.getRunData();
 64  
         // Context properties are specified in lines in the properties
 65  
         // file that begin with "context.contextname.", allowing
 66  
         // multiple named contexts to be used. Everything after the
 67  
         // "contextname." is the name of the property that will be
 68  
         // used by the InitialContext class to create a new context
 69  
         // instance.
 70  
 
 71  0
         Hashtable<String, Properties> contextPropsList = new Hashtable<String, Properties>();
 72  0
         for (Iterator<String> contextKeys = conf.getKeys("context."); contextKeys.hasNext();)
 73  
         {
 74  0
             String key = contextKeys.next();
 75  0
             int start = key.indexOf(".") + 1;
 76  0
             int end = key.indexOf(".", start);
 77  0
             String contextName = key.substring(start, end);
 78  0
             Properties contextProps = null;
 79  0
             if (contextPropsList.containsKey(contextName))
 80  
             {
 81  0
                 contextProps = contextPropsList.get(contextName);
 82  
             }
 83  
             else
 84  
             {
 85  0
                 contextProps = new Properties();
 86  
             }
 87  0
             contextProps.put(key.substring(end + 1), conf.getString(key));
 88  0
             contextPropsList.put(contextName, contextProps);
 89  0
         }
 90  
 
 91  0
         for (Entry<String, Properties> contextProps : contextPropsList.entrySet())
 92  
         {
 93  0
             InitialContext context = new InitialContext(contextProps.getValue());
 94  0
             data.getJNDIContexts().put(contextProps.getKey(), context);
 95  0
         }
 96  0
     }
 97  
 }