blob: b0fadfbdc4a202cf662a6459814c37327cc481e0 [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>TemplateURI.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.uri</a> &gt; <span class="el_source">TemplateURI.java</span></div><h1>TemplateURI.java</h1><pre class="source lang-java linenums">package org.apache.turbine.util.uri;
/*
* 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 org.apache.commons.lang3.StringUtils;
import org.apache.fulcrum.parser.ParameterParser;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.ServerData;
import java.util.stream.Stream;
/**
* This class allows you to keep all the information needed for a single
* link at one place. It keeps your query data, path info, the server
* scheme, name, port and the script path. It is tuned for usage with a
* Template System e.g. Velocity.
*
* If you must generate a Turbine Link in a Template System, use this class.
*
* @author &lt;a href=&quot;mailto:hps@intermeta.de&quot;&gt;Henning P. Schmiedehausen&lt;/a&gt;
* @version $Id$
*/
public class TemplateURI
extends TurbineURI
{
/**
* Empty C'tor. Uses Turbine.getDefaultServerData().
*
*/
public TemplateURI()
{
<span class="nc" id="L51"> super();</span>
<span class="nc" id="L52"> }</span>
/**
* Constructor with a RunData object
*
* @param runData A RunData object
*/
public TemplateURI(RunData runData)
{
<span class="nc" id="L61"> super(runData);</span>
<span class="nc" id="L62"> }</span>
/**
* Constructor, set explicit redirection
*
* @param runData A RunData object
* @param redirect True if redirection allowed.
*/
public TemplateURI(RunData runData, boolean redirect)
{
<span class="nc" id="L72"> super(runData, redirect);</span>
<span class="nc" id="L73"> }</span>
/**
* Constructor, set Template
*
* @param runData A RunData object
* @param template A Template Name
*/
public TemplateURI(RunData runData, String template)
{
<span class="nc" id="L83"> super(runData);</span>
<span class="nc" id="L84"> setTemplate(template);</span>
<span class="nc" id="L85"> }</span>
/**
* Constructor, set Template, set explicit redirection
*
* @param runData A RunData object
* @param template A Template Name
* @param redirect True if redirection allowed.
*/
public TemplateURI(RunData runData, String template, boolean redirect)
{
<span class="nc" id="L96"> super(runData, redirect);</span>
<span class="nc" id="L97"> setTemplate(template);</span>
<span class="nc" id="L98"> }</span>
/**
* Constructor, set Template and Action
*
* @param runData A RunData object
* @param template A Template Name
* @param action An Action Name
*/
public TemplateURI(RunData runData, String template, String action)
{
<span class="nc" id="L109"> this(runData, template);</span>
<span class="nc" id="L110"> setAction(action);</span>
<span class="nc" id="L111"> }</span>
/**
* Constructor, set Template and Action, set explicit redirection
*
* @param runData A RunData object
* @param template A Template Name
* @param action An Action Name
* @param redirect True if redirection allowed.
*/
public TemplateURI(RunData runData, String template, String action, boolean redirect)
{
<span class="nc" id="L123"> this(runData, template, redirect);</span>
<span class="nc" id="L124"> setAction(action);</span>
<span class="nc" id="L125"> }</span>
/**
* Constructor with a ServerData object
*
* @param serverData A ServerData object
*/
public TemplateURI(ServerData serverData)
{
<span class="nc" id="L134"> super(serverData);</span>
<span class="nc" id="L135"> }</span>
/**
* Constructor, set explicit redirection
*
* @param serverData A ServerData object
* @param redirect True if redirection allowed.
*/
public TemplateURI(ServerData serverData, boolean redirect)
{
<span class="nc" id="L145"> super(serverData, redirect);</span>
<span class="nc" id="L146"> }</span>
/**
* Constructor, set Template
*
* @param serverData A ServerData object
* @param template A Template Name
*/
public TemplateURI(ServerData serverData, String template)
{
<span class="nc" id="L156"> super(serverData);</span>
<span class="nc" id="L157"> setTemplate(template);</span>
<span class="nc" id="L158"> }</span>
/**
* Constructor, set Template, set explicit redirection
*
* @param serverData A ServerData object
* @param template A Template Name
* @param redirect True if redirection allowed.
*/
public TemplateURI(ServerData serverData, String template, boolean redirect)
{
<span class="nc" id="L169"> super(serverData, redirect);</span>
<span class="nc" id="L170"> setTemplate(template);</span>
<span class="nc" id="L171"> }</span>
/**
* Constructor, set Template and Action
*
* @param serverData A ServerData object
* @param template A Template Name
* @param action An Action Name
*/
public TemplateURI(ServerData serverData, String template, String action)
{
<span class="nc" id="L182"> this(serverData, template);</span>
<span class="nc" id="L183"> setAction(action);</span>
<span class="nc" id="L184"> }</span>
/**
* Constructor, set Template and Action, set explicit redirection
*
* @param serverData A ServerData object
* @param template A Template Name
* @param action An Action Name
* @param redirect True if redirection allowed.
*/
public TemplateURI(ServerData serverData, String template, String action, boolean redirect)
{
<span class="nc" id="L196"> this(serverData, template, redirect);</span>
<span class="nc" id="L197"> setAction(action);</span>
<span class="nc" id="L198"> }</span>
/**
* Constructor, user Turbine.getDefaultServerData(), set Template and Action
*
* @param template A Template Name
* @param action An Action Name
*/
public TemplateURI(String template, String action)
{
<span class="nc" id="L208"> this();</span>
<span class="nc" id="L209"> setTemplate(template);</span>
<span class="nc" id="L210"> setAction(action);</span>
<span class="nc" id="L211"> }</span>
/**
* Sets the template= value for this URL.
*
* By default it adds the information to the path_info instead
* of the query data. An empty value (null or &quot;&quot;) cleans out
* an existing value.
*
* @param template A String with the template value.
*/
public void setTemplate(String template)
{
<span class="nc bnc" id="L224" title="All 2 branches missed."> if(StringUtils.isNotEmpty(template))</span>
{
<span class="nc" id="L226"> add(PATH_INFO, CGI_TEMPLATE_PARAM, template);</span>
}
else
{
<span class="nc" id="L230"> clearTemplate();</span>
}
<span class="nc" id="L232"> }</span>
/**
* Clears the template= value for this URL.
*
*/
public void clearTemplate()
{
<span class="nc" id="L240"> removePathInfo(CGI_TEMPLATE_PARAM);</span>
<span class="nc" id="L241"> }</span>
/*
* ========================================================================
*
* Protected / Private Methods
*
* ========================================================================
*
*/
/**
* Method for a quick way to add all the parameters in a
* ParameterParser.
*
* &lt;p&gt;If the type is P (0), then add name/value to the pathInfo
* hashtable.
*
* &lt;p&gt;If the type is Q (1), then add name/value to the queryData
* hashtable.
*
* @param type Type of insertion (@see #add(char type, String name, String value))
* @param pp A ParameterParser.
*/
@Override
protected void add(int type,
ParameterParser pp)
{
<span class="nc bnc" id="L269" title="All 2 branches missed."> for (Object name : pp.keySet())</span>
{
<span class="nc" id="L271"> String key = (String) name;</span>
<span class="nc bnc" id="L273" title="All 2 branches missed."> if (Stream.of(CGI_ACTION_PARAM, CGI_SCREEN_PARAM, CGI_TEMPLATE_PARAM).noneMatch(key::equalsIgnoreCase))</span>
{
<span class="nc" id="L275"> String[] values = pp.getStrings(key);</span>
<span class="nc bnc" id="L276" title="All 2 branches missed."> if(values != null)</span>
{
<span class="nc bnc" id="L278" title="All 2 branches missed."> for (String value : values)</span>
{
<span class="nc" id="L280"> add(type, key, value);</span>
}
}
else
{
<span class="nc" id="L285"> add(type, key, &quot;&quot;);</span>
}
}
<span class="nc" id="L288"> }</span>
<span class="nc" id="L289"> }</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>