Class Path
- java.lang.Object
-
- org.apache.sling.api.resource.path.Path
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringGLOB_PREFIXThe prefix to be used for glob patterns
-
Constructor Summary
Constructors Constructor Description Path(@NotNull java.lang.String path)Create a new path object either from a concrete path or from a glob pattern.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(@NotNull Path o)booleanequals(java.lang.Object obj)java.lang.StringgetPath()Return the path if thisPathobject holds a path, returns the pattern otherwise.inthashCode()booleanisPattern()Returns {code true} if thisPathobject is holding a patternbooleanmatches(java.lang.String otherPath)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.java.lang.StringtoString()
-
-
-
Field Detail
-
GLOB_PREFIX
public static final java.lang.String GLOB_PREFIX
The prefix to be used for glob patterns- Since:
- 1.2.0 (Sling API Bundle 2.15.0)
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Path
public Path(@NotNull @NotNull java.lang.String path)Create a new path object either from a concrete path or from a glob pattern.
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:
java.lang.NullPointerException- IfotherPathisnulljava.lang.IllegalArgumentException- If the provided path is not absolute, or if the glob pattern does not start with a slash.
- The
-
-
Method Detail
-
matches
public boolean matches(java.lang.String otherPath)
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 not an absolute path (e.g. if it is a relative path or a pattern), this method returnsfalse.- Parameters:
otherPath- Absolute path to check.- Returns:
trueIf other path is within the sub tree of this path or matches the pattern.- Throws:
java.lang.NullPointerException- IfotherPathisnulljava.lang.IllegalArgumentException- If the provided path is not absolute, or if the glob pattern does not start with a slash.- See Also:
isPattern()
-
getPath
public java.lang.String getPath()
Return the path if thisPathobject holds a path, returns the pattern otherwise.- Returns:
- The path or pattern.
- See Also:
isPattern()
-
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
public int compareTo(@NotNull @NotNull Path o)- Specified by:
compareToin interfacejava.lang.Comparable<Path>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-