com.sun.ws.rest.api.uri
Class UriComponent

java.lang.Object
  extended by com.sun.ws.rest.api.uri.UriComponent

public final class UriComponent
extends java.lang.Object

Utility class for validating, encoding and decoding components of a URI. TODO rewrite to use masks and not lookup tables


Nested Class Summary
static class UriComponent.Type
           
 
Method Summary
static java.lang.String decode(java.lang.String s, UriComponent.Type t)
          Decodes characters of a string that are percent-encoded octets using UTF-8 decoding (if needed).
static javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> decodeQuery(java.lang.String q, boolean decode)
          Decode the query component of a URI.
static javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> decodeQuery(java.net.URI u, boolean decode)
          Decode the query component of a URI.
static java.lang.String encode(java.lang.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.
static java.lang.String encode(java.lang.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 boolean valid(java.lang.String s, UriComponent.Type t)
          Validates the legal characters of a percent-encoded string that represents a URI component type.
static boolean valid(java.lang.String s, UriComponent.Type t, boolean template)
          Validates the legal characters of a percent-encoded string that represents a URI component type.
static void validate(java.lang.String s, UriComponent.Type t)
          Validates the legal characters of a percent-encoded string that represents a URI component type.
static void validate(java.lang.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 Detail

validate

public static void validate(java.lang.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:
java.lang.IllegalArgumentException - if the encoded string contains illegal characters.

validate

public static void validate(java.lang.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:
java.lang.IllegalArgumentException - if the encoded string contains illegal characters.

valid

public static boolean valid(java.lang.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(java.lang.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.

encode

public static java.lang.String encode(java.lang.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 java.lang.String encode(java.lang.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.

decode

public static java.lang.String decode(java.lang.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.

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

decodeQuery

public static javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> decodeQuery(java.net.URI u,
                                                                                             boolean decode)
Decode the query component of a URI.

Parameters:
u - the URI.
decode - true of the query parameters of the query component should be in decoded form.
Returns:
the multivalued map of query parameters.

decodeQuery

public static javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> decodeQuery(java.lang.String q,
                                                                                             boolean decode)
Decode the query component of a URI.

TODO the implementation is not very efficient.

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.