Class Path
- All Implemented Interfaces:
Comparable<Path>
- Since:
- 1.0.0 (Sling API Bundle 2.11.0)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbooleangetPath()Return the normalized path if thisPathobject holds a path, returns the pattern otherwise.inthashCode()booleanReturns {code true} if thisPathobject is holding a patternbooleanIf thisPathobject holds a path (and not a pattern), this method checks whether the provided path is equal to this path or a sub path of it.toString()
-
Field Details
-
GLOB_PREFIX
The prefix to be used for glob patterns- Since:
- 1.2.0 (Sling API Bundle 2.15.0)
- See Also:
-
-
Constructor Details
-
Path
Create a new path object either from a concrete path or from a glob pattern.
Concrete paths are normalized using
ResourceUtil.normalize(String)before being stored, resolving.and..segments and collapsing consecutive slashes. Paths that cannot be normalized are rejected. Glob pattern segments are not normalized.A glob pattern must start with the
glob:prefix (e.g.glob:**/*.html). The following rules are used to interpret glob patterns:- The
*character matches zero or more characters of a name component without crossing directory boundaries. - The
**characters match zero or more characters crossing directory boundaries.
- Parameters:
path- The resource path or a glob pattern.- Throws:
NullPointerException- IfpathisnullIllegalArgumentException- If the provided path is not absolute or cannot be normalized, or if the glob pattern does not start with a slash.
- The
-
-
Method Details
-
matches
If thisPathobject holds a path (and not a pattern), this method checks whether the provided path is equal to this path or a sub path of it. If a glob pattern is provided as the argument, it performs the same check and respects the provided pattern. This means it returnstrueif this path is a parent to any potential path matching the provided pattern. For example if this path is/apps/fooand the provided pattern isglob:/apps/foo/bar/*.jspthis method will return true. Same if the provided pattern isglob:/apps/**/hello.html. If thisPathobject holds a pattern, it checks whether the provided path matches the pattern. If this path object holds a pattern and a pattern is provided as the argument, it returns onlytrueif the pattern is the same. If the provided argument is a concrete path, it is normalized usingResourceUtil.normalize(String)before matching, resolving.and..segments and collapsing consecutive slashes. If normalization fails, this method returnsfalse. Glob pattern arguments retain their pattern semantics. If the provided argument is not an absolute path or an absolute glob pattern, this method throwsIllegalArgumentException.Warning: A glob pattern supplied as
otherPathcan produce an incorrect result if this method is used as a containment check. For example,new Path("/apps").matches("glob:/**")returnstrue, althoughglob:/**is not a concrete path inside/appsand also matches paths outside that subtree. Pattern arguments establish overlap, not containment of all matching paths. For concrete-path containment or authorization checks, callers must ensure thatotherPathis a concrete absolute path, not a glob pattern. See SLING-13380.- Parameters:
otherPath- Absolute path to check.- Returns:
trueIf other path is within the sub tree of this path or matches the pattern.- Throws:
NullPointerException- IfotherPathisnullIllegalArgumentException- If the provided path is not absolute, or if the glob pattern does not start with a slash.- See Also:
-
getPath
Return the normalized path if thisPathobject holds a path, returns the pattern otherwise.- Returns:
- The path or pattern.
- See Also:
-
isPattern
public boolean isPattern()Returns {code true} if thisPathobject is holding a pattern- Returns:
- {code true} for a pattern,
falsefor a path. - Since:
- 1.2.0 (Sling API Bundle 2.15.0)
-
compareTo
- Specified by:
compareToin interfaceComparable<Path>
-
hashCode
public int hashCode() -
equals
-
toString
-