Class URISupport

java.lang.Object
org.apache.activemq.util.URISupport

public class URISupport extends Object
Utility class that provides methods for parsing URI's This class can be used to split composite URI's into their component parts and is used to extract any URI options from each URI in order to set specific properties on Beans.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A composite URI can be split into one or more CompositeData object which each represent the individual URIs that comprise the composite one.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static URI
    applyParameters(URI uri, Map<String,String> queryParameters)
    Given a Key / Value mapping create and append a URI query value that represents the mapped entries, return the newly updated URI that contains the value of the given URI and the appended query value.
    static URI
    applyParameters(URI uri, Map<String,String> queryParameters, String optionPrefix)
    Given a Key / Value mapping create and append a URI query value that represents the mapped entries, return the newly updated URI that contains the value of the given URI and the appended query value.
    static URI
    changeScheme(URI bindAddr, String scheme)
    Given a URI value create and return a new URI that matches the target one but with the scheme value supplied to this method.
    static boolean
    Examine the supplied string and ensure that all parends appear as matching pairs.
    static String
    createQueryString(Map<String,? extends Object> options)
    Given a key / value mapping, create and return a URI formatted query string that is valid and can be appended to a URI.
    static URI
    createRemainingURI(URI originalURI, Map<String,String> params)
    Creates a URI from the original URI and the remaining parameters.
    static URI
    Creates a URI with the given query, removing an previous query value from the given URI.
    static int
    Given a string and a position in that string of an open parend, find the matching close parend.
    static boolean
    Examine a URI and determine if it is a Composite type or not.
    Given a composite URI, parse the individual URI elements contained within that URI and return a CompsoteData instance that contains the parsed URI values.
    static Map<String,String>
    Given a URI parse and extract any URI query options and return them as a Key / Value mapping.
    static Map<String,String>
    Give a URI break off any URI options and store them in a Key / Value Mapping.
    static URI
    Removes any URI query from the given uri and return a new URI that does not contain the query portion.
    static String
    stripPrefix(String value, String prefix)
    String the given prefix from the target string and return the result.
    static URI
    Strip a URI of its scheme element.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • URISupport

      public URISupport()
  • Method Details

    • parseQuery

      public static Map<String,String> parseQuery(String uri) throws URISyntaxException
      Give a URI break off any URI options and store them in a Key / Value Mapping.
      Parameters:
      uri - The URI whose query should be extracted and processed.
      Returns:
      A Mapping of the URI options.
      Throws:
      URISyntaxException
    • parseParameters

      public static Map<String,String> parseParameters(URI uri) throws URISyntaxException
      Given a URI parse and extract any URI query options and return them as a Key / Value mapping. This method differs from the parseQuery(java.lang.String) method in that it handles composite URI types and will extract the URI options from the outermost composite URI.
      Parameters:
      uri - The URI whose query should be extracted and processed.
      Returns:
      A Mapping of the URI options.
      Throws:
      URISyntaxException
    • applyParameters

      public static URI applyParameters(URI uri, Map<String,String> queryParameters) throws URISyntaxException
      Given a Key / Value mapping create and append a URI query value that represents the mapped entries, return the newly updated URI that contains the value of the given URI and the appended query value.
      Parameters:
      uri - The source URI that will have the Map entries appended as a URI query value.
      queryParameters - The Key / Value mapping that will be transformed into a URI query string.
      Returns:
      A new URI value that combines the given URI and the constructed query string.
      Throws:
      URISyntaxException
    • applyParameters

      public static URI applyParameters(URI uri, Map<String,String> queryParameters, String optionPrefix) throws URISyntaxException
      Given a Key / Value mapping create and append a URI query value that represents the mapped entries, return the newly updated URI that contains the value of the given URI and the appended query value. Each entry in the query string is prefixed by the supplied optionPrefix string.
      Parameters:
      uri - The source URI that will have the Map entries appended as a URI query value.
      queryParameters - The Key / Value mapping that will be transformed into a URI query string.
      optionPrefix - A string value that when not null or empty is used to prefix each query option key.
      Returns:
      A new URI value that combines the given URI and the constructed query string.
      Throws:
      URISyntaxException
    • removeQuery

      public static URI removeQuery(URI uri) throws URISyntaxException
      Removes any URI query from the given uri and return a new URI that does not contain the query portion.
      Parameters:
      uri - The URI whose query value is to be removed.
      Returns:
      a new URI that does not contain a query value.
      Throws:
      URISyntaxException
    • createURIWithQuery

      public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException
      Creates a URI with the given query, removing an previous query value from the given URI.
      Parameters:
      uri - The source URI whose existing query is replaced with the newly supplied one.
      query - The new URI query string that should be appended to the given URI.
      Returns:
      a new URI that is a combination of the original URI and the given query string.
      Throws:
      URISyntaxException
    • parseComposite

      public static URISupport.CompositeData parseComposite(URI uri) throws URISyntaxException
      Given a composite URI, parse the individual URI elements contained within that URI and return a CompsoteData instance that contains the parsed URI values.
      Parameters:
      uri - The target URI that should be parsed.
      Returns:
      a new CompsiteData instance representing the parsed composite URI.
      Throws:
      URISyntaxException
    • isCompositeURI

      public static boolean isCompositeURI(URI uri)
      Examine a URI and determine if it is a Composite type or not.
      Parameters:
      uri - The URI that is to be examined.
      Returns:
      true if the given URI is a Compsote type.
    • indexOfParenthesisMatch

      public static int indexOfParenthesisMatch(String str, int first) throws URISyntaxException
      Given a string and a position in that string of an open parend, find the matching close parend.
      Parameters:
      str - The string to be searched for a matching parend.
      first - The index in the string of the opening parend whose close value is to be searched.
      Returns:
      the index in the string where the closing parend is located.
      Throws:
      URISyntaxException - fi the string does not contain a matching parend.
    • stripPrefix

      public static String stripPrefix(String value, String prefix)
      String the given prefix from the target string and return the result.
      Parameters:
      value - The string that should be trimmed of the given prefix if present.
      prefix - The prefix to remove from the target string.
      Returns:
      either the original string or a new string minus the supplied prefix if present.
    • stripScheme

      public static URI stripScheme(URI uri) throws URISyntaxException
      Strip a URI of its scheme element.
      Parameters:
      uri - The URI whose scheme value should be stripped.
      Returns:
      The stripped URI value.
      Throws:
      URISyntaxException
    • createQueryString

      public static String createQueryString(Map<String,? extends Object> options) throws URISyntaxException
      Given a key / value mapping, create and return a URI formatted query string that is valid and can be appended to a URI.
      Parameters:
      options - The Mapping that will create the new Query string.
      Returns:
      a URI formatted query string.
      Throws:
      URISyntaxException
    • createRemainingURI

      public static URI createRemainingURI(URI originalURI, Map<String,String> params) throws URISyntaxException
      Creates a URI from the original URI and the remaining parameters. When the query options of a URI are applied to certain objects the used portion of the query options needs to be removed and replaced with those that remain so that other parts of the code can attempt to apply the remainder or give an error is unknown values were given. This method is used to update a URI with those remainder values.
      Parameters:
      originalURI - The URI whose current parameters are remove and replaced with the given remainder value.
      params - The URI params that should be used to replace the current ones in the target.
      Returns:
      a new URI that matches the original one but has its query options replaced with the given ones.
      Throws:
      URISyntaxException
    • changeScheme

      public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException
      Given a URI value create and return a new URI that matches the target one but with the scheme value supplied to this method.
      Parameters:
      bindAddr - The URI whose scheme value should be altered.
      scheme - The new scheme value to use for the returned URI.
      Returns:
      a new URI that is a copy of the original except that its scheme matches the supplied one.
      Throws:
      URISyntaxException
    • checkParenthesis

      public static boolean checkParenthesis(String str)
      Examine the supplied string and ensure that all parends appear as matching pairs.
      Parameters:
      str - The target string to examine.
      Returns:
      true if the target string has valid parend pairings.