Package com.day.cq.commons
Class PathInfo
- java.lang.Object
-
- com.day.cq.commons.PathInfo
-
- All Implemented Interfaces:
RequestPathInfo
public class PathInfo extends java.lang.Object implements RequestPathInfo
Utility class for creating a slingRequestPathInfoby parsing a URL path. Note that this does not check for the existence of the resource and finding the longest-matching path as the default Sling resource resolution does, it only works by parsing the raw string.The parsing structure looks like this:
/resource/path.selector.ext/suffix. The rules are (following the Sling convention):- extension is everything between the last dot in the URL and the next slash (or the end of the string)
- suffix is everything after the extension (including the slash)
- resource path is everything from the start up to the first dot after the last slash (excluding extension and suffix)
- selectors are the dot-separated elements between the path and the extension
-
-
Constructor Summary
Constructors Constructor Description PathInfo(java.lang.String urlPath)Creates aRequestPathInfoby parsing the path part of a URL.PathInfo(ResourceResolver resolver, java.lang.String urlPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetExtension()Returns the extension from the URL ornullif the request URL does not contain an extension.java.lang.StringgetResourcePath()Return the "resource path" part of the URL, what comes before selectors, extension and suffix.java.lang.String[]getSelectors()Returns the selectors decoded from the request URL as an array of strings.java.lang.StringgetSelectorString()Returns the selectors decoded from the request URL as string.java.lang.StringgetSuffix()Returns the suffix part of the URL ornullif the request URL does not contain a suffix.ResourcegetSuffixResource()Returns the resource addressed by the suffix or null if the request does not have a suffix or the suffix does not address an accessible resource.
-
-
-
Constructor Detail
-
PathInfo
public PathInfo(java.lang.String urlPath)
Creates aRequestPathInfoby parsing the path part of a URL. This method does not support url path suffixes containing dots (".").- Parameters:
urlPath- the path part of a URL
-
PathInfo
public PathInfo(ResourceResolver resolver, java.lang.String urlPath)
Create aRequestPathInfoobject using the givenResourceResolverandurlPath. The resolver is used to map the underlying resource and reliably disassemble the urlPath into its segments.- Parameters:
resolver- The resource resolver.urlPath- The url path.
-
-
Method Detail
-
getResourcePath
public java.lang.String getResourcePath()
Description copied from interface:RequestPathInfoReturn the "resource path" part of the URL, what comes before selectors, extension and suffix. This string is part of the request URL and need not be equal to theResource.getPath(). Rather it is equal to theresolution path metadata propertyof the resource.- Specified by:
getResourcePathin interfaceRequestPathInfo- Returns:
- The resource path
-
getSelectorString
public java.lang.String getSelectorString()
Description copied from interface:RequestPathInfoReturns the selectors decoded from the request URL as string. Returnsnullif the request has no selectors.Decomposition of the request URL is defined in the Decomposition of a Request URL above.
- Specified by:
getSelectorStringin interfaceRequestPathInfo- Returns:
- The selector string or
null - See Also:
RequestPathInfo.getSelectors()
-
getSelectors
public java.lang.String[] getSelectors()
Description copied from interface:RequestPathInfoReturns the selectors decoded from the request URL as an array of strings. This array is derived from theselector stringby splitting the string on dots. Returns an empty array if the request has no selectors.Decomposition of the request URL is defined in the Decomposition of a Request URL above.
- Specified by:
getSelectorsin interfaceRequestPathInfo- Returns:
- An array of selectors
- See Also:
RequestPathInfo.getSelectorString()
-
getExtension
public java.lang.String getExtension()
Description copied from interface:RequestPathInfoReturns the extension from the URL ornullif the request URL does not contain an extension.Decomposition of the request URL is defined in the Decomposition of a Request URL above.
- Specified by:
getExtensionin interfaceRequestPathInfo- Returns:
- The extension from the request URL.
-
getSuffix
public java.lang.String getSuffix()
Description copied from interface:RequestPathInfoReturns the suffix part of the URL ornullif the request URL does not contain a suffix.Decomposition of the request URL is defined in the Decomposition of a Request URL above.
- Specified by:
getSuffixin interfaceRequestPathInfo- Returns:
- The suffix part of the request URL.
-
getSuffixResource
public Resource getSuffixResource()
Description copied from interface:RequestPathInfoReturns the resource addressed by the suffix or null if the request does not have a suffix or the suffix does not address an accessible resource.The suffix is expected to be the absolute path to the resource suitable as an argument to the
ResourceResolver.getResource(String)method.- Specified by:
getSuffixResourcein interfaceRequestPathInfo- Returns:
- The suffix resource or
null.
-
-