Class SlingFunctions
java.lang.Object
org.apache.sling.scripting.jsp.taglib.SlingFunctions
Class containing the TagLib Functions for Sling.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Adapt the adaptable to the adapter class.static String
XSS encodes the specified text using the specified mode.static Iterator<org.apache.sling.api.resource.Resource>
findResources
(org.apache.sling.api.resource.ResourceResolver resourceResolver, String query, String language) Searches for resources using the given query formulated in the given language.static final org.apache.sling.api.resource.Resource
getAbsoluteParent
(org.apache.sling.api.resource.Resource current, String level) Method for retrieving an absolute parent resource.static final org.apache.sling.api.resource.Resource
getCAConfigResource
(org.apache.sling.api.resource.Resource resource, String bucket, String name) Method for retrieving the CA Config resource for a specified resourcestatic final Iterator<org.apache.sling.api.resource.Resource>
getCAConfigResources
(org.apache.sling.api.resource.Resource resource, String bucket, String name) Method for retrieving the CA Config resources for a specified resourcestatic final Iterator<org.apache.sling.api.resource.Resource>
getParents
(org.apache.sling.api.resource.Resource current, String startDepth) Function for retrieving all of the parent resources of a specified resource, returning them in hierarchy order.static org.apache.sling.api.resource.Resource
getRelativeResource
(org.apache.sling.api.resource.Resource base, String path) Gets the resource at the relative path to the provided resource.static final org.apache.sling.api.resource.Resource
getResource
(org.apache.sling.api.resource.ResourceResolver resolver, String path) Method allow for the retrieval of resources.protected static final org.apache.sling.api.resource.ResourceResolver
getResourceResolver
(javax.servlet.jsp.PageContext pageContext) Method for retrieving the ResourceResolver from the page context.static final <E> E
Gets the value of the specified key from the ValueMap and either coerses the value into the specified type or uses the specified type as a default depending on the parameter passed in.static final boolean
hasChildren
(org.apache.sling.api.resource.Resource resource) Method for checking whether or not a resource has child resources.static final Iterator<org.apache.sling.api.resource.Resource>
listChildren
(org.apache.sling.api.resource.Resource resource) Method for allowing the invocation of the Sling Resource listChildren method.
-
Constructor Details
-
SlingFunctions
public SlingFunctions()
-
-
Method Details
-
adaptTo
public static Object adaptTo(org.apache.sling.api.adapter.Adaptable adaptable, String adapter) throws ClassNotFoundException Adapt the adaptable to the adapter class.- Parameters:
adaptable
- the adaptable instanceadapter
- the class to which to adapt the adaptable- Returns:
- the adapted class instance
- Throws:
ClassNotFoundException
- the adapter class was not found by the Classloader
-
encode
XSS encodes the specified text using the specified mode.- Parameters:
value
- The text to encodemode
- The XSS mode to use, see XSSSupport for the list of available modes- Returns:
- the encoded text
-
findResources
public static Iterator<org.apache.sling.api.resource.Resource> findResources(org.apache.sling.api.resource.ResourceResolver resourceResolver, String query, String language) Searches for resources using the given query formulated in the given language.- Parameters:
resourceResolver
- the resource resolver to use to find resources with the specified queryquery
- The query string to use to find the resources.language
- The language in which the query is formulated.- Returns:
- An Iterator of Resource objects matching the query.
-
getAbsoluteParent
public static final org.apache.sling.api.resource.Resource getAbsoluteParent(org.apache.sling.api.resource.Resource current, String level) Method for retrieving an absolute parent resource.- Parameters:
current
- the current resourcelevel
- the absolute level for the parent resource to retrieve- Returns:
- the parent resource at the level
-
getCAConfigResource
public static final org.apache.sling.api.resource.Resource getCAConfigResource(org.apache.sling.api.resource.Resource resource, String bucket, String name) Method for retrieving the CA Config resource for a specified resource- Parameters:
resource
- the resource for which to retrieve the CA Config resourcebucket
- the bucket name of the configuration to retrievename
- the configuration name to retrieve- Returns:
- the config resource
-
getCAConfigResources
public static final Iterator<org.apache.sling.api.resource.Resource> getCAConfigResources(org.apache.sling.api.resource.Resource resource, String bucket, String name) Method for retrieving the CA Config resources for a specified resource- Parameters:
resource
- the resource for which to retrieve the CA Config resourcesbucket
- the bucket name of the configuration to retrievename
- the configuration name to retrieve- Returns:
- the config resources
-
getParents
public static final Iterator<org.apache.sling.api.resource.Resource> getParents(org.apache.sling.api.resource.Resource current, String startDepth) Function for retrieving all of the parent resources of a specified resource, returning them in hierarchy order.- Parameters:
current
- the current resource for which to retrieve the parentsstartDepth
- The depth at which to start, for example given a path of: /content/page1/page2/page3 and a start depth of 3, the parents page2/page3 would be returned- Returns:
- an iterator of the parent resources in order
-
getRelativeResource
public static org.apache.sling.api.resource.Resource getRelativeResource(org.apache.sling.api.resource.Resource base, String path) Gets the resource at the relative path to the provided resource.- Parameters:
base
- the resource relative to which to find the pathpath
- the relative path at which to find the resource- Returns:
- the resource
-
getResource
public static final org.apache.sling.api.resource.Resource getResource(org.apache.sling.api.resource.ResourceResolver resolver, String path) Method allow for the retrieval of resources.- Parameters:
resolver
- the current resource resolverpath
- the path of the resource to retrieve- Returns:
- the resource at the path or null
-
getResourceResolver
protected static final org.apache.sling.api.resource.ResourceResolver getResourceResolver(javax.servlet.jsp.PageContext pageContext) Method for retrieving the ResourceResolver from the page context.- Returns:
- the resource resolver
-
getValue
public static final <E> E getValue(org.apache.sling.api.resource.ValueMap properties, String key, Object defaultOrType) Gets the value of the specified key from the ValueMap and either coerses the value into the specified type or uses the specified type as a default depending on the parameter passed in.- Parameters:
properties
- the ValueMap from which to retrieve the valuekey
- the key for the value to retrievedefaultOrType
- either the default value or the class to which to coerce the value- Returns:
- the value for the specified key or the default
-
hasChildren
public static final boolean hasChildren(org.apache.sling.api.resource.Resource resource) Method for checking whether or not a resource has child resources.- Parameters:
resource
- the resource to check for child resources- Returns:
- true if the resource has child resources, false otherwise
- Since:
- 2.2.2
-
listChildren
public static final Iterator<org.apache.sling.api.resource.Resource> listChildren(org.apache.sling.api.resource.Resource resource) Method for allowing the invocation of the Sling Resource listChildren method.- Parameters:
resource
- the resource of which to list the children- Returns:
- the children of the resource
- See Also:
-
Resource.listChildren()
-