| java.lang.Object org.restlet.data.Reference
All known Subclasses: org.restlet.data.LocalReference,
Reference | public class Reference (Code) | | Reference to a Uniform Resource Identifier (URI). Contrary to the
java.net.URI class, this interface represents mutable references. It strictly
conforms to the RFC 3986 specifying URIs and follow its naming conventions.
URI reference = absolute-reference | relative-reference
absolute-reference = scheme ":" scheme-specific-part [ "#" fragment ]
scheme-specific-part = ( hierarchical-part [ "?" query ] ) | opaque-part
hierarchical-part = ( "//" authority path-abempty ) | path-absolute | path-rootless | path-empty
authority = [ user-info "@" ] host-domain [ ":" host-port ]
relative-reference = relative-part [ "?" query ] [ "#" fragment ]
relative-part = ( "//" authority path-abempty ) | path-absolute | path-noscheme | path-empty
path-abempty = begins with "/" or is empty
path-absolute = begins with "/" but not "//"
path-noscheme = begins with a non-colon segment
path-rootless = begins with a segment
path-empty = zero characters
Note that this class doesn't encode or decode the reserved characters. It
assumes that the URIs or the URI parts passed in are properly encoded using
the standard URI encoding mechanism. You can use the static "encode()" and
"decode()" methods for this purpose.
The fundamental point to underline is the difference between an URI
"reference" and an URI. Contrary to an URI (the target identifier of a REST
resource), an URI reference can be relative (with or without query and
fragment part). This relative URI reference can then be resolved against a
base reference via the getTargetRef() method which will return a new resolved
Reference instance, an absolute URI reference with no base reference and with
no dot-segments (the path segments "." and "..").
You can also apply the getTargetRef() method on absolute references in order
to solve the dot-segments. Note that applying the getRelativeRef() method on
an absolute reference returns the current reference relatively to a base
reference, if any, and solves the dot-segments.
The Reference stores its data as a single string, the one passed to the
constructor. This string can always be obtained using the toString() method.
A couple of integer indexes are maintained to improve the extraction time of
various reference properties (URI components).
When you modify a specific component of the URI reference, via the setPath()
method for example, the internal string is simply regenerated by updating
only the relevant part. We try as much as possible to protect the bytes given
to the Reference class instead of transparently parsing and normalizing the
URI data. Our idea is to protect encodings and special characters in all case
and reduce the memory size taken by this class while making Reference
instances mutable.
Because the base reference is only a property of the Reference ("baseRef").
When you use the "Reference(base, path)" constructor, it is equivalent to
doing:
ref = new Reference(path);
ref.setBaseRef(base);
The base ref is not automatically resolved or "merged" with the rest of the
reference information (the path here). For example, this let's you reuse a
single reference as the base of several relative references. If you modify
the base reference, all relative references are still accurate.
author: Jerome Louvel (contact@noelios.com) See Also: RFC 3986 |
Constructor Summary | |
public | Reference() Empty constructor. | public | Reference(Reference ref) Clone constructor. | public | Reference(Reference baseRef, String uriReference) Constructor from an URI reference (most likely relative). | public | Reference(Reference baseRef, String relativePart, String query, String fragment) Constructor of relative reference from its parts. | public | Reference(String uriReference) Constructor from an URI reference. | public | Reference(String identifier, String fragment) Constructor from an identifier and a fragment. | public | Reference(String scheme, String hostName, int hostPort, String path, String query, String fragment) Constructor of absolute reference from its parts. |
Method Summary | |
public static String | decode(String toDecode) Decodes a given string using the standard URI encoding mechanism and the
UTF-8 character set.
Parameters: toDecode - The string to decode. | public static String | decode(String toDecode, CharacterSet characterSet) Decodes a given string using the standard URI encoding mechanism. | public static String | encode(String toEncode) Encodes a given string using the standard URI encoding mechanism and the
UTF-8 character set.
Parameters: toEncode - The string to encode. | public static String | encode(String toEncode, CharacterSet characterSet) Encodes a given string using the standard URI encoding mechanism. | public boolean | equals(Object object) Indicates whether some other object is "equal to" this one.
Parameters: object - The object to compare to. | public String | getAuthority() Returns the authority component for hierarchical identifiers. | public Reference | getBaseRef() Returns the base reference for relative references. | public String | getFragment() Returns the fragment identifier. | public String | getHierarchicalPart() Returns the hierarchical part which is equivalent to the scheme specific
part less the query component. | public String | getHostDomain() Returns the host domain name component for server based hierarchical
identifiers. | public String | getHostIdentifier() Returns the host identifier. | public int | getHostPort() Returns the optional port number for server based hierarchical
identifiers. | public String | getIdentifier() Returns the absolute resource identifier, without the fragment. | public String | getLastSegment() Returns the last segment of a hierarchical path. For example the
"/a/b/c" and "/a/b/c/" paths have the same segments: "a", "b", "c. | public Reference | getParentRef() Returns the parent reference of a hierarchical reference. | public String | getPath() Returns the path component for hierarchical identifiers. | public String | getQuery() Returns the optional query component for hierarchical identifiers. | public Form | getQueryAsForm() Returns the optional query component as a form submission. | public Form | getQueryAsForm(CharacterSet characterSet) Returns the optional query component as a form submission.
Parameters: characterSet - The supported character encoding. | public String | getRelativePart() Returns the relative part of relative references, without the query and
fragment. | public Reference | getRelativeRef() Returns the current reference as a relative reference to the current base
reference. | public Reference | getRelativeRef(Reference base) Returns the current reference relatively to a base reference. | public String | getRemainingPart() Returns the part of the resource identifier remaining after the base
reference. | public String | getScheme() Returns the scheme component. | public Protocol | getSchemeProtocol() Returns the protocol associated with the scheme component. | public String | getSchemeSpecificPart() Returns the scheme specific part. | public List<String> | getSegments() Returns the segments of a hierarchical path. A new list is created
for each call. | public Reference | getTargetRef() Returns the target reference. | public String | getUserInfo() Returns the user info component for server based hierarchical
identifiers. | public int | hashCode() Returns a hash code value for the object. | public boolean | isAbsolute() Indicates if the reference is absolute. | public boolean | isEquivalentTo(Reference ref) Returns true if both reference are equivalent, meaning that they resolve
to the same target reference.
Parameters: ref - The reference to compare. | public boolean | isHierarchical() Indicates if the identifier is hierarchical. | public boolean | isOpaque() Indicates if the identifier is opaque. | public boolean | isParent(Reference childRef) Indicates if the reference is a parent of the hierarchical child
reference.
Parameters: childRef - The hierarchical reference. | public boolean | isRelative() Indicates if the reference is relative. | public Reference | normalize() Normalizes the reference. | public void | setAuthority(String authority) Sets the authority component for hierarchical identifiers. | public void | setBaseRef(String baseUri) Sets the base reference for relative references. | public void | setBaseRef(Reference baseRef) Sets the base reference for relative references. | public void | setFragment(String fragment) Sets the fragment identifier. | public void | setHostDomain(String domain) Sets the host domain component for server based hierarchical identifiers. | public void | setHostPort(Integer port) Sets the optional port number for server based hierarchical identifiers. | public void | setIdentifier(String identifier) Sets the absolute resource identifier. | public void | setPath(String path) Sets the path component for hierarchical identifiers. | public void | setProtocol(Protocol protocol) Sets the scheme component based on this protocol. | public void | setQuery(String query) Sets the query component for hierarchical identifiers. | public void | setRelativePart(String relativePart) Sets the relative part for relative references only. | public void | setScheme(String scheme) Sets the scheme component. | public void | setSchemeSpecificPart(String schemeSpecificPart) Sets the scheme specific part. | public void | setSegments(List<String> segments) Sets the segments of a hierarchical path. A new absolute path will
replace any existing one. | public void | setUserInfo(String userInfo) Sets the user info component for server based hierarchical identifiers. | public static String | toString(String scheme, String hostName, Integer hostPort, String path, String query, String fragment) Creates a reference string from its parts. | public static String | toString(String relativePart, String query, String fragment) Creates a relative reference string from its parts. | public static String | toString(String scheme, String host, String path, String query, String fragment) Creates a reference string from its parts. | public String | toString() Returns the reference as an URI string. | public String | toString(boolean query, boolean fragment) Returns the URI reference string. |
Reference | public Reference()(Code) | | Empty constructor.
|
Reference | public Reference(Reference ref)(Code) | | Clone constructor.
Parameters: ref - The reference to clone. |
Reference | public Reference(Reference baseRef, String uriReference)(Code) | | Constructor from an URI reference (most likely relative).
Parameters: baseRef - The base reference. Parameters: uriReference - The URI reference, either absolute or relative. |
Reference | public Reference(Reference baseRef, String relativePart, String query, String fragment)(Code) | | Constructor of relative reference from its parts.
Parameters: baseRef - The base reference. Parameters: relativePart - The relative part component (most of the time it is the pathcomponent). Parameters: query - The optional query component for hierarchical identifiers. Parameters: fragment - The optional fragment identifier. |
Reference | public Reference(String uriReference)(Code) | | Constructor from an URI reference.
Parameters: uriReference - The URI reference, either absolute or relative. |
Reference | public Reference(String identifier, String fragment)(Code) | | Constructor from an identifier and a fragment.
Parameters: identifier - The resource identifier. Parameters: fragment - The fragment identifier. |
Reference | public Reference(String scheme, String hostName, int hostPort, String path, String query, String fragment)(Code) | | Constructor of absolute reference from its parts.
Parameters: scheme - The scheme ("http", "https" or "ftp"). Parameters: hostName - The host name or IP address. Parameters: hostPort - The host port (default ports are correctly ignored). Parameters: path - The path component for hierarchical identifiers. Parameters: query - The optional query component for hierarchical identifiers. Parameters: fragment - The optional fragment identifier. |
decode | public static String decode(String toDecode)(Code) | | Decodes a given string using the standard URI encoding mechanism and the
UTF-8 character set.
Parameters: toDecode - The string to decode. The decoded string. |
decode | public static String decode(String toDecode, CharacterSet characterSet)(Code) | | Decodes a given string using the standard URI encoding mechanism. If the
provided character set is null, the string is returned but not decoded.
Note: The
World Wide Web Consortium Recommendation states that UTF-8 should be
used. Not doing so may introduce incompatibilites.
Parameters: toDecode - The string to decode. Parameters: characterSet - The name of a supported character encoding. The decoded string or null if the named character encoding is notsupported. |
encode | public static String encode(String toEncode)(Code) | | Encodes a given string using the standard URI encoding mechanism and the
UTF-8 character set.
Parameters: toEncode - The string to encode. The encoded string. |
encode | public static String encode(String toEncode, CharacterSet characterSet)(Code) | | Encodes a given string using the standard URI encoding mechanism. If the
provided character set is null, the string is returned but not encoded.
Note: The
World Wide Web Consortium Recommendation states that UTF-8 should be
used. Not doing so may introduce incompatibilites.
Parameters: toEncode - The string to encode. Parameters: characterSet - The supported character encoding. The encoded string or null if the named character encoding is notsupported. |
equals | public boolean equals(Object object)(Code) | | Indicates whether some other object is "equal to" this one.
Parameters: object - The object to compare to. True if this object is the same as the obj argument. |
getAuthority | public String getAuthority()(Code) | | Returns the authority component for hierarchical identifiers. Includes
the user info, host name and the host port number.
The authority component for hierarchical identifiers. |
getBaseRef | public Reference getBaseRef()(Code) | | Returns the base reference for relative references.
The base reference for relative references. |
getFragment | public String getFragment()(Code) | | Returns the fragment identifier.
The fragment identifier. |
getHierarchicalPart | public String getHierarchicalPart()(Code) | | Returns the hierarchical part which is equivalent to the scheme specific
part less the query component.
The hierarchical part . |
getHostDomain | public String getHostDomain()(Code) | | Returns the host domain name component for server based hierarchical
identifiers. It can also be replaced by an IP address when no domain name
was registered.
The host domain name component for server based hierarchicalidentifiers. |
getHostIdentifier | public String getHostIdentifier()(Code) | | Returns the host identifier. Includes the scheme, the host name and the
host port number.
The host identifier. |
getHostPort | public int getHostPort()(Code) | | Returns the optional port number for server based hierarchical
identifiers.
The optional port number for server based hierarchicalidentifiers or -1 if the port number does not exist. |
getIdentifier | public String getIdentifier()(Code) | | Returns the absolute resource identifier, without the fragment.
The absolute resource identifier, without the fragment. |
getLastSegment | public String getLastSegment()(Code) | | Returns the last segment of a hierarchical path. For example the
"/a/b/c" and "/a/b/c/" paths have the same segments: "a", "b", "c.
The last segment of a hierarchical path. |
getParentRef | public Reference getParentRef()(Code) | | Returns the parent reference of a hierarchical reference. The last slash
of the path will be considered as the end of the parent path.
The parent reference of a hierarchical reference. |
getPath | public String getPath()(Code) | | Returns the path component for hierarchical identifiers.
The path component for hierarchical identifiers. |
getQuery | public String getQuery()(Code) | | Returns the optional query component for hierarchical identifiers.
The optional query component for hierarchical identifiers. |
getQueryAsForm | public Form getQueryAsForm()(Code) | | Returns the optional query component as a form submission.
The optional query component as a form submission. throws: IOException - |
getQueryAsForm | public Form getQueryAsForm(CharacterSet characterSet)(Code) | | Returns the optional query component as a form submission.
Parameters: characterSet - The supported character encoding. The optional query component as a form submission. throws: IOException - |
getRelativePart | public String getRelativePart()(Code) | | Returns the relative part of relative references, without the query and
fragment. If the reference is absolute, then null is returned.
The relative part. |
getRelativeRef | public Reference getRelativeRef()(Code) | | Returns the current reference as a relative reference to the current base
reference. This method should only be invoked for absolute references,
otherwise an IllegalArgumentException will be raised.
The current reference as a relative reference to the current basereference. See Also: Reference.getRelativeRef(Reference) |
getRelativeRef | public Reference getRelativeRef(Reference base)(Code) | | Returns the current reference relatively to a base reference. This method
should only be invoked for absolute references, otherwise an
IllegalArgumentException will be raised.
throws: IllegalArgumentException - If the relative reference is computed although the referenceor the base reference are not absolute or not hierarchical. Parameters: base - The base reference to use. The current reference relatively to a base reference. |
getRemainingPart | public String getRemainingPart()(Code) | | Returns the part of the resource identifier remaining after the base
reference. Note that the optional fragment is not returned by this
method. Must be used with the following prerequisites:
- the reference is absolute
- the reference identifier starts with the resource baseRef
The remaining resource part or null if the prerequisites are notsatisfied. |
getScheme | public String getScheme()(Code) | | Returns the scheme component.
The scheme component. |
getSchemeProtocol | public Protocol getSchemeProtocol()(Code) | | Returns the protocol associated with the scheme component.
The protocol associated with the scheme component. |
getSchemeSpecificPart | public String getSchemeSpecificPart()(Code) | | Returns the scheme specific part.
The scheme specific part. |
getSegments | public List<String> getSegments()(Code) | | Returns the segments of a hierarchical path. A new list is created
for each call.
The segments of a hierarchical path. |
getTargetRef | public Reference getTargetRef()(Code) | | Returns the target reference. This method resolves relative references
against the base reference then normalize them.
throws: IllegalArgumentException - If the base reference (after resolution) is not absolute. throws: IllegalArgumentException - If the reference is relative and not base reference has beenprovided. The target reference. |
getUserInfo | public String getUserInfo()(Code) | | Returns the user info component for server based hierarchical
identifiers.
The user info component for server based hierarchicalidentifiers. |
hashCode | public int hashCode()(Code) | | Returns a hash code value for the object.
A hash code value for the object. |
isAbsolute | public boolean isAbsolute()(Code) | | Indicates if the reference is absolute.
True if the reference is absolute. |
isEquivalentTo | public boolean isEquivalentTo(Reference ref)(Code) | | Returns true if both reference are equivalent, meaning that they resolve
to the same target reference.
Parameters: ref - The reference to compare. True if both reference are equivalent. |
isHierarchical | public boolean isHierarchical()(Code) | | Indicates if the identifier is hierarchical.
True if the identifier is hierarchical, false if it is opaque. |
isOpaque | public boolean isOpaque()(Code) | | Indicates if the identifier is opaque.
True if the identifier is opaque, false if it is hierarchical. |
isParent | public boolean isParent(Reference childRef)(Code) | | Indicates if the reference is a parent of the hierarchical child
reference.
Parameters: childRef - The hierarchical reference. True if the reference is a parent of the hierarchical childreference. |
isRelative | public boolean isRelative()(Code) | | Indicates if the reference is relative.
True if the reference is relative. |
normalize | public Reference normalize()(Code) | | Normalizes the reference. Useful before comparison between references or
when building a target reference from a base and a relative references.
The current reference. |
setAuthority | public void setAuthority(String authority)(Code) | | Sets the authority component for hierarchical identifiers.
Parameters: authority - The authority component for hierarchical identifiers. |
setBaseRef | public void setBaseRef(String baseUri)(Code) | | Sets the base reference for relative references.
Parameters: baseUri - The base URI for relative references. |
setBaseRef | public void setBaseRef(Reference baseRef)(Code) | | Sets the base reference for relative references.
Parameters: baseRef - The base reference for relative references. |
setFragment | public void setFragment(String fragment)(Code) | | Sets the fragment identifier.
throws: IllegalArgumentException - if the fragment parameter contains the fragment delimiter('#'). Parameters: fragment - The fragment identifier. |
setHostDomain | public void setHostDomain(String domain)(Code) | | Sets the host domain component for server based hierarchical identifiers.
Parameters: domain - The host component for server based hierarchical identifiers. |
setHostPort | public void setHostPort(Integer port)(Code) | | Sets the optional port number for server based hierarchical identifiers.
throws: IllegalArgumentException - If the autority has not been defined. Parameters: port - The optional port number for server based hierarchicalidentifiers. |
setIdentifier | public void setIdentifier(String identifier)(Code) | | Sets the absolute resource identifier.
throws: IllegalArgumentException - If the identifier parameter contains the fragment delimiter('#'). Parameters: identifier - The absolute resource identifier. |
setPath | public void setPath(String path)(Code) | | Sets the path component for hierarchical identifiers.
Parameters: path - The path component for hierarchical identifiers. |
setProtocol | public void setProtocol(Protocol protocol)(Code) | | Sets the scheme component based on this protocol.
Parameters: protocol - The protocol of the scheme component. |
setQuery | public void setQuery(String query)(Code) | | Sets the query component for hierarchical identifiers.
Parameters: query - The query component for hierarchical identifiers. |
setRelativePart | public void setRelativePart(String relativePart)(Code) | | Sets the relative part for relative references only.
Parameters: relativePart - The relative part to set. |
setScheme | public void setScheme(String scheme)(Code) | | Sets the scheme component.
Parameters: scheme - The scheme component. |
setSchemeSpecificPart | public void setSchemeSpecificPart(String schemeSpecificPart)(Code) | | Sets the scheme specific part.
Parameters: schemeSpecificPart - The scheme specific part. |
setSegments | public void setSegments(List<String> segments)(Code) | | Sets the segments of a hierarchical path. A new absolute path will
replace any existing one.
Parameters: segments - The segments of the hierarchical path. |
setUserInfo | public void setUserInfo(String userInfo)(Code) | | Sets the user info component for server based hierarchical identifiers.
throws: IllegalArgumentException - If the autority part has not been defined. Parameters: userInfo - The user info component for server based hierarchicalidentifiers. |
toString | public static String toString(String scheme, String hostName, Integer hostPort, String path, String query, String fragment)(Code) | | Creates a reference string from its parts.
Parameters: scheme - The scheme ("http", "https" or "ftp"). Parameters: hostName - The host name or IP address. Parameters: hostPort - The host port (default ports are correctly ignored). Parameters: path - The path component for hierarchical identifiers. Parameters: query - The optional query component for hierarchical identifiers. Parameters: fragment - The optional fragment identifier. |
toString | public static String toString(String relativePart, String query, String fragment)(Code) | | Creates a relative reference string from its parts.
Parameters: relativePart - The relative part component. Parameters: query - The optional query component for hierarchical identifiers. Parameters: fragment - The optional fragment identifier. |
toString | public static String toString(String scheme, String host, String path, String query, String fragment)(Code) | | Creates a reference string from its parts.
Parameters: scheme - The scheme ("http", "https" or "ftp"). Parameters: host - The host name or IP address plus the optional port number. Parameters: path - The path component for hierarchical identifiers. Parameters: query - The optional query component for hierarchical identifiers. Parameters: fragment - The optional fragment identifier. |
toString | public String toString()(Code) | | Returns the reference as an URI string.
The reference as an URI string. |
toString | public String toString(boolean query, boolean fragment)(Code) | | Returns the URI reference string.
Parameters: query - Indicates if the query should be included; Parameters: fragment - Indicates if the fragment should be included; The URI reference string. |
|
|