Class UriComponent

java.lang.Object
org.atmosphere.util.uri.UriComponent

public class UriComponent extends Object
Utility class for validating, encoding and decoding components of a URI.
Author:
Paul.Sandoz@Sun.Com
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The URI component type.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Contextually encodes the characters of string that are either non-ASCII characters or are ASCII characters that must be percent-encoded using the UTF-8 encoding.
    static String
    contextualEncode(String s, UriComponent.Type t, boolean template)
    Contextually encodes the characters of string that are either non-ASCII characters or are ASCII characters that must be percent-encoded using the UTF-8 encoding.
    static String
    Decodes characters of a string that are percent-encoded octets using UTF-8 decoding (if needed).
    static Map<String,String>
    decodeMatrix(String pathSegment, boolean decode)
    Decode the matrix component of a URI path segment.
    static List<org.atmosphere.util.uri.UriComponent.PathSegmentImpl>
    decodePath(String path, boolean decode)
    Decode the path component of a URI as path segments.
    static List<org.atmosphere.util.uri.UriComponent.PathSegmentImpl>
    decodePath(URI u, boolean decode)
    Decode the path component of a URI as path segments.
    static void
    decodePathSegment(List<org.atmosphere.util.uri.UriComponent.PathSegmentImpl> segments, String segment, boolean decode)
     
    static Map<String,String>
    decodeQuery(String q, boolean decode)
    Decode the query component of a URI.
    static Map<String,String>
    decodeQuery(URI u, boolean decode)
    Decode the query component of a URI.
    static String
    Encodes the characters of string that are either non-ASCII characters or are ASCII characters that must be percent-encoded using the UTF-8 encoding.
    static String
    encode(String s, UriComponent.Type t, boolean template)
    Encodes the characters of string that are either non-ASCII characters or are ASCII characters that must be percent-encoded using the UTF-8 encoding.
    static String
    Encodes a string with template parameters names present, specifically the characters '{' and '}' will be percent-encoded.
    static boolean
    Validates the legal characters of a percent-encoded string that represents a URI component type.
    static boolean
    valid(String s, UriComponent.Type t, boolean template)
    Validates the legal characters of a percent-encoded string that represents a URI component type.
    static void
    Validates the legal characters of a percent-encoded string that represents a URI component type.
    static void
    validate(String s, UriComponent.Type t, boolean template)
    Validates the legal characters of a percent-encoded string that represents a URI component type.

    Methods inherited from class java.lang.Object

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

    • validate

      public static void validate(String s, UriComponent.Type t)
      Validates the legal characters of a percent-encoded string that represents a URI component type.
      Parameters:
      s - the encoded string.
      t - the URI compontent type identifying the legal characters.
      Throws:
      IllegalArgumentException - if the encoded string contains illegal characters.
    • validate

      public static void validate(String s, UriComponent.Type t, boolean template)
      Validates the legal characters of a percent-encoded string that represents a URI component type.
      Parameters:
      s - the encoded string.
      t - the URI compontent type identifying the legal characters.
      template - true if the encoded string contains URI template variables
      Throws:
      IllegalArgumentException - if the encoded string contains illegal characters.
    • valid

      public static boolean valid(String s, UriComponent.Type t)
      Validates the legal characters of a percent-encoded string that represents a URI component type.
      Parameters:
      s - the encoded string.
      t - the URI compontent type identifying the legal characters.
      Returns:
      true if the encoded string is valid, otherwise false.
    • valid

      public static boolean valid(String s, UriComponent.Type t, boolean template)
      Validates the legal characters of a percent-encoded string that represents a URI component type.
      Parameters:
      s - the encoded string.
      t - the URI compontent type identifying the legal characters.
      template - true if the encoded string contains URI template variables
      Returns:
      true if the encoded string is valid, otherwise false.
    • contextualEncode

      public static String contextualEncode(String s, UriComponent.Type t)
      Contextually encodes the characters of string that are either non-ASCII characters or are ASCII characters that must be percent-encoded using the UTF-8 encoding. Percent-encoded characters will be recognized and not double encoded.
      Parameters:
      s - the string to be encoded.
      t - the URI compontent type identifying the ASCII characters that must be percent-encoded.
      Returns:
      the encoded string.
    • contextualEncode

      public static String contextualEncode(String s, UriComponent.Type t, boolean template)
      Contextually encodes the characters of string that are either non-ASCII characters or are ASCII characters that must be percent-encoded using the UTF-8 encoding. Percent-encoded characters will be recognized and not double encoded.
      Parameters:
      s - the string to be encoded.
      t - the URI compontent type identifying the ASCII characters that must be percent-encoded.
      template - true if the encoded string contains URI template variables
      Returns:
      the encoded string.
    • encode

      public static String encode(String s, UriComponent.Type t)
      Encodes the characters of string that are either non-ASCII characters or are ASCII characters that must be percent-encoded using the UTF-8 encoding.
      Parameters:
      s - the string to be encoded.
      t - the URI compontent type identifying the ASCII characters that must be percent-encoded.
      Returns:
      the encoded string.
    • encode

      public static String encode(String s, UriComponent.Type t, boolean template)
      Encodes the characters of string that are either non-ASCII characters or are ASCII characters that must be percent-encoded using the UTF-8 encoding.
      Parameters:
      s - the string to be encoded.
      t - the URI compontent type identifying the ASCII characters that must be percent-encoded.
      template - true if the encoded string contains URI template variables
      Returns:
      the encoded string.
    • encodeTemplateNames

      public static String encodeTemplateNames(String s)
      Encodes a string with template parameters names present, specifically the characters '{' and '}' will be percent-encoded.
      Parameters:
      s - the string with zero or more template parameters names
      Returns:
      the string with encoded template parameters names.
    • decode

      public static String decode(String s, UriComponent.Type t)
      Decodes characters of a string that are percent-encoded octets using UTF-8 decoding (if needed).

      It is assumed that the string is valid according to an (unspecified) URI component type. If a sequence of contiguous percent-encoded octets is not a valid UTF-8 character then the octets are replaced with '�'.

      If the URI component is of type HOST then any "%" found between "[]" is left alone. It is an IPv6 literal with a scope_id.

      If the URI component is of type QUERY_PARAM then any "+" is decoded as as ' '.

      Parameters:
      s - the string to be decoded.
      t - the URI component type, may be null.
      Returns:
      the decoded string.
      Throws:
      IllegalArgumentException - if a malformed percent-encoded octet is detected
    • decodeQuery

      public static Map<String,String> decodeQuery(URI u, boolean decode)
      Decode the query component of a URI.
      Parameters:
      u - the URI.
      decode - true if the query parameters of the query component should be in decoded form.
      Returns:
      the multivalued map of query parameters.
    • decodeQuery

      public static Map<String,String> decodeQuery(String q, boolean decode)
      Decode the query component of a URI.
      Parameters:
      q - the query component in encoded form.
      decode - true of the query parameters of the query component should be in decoded form.
      Returns:
      the multivalued map of query parameters.
    • decodePath

      public static List<org.atmosphere.util.uri.UriComponent.PathSegmentImpl> decodePath(URI u, boolean decode)
      Decode the path component of a URI as path segments.
      Parameters:
      u - the URI. If the path component is an absolute path component then the leading '/' is ignored and is not considered a delimiator of a path segment.
      decode - true if the path segments of the path component should be in decoded form.
      Returns:
      the list of path segments.
    • decodePath

      public static List<org.atmosphere.util.uri.UriComponent.PathSegmentImpl> decodePath(String path, boolean decode)
      Decode the path component of a URI as path segments.

      Any '/' character in the path is considered to be a deliminator between two path segments. Thus if the path is '/' then the path segment list will contain two empty path segments. If the path is "//" then the path segment list will contain three empty path segments. If the path is "/a/" the path segment list will consist of the following path segments in order: "", "a" and "".

      Parameters:
      path - the path component in encoded form.
      decode - true if the path segments of the path component should be in decoded form.
      Returns:
      the list of path segments.
    • decodePathSegment

      public static void decodePathSegment(List<org.atmosphere.util.uri.UriComponent.PathSegmentImpl> segments, String segment, boolean decode)
    • decodeMatrix

      public static Map<String,String> decodeMatrix(String pathSegment, boolean decode)
      Decode the matrix component of a URI path segment.
      Parameters:
      pathSegment - the path segment component in encoded form.
      decode - true if the matrix parameters of the path segment component should be in decoded form.
      Returns:
      the multivalued map of matrix parameters.