Class URISupport


  • public class URISupport
    extends java.lang.Object
    Provides support methods for dealing with URI values.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  URISupport.CompositeData
      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
      URISupport()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.net.URI applyParameters​(java.net.URI uri, java.util.Map<java.lang.String,​java.lang.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 java.net.URI applyParameters​(java.net.URI uri, java.util.Map<java.lang.String,​java.lang.String> queryParameters, java.lang.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 boolean checkParenthesis​(java.lang.String str)
      Examine the supplied string and ensure that all parends appear as matching pairs.
      static int indexOfParenthesisMatch​(java.lang.String str, int first)
      Given a string and a position in that string of an open parend, find the matching close parend.
      static boolean isCompositeURI​(java.net.URI uri)
      Examine a URI and determine if it is a Composite type or not.
      static URISupport.CompositeData parseComposite​(java.net.URI uri)
      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 java.util.Map<java.lang.String,​java.lang.String> parseParameters​(java.net.URI uri)
      Given a URI parse and extract any URI query options and return them as a Key / Value mapping.
      static java.net.URI removeQuery​(java.net.URI uri)
      Removes any URI query from the given uri and return a new URI that does not contain the query portion.
      static java.lang.String[] splitComponents​(java.lang.String str)
      Given the inner portion of a composite URI, split and return each inner URI as a string element in a new String array.
      • Methods inherited from class java.lang.Object

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

      • URISupport

        public URISupport()
    • Method Detail

      • parseComposite

        public static URISupport.CompositeData parseComposite​(java.net.URI uri)
                                                       throws java.net.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:
        java.net.URISyntaxException - if the given URI is invalid.
      • isCompositeURI

        public static boolean isCompositeURI​(java.net.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 Composite type.
      • checkParenthesis

        public static boolean checkParenthesis​(java.lang.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.
      • indexOfParenthesisMatch

        public static int indexOfParenthesisMatch​(java.lang.String str,
                                                  int first)
                                           throws java.net.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:
        java.net.URISyntaxException - if the string does not contain a matching parend.
      • splitComponents

        public static java.lang.String[] splitComponents​(java.lang.String str)
        Given the inner portion of a composite URI, split and return each inner URI as a string element in a new String array.
        Parameters:
        str - The inner URI elements of a composite URI string.
        Returns:
        an array containing each inner URI from the composite one.
      • removeQuery

        public static java.net.URI removeQuery​(java.net.URI uri)
                                        throws java.net.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:
        java.net.URISyntaxException - if the given URI is invalid.
      • parseParameters

        public static java.util.Map<java.lang.String,​java.lang.String> parseParameters​(java.net.URI uri)
                                                                                      throws java.net.URISyntaxException
        Given a URI parse and extract any URI query options and return them as a Key / Value mapping. This method 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:
        java.net.URISyntaxException - if the given URI is invalid.
      • applyParameters

        public static java.net.URI applyParameters​(java.net.URI uri,
                                                   java.util.Map<java.lang.String,​java.lang.String> queryParameters)
                                            throws java.net.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. The values in the parameters map should not be URL encoded values as this method will perform an encode on them resulting in double encoded values.
        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:
        java.net.URISyntaxException - if the given URI is invalid.
      • applyParameters

        public static java.net.URI applyParameters​(java.net.URI uri,
                                                   java.util.Map<java.lang.String,​java.lang.String> queryParameters,
                                                   java.lang.String optionPrefix)
                                            throws java.net.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. Only values in the given options map that start with the provided prefix are appended to the provided URI, the prefix is stripped off before the insertion.

        This method replaces the value of any matching query string options in the original URI with the value given in the provided query parameters map.

        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:
        java.net.URISyntaxException - if the given URI is invalid.