| <?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>TurbineURI.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.util.uri</a> > <span class="el_source">TurbineURI.java</span></div><h1>TurbineURI.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 |
| * "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.io.UnsupportedEncodingException; |
| import java.net.URLEncoder; |
| import java.nio.charset.Charset; |
| import java.nio.charset.IllegalCharsetNameException; |
| import java.nio.charset.UnsupportedCharsetException; |
| import java.util.ArrayList; |
| import java.util.Collection; |
| import java.util.List; |
| import java.util.Objects; |
| import java.util.stream.Collectors; |
| |
| import org.apache.commons.lang3.StringUtils; |
| import org.apache.fulcrum.parser.ParameterParser; |
| import org.apache.fulcrum.parser.ParserService; |
| import org.apache.logging.log4j.LogManager; |
| import org.apache.logging.log4j.Logger; |
| import org.apache.turbine.services.TurbineServices; |
| import org.apache.turbine.util.RunData; |
| import org.apache.turbine.util.ServerData; |
| |
| /** |
| * 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. |
| * |
| * If you must generate a Turbine Link, use this class. |
| * |
| * @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a> |
| * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a> |
| * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> |
| * @version $Id$ |
| */ |
| |
| public class TurbineURI |
| extends BaseURI |
| { |
| /** Logging */ |
| <span class="nc" id="L59"> private static final Logger log = LogManager.getLogger(TurbineURI.class);</span> |
| |
| /** Contains the PathInfo and QueryData vectors */ |
| <span class="nc" id="L62"> private List<URIParam> [] dataVectors = null;</span> |
| |
| /** Local reference to the parser service for URI parameter folding */ |
| private ParserService parserService; |
| |
| /** URI Parameter encoding as defined by the parser service */ |
| private Charset parameterEncoding; |
| |
| /* |
| * ======================================================================== |
| * |
| * Constructors |
| * |
| * ======================================================================== |
| * |
| */ |
| |
| /** |
| * Empty C'tor. Uses Turbine.getDefaultServerData(). |
| */ |
| public TurbineURI() |
| { |
| <span class="nc" id="L84"> super();</span> |
| <span class="nc" id="L85"> init();</span> |
| <span class="nc" id="L86"> }</span> |
| |
| /** |
| * Constructor with a RunData object. |
| * |
| * @param runData A RunData object |
| */ |
| public TurbineURI(RunData runData) |
| { |
| <span class="nc" id="L95"> super(runData);</span> |
| <span class="nc" id="L96"> init();</span> |
| <span class="nc" id="L97"> }</span> |
| |
| /** |
| * Constructor, set explicit redirection. |
| * |
| * @param runData A RunData object |
| * @param redirect True if redirection allowed. |
| */ |
| public TurbineURI(RunData runData, boolean redirect) |
| { |
| <span class="nc" id="L107"> super(runData, redirect);</span> |
| <span class="nc" id="L108"> init();</span> |
| <span class="nc" id="L109"> }</span> |
| |
| /** |
| * Constructor, set Screen. |
| * |
| * @param runData A RunData object |
| * @param screen A Screen Name |
| */ |
| public TurbineURI(RunData runData, String screen) |
| { |
| <span class="nc" id="L119"> this(runData);</span> |
| <span class="nc" id="L120"> setScreen(screen);</span> |
| <span class="nc" id="L121"> }</span> |
| |
| /** |
| * Constructor, set Screen, set explicit redirection. |
| * |
| * @param runData A RunData object |
| * @param screen A Screen Name |
| * @param redirect True if redirection allowed. |
| */ |
| public TurbineURI(RunData runData, String screen, boolean redirect) |
| { |
| <span class="nc" id="L132"> this(runData, redirect);</span> |
| <span class="nc" id="L133"> setScreen(screen);</span> |
| <span class="nc" id="L134"> }</span> |
| |
| /** |
| * Constructor, set Screen and Action. |
| * |
| * @param runData A RunData object |
| * @param screen A Screen Name |
| * @param action An Action Name |
| */ |
| public TurbineURI(RunData runData, String screen, String action) |
| { |
| <span class="nc" id="L145"> this(runData, screen);</span> |
| <span class="nc" id="L146"> setAction(action);</span> |
| <span class="nc" id="L147"> }</span> |
| |
| /** |
| * Constructor, set Screen and Action, set explicit redirection. |
| * |
| * @param runData A RunData object |
| * @param screen A Screen Name |
| * @param action An Action Name |
| * @param redirect True if redirection allowed. |
| */ |
| public TurbineURI(RunData runData, String screen, String action, boolean redirect) |
| { |
| <span class="nc" id="L159"> this(runData, screen, redirect);</span> |
| <span class="nc" id="L160"> setAction(action);</span> |
| <span class="nc" id="L161"> }</span> |
| |
| /** |
| * Constructor with a ServerData object. |
| * |
| * @param serverData A ServerData object |
| */ |
| public TurbineURI(ServerData serverData) |
| { |
| <span class="nc" id="L170"> super(serverData);</span> |
| <span class="nc" id="L171"> init();</span> |
| <span class="nc" id="L172"> }</span> |
| |
| /** |
| * Constructor, set explicit redirection. |
| * |
| * @param serverData A ServerData object |
| * @param redirect True if redirection allowed. |
| */ |
| public TurbineURI(ServerData serverData, boolean redirect) |
| { |
| <span class="nc" id="L182"> super(serverData, redirect);</span> |
| <span class="nc" id="L183"> init();</span> |
| <span class="nc" id="L184"> }</span> |
| |
| /** |
| * Constructor, set Screen. |
| * |
| * @param serverData A ServerData object |
| * @param screen A Screen Name |
| */ |
| public TurbineURI(ServerData serverData, String screen) |
| { |
| <span class="nc" id="L194"> this(serverData);</span> |
| <span class="nc" id="L195"> setScreen(screen);</span> |
| <span class="nc" id="L196"> }</span> |
| |
| /** |
| * Constructor, set Screen, set explicit redirection. |
| * |
| * @param serverData A ServerData object |
| * @param screen A Screen Name |
| * @param redirect True if redirection allowed. |
| */ |
| public TurbineURI(ServerData serverData, String screen, boolean redirect) |
| { |
| <span class="nc" id="L207"> this(serverData, redirect);</span> |
| <span class="nc" id="L208"> setScreen(screen);</span> |
| <span class="nc" id="L209"> }</span> |
| |
| /** |
| * Constructor, set Screen and Action. |
| * |
| * @param serverData A ServerData object |
| * @param screen A Screen Name |
| * @param action An Action Name |
| */ |
| public TurbineURI(ServerData serverData, String screen, String action) |
| { |
| <span class="nc" id="L220"> this(serverData, screen);</span> |
| <span class="nc" id="L221"> setAction(action);</span> |
| <span class="nc" id="L222"> }</span> |
| |
| /** |
| * Constructor, set Screen and Action, set explicit redirection. |
| * |
| * @param serverData A ServerData object |
| * @param screen A Screen Name |
| * @param action An Action Name |
| * @param redirect True if redirection allowed. |
| */ |
| public TurbineURI(ServerData serverData, String screen, String action, |
| boolean redirect) |
| { |
| <span class="nc" id="L235"> this(serverData, screen, redirect);</span> |
| <span class="nc" id="L236"> setAction(action);</span> |
| <span class="nc" id="L237"> }</span> |
| |
| /** |
| * Constructor, user Turbine.getDefaultServerData(), set Screen and Action. |
| * |
| * @param screen A Screen Name |
| * @param action An Action Name |
| */ |
| public TurbineURI(String screen, String action) |
| { |
| <span class="nc" id="L247"> this();</span> |
| <span class="nc" id="L248"> setScreen(screen);</span> |
| <span class="nc" id="L249"> setAction(action);</span> |
| <span class="nc" id="L250"> }</span> |
| |
| /* |
| * ======================================================================== |
| * |
| * Init |
| * |
| * ======================================================================== |
| * |
| */ |
| |
| /** |
| * Init the TurbineURI. |
| */ |
| @SuppressWarnings("unchecked") |
| private void init() |
| { |
| <span class="nc" id="L267"> dataVectors = new List[2];</span> |
| <span class="nc" id="L268"> dataVectors[PATH_INFO] = new ArrayList<>();</span> |
| <span class="nc" id="L269"> dataVectors[QUERY_DATA] = new ArrayList<>();</span> |
| <span class="nc" id="L270"> parserService = (ParserService)TurbineServices.getInstance().getService(ParserService.ROLE);</span> |
| |
| try |
| { |
| <span class="nc" id="L274"> parameterEncoding = Charset.forName(parserService.getParameterEncoding());</span> |
| } |
| <span class="nc" id="L276"> catch (IllegalCharsetNameException | UnsupportedCharsetException e)</span> |
| { |
| <span class="nc" id="L278"> log.error("Unsupported encoding {}", parserService.getParameterEncoding(), e);</span> |
| <span class="nc" id="L279"> }</span> |
| <span class="nc" id="L280"> }</span> |
| |
| /** |
| * Sets the action= value for this URL. |
| * |
| * By default it adds the information to the path_info instead |
| * of the query data. An empty value (null or "") cleans out |
| * an existing value. |
| * |
| * @param action A String with the action value. |
| */ |
| public void setAction(String action) |
| { |
| <span class="nc bnc" id="L293" title="All 2 branches missed."> if(StringUtils.isNotEmpty(action))</span> |
| { |
| <span class="nc" id="L295"> add(PATH_INFO, CGI_ACTION_PARAM, action);</span> |
| } |
| else |
| { |
| <span class="nc" id="L299"> clearAction();</span> |
| } |
| <span class="nc" id="L301"> }</span> |
| |
| /** |
| * Sets the fired eventSubmit= value for this URL. |
| * |
| * @param event The event to fire. |
| * |
| */ |
| public void setEvent(String event) |
| { |
| <span class="nc" id="L311"> add(PATH_INFO, EVENT_PREFIX + event, event);</span> |
| <span class="nc" id="L312"> }</span> |
| |
| /** |
| * Sets the action= and eventSubmit= values for this URL. |
| * |
| * By default it adds the information to the path_info instead |
| * of the query data. An empty value (null or "") for the action cleans out |
| * an existing value. An empty value (null or "") for the event has no |
| * effect. |
| * |
| * @param action A String with the action value. |
| * @param event A string with the event name. |
| */ |
| public void setActionEvent(String action, String event) |
| { |
| <span class="nc" id="L327"> setAction(action);</span> |
| <span class="nc bnc" id="L328" title="All 2 branches missed."> if(StringUtils.isNotEmpty(event))</span> |
| { |
| <span class="nc" id="L330"> setEvent(event);</span> |
| } |
| <span class="nc" id="L332"> }</span> |
| |
| /** |
| * Clears the action= value for this URL. |
| */ |
| public void clearAction() |
| { |
| <span class="nc" id="L339"> removePathInfo(CGI_ACTION_PARAM);</span> |
| <span class="nc" id="L340"> }</span> |
| |
| /** |
| * Sets the screen= value for this URL. |
| * |
| * By default it adds the information to the path_info instead |
| * of the query data. An empty value (null or "") cleans out |
| * an existing value. |
| * |
| * @param screen A String with the screen value. |
| */ |
| public void setScreen(String screen) |
| { |
| <span class="nc bnc" id="L353" title="All 2 branches missed."> if(StringUtils.isNotEmpty(screen))</span> |
| { |
| <span class="nc" id="L355"> add(PATH_INFO, CGI_SCREEN_PARAM, screen);</span> |
| } |
| else |
| { |
| <span class="nc" id="L359"> clearScreen();</span> |
| } |
| <span class="nc" id="L361"> }</span> |
| |
| /** |
| * Clears the screen= value for this URL. |
| */ |
| public void clearScreen() |
| { |
| <span class="nc" id="L368"> removePathInfo(CGI_SCREEN_PARAM);</span> |
| <span class="nc" id="L369"> }</span> |
| |
| /* |
| * ======================================================================== |
| * |
| * Adding and removing Data from the Path Info and Query Data |
| * |
| * ======================================================================== |
| */ |
| |
| |
| /** |
| * Adds a name=value pair for every entry in a ParameterParser |
| * object to the path_info string. |
| * |
| * @param pp A ParameterParser. |
| */ |
| public void addPathInfo(ParameterParser pp) |
| { |
| <span class="nc" id="L388"> add(PATH_INFO, pp);</span> |
| <span class="nc" id="L389"> }</span> |
| |
| /** |
| * Adds an existing List of URIParam objects to |
| * the path_info string. |
| * |
| * @param list A list with URIParam objects. |
| */ |
| public void addPathInfo(List<URIParam> list) |
| { |
| <span class="nc" id="L399"> add(PATH_INFO, list);</span> |
| <span class="nc" id="L400"> }</span> |
| |
| /** |
| * Adds a name=value pair to the path_info string. |
| * |
| * @param name A String with the name to add. |
| * @param value An Object with the value to add. |
| */ |
| public void addPathInfo(String name, Object value) |
| { |
| <span class="nc bnc" id="L410" title="All 2 branches missed."> add(PATH_INFO, name, null == value ? null : value.toString());</span> |
| <span class="nc" id="L411"> }</span> |
| |
| /** |
| * Adds a name=value pair to the path_info string. |
| * |
| * @param name A String with the name to add. |
| * @param value A String with the value to add. |
| */ |
| public void addPathInfo(String name, String value) |
| { |
| <span class="nc" id="L421"> add(PATH_INFO, name, value);</span> |
| <span class="nc" id="L422"> }</span> |
| |
| /** |
| * Adds a name=value pair to the path_info string. |
| * |
| * @param name A String with the name to add. |
| * @param value A double with the value to add. |
| */ |
| public void addPathInfo(String name, double value) |
| { |
| <span class="nc" id="L432"> add(PATH_INFO, name, Double.toString(value));</span> |
| <span class="nc" id="L433"> }</span> |
| |
| /** |
| * Adds a name=value pair to the path_info string. |
| * |
| * @param name A String with the name to add. |
| * @param value An int with the value to add. |
| */ |
| public void addPathInfo(String name, int value) |
| { |
| <span class="nc" id="L443"> add(PATH_INFO, name, Integer.toString(value));</span> |
| <span class="nc" id="L444"> }</span> |
| |
| /** |
| * Adds a name=value pair to the path_info string. |
| * |
| * @param name A String with the name to add. |
| * @param value A long with the value to add. |
| */ |
| public void addPathInfo(String name, long value) |
| { |
| <span class="nc" id="L454"> add(PATH_INFO, name, Long.toString(value));</span> |
| <span class="nc" id="L455"> }</span> |
| |
| /** |
| * Adds a name=value pair to the query string. |
| * |
| * @param name A String with the name to add. |
| * @param value An Object with the value to add. |
| */ |
| public void addQueryData(String name, Object value) |
| { |
| <span class="nc bnc" id="L465" title="All 2 branches missed."> add(QUERY_DATA, name, null == value ? null : value.toString());</span> |
| <span class="nc" id="L466"> }</span> |
| |
| /** |
| * Adds a name=value pair to the query string. |
| * |
| * @param name A String with the name to add. |
| * @param value A String with the value to add. |
| */ |
| public void addQueryData(String name, String value) |
| { |
| <span class="nc" id="L476"> add(QUERY_DATA, name, value);</span> |
| <span class="nc" id="L477"> }</span> |
| |
| /** |
| * Adds a name=value pair to the query string. |
| * |
| * @param name A String with the name to add. |
| * @param value A double with the value to add. |
| */ |
| public void addQueryData(String name, double value) |
| { |
| <span class="nc" id="L487"> add(QUERY_DATA, name, Double.toString(value));</span> |
| <span class="nc" id="L488"> }</span> |
| |
| /** |
| * Adds a name=value pair to the query string. |
| * |
| * @param name A String with the name to add. |
| * @param value An int with the value to add. |
| */ |
| public void addQueryData(String name, int value) |
| { |
| <span class="nc" id="L498"> add(QUERY_DATA, name, Integer.toString(value));</span> |
| <span class="nc" id="L499"> }</span> |
| |
| /** |
| * Adds a name=value pair to the query string. |
| * |
| * @param name A String with the name to add. |
| * @param value A long with the value to add. |
| */ |
| public void addQueryData(String name, long value) |
| { |
| <span class="nc" id="L509"> add(QUERY_DATA, name, Long.toString(value));</span> |
| <span class="nc" id="L510"> }</span> |
| |
| /** |
| * Adds a name=value pair for every entry in a ParameterParser |
| * object to the query string. |
| * |
| * @param pp A ParameterParser. |
| */ |
| public void addQueryData(ParameterParser pp) |
| { |
| <span class="nc" id="L520"> add(QUERY_DATA, pp);</span> |
| <span class="nc" id="L521"> }</span> |
| |
| /** |
| * Adds an existing List of URIParam objects to the query data. |
| * |
| * @param list A list with URIParam objects. |
| */ |
| public void addQueryData(List<URIParam> list) |
| { |
| <span class="nc" id="L530"> add(QUERY_DATA, list);</span> |
| <span class="nc" id="L531"> }</span> |
| |
| /** |
| * Is Path Info data set in this URI? |
| * |
| * @return true if Path Info has values |
| */ |
| public boolean hasPathInfo() |
| { |
| <span class="nc bnc" id="L540" title="All 2 branches missed."> return !dataVectors[PATH_INFO].isEmpty();</span> |
| } |
| |
| /** |
| * Removes all the path info elements. |
| */ |
| public void removePathInfo() |
| { |
| <span class="nc" id="L548"> dataVectors[PATH_INFO].clear();</span> |
| <span class="nc" id="L549"> }</span> |
| |
| /** |
| * Removes a name=value pair from the path info. |
| * |
| * @param name A String with the name to be removed. |
| */ |
| public void removePathInfo(String name) |
| { |
| <span class="nc" id="L558"> remove(PATH_INFO, name);</span> |
| <span class="nc" id="L559"> }</span> |
| |
| /** |
| * Is Query data set in this URI? |
| * |
| * @return true if Query data has values |
| */ |
| public boolean hasQueryData() |
| { |
| <span class="nc bnc" id="L568" title="All 2 branches missed."> return !dataVectors[QUERY_DATA].isEmpty();</span> |
| } |
| |
| /** |
| * Removes all the query string elements. |
| */ |
| public void removeQueryData() |
| { |
| <span class="nc" id="L576"> dataVectors[QUERY_DATA].clear();</span> |
| <span class="nc" id="L577"> }</span> |
| |
| /** |
| * Removes a name=value pair from the query string. |
| * |
| * @param name A String with the name to be removed. |
| */ |
| public void removeQueryData(String name) |
| { |
| <span class="nc" id="L586"> remove (QUERY_DATA, name);</span> |
| <span class="nc" id="L587"> }</span> |
| |
| /** |
| * Template Link and friends want to be able to turn the encoding |
| * of the servlet container off. After calling this method, |
| * the no encoding will happen any longer. If you think, that you |
| * need this outside a template context, think again. |
| */ |
| public void clearResponse() |
| { |
| <span class="nc" id="L597"> setResponse(null);</span> |
| <span class="nc" id="L598"> }</span> |
| |
| |
| /** |
| * Builds the URL with all of the data URL-encoded as well as |
| * encoded using HttpServletResponse.encodeUrl(). The resulting |
| * URL is absolute; it starts with http/https... |
| * |
| * <pre> |
| * TurbineURI tui = new TurbineURI (data, "UserScreen"); |
| * tui.addPathInfo("user","jon"); |
| * tui.getAbsoluteLink(); |
| * </pre> |
| * |
| * The above call to absoluteLink() would return the String: |
| * |
| * <p> |
| * http://www.server.com/servlets/Turbine/screen/UserScreen/user/jon |
| * </p> |
| * |
| * @return A String with the built URL. |
| */ |
| public String getAbsoluteLink() |
| { |
| <span class="nc" id="L622"> StringBuilder output = new StringBuilder();</span> |
| |
| <span class="nc" id="L624"> getSchemeAndPort(output);</span> |
| |
| <span class="nc" id="L626"> buildRelativeLink(output);</span> |
| |
| // |
| // Encode Response does all the fixup for the Servlet Container |
| // |
| <span class="nc" id="L631"> return encodeResponse(output.toString());</span> |
| } |
| |
| /** |
| * Builds the URL with all of the data URL-encoded as well as |
| * encoded using HttpServletResponse.encodeUrl(). The resulting |
| * URL is relative to the webserver root. |
| * |
| * <pre> |
| * TurbineURI tui = new TurbineURI (data, "UserScreen"); |
| * tui.addPathInfo("user","jon"); |
| * tui.getRelativeLink(); |
| * </pre> |
| * |
| * The above call to relativeLink() would return the String: |
| * |
| * <p> |
| * /servlets/Turbine/screen/UserScreen/user/jon |
| * </p> |
| * |
| * @return A String with the built URL. |
| */ |
| public String getRelativeLink() |
| { |
| <span class="nc" id="L655"> StringBuilder output = new StringBuilder();</span> |
| |
| <span class="nc" id="L657"> buildRelativeLink(output);</span> |
| |
| // |
| // Encode Response does all the fixup for the Servlet Container |
| // |
| <span class="nc" id="L662"> return encodeResponse(output.toString());</span> |
| } |
| |
| /** |
| * Add everything needed for a relative link to the passed StringBuilder. |
| * |
| * @param output A Stringbuffer |
| */ |
| private void buildRelativeLink(StringBuilder output) |
| { |
| <span class="nc" id="L672"> getContextAndScript(output);</span> |
| |
| <span class="nc bnc" id="L674" title="All 2 branches missed."> if (hasPathInfo())</span> |
| { |
| <span class="nc" id="L676"> output.append('/');</span> |
| <span class="nc" id="L677"> getPathInfoAsString(output);</span> |
| } |
| |
| <span class="nc bnc" id="L680" title="All 2 branches missed."> if (hasReference())</span> |
| { |
| <span class="nc" id="L682"> output.append('#');</span> |
| <span class="nc" id="L683"> output.append(getReference());</span> |
| } |
| |
| <span class="nc bnc" id="L686" title="All 2 branches missed."> if (hasQueryData())</span> |
| { |
| <span class="nc" id="L688"> output.append('?');</span> |
| <span class="nc" id="L689"> getQueryDataAsString(output);</span> |
| } |
| <span class="nc" id="L691"> }</span> |
| |
| /** |
| * Gets the current Path Info List. |
| * |
| * @return A List which contains all query data keys. The keys |
| * are URIParam objects. |
| */ |
| public List<URIParam> getPathInfo() |
| { |
| <span class="nc" id="L701"> return dataVectors[PATH_INFO];</span> |
| } |
| |
| /** |
| * Sets the Query Data List. Replaces the current query data list |
| * with the one supplied. The list must contain only URIParam |
| * objects! |
| * |
| * @param pathInfo A List with new param objects. |
| */ |
| |
| public void setPathInfo(List<URIParam> pathInfo) |
| { |
| <span class="nc" id="L714"> dataVectors[PATH_INFO] = pathInfo;</span> |
| <span class="nc" id="L715"> }</span> |
| |
| /** |
| * Gets the current Query Data List. |
| * |
| * @return A List which contains all query data keys. The keys |
| * are URIParam objects. |
| */ |
| public List<URIParam> getQueryData() |
| { |
| <span class="nc" id="L725"> return dataVectors[QUERY_DATA];</span> |
| } |
| |
| /** |
| * Sets the Query Data List. Replaces the current query data list |
| * with the one supplied. The list must contain only URIParam |
| * objects! |
| * |
| * @param queryData A List with new param objects. |
| */ |
| |
| public void setQueryData(List<URIParam> queryData) |
| { |
| <span class="nc" id="L738"> dataVectors[QUERY_DATA] = queryData;</span> |
| <span class="nc" id="L739"> }</span> |
| |
| /** |
| * Simply calls getAbsoluteLink(). You should not use this in your |
| * code unless you have to. Use getAbsoluteLink. |
| * |
| * @return This URI as a String |
| * |
| */ |
| @Override |
| public String toString() |
| { |
| <span class="nc" id="L751"> return getAbsoluteLink();</span> |
| } |
| |
| /* |
| * ======================================================================== |
| * |
| * Protected / Private Methods |
| * |
| * ======================================================================== |
| * |
| */ |
| |
| /** |
| * Returns the Path Info data as a String. |
| * |
| * @param output The StringBuilder that should hold the path info. |
| */ |
| private void getPathInfoAsString(StringBuilder output) |
| { |
| <span class="nc" id="L770"> doEncode(output, dataVectors[PATH_INFO], "/", "/");</span> |
| <span class="nc" id="L771"> }</span> |
| |
| /** |
| * Returns the Query data as a String. |
| * |
| * @param output The StringBuilder that should hold the query data. |
| */ |
| private void getQueryDataAsString(StringBuilder output) |
| { |
| <span class="nc" id="L780"> doEncode(output, dataVectors[QUERY_DATA], "&", "=");</span> |
| <span class="nc" id="L781"> }</span> |
| |
| /** |
| * URL encode the given string, catching possible Exceptions |
| * |
| * @param string the string |
| * @return the encoded string |
| */ |
| private String urlEncode(String string) |
| { |
| try |
| { |
| // Java10: return URLEncoder.encode(string, parameterEncoding); |
| <span class="nc" id="L794"> return URLEncoder.encode(string, parameterEncoding.name());</span> |
| } |
| <span class="nc" id="L796"> catch (UnsupportedEncodingException e)</span> |
| { |
| <span class="nc" id="L798"> log.warn("Unsupported encoding {}", parameterEncoding);</span> |
| } |
| |
| <span class="nc" id="L801"> return StringUtils.EMPTY;</span> |
| } |
| |
| /** |
| * Does the actual encoding for pathInfoAsString and queryDataAsString. |
| * |
| * @param output The String builder that should contain the information. |
| * @param list A list of key to value pairs |
| * @param fieldDelim A char which is used to separate key/value pairs |
| * @param valueDelim A char which is used to separate key and value |
| */ |
| private void doEncode(StringBuilder output, Collection<URIParam> list, String fieldDelim, String valueDelim) |
| { |
| <span class="nc bnc" id="L814" title="All 2 branches missed."> if(!list.isEmpty())</span> |
| { |
| <span class="nc" id="L816"> output.append(list.stream()</span> |
| <span class="nc" id="L817"> .map(uriParam -></span> |
| <span class="nc" id="L818"> String.join(</span> |
| valueDelim, |
| <span class="nc" id="L820"> urlEncode(uriParam.getKey()),</span> |
| <span class="nc" id="L821"> urlEncode(Objects.toString(uriParam.getValue()))))</span> |
| <span class="nc" id="L822"> .collect(Collectors.joining(fieldDelim)));</span> |
| } |
| <span class="nc" id="L824"> }</span> |
| |
| /** |
| * If the type is PATH_INFO, then add name/value to the pathInfo |
| * hashtable. |
| * <p> |
| * If the type is QUERY_DATA, then add name/value to the queryData |
| * hashtable. |
| * |
| * @param type Type (PATH_INFO or QUERY_DATA) of insertion. |
| * @param name A String with the name to add. |
| * @param value A String with the value to add. |
| */ |
| protected void add(int type, |
| String name, |
| String value) |
| { |
| <span class="nc" id="L841"> URIParam uriParam = new URIParam(parserService.convertAndTrim(name), value);</span> |
| <span class="nc" id="L842"> dataVectors[type].add(uriParam); // Code so clean you can eat from...</span> |
| <span class="nc" id="L843"> }</span> |
| |
| /** |
| * Method for a quick way to add all the parameters in a |
| * ParameterParser. |
| * |
| * <p>If the type is P (0), then add name/value to the pathInfo |
| * hashtable. |
| * |
| * <p>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. |
| */ |
| protected void add(int type, |
| ParameterParser pp) |
| { |
| <span class="nc bnc" id="L861" title="All 2 branches missed."> for(String key : pp.keySet())</span> |
| { |
| <span class="nc bnc" id="L863" title="All 2 branches missed."> if (!key.equalsIgnoreCase(CGI_ACTION_PARAM) &&</span> |
| <span class="nc bnc" id="L864" title="All 2 branches missed."> !key.equalsIgnoreCase(CGI_SCREEN_PARAM))</span> |
| { |
| <span class="nc" id="L866"> String[] values = pp.getStrings(key);</span> |
| <span class="nc bnc" id="L867" title="All 2 branches missed."> if(values != null)</span> |
| { |
| <span class="nc bnc" id="L869" title="All 2 branches missed."> for (String value : values)</span> |
| { |
| <span class="nc" id="L871"> add(type, key, value);</span> |
| } |
| } |
| else |
| { |
| <span class="nc" id="L876"> add(type, key, "");</span> |
| } |
| } |
| <span class="nc" id="L879"> }</span> |
| <span class="nc" id="L880"> }</span> |
| |
| /** |
| * Method for a quick way to add all the parameters in a |
| * List with URIParam objects. |
| * |
| * <p>If the type is P (0), then add name/value to the pathInfo |
| * hashtable. |
| * |
| * <p>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 list A List of URIParam objects |
| */ |
| protected void add(int type, List<URIParam> list) |
| { |
| <span class="nc" id="L897"> dataVectors[type].addAll(list);</span> |
| <span class="nc" id="L898"> }</span> |
| |
| /** |
| * If the type is P (0), then remove name/value from the |
| * pathInfo hashtable. |
| * |
| * <p>If the type is Q (1), then remove name/value from the |
| * queryData hashtable. |
| * |
| * @param type Type (P or Q) of removal. |
| * @param name A String with the name to be removed. |
| */ |
| protected void remove (int type, String name) |
| { |
| <span class="nc" id="L912"> String key = parserService.convertAndTrim(name);</span> |
| |
| <span class="nc" id="L914"> dataVectors[type].removeIf(uriParam -> key.equals(uriParam.getKey()));</span> |
| <span class="nc" id="L915"> }</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> |