Class PathBuilder
java.lang.Object
org.apache.sling.api.resource.path.PathBuilder
The
PathBuilder offers a convenient way of creating an absolute path from multiple fragments.
Use build() to obtain a normalized path.
Normalization does not confine the result to the initial path's subtree.- Since:
- 1.0.0 (Sling API Bundle 2.11.0)
-
Constructor Summary
ConstructorsConstructorDescriptionPathBuilder(String path) Creates a newPathBuilderinstance with an absolute initial path. -
Method Summary
-
Constructor Details
-
PathBuilder
Creates a newPathBuilderinstance with an absolute initial path. Normalization is performed only whenbuild()is called.- Parameters:
path- the nonempty initial path, starting with/- Throws:
IllegalArgumentException- if the path is null, empty, or relative
-
-
Method Details
-
append
Appends a path fragment to the accumulated path. Fragments may be relative and contain.or..segments, which are resolved whenbuild()is called. A leading/does not replace the accumulated path; the fragment is joined to it with a slash at the boundary.- Parameters:
path- the nonempty path fragment to append- Returns:
- this instance
- Throws:
IllegalArgumentException- if the fragment is null or empty
-
toString
Returns the joined path without normalization. In most cases,build()is the better choice, as it resolves dot segments and removes redundant slashes. -
build
Returns the normalized path without changing the accumulated fragments. Dot segments are resolved, duplicate slashes are collapsed, and trailing slashes are removed except for the root path.- Returns:
- the normalized absolute path
- Throws:
IllegalArgumentException- if the path cannot be normalized, for example because it traverses above root- Since:
- 1.3.0
-