Class ParsedURL

java.lang.Object
com.zfabrik.util.net.ParsedURL

public class ParsedURL extends Object
URI is a convenience class for manipulation of URLs based on the W3C RFC 2396 (see the World Wide Web Consortium pages). In general a URI consists of the parts
  • scheme, e.g. http, https, ftp,...etc
  • user info
  • host
  • port
  • path
  • query
  • fragment
concatenated as <scheme>://<user info>@<host>:<port><path>?<query>#<fragment> Many combinations are admissable. Examples
  1. <scheme>:/<path>#<fragment>
  2. <scheme>://<user info>@<host>/<path>
  3. <scheme>://<user info>@<host>:<port>?<query>
  • Constructor Details

    • ParsedURL

      public ParsedURL()
      Constructor.
    • ParsedURL

      public ParsedURL(String uri)
      Constructor with initial URL.
      Parameters:
      uri - The URI to hanlde.
    • ParsedURL

      public ParsedURL(ParsedURL uri)
      Constructor with initial URL.
      Parameters:
      uri - The URI to hanlde.
  • Method Details

    • setURI

      public void setURI(String uri)
      Sets the URI handled by this instance.
      Parameters:
      uri -
    • parse

      protected void parse(String uri)
      parse a given URI. We try to parse a wide variety of not necessarily "correct" URIs.
      Parameters:
      uri -
    • setScheme

      public void setScheme(String scheme)
      Sets the scheme of the URI, e.g. http, https, file, ftp, ...etc.
      Parameters:
      scheme -
    • getScheme

      public String getScheme()
      Gets the scheme of the current URI.
    • isAbsolute

      public boolean isAbsolute()
      Gets wether this URI is absolute.
    • setFragment

      public void setFragment(String fragment)
      Sets the fragment of the URI
      Parameters:
      fragment -
    • getFragment

      public String getFragment()
      Gets the scheme of the current URI.
    • setUserInfo

      public void setUserInfo(String userInfo)
      Sets the User-info of the URI
      Parameters:
      userInfo -
    • getUserInfo

      public String getUserInfo()
      Gets the UserInfo of the current URI.
    • setHost

      public void setHost(String host)
      Sets the Host of the URI
      Parameters:
      host -
    • getHost

      public String getHost()
      Gets the Host of the current URI.
    • setPort

      public void setPort(String port)
      Sets the port of the URI
      Parameters:
      port -
    • getPort

      public String getPort()
      Gets the port of the current URI.
    • setPath

      public void setPath(String path)
      Sets the path of the URI
      Parameters:
      path -
    • getPath

      public String getPath()
      Gets the path of the current URI.
    • removeParameters

      public void removeParameters()
      Removes all parameters from the query part.
    • removeParameter

      public void removeParameter(String name)
      Removes the specified parameter from the query part.
      Parameters:
      name - the name of the parameter to be removed
    • removeParameter

      public void removeParameter(String name, String value)
      Removes the specified name-value pair from the query part.
      Parameters:
      name - the name of the parameter to be removed
      value -
    • addParameter

      public void addParameter(String name, String value)
      Adds a parameter with value to the query part.
      Parameters:
      name - the name of the parameter to add.
      value - the value of the parameter to add.
    • setParameter

      public void setParameter(String name, String value)
      Sets a parameter with value to the query part removing all previous values
      Parameters:
      name - the name of the parameter to add.
      value - the value of the parameter to add.
    • getParameterValues

      public String[] getParameterValues(String name)
      Gets all values assigned to a parameter from the query part.
      Parameters:
      name - the name of the parameter to get the values of.
      Returns:
      a String Array containing all the values of the specified parameter.
    • getParameterValue

      public String getParameterValue(String name)
      Gets the lone value assigned to a parameter from the query part. If the parameter is multi-valued, the result can be any of the values.
      Parameters:
      name - the name of the parameter to get the values of.
      Returns:
      a String containing one value of the specified parameter.
    • getParametersSet

      public Set<String> getParametersSet()
      Gets all parameters of the query part.
    • getQuery

      public String getQuery()
      Gets the query String.
      Returns:
      String representation of the query part of the URI
    • toRegEx

      public String toRegEx()
      constructs a regular expression that matches all valid url that would result into the same properties for all properties that are currently set - up to the last piece that has been set. The address part of the URL vs. the resource path of the URL requires special handling. If there is no property relating to the address part, it will be completely omitted from the URL. So, if you have a URL with a host specified, all urls for that the host will be matched. If you only have a path, no host must be set and the regex stops at that path. If you have host and path, host must be set, scheme doesn't matter, path must be present, regex stops at path... and so on.
      Returns:
    • toString

      public String toString(boolean absolute)
      Gets a string representation of the URI.
      Parameters:
      absolute - if true the URI will be returned as absolute URL including protocol, host and port. If set to false only the path will be taken into account
      Returns:
      the URI as a String.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
      Object.toString()