| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang=""><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>InitContextsAction.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Turbine</a> > <a href="index.source.html" class="el_package">org.apache.turbine.modules.actions</a> > <span class="el_source">InitContextsAction.java</span></div><h1>InitContextsAction.java</h1><pre class="source lang-java linenums">package org.apache.turbine.modules.actions; |
| |
| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| import java.util.Hashtable; |
| import java.util.Iterator; |
| import java.util.Map.Entry; |
| import java.util.Properties; |
| |
| import javax.naming.InitialContext; |
| import javax.naming.NamingException; |
| |
| import org.apache.commons.configuration2.Configuration; |
| import org.apache.turbine.annotation.TurbineConfiguration; |
| import org.apache.turbine.modules.Action; |
| import org.apache.turbine.pipeline.PipelineData; |
| import org.apache.turbine.util.RunData; |
| |
| /** |
| * Used to initialize JNDI contexts. |
| * |
| * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a> |
| * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> |
| * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> |
| * @version $Id$ |
| */ |
| <span class="nc" id="L44">public class InitContextsAction implements Action</span> |
| { |
| /** Injected configuration instance */ |
| @TurbineConfiguration |
| private Configuration conf; |
| |
| /** |
| * This action will place the contexts defined in the TurbineResources |
| * instance (if any) into the data.contexts Hashtable. |
| * |
| * @param pipelineData |
| * The PipelineRunData object for the current request. |
| * @throws NamingException |
| * could not create InitialContext |
| */ |
| @Override |
| public void doPerform(PipelineData pipelineData) |
| throws NamingException |
| { |
| <span class="nc" id="L63"> RunData data = pipelineData.getRunData();</span> |
| // Context properties are specified in lines in the properties |
| // file that begin with "context.contextname.", allowing |
| // multiple named contexts to be used. Everything after the |
| // "contextname." is the name of the property that will be |
| // used by the InitialContext class to create a new context |
| // instance. |
| |
| <span class="nc" id="L71"> Hashtable<String, Properties> contextPropsList = new Hashtable<>();</span> |
| <span class="nc bnc" id="L72" title="All 2 branches missed."> for (Iterator<String> contextKeys = conf.getKeys("context."); contextKeys.hasNext();)</span> |
| { |
| <span class="nc" id="L74"> String key = contextKeys.next();</span> |
| <span class="nc" id="L75"> int start = key.indexOf(".") + 1;</span> |
| <span class="nc" id="L76"> int end = key.indexOf(".", start);</span> |
| <span class="nc" id="L77"> String contextName = key.substring(start, end);</span> |
| <span class="nc" id="L78"> Properties contextProps = null;</span> |
| <span class="nc bnc" id="L79" title="All 2 branches missed."> if (contextPropsList.containsKey(contextName))</span> |
| { |
| <span class="nc" id="L81"> contextProps = contextPropsList.get(contextName);</span> |
| } |
| else |
| { |
| <span class="nc" id="L85"> contextProps = new Properties();</span> |
| } |
| <span class="nc" id="L87"> contextProps.put(key.substring(end + 1), conf.getString(key));</span> |
| <span class="nc" id="L88"> contextPropsList.put(contextName, contextProps);</span> |
| <span class="nc" id="L89"> }</span> |
| |
| <span class="nc bnc" id="L91" title="All 2 branches missed."> for (Entry<String, Properties> contextProps : contextPropsList.entrySet())</span> |
| { |
| <span class="nc" id="L93"> InitialContext context = new InitialContext(contextProps.getValue());</span> |
| <span class="nc" id="L94"> data.getJNDIContexts().put(contextProps.getKey(), context);</span> |
| <span class="nc" id="L95"> }</span> |
| <span class="nc" id="L96"> }</span> |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.12.202403310830</span></div></body></html> |