Class UriComponent
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classstatic enumThe URI component type. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String_encode(String s, UriComponent.Type t, boolean template, boolean contextualEncode) private static int_valid(String s, UriComponent.Type t, boolean template) private static voidappendPercentEncodedOctet(StringBuilder sb, int b) private static voidappendUTF8EncodedCharacter(StringBuilder sb, int codePoint) static StringContextually 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 StringcontextualEncode(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.private static Stringstatic Stringdecode(String s, UriComponent.Type t) Decodes characters of a string that are percent-encoded octets using UTF-8 decoding (if needed).private static intdecodeHex(char c) private static intprivate static StringdecodeHost(String s, int n) decodeMatrix(String pathSegment, boolean decode) Decode the matrix component of a URI path segment.private static voiddecodeMatrixParam(javax.ws.rs.core.MultivaluedMap<String, String> params, String param, boolean decode) private static intdecodeOctets(int i, ByteBuffer bb, StringBuilder sb) Decodes octets to characters using the UTF-8 decoding and appends the characters to a StringBuffer.static List<javax.ws.rs.core.PathSegment> decodePath(String path, boolean decode) Decode the path component of a URI as path segments.static List<javax.ws.rs.core.PathSegment> decodePath(URI u, boolean decode) Decode the path component of a URI as path segments.static voiddecodePathSegment(List<javax.ws.rs.core.PathSegment> segments, String segment, boolean decode) Decode the path segment and add it to the list of path segments.private static ByteBufferdecodePercentEncodedOctets(String s, int i, ByteBuffer bb) Decode a continuous sequence of percent encoded octets.decodeQuery(String q, boolean decode) Decode the query component of a URI.decodeQuery(String q, boolean decodeNames, boolean decodeValues) Decode the query component of a URI.decodeQuery(URI u, boolean decode) Decode the query component of a URI.private static StringdecodeQueryParam(String s, int n) private static voiddecodeQueryParam(javax.ws.rs.core.MultivaluedMap<String, String> params, String param, boolean decodeNames, boolean decodeValues) static Stringencode(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 Stringencode(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 StringEncodes a string with template parameters names present, specifically the characters '{' and '}' will be percent-encoded.static StringfullRelativeUri(URI uri) Return theRequest-Urirepresentation as defined by HTTP spec.private static boolean[]initEncodingTable(List<String> allowed) private static boolean[][]private static int[]static booleanisHexCharacter(char c) Checks whether the charactercis hexadecimal character.static booleanvalid(String s, UriComponent.Type t) Validates the legal characters of a percent-encoded string that represents a URI component type.static booleanvalid(String s, UriComponent.Type t, boolean template) Validates the legal characters of a percent-encoded string that represents a URI component type.static voidvalidate(String s, UriComponent.Type t) Validates the legal characters of a percent-encoded string that represents a URI component type.static voidvalidate(String s, UriComponent.Type t, boolean template) Validates the legal characters of a percent-encoded string that represents a URI component type.
-
Field Details
-
HEX_DIGITS
private static final char[] HEX_DIGITS -
SCHEME
-
UNRESERVED
-
SUB_DELIMS
-
ENCODING_TABLES
private static final boolean[][] ENCODING_TABLES -
UTF_8_CHARSET
-
HEX_TABLE
private static final int[] HEX_TABLE
-
-
Constructor Details
-
UriComponent
private UriComponent()
-
-
Method Details
-
validate
Validates the legal characters of a percent-encoded string that represents a URI component type.- Parameters:
s- the encoded string.t- the URI component type identifying the legal characters.- Throws:
IllegalArgumentException- if the encoded string contains illegal characters.
-
validate
Validates the legal characters of a percent-encoded string that represents a URI component type.- Parameters:
s- the encoded string.t- the URI component 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
Validates the legal characters of a percent-encoded string that represents a URI component type.- Parameters:
s- the encoded string.t- the URI component type identifying the legal characters.- Returns:
- true if the encoded string is valid, otherwise false.
-
valid
Validates the legal characters of a percent-encoded string that represents a URI component type.- Parameters:
s- the encoded string.t- the URI component 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.
-
_valid
-
contextualEncode
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 component type identifying the ASCII characters that must be percent-encoded.- Returns:
- the encoded string.
-
contextualEncode
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 component 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
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 component type identifying the ASCII characters that must be percent-encoded.- Returns:
- the encoded string.
-
encode
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 component 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
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.
-
_encode
private static String _encode(String s, UriComponent.Type t, boolean template, boolean contextualEncode) -
appendPercentEncodedOctet
-
appendUTF8EncodedCharacter
-
initEncodingTables
private static boolean[][] initEncodingTables() -
initEncodingTable
-
decode
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
Decode the query component of a URI.Query parameter names in the returned map are always decoded. Decoding of query parameter values can be controlled using the
decodeparameter flag.- Parameters:
u- the URI.decode-trueif the returned query parameter values of the query component should be in decoded form.- Returns:
- the multivalued map of query parameters.
-
decodeQuery
Decode the query component of a URI.Query parameter names in the returned map are always decoded. Decoding of query parameter values can be controlled using the
decodeparameter flag.- Parameters:
q- the query component in encoded form.decode-trueif the returned query parameter values of the query component should be in decoded form.- Returns:
- the multivalued map of query parameters.
-
decodeQuery
public static javax.ws.rs.core.MultivaluedMap<String,String> decodeQuery(String q, boolean decodeNames, boolean decodeValues) Decode the query component of a URI.Decoding of query parameter names and values can be controlled using the
decodeNamesanddecodeValuesparameter flags.- Parameters:
q- the query component in encoded form.decodeNames-trueif the returned query parameter names of the query component should be in decoded form.decodeValues-trueif the returned query parameter values of the query component should be in decoded form.- Returns:
- the multivalued map of query parameters.
-
decodeQueryParam
-
decodePath
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
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<javax.ws.rs.core.PathSegment> segments, String segment, boolean decode) Decode the path segment and add it to the list of path segments.- Parameters:
segments- mutable list of path segments.segment- path segment to be decoded.decode-trueif the path segment should be in a decoded form.
-
decodeMatrix
public static javax.ws.rs.core.MultivaluedMap<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.
-
decodeMatrixParam
-
decode
-
decodeQueryParam
-
decodeHost
-
decodePercentEncodedOctets
Decode a continuous sequence of percent encoded octets. Assumes the index, i, starts that the first hex digit of the first percent-encoded octet. -
decodeOctets
Decodes octets to characters using the UTF-8 decoding and appends the characters to a StringBuffer.- Returns:
- the index to the next unchecked character in the string to decode
-
decodeHex
-
initHexTable
private static int[] initHexTable() -
decodeHex
private static int decodeHex(char c) -
isHexCharacter
public static boolean isHexCharacter(char c) Checks whether the charactercis hexadecimal character.- Parameters:
c- Any character- Returns:
- The is
cis a hexadecimal character (e.g. 0, 5, a, A, f, ...)
-
fullRelativeUri
Return theRequest-Urirepresentation as defined by HTTP spec. For example:<Method> <Request-URI> HTTP/<Version> (e.g. GET /auth;foo=bar/hello?foo=bar HTTP/1.1)
- Parameters:
uri- uri to obtainRequest-Urifrom.- Returns:
Request-Urirepresentation ornullifuriis not provided.
-