Class Uri
Syntax of valid DMT URIs:
- A slash (
'/'
\u002F) is the separator of the node names. Slashes used in node name must therefore be escaped using a backslash slash ("\/"
). The backslash must be escaped with a double backslash sequence. A backslash found must be ignored when it is not followed by a slash or backslash. - The node name can be constructed using full Unicode character set (except
the Supplementary code, not being supported by CLDC/CDC). However, using the
full Unicode character set for node names is discouraged because the encoding
in the underlying storage as well as the encoding needed in communications
can create significant performance and memory usage overhead. Names that are
restricted to the URI set
[-a-zA-Z0-9_.!~*'()]
are most efficient. - URIs used in the DMT must be treated and interpreted as case sensitive.
- No End Slash: URI must not end with the delimiter slash (
'/'
\u002F). This implies that the root node must be denoted as"."
and not"./"
. - No parent denotation: URI must not be constructed using the character
sequence
"../"
to traverse the tree upwards. - Single Root: The character sequence
"./"
must not be used anywhere else but in the beginning of a URI.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
This constant stands for a string identifying the path separator in the DmTree ("/").static final char
This constant stands for a char identifying the path separator in the DmTree ('/').static final String
This constant stands for a string identifying the root of the DmTree (".").static final char
This constant stands for a char identifying the root of the DmTree ('.'). -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Decode the node name so that back slash and forward slash are unescaped from a back slash.static String
Encode the node name so that back slash and forward slash are escaped with a back slash.static boolean
isAbsoluteUri
(String uri) Checks whether the specified URI is an absolute URI.static boolean
isValidUri
(String uri) Checks whether the specified URI is valid.static String
Returns a node name that is valid for the tree operation methods, based on the given node name.static String[]
Split the specified URI along the path separator '/' characters and return an array of URI segments.static String
Construct a URI from the specified URI segments.
-
Field Details
-
ROOT_NODE
This constant stands for a string identifying the root of the DmTree (".").- Since:
- 2.0
- See Also:
-
ROOT_NODE_CHAR
public static final char ROOT_NODE_CHARThis constant stands for a char identifying the root of the DmTree ('.').- Since:
- 2.0
- See Also:
-
PATH_SEPARATOR
This constant stands for a string identifying the path separator in the DmTree ("/").- Since:
- 2.0
- See Also:
-
PATH_SEPARATOR_CHAR
public static final char PATH_SEPARATOR_CHARThis constant stands for a char identifying the path separator in the DmTree ('/').- Since:
- 2.0
- See Also:
-
-
Method Details
-
mangle
Returns a node name that is valid for the tree operation methods, based on the given node name. This transformation is not idempotent, so it must not be called with a parameter that is the result of a previousmangle
method call.Node name mangling is needed in the following cases:
- if the name contains '/' or '\' characters
A node name that does not suffer from either of these problems is guaranteed to remain unchanged by this method. Therefore the client may skip the mangling if the node name is known to be valid (though it is always safe to call this method).
The method returns the normalized
nodeName
as described below. Invalid node names are normalized in different ways, depending on the cause. If the name contains '/' or '\' characters, then these are simply escaped by inserting an additional '\' before each occurrence. If the length of the name does exceed the limit, the following mechanism is used to normalize it:- the SHA-1 digest of the name is calculated
- the digest is encoded with the base 64 algorithm
- all '/' characters in the encoded digest are replaced with '_'
- trailing '=' signs are removed
- Parameters:
nodeName
- the node name to be mangled (if necessary), must not benull
or empty- Returns:
- the normalized node name that is valid for tree operations
- Throws:
NullPointerException
- ifnodeName
isnull
IllegalArgumentException
- ifnodeName
is empty
-
toUri
Construct a URI from the specified URI segments. The segments must already be mangled.If the specified path is an empty array then an empty URI (
""
) is returned.- Parameters:
path
- a possibly empty array of URI segments, must not benull
- Returns:
- the URI created from the specified segments
- Throws:
NullPointerException
- if the specified path or any of its segments arenull
IllegalArgumentException
- if the specified path contains too many or malformed segments or the resulting URI is too long
-
toPath
Split the specified URI along the path separator '/' characters and return an array of URI segments. Special characters in the returned segments are escaped. The returned array may be empty if the specified URI was empty.- Parameters:
uri
- the URI to be split, must not benull
- Returns:
- an array of URI segments created by splitting the specified URI
- Throws:
NullPointerException
- if the specified URI isnull
IllegalArgumentException
- if the specified URI is malformed
-
isAbsoluteUri
Checks whether the specified URI is an absolute URI. An absolute URI contains the complete path to a node in the DMT starting from the DMT root (".").- Parameters:
uri
- the URI to be checked, must not benull
and must contain a valid URI- Returns:
- whether the specified URI is absolute
- Throws:
NullPointerException
- if the specified URI isnull
IllegalArgumentException
- if the specified URI is malformed
-
encode
Encode the node name so that back slash and forward slash are escaped with a back slash. This method is the reverse ofdecode(String)
.- Parameters:
nodeName
- the node name to be encoded- Returns:
- the encoded node name
- Since:
- 2.0
-
decode
Decode the node name so that back slash and forward slash are unescaped from a back slash.- Parameters:
nodeName
- the node name to be decoded- Returns:
- the decoded node name
- Since:
- 2.0
-
isValidUri
Checks whether the specified URI is valid. A URI is considered valid if it meets the following constraints:- the URI is not
null
; - the URI follows the syntax defined for valid DMT URIs;
getMaxUriLength()
andgetMaxSegmentNameLength()
methods.- Parameters:
uri
- the URI to be validated- Returns:
- whether the specified URI is valid
- the URI is not
-