Class UrlParameter

java.lang.Object
de.cuioss.tools.net.UrlParameter
All Implemented Interfaces:
Serializable, Comparable<UrlParameter>

public class UrlParameter extends Object implements Serializable, Comparable<UrlParameter>
Simple wrapper around an Url Parameter Object.

Depending on the constructor arguments the attributes #getName() and #getValue() are implicitly encoded properly using URLEncoder.encode(String, String). This is helpful for reliable handling of special characters.

Author:
Oliver Wolff
See Also:
  • Field Details

  • Constructor Details

    • UrlParameter

      public UrlParameter(String name, String value)
      Constructor. Name and value are implicitly encoded using UTF-8.
      Parameters:
      name - must not be null or empty
      value - may be null.
    • UrlParameter

      public UrlParameter(String name, String value, boolean encode)
      Constructor.
      Parameters:
      name - must not be null or empty
      value - value may be null.
      encode - indicates whether to encode the parameter name and value as UTF-8
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns a boolean indicating whether the UrlParameter is empty, saying has a null value
      Returns:
      boolean flag whether the UrlParameter is empty
    • createParameterString

      public static String createParameterString(UrlParameter... parameters)
      Creates a parameter String for a given number of UrlParameter.
      Parameters:
      parameters - to be appended, must not be null
      Returns:
      the concatenated ParameterString in the form "?parameter1Name=parameter1Value&parameter2Name=parameter2Value"
    • createParameterString

      public static String createParameterString(boolean encode, UrlParameter... parameters)
      Create a String-representation of the URL-Parameter
      Parameters:
      encode -
      parameters -
      Returns:
      the created parameter String
    • getUrlParameterFromMap

      public static final List<UrlParameter> getUrlParameterFromMap(Map<String,List<String>> map, ParameterFilter parameterFilter, boolean encode)
      Convert a map of raw Url-parameter into a list of UrlParameter
      Parameters:
      map - containing the parameter extracted usually directly from servlet request. From the String[] solely the first element will be extracted. The others will be ignored.
      parameterFilter - defines the parameter to be filtered. May be null or empty.
      encode - indicates whether to encode the parameter name and value as UTF-8
      Returns:
      the found List of UrlParameter or empty list if the given map is null or empty. The List is always sorted by #getName()
    • filterParameter

      public static List<UrlParameter> filterParameter(List<UrlParameter> toBeFiltered, ParameterFilter parameterFilter)
      Filters the given list of UrlParameter
      Parameters:
      toBeFiltered - may be null or empty
      parameterFilter - used for filtering, may be null
      Returns:
      the filtered parameter list or empty List if toBeFiltered is null or empty.
    • createParameterMap

      public static final Map<String,List<String>> createParameterMap(List<UrlParameter> urlParameters)
      Create a parameterMap for a given list of UrlParameter
      Parameters:
      urlParameters - may be null or empty
      Returns:
      parameter Map, may be empty if urlParameters is empty. The list of String will solely contain one element.
    • fromQueryString

      public static List<UrlParameter> fromQueryString(String queryString)
      Helper class that create a list of UrlParameter from a given query-String
      Parameters:
      queryString - if it is null or empty or solely consists of an "?" an empty List
      Returns:
      if queryString is null or empty or solely consists of an "?" an empty List will be returned. An immutable List of UrlParameter otherwise
    • createNameValueString

      Create a String representation of a name value pair, saying name=value
      Returns:
      String representation of a name value pair, saying name=value
    • createNameValueString

      public String createNameValueString(boolean encode)
      Parameters:
      encode - flag indicate if the result need to be encoded
      Returns:
      string representation of name + vale
    • compareTo

      public int compareTo(UrlParameter compareTo)
      Specified by:
      compareTo in interface Comparable<UrlParameter>