|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jboss.dna.common.jcr.Path
@Immutable public class Path
An object representation of a node path within a repository.
A path consists of zero or more segments that can contain any characters, although the string representation may require some
characters to be encoded. For example, if a path contains a segment with a forward slash, then this forward slash must be
escaped when writing the whole path to a string (since a forward slash is used as the delimiter between
segments).
Because of this encoding and decoding issue, there is no standard representation of a path as a string. Instead, this class
uses text encoders to escape certain characters when writing to a string or unescaping the string
representation. These encoders and used only with individual segments, and therefore are not used to encode the
delimiter. Three standard encoders are provided, although others can certainly be used:
Jsr283Encoder - an encoder and decoder that is compliant with JSR-283 by converting the reserved characters (namely '*', '/', ':', '[', ']'
and '|') to their unicode equivalent.
UrlEncoder - an encoder and decoder that is useful for converting text to be used within a URL, as
defined by Section 2.3 of RFC 2396. This encoder does encode many characters
(including '`', '@', '#', '$', '^', '&', '{', '[', '}', ']', '|', ':', ';', '\', '"', '<', ',', '>', '?', '/', and ' '), while
others are not encoded (including '-', '_', '.', '!', '~', '*', '\', ''', '(', and ')'). Note that only the '*' character is
the only character reserved by JSR-283 that is not encoded by the URL encoder.NoOpEncoder - an encoder implementation that does nothing.
This class simplifies working with paths and using a Path is often more efficient that processing and
manipulating the equivalent String. This class can easily iterate over the segments, return
the number of segments, compare with other paths, resolve
relative paths, return the ancestor (or parent), determine whether one path is an
ancestor or decendent of another path, and creating
subpaths.
| Nested Class Summary | |
|---|---|
static class |
Path.Segment
A segment of a path. |
| Field Summary | |
|---|---|
static TextEncoder |
DEFAULT_ENCODER
|
static char |
DELIMITER
|
static java.lang.String |
DELIMITER_STR
|
static TextEncoder |
JSR283_ENCODER
|
static TextEncoder |
NO_OP_ENCODER
|
static java.lang.String |
PARENT
|
static Path |
ROOT
|
static java.lang.String |
SELF
|
static TextEncoder |
URL_ENCODER
|
| Constructor Summary | |
|---|---|
Path(java.lang.String path)
Create a path by parsing the supplied absolute or relative path. |
|
Path(java.lang.String path,
TextEncoder encoder)
Create a path by parsing the supplied absolute or relative path. |
|
| Method Summary | |
|---|---|
Path |
append(java.lang.String... segments)
Create a path by appending a single segment without decoding any of the characters. |
Path |
append(java.lang.String segment)
Create a path by appending a single segment without decoding any of the characters. |
Path |
append(java.lang.String[] segments,
TextEncoder encoder)
Create a path by appending multiple segment. |
Path |
append(java.lang.String segment,
TextEncoder encoder)
Create a path by appending a single segment. |
Path |
clone()
|
int |
compareTo(Path that)
|
boolean |
endsWith(java.lang.String segment)
Determine whether the last segment matches that supplied. |
boolean |
endsWith(java.lang.String segment,
TextEncoder encoder)
Determine whether the last segment matches that supplied. |
boolean |
equals(java.lang.Object obj)
|
Path |
getAncestor()
Return the path to the parent, or this path if it is the root. |
Path |
getAncestor(int degree)
Return the path to the ancestor of the supplied degree. |
Path |
getCanonicalPath()
Get the canonical form of this path. |
Path |
getCommonAncestor(Path that)
|
Path.Segment |
getLastSegment()
Get the last segment in this path. |
Path |
getNormalizedPath()
Get a normalized path with as many ".." segments and all "." resolved. |
Path.Segment |
getSegment(int index)
Get the segment at the supplied index. |
java.lang.String |
getString()
Get the string form of the path. |
java.lang.String |
getString(TextEncoder encoder)
Get the encoded string form of the path, using the supplied encoder to encode characters in each of the path segments. |
int |
hashCode()
|
boolean |
hasSameAncestor(Path that)
|
boolean |
isAbsolute()
Return whether this path is an absolute path. |
boolean |
isAncestorOf(Path decendant)
Determine whether this path is an ancestor of the supplied path. |
boolean |
isDecendantOf(Path ancestor)
Determine whether this path is an decendant of the supplied path. |
boolean |
isNormalized()
Return whether this path is normalized and contains no "." segments and as few ".." segments as possible. |
boolean |
isRoot()
Return whether this path represents the root path. |
boolean |
isSame(Path other)
Determine whether this path represents the same as the supplied path. |
java.util.Iterator<Path.Segment> |
iterator()
|
Path |
relativeTo(Path startingPath)
Get a relative path from the supplied path to this path. |
Path |
resolve(Path relativePath)
Get the absolute path by resolving the supplied relative (non-absolute) path against this absolute path. |
Path |
resolve(java.lang.String relativePath)
Get the absolute path by resolving the supplied relative (non-absolute) path against this absolute path. |
Path |
resolve(java.lang.String relativePath,
TextEncoder encoder)
Get the absolute path by resolving the supplied relative (non-absolute) path against this absolute path. |
Path |
resolveAgainst(Path absolutePath)
Get the absolute path by resolving this relative (non-absolute) path against the supplied absolute path. |
Path |
resolveAgainst(java.lang.String absolutePath)
Get the absolute path by resolving this relative (non-absolute) path against the supplied absolute path. |
Path |
resolveAgainst(java.lang.String absolutePath,
TextEncoder encoder)
Get the absolute path by resolving this relative (non-absolute) path against the supplied absolute path. |
int |
size()
Return the number of segments in this path. |
Path.Segment[] |
toArray()
Obtain a copy of the segments in this path. |
java.util.List<Path.Segment> |
toList()
Get an unmodifiable list of the path segments. |
java.lang.String |
toString()
|
java.lang.String[] |
toStringArray()
Obtain a copy of the segments in this path. |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final TextEncoder NO_OP_ENCODER
public static final TextEncoder JSR283_ENCODER
public static final TextEncoder URL_ENCODER
public static final TextEncoder DEFAULT_ENCODER
public static final char DELIMITER
public static final java.lang.String DELIMITER_STR
public static final java.lang.String PARENT
public static final java.lang.String SELF
public static final Path ROOT
| Constructor Detail |
|---|
public Path(java.lang.String path)
throws InvalidPathException
delimiters are treated as a
single delimiter.
path - the string containing the path with delimiters separating the different path segments
InvalidPathException - if the path is null, empty, or invalid
public Path(java.lang.String path,
TextEncoder encoder)
throws InvalidPathException
delimiters are treated as a
single delimiter.
path - the string containing the path with delimiters separating the different path segmentsencoder - the encoder that should be used to convert escaped characters
InvalidPathException - if the path is null, empty, or invalid| Method Detail |
|---|
public int size()
public boolean isRoot()
root path.
public boolean isSame(Path other)
this.compareTo(other) == 0 .
other - the other path to compare with this path
public boolean isAncestorOf(Path decendant)
decendant - the path that may be the decendant
public boolean isDecendantOf(Path ancestor)
ancestor - the path that may be the ancestor
public boolean isAbsolute()
absolute. An absolute
path starts with a "/".
public boolean isNormalized()
public Path getNormalizedPath()
InvalidPathException - if the normalized form would result in a path with negative length (e.g., "/a/../../..")public Path getCanonicalPath()
absolute and isNormalized().
InvalidPathException - if the path is not absolute and cannot be canonicalizedpublic Path relativeTo(Path startingPath)
startingPath - the path specifying the starting point for the new relative path; may not be null
java.lang.IllegalArgumentException - if the supplied path is null
PathNotFoundException - if both this path and the supplied path are not absolutepublic Path resolve(Path relativePath)
relativePath - the relative path that is to be resolved against this path
java.lang.IllegalArgumentException - if the supplied path is null
InvalidPathException - if the this path is not absolute or if the supplied path is not relative.resolve(String),
resolve(String, TextEncoder)public Path resolve(java.lang.String relativePath)
relativePath - the relative path that is to be resolved against this path
java.lang.IllegalArgumentException - if the supplied path is null
InvalidPathException - if the this path is not absolute or if the supplied path is not relative.resolve(String),
resolve(String, TextEncoder)
public Path resolve(java.lang.String relativePath,
TextEncoder encoder)
relativePath - the relative path that is to be resolved against this pathencoder - the encoder to use, or null if the default encoder should be used
java.lang.IllegalArgumentException - if the supplied path is null
InvalidPathException - if the this path is not absolute or if the supplied path is not relative.resolve(String),
resolve(String, TextEncoder)public Path resolveAgainst(Path absolutePath)
absolutePath - the absolute path to which this relative path should be resolve
java.lang.IllegalArgumentException - if the supplied path is null
InvalidPathException - if the supplied path is not absolute or if this path is not relative.resolveAgainst(String),
resolveAgainst(String, TextEncoder)public Path resolveAgainst(java.lang.String absolutePath)
absolutePath - the absolute path to which this relative path should be resolve
java.lang.IllegalArgumentException - if the supplied path is null
InvalidPathException - if the supplied path is not absolute or if this path is not relative.resolveAgainst(Path),
resolveAgainst(String, TextEncoder)
public Path resolveAgainst(java.lang.String absolutePath,
TextEncoder encoder)
absolutePath - the absolute path to which this relative path should be resolveencoder - the encoder to use, or null if the default encoder should be used
java.lang.IllegalArgumentException - if the supplied path is null
InvalidPathException - if the supplied path is not absolute or if this path is not relative.resolveAgainst(Path),
resolveAgainst(String)public Path getAncestor()
root. This is an efficient operation that does
not require copying any data.
public Path getAncestor(int degree)
x is the path that is
x levels up along the path. For example, degree = 0 returns this path, while
degree = 1 returns the parent of this path, degree = 2 returns the grandparent of this path,
and so on. Note that the result may be unexpected if this path is not normalized, as a
non-normalized path contains ".." and "." segments.
degree -
java.lang.IllegalArgumentException - if the degree is negative
PathNotFoundException - if the degree is greater than the length of this pathpublic boolean hasSameAncestor(Path that)
public Path getCommonAncestor(Path that)
public boolean endsWith(java.lang.String segment)
segment - the value for the last segment; if null, false is returned
public boolean endsWith(java.lang.String segment,
TextEncoder encoder)
segment - the value for the last segment; if null, false is returnedencoder - the encoder to use, or null if the default encoder should be used
public Path.Segment getLastSegment()
public Path.Segment getSegment(int index)
index - the index
java.lang.IndexOutOfBoundsException - if the index is out of boundspublic Path append(java.lang.String segment)
append(segment,null).
segment - the segment to append to this path
public Path append(java.lang.String... segments)
append(segment,null).
segments - the segments to append to the path
public Path append(java.lang.String segment,
TextEncoder encoder)
encoder.
segment - the segment to append to this pathencoder - the encoder to use, or null if the default encoder should be used
InvalidPathException - if the segment is empty or blank
public Path append(java.lang.String[] segments,
TextEncoder encoder)
encoder.
segments - the segments to append to this pathencoder - the encoder to use, or null if the default encoder should be used
InvalidPathException - if a segment is empty or blankpublic java.util.Iterator<Path.Segment> iterator()
iterator in interface java.lang.Iterable<Path.Segment>public Path.Segment[] toArray()
public java.lang.String[] toStringArray()
public java.util.List<Path.Segment> toList()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int compareTo(Path that)
compareTo in interface java.lang.Comparable<Path>public Path clone()
clone in class java.lang.Objectpublic java.lang.String getString()
default encoder is used to encode characters in each of the
path segments.
getString(TextEncoder)public java.lang.String getString(TextEncoder encoder)
encoder - the encoder to use, or null if the default encoder should be used
getString()public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||