Interface Path
-
- All Superinterfaces:
Serializable
public interface Path extends Serializable
ThePathinterface defines the SPI level representation of a JCR path. It consists of an ordered list ofPath.Elementobjects and is immutable.A
Path.Elementis eithernamedor one of the following special elements:- the
currentelement (Notation: "."), - the
parentelement (Notation: ".."), - the
rootelement (Notation: {}), which can only occur as the first element in a path, or - an
identifierelement, which can only occur as the first element in a path.
A
Pathis defined to have the following characteristics:Equality:
Two paths are equal if they consist of the same elements.Length:
Thelengthof a path is the number of its elements.Depth:
Thedepthof a path is- 0 for the root path,
- 0 for a path consisting of an identifier element only,
- 0 for the path consisting of the current element only,
- -1 for the path consisting of the parent element only,
- 1 for the path consisting of a single named element,
- depth(P) + depth(Q) for the path P/Q.
The depth of a normalized absolute path equals its length minus 1.
Absolute vs. Relative
A path can be absolute or relative:
A pathis absoluteif its first element is the root or an identifier element. A path is relative if it is not absolute.- An absolute path is valid if its depth is greater or equals 0. A relative path is always valid.
- Two absolute paths are equivalent if "they refer to the same item in the hierarchy".
- Two relative paths P and Q are equivalent if for every absolute path R such that R/P and R/Q are valid, R/P and R/Q are equivalent.
Normalization:
A path Pis normalizedif P has minimal length amongst the set of all paths Q which are equivalent to P.
This means that '.' and '..' elements are resolved as much as possible. An absolute path it is normalized if it is not identifier-based and contains no current or parent elements. The normalization of a path is unique.
Equivalence:
Path P isequivalentto path Q (in the above sense) if the normalization of P is equal to the normalization of Q. This is an equivalence relation (i.e. reflexive, transitive, and symmetric).Canonical Paths:
A pathis canonicalif its absolute and normalized.Hierarchical Relationship:
The ancestor relationship is a strict partial order (i.e. irreflexive, transitive, and asymmetric). Path P is a direct ancestor of path Q if P is equivalent to Q/..
Path P is anancestorof path Q if- P is a direct ancestor of Q or
- P is a direct ancestor of some path S which is an ancestor of Q.
Path P is an
descendantof path Q if- Path P is a descendant of path Q if Q is an ancestor of P.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfacePath.ElementObject representation of a single JCR path element.
-
Field Summary
Fields Modifier and Type Field Description static charDELIMITERDelimiter used in order to concatenate the Path.Element objects upongetString().static intINDEX_DEFAULTConstant representing the default (initial) index value.static intINDEX_UNDEFINEDConstant representing an undefined index valuestatic intROOT_DEPTHConstant defining the depth of the root path
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description PathcomputeRelativePath(Path other)Computes the relative path fromthisabsolute path toother.booleandenotesCurrent()Checks if the last path element is the current element (".").booleandenotesIdentifier()Test if this path consists of a single identifier element.booleandenotesName()Checks if the last path element is a named and optionally indexed element.booleandenotesParent()Checks if the last path element is the parent element ("..").booleandenotesRoot()Tests whether this is the root path, i.e.PathgetAncestor(int degree)Normalizes this path and returns the ancestor path of the specified relative degree.intgetAncestorCount()Returns the number of ancestors of this path.PathgetCanonicalPath()Returns the canonical path representation of this path.intgetDepth()Returns the depth of this path.Path.Element[]getElements()Returns the elements of this path.PathgetFirstElements()Returns a path that consists of all but the last element of this path.StringgetIdentifier()Returns the identifier of a single identifier element.intgetIndex()Returns the index of the last path element, orINDEX_UNDEFINEDif the index is not defined or not applicable.PathgetLastElement()Returns a path that consists of only the last element of this path.intgetLength()Returns the length of this path, i.e.NamegetName()Returns the name of the last path element, ornullfor an identifier.Path.ElementgetNameElement()Returns the name element (i.e.intgetNormalizedIndex()Returns the normalized index of the last path element.PathgetNormalizedPath()Returns the normalized path representation of this path.StringgetString()Returns the String representation of this Path as it is used byPathFactory.create(String).booleanisAbsolute()Tests whether this path is absolute, i.e.booleanisAncestorOf(Path other)Determines if this path is an ancestor of the specified path, based on their (absolute or relative) hierarchy level as returned by.getDepth()booleanisCanonical()Tests whether this path is canonical, i.e.booleanisDescendantOf(Path other)Determines if this path is a descendant of the specified path, based on their (absolute or relative) hierarchy level as returned by.getDepth()booleanisEquivalentTo(Path other)Determines if the theotherpath would be equal tothispath if both of them are normalized.booleanisIdentifierBased()Test if this path represents an unresolved identifier-based path.booleanisNormalized()Tests whether this path is normalized, i.e.Pathresolve(Path relative)Resolves the given path against this path.Pathresolve(Path.Element element)Resolves the given path element against this path.PathsubPath(int from, int to)Returns a newPathconsisting of those Path.Element objects between the givenfrom, inclusive, and the givento, exclusive.
-
-
-
Field Detail
-
INDEX_UNDEFINED
static final int INDEX_UNDEFINED
Constant representing an undefined index value- See Also:
- Constant Field Values
-
INDEX_DEFAULT
static final int INDEX_DEFAULT
Constant representing the default (initial) index value.- See Also:
- Constant Field Values
-
ROOT_DEPTH
static final int ROOT_DEPTH
Constant defining the depth of the root path- See Also:
- Constant Field Values
-
DELIMITER
static final char DELIMITER
Delimiter used in order to concatenate the Path.Element objects upongetString().- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
Name getName()
Returns the name of the last path element, ornullfor an identifier. The names of the special root, current and parent elements are "", "." and ".." in the default namespace.- Returns:
- name of the last path element, or
null
-
getIndex
int getIndex()
Returns the index of the last path element, orINDEX_UNDEFINEDif the index is not defined or not applicable. The index of an identifier or the special root, current or parent element is always undefined.- Returns:
- index of the last path element, or
INDEX_UNDEFINED
-
getNormalizedIndex
int getNormalizedIndex()
Returns the normalized index of the last path element. The normalized index of an element with an undefined index isINDEX_DEFAULT.- Returns:
- normalized index of the last path element
-
getIdentifier
String getIdentifier()
Returns the identifier of a single identifier element. Returns null for non-identifier paths or identifier paths with other relative path elements.- Returns:
- identifier, or
null
-
denotesRoot
boolean denotesRoot()
Tests whether this is the root path, i.e. "/".- Returns:
trueif this is the root path,falseotherwise.
-
denotesIdentifier
boolean denotesIdentifier()
Test if this path consists of a single identifier element.- Returns:
trueif this path is an identifier
-
denotesParent
boolean denotesParent()
Checks if the last path element is the parent element ("..").- Returns:
trueif the last path element is the parent element,falseotherwise
-
denotesCurrent
boolean denotesCurrent()
Checks if the last path element is the current element (".").- Returns:
trueif the last path element is the current element,falseotherwise
-
denotesName
boolean denotesName()
Checks if the last path element is a named and optionally indexed element.- Returns:
trueif the last path element is a named element,falseotherwise
-
isIdentifierBased
boolean isIdentifierBased()
Test if this path represents an unresolved identifier-based path.- Returns:
trueif this path represents an unresolved identifier-based path.
-
isAbsolute
boolean isAbsolute()
Tests whether this path is absolute, i.e. whether it starts with "/" or is an identifier based path.- Returns:
- true if this path is absolute; false otherwise.
-
isCanonical
boolean isCanonical()
Tests whether this path is canonical, i.e. whether it is absolute and does not contain redundant elements such as "." and "..".- Returns:
- true if this path is canonical; false otherwise.
- See Also:
isAbsolute()
-
isNormalized
boolean isNormalized()
Tests whether this path is normalized, i.e. whether it does not contain redundant elements such as "." and "..".Note that a normalized path can still contain ".." elements if they are not redundant, e.g. "../../a/b/c" would be a normalized relative path, whereas "../a/../../a/b/c" wouldn't (although they're semantically equivalent).
- Returns:
- true if this path is normalized; false otherwise.
- See Also:
getNormalizedPath()
-
getNormalizedPath
Path getNormalizedPath() throws RepositoryException
Returns the normalized path representation of this path.If the path cannot be normalized (e.g. if an absolute path is normalized that would result in a 'negative' path) a RepositoryException is thrown.
- Returns:
- a normalized path representation of this path.
- Throws:
RepositoryException- if the path cannot be normalized.- See Also:
isNormalized()
-
getCanonicalPath
Path getCanonicalPath() throws RepositoryException
Returns the canonical path representation of this path.If the path is relative or cannot be normalized a RepositoryException is thrown.
- Returns:
- a canonical path representation of this path.
- Throws:
RepositoryException- if this path can not be canonicalized (e.g. if it is relative).
-
resolve
Path resolve(Path.Element element)
Resolves the given path element against this path. If the given element is absolute (i.e. the root or an identifier element), then a path containing just that element is returned. Otherwise the returned path consists of this path followed by the given element.- Parameters:
element- path element- Returns:
- resolved path
-
resolve
Path resolve(Path relative)
Resolves the given path against this path. If the given path is absolute, then it is returned as-is. Otherwise the path is resolved relative to this path and the resulting resolved path is returned.- Parameters:
relative- the path to be resolved- Returns:
- resolved path
-
computeRelativePath
Path computeRelativePath(Path other) throws RepositoryException
Computes the relative path fromthisabsolute path toother.- Parameters:
other- an absolute path.- Returns:
- the relative path from
thispath tootherpath. - Throws:
RepositoryException- if eitherthisorotherpath is not absolute.
-
getAncestor
Path getAncestor(int degree) throws IllegalArgumentException, PathNotFoundException, RepositoryException
Normalizes this path and returns the ancestor path of the specified relative degree.An ancestor of relative degree x is the path that is x levels up along the path.
- degree = 0 returns this path.
- degree = 1 returns the parent of this path.
- degree = 2 returns the grandparent of this path.
- And so on to degree = n, where n is the depth of this path, which returns the root path.
If this path is relative the implementation may not be able to determine if the ancestor at
degreeexists. Such an implementation should properly build the ancestor (i.e. parent of .. is ../..) and leave if it the caller to throwPathNotFoundException.- Parameters:
degree- the relative degree of the requested ancestor.- Returns:
- the normalized ancestor path of the specified degree.
- Throws:
IllegalArgumentException- ifdegreeis negative.PathNotFoundException- if the implementation is able to determine that there is no ancestor of the specified degree. In case of this being an absolute path, this would be the case ifdegreeis greater that thedepthof this path.RepositoryException- If the implementation is not able to determine the ancestor of the specified degree for some other reason.
-
getAncestorCount
int getAncestorCount()
Returns the number of ancestors of this path. This is the equivalent ofin case of a absolute path. For relative path the number of ancestors cannot be determined and -1 should be returned.getDepth()- Returns:
- the number of ancestors of this path or -1 if the number of ancestors cannot be determined.
- See Also:
getDepth(),getLength(),isCanonical()
-
getLength
int getLength()
Returns the length of this path, i.e. the number of its elements. Note that the root element "/" counts as a separate element, e.g. the length of "/a/b/c" is 4 whereas the length of "a/b/c" is 3.Also note that the special elements "." and ".." are not treated specially, e.g. both "/a/./.." and "/a/b/c" have a length of 4 but this value does not necessarily reflect the true hierarchy level as returned by
.getDepth()- Returns:
- the length of this path
- See Also:
getDepth(),getAncestorCount()
-
getDepth
int getDepth()
Returns the depth of this path. The depth reflects the absolute or relative hierarchy level this path is representing, depending on whether this path is an absolute or a relative path. The depth also takes '.' and '..' elements into account. The depth of the root path, an identifier and the current path must be 0.Note that the returned value might be negative if this path is not canonical, e.g. the depth of "../../a" is -1.
- Returns:
- the depth this path
- See Also:
getLength(),getAncestorCount()
-
isEquivalentTo
boolean isEquivalentTo(Path other) throws IllegalArgumentException, RepositoryException
Determines if the theotherpath would be equal tothispath if both of them are normalized.- Parameters:
other- Another path.- Returns:
- true if the given other path is equivalent to this path.
- Throws:
IllegalArgumentException- if the given path isnullor if not both paths are either absolute or relative.RepositoryException- if any of the path cannot be normalized.
-
isAncestorOf
boolean isAncestorOf(Path other) throws IllegalArgumentException, RepositoryException
Determines if this path is an ancestor of the specified path, based on their (absolute or relative) hierarchy level as returned by. In case of undefined ancestor/descendant relationship that might occur with relative paths, the return value should begetDepth()false.- Returns:
trueifotheris a descendant; otherwisefalse.- Throws:
IllegalArgumentException- if the given path isnullor if not both paths are either absolute or relative.RepositoryException- if any of the path cannot be normalized.- See Also:
getDepth()
-
isDescendantOf
boolean isDescendantOf(Path other) throws IllegalArgumentException, RepositoryException
Determines if this path is a descendant of the specified path, based on their (absolute or relative) hierarchy level as returned by. In case of undefined ancestor/descendant relationship that might occur with relative paths, the return value should begetDepth()false.- Returns:
trueifotheris an ancestor; otherwisefalse.- Throws:
IllegalArgumentException- if the given path isnullor if not both paths are either absolute or relative.RepositoryException- if any of the path cannot be normalized.- See Also:
isAncestorOf(Path)
-
subPath
Path subPath(int from, int to) throws IllegalArgumentException
Returns a newPathconsisting of those Path.Element objects between the givenfrom, inclusive, and the givento, exclusive. AnIllegalArgumentExceptionis thrown iffromis greater or equal thantoor if any of both params is out of the possible range.- Parameters:
from- index of the element to start with and low endpoint (inclusive) within the list of elements to use for the sub-path.to- index of the element outside of the range i.e. high endpoint (exclusive) within the list of elements to use for the sub-path.- Returns:
- a new
Pathconsisting of those Path.Element objects between the givenfrom, inclusive, and the givento, exclusive. - Throws:
IllegalArgumentException- iffromis greater or equal thantoor if any of both params is out of the possible range.
-
getElements
Path.Element[] getElements()
Returns the elements of this path.- Returns:
- the elements of this path.
-
getNameElement
Path.Element getNameElement()
Returns the name element (i.e. the last element) of this path.- Returns:
- the name element of this path
-
getLastElement
Path getLastElement()
Returns a path that consists of only the last element of this path.- Returns:
- last element of this path
- See Also:
getFirstElements()
-
getFirstElements
Path getFirstElements()
Returns a path that consists of all but the last element of this path. Returnsnullif this path contains just a single element.- Returns:
- first elements of this path, or
null - See Also:
getLastElement()
-
getString
String getString()
Returns the String representation of this Path as it is used byPathFactory.create(String).The String representation must consist of the String representation of its elements separated by
DELIMITER.- Returns:
- Returns the String representation of this Path.
- See Also:
Path.Element.getString()
-
-