blob: 13b944c5f30881ca7ca1b74041189123df71695d [file] [log] [blame]
<?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>TemplateInfo.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> &gt; <a href="index.source.html" class="el_package">org.apache.turbine.util.template</a> &gt; <span class="el_source">TemplateInfo.java</span></div><h1>TemplateInfo.java</h1><pre class="source lang-java linenums">package org.apache.turbine.util.template;
/*
* 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
* &quot;License&quot;); 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
* &quot;AS IS&quot; 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.HashMap;
import java.util.Map;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.template.TemplateService;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.uri.URIConstants;
/**
* This is a wrapper for Template specific information. It's part of
* the RunData object and can extract the information it needs to do
* the job directly from the data.getParameters().
*
* @author &lt;a href=&quot;mailto:mbryson@mindspring.com&quot;&gt;Dave Bryson&lt;/a&gt;
* @author &lt;a href=&quot;mailto:jvanzyl@apache.org&quot;&gt;Jason van Zyl&lt;/a&gt;
* @author &lt;a href=&quot;mailto:hps@intermeta.de&quot;&gt;Henning P. Schmiedehausen&lt;/a&gt;
* @version $Id$
*/
public class TemplateInfo
{
/** Constants for tempStorage hash map. */
public static final String NAVIGATION_TEMPLATE = &quot;00navigation_template00&quot;;
/** Constants for tempStorage hash map. */
public static final String LAYOUT_TEMPLATE = &quot;00layout_template00&quot;;
/** Constants for tempStorage hash map. */
public static final String SERVICE_NAME = &quot;template_service&quot;;
/* Handle to the RunData object. */
<span class="nc" id="L54"> private RunData data = null;</span>
/* Place to store information about templates. */
<span class="nc" id="L57"> private Map&lt;String, Object&gt; tempStorage = null;</span>
/**
* Constructor
*
* @param data A Turbine RunData object.
*/
public TemplateInfo(RunData data)
<span class="nc" id="L65"> {</span>
<span class="nc" id="L66"> this.data = data;</span>
<span class="nc" id="L67"> tempStorage = new HashMap&lt;&gt;(10);</span>
<span class="nc" id="L68"> }</span>
/**
* Get the value of navigationTemplate.
*
* @return A String with the value of navigationTemplate.
*/
public String getNavigationTemplate()
{
<span class="nc" id="L77"> return getString(TemplateInfo.NAVIGATION_TEMPLATE);</span>
}
/**
* Set the value of navigationTemplate.
*
* @param v Value to assign to navigationTemplate.
*/
public void setNavigationTemplate(String v)
{
<span class="nc" id="L87"> setTemp(TemplateInfo.NAVIGATION_TEMPLATE, v);</span>
<span class="nc" id="L88"> }</span>
/**
* Get the value of screen for the RunData parameters. This
* information comes from PathInfo or a QueryString.
*
* @return A String with the value of screen.
*/
public String getScreenTemplate()
{
<span class="nc" id="L98"> return data.getParameters().getString(URIConstants.CGI_TEMPLATE_PARAM, null);</span>
}
/**
* Set the value of screen. This is really just a method to hide
* using the RunData Parameter.
*
* @param v Value to assign to screen.
*/
public void setScreenTemplate(String v)
{
<span class="nc" id="L109"> data.getParameters().setString(URIConstants.CGI_TEMPLATE_PARAM, v);</span>
// We have changed the screen template so
// we should now update the layout template
// as well. We will use the template service
// to help us out.
try
{
<span class="nc" id="L117"> TemplateService templateService = (TemplateService)TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);</span>
<span class="nc" id="L118"> setLayoutTemplate(templateService.getLayoutTemplateName(v));</span>
}
<span class="nc" id="L120"> catch (Exception e)</span>
{
/*
* do nothing.
*/
<span class="nc" id="L125"> }</span>
<span class="nc" id="L126"> }</span>
/**
* Get the value of layout.
*
* @return A String with the value of layout.
*/
public String getLayoutTemplate()
{
<span class="nc" id="L135"> String value = getString(TemplateInfo.LAYOUT_TEMPLATE);</span>
<span class="nc" id="L136"> return value;</span>
}
/**
* Set the value of layout.
*
* @param v Value to assign to layout.
*/
public void setLayoutTemplate(String v)
{
<span class="nc" id="L146"> setTemp(TemplateInfo.LAYOUT_TEMPLATE, v);</span>
<span class="nc" id="L147"> }</span>
/**
* Get the value of Template context. This will be cast to the
* proper Context by its Service.
*
* @param name The name of the template context.
* @return An Object with the Value of context.
*/
public Object getTemplateContext(String name)
{
<span class="nc" id="L158"> return getTemp(name);</span>
}
/**
* Set the value of context.
*
* @param name The name of the template context.
* @param v Value to assign to context.
*/
public void setTemplateContext(String name, Object v)
{
<span class="nc" id="L169"> setTemp(name, v);</span>
<span class="nc" id="L170"> }</span>
/**
* Get the value of service.
*
* @return A String with the value of service.
*/
public String getService()
{
<span class="nc" id="L179"> return getString(TemplateInfo.SERVICE_NAME);</span>
}
/**
* Set the value of service.
*
* @param v Value to assign to service.
*/
public void setService(String v)
{
<span class="nc" id="L189"> setTemp(TemplateInfo.SERVICE_NAME, v);</span>
<span class="nc" id="L190"> }</span>
/**
* Get an object from temporary storage.
*
* @param name A String with the name of the object.
* @return An Object.
*/
public Object getTemp(String name)
{
<span class="nc" id="L200"> return tempStorage.get(name);</span>
}
/**
* Get an object from temporary storage, or a default value.
*
* @param name A String with the name of the object.
* @param def An Object, the default value.
* @return An Object.
*/
public Object getTemp(String name, Object def)
{
try
{
<span class="nc" id="L214"> Object val = tempStorage.get(name);</span>
<span class="nc bnc" id="L215" title="All 2 branches missed."> return (val != null) ? val : def;</span>
}
<span class="nc" id="L217"> catch (Exception e)</span>
{
<span class="nc" id="L219"> return def;</span>
}
}
/**
* Put an object into temporary storage.
*
* @param name A String with the name of the object.
* @param value An Object, the value.
*/
public void setTemp(String name, Object value)
{
<span class="nc" id="L231"> tempStorage.put(name, value);</span>
<span class="nc" id="L232"> }</span>
/**
* Return a String[] from the temp hash map.
*
* @param name A String with the name of the object.
* @return A String[].
*/
public String[] getStringArray(String name)
{
<span class="nc" id="L242"> String[] value = null;</span>
<span class="nc" id="L243"> Object object = getTemp(name, null);</span>
<span class="nc bnc" id="L244" title="All 2 branches missed."> if (object != null)</span>
{
<span class="nc" id="L246"> value = (String[]) object;</span>
}
<span class="nc" id="L248"> return value;</span>
}
/**
* Return a String from the temp hash map.
*
* @param name A String with the name of the object.
* @return A String.
*/
public String getString(String name)
{
<span class="nc" id="L259"> String value = null;</span>
<span class="nc" id="L260"> Object object = getTemp(name, null);</span>
<span class="nc bnc" id="L261" title="All 2 branches missed."> if (object != null)</span>
{
<span class="nc" id="L263"> value = (String) object;</span>
}
<span class="nc" id="L265"> return value;</span>
}
/**
* Remove an object from the temporary storage.
*
* @param name A String with the name of the object.
* @return The object that was removed or &lt;code&gt;null&lt;/code&gt;
* if the name was not a key.
*/
public Object removeTemp(String name)
{
<span class="nc" id="L277"> return tempStorage.remove(name);</span>
}
/**
* Returns all the available names in the temporary storage.
*
* @return A object array with the keys.
*/
public Object[] getTempKeys()
{
<span class="nc" id="L287"> return tempStorage.keySet().toArray();</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>