Class SlingFunctions


  • public class SlingFunctions
    extends java.lang.Object
    Class containing the TagLib Functions for Sling.
    • Constructor Summary

      Constructors 
      Constructor Description
      SlingFunctions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object adaptTo​(Adaptable adaptable, java.lang.String adapter)
      Adapt the adaptable to the adapter class.
      static java.lang.String encode​(java.lang.String value, java.lang.String mode)
      XSS encodes the specified text using the specified mode.
      static java.util.Iterator<Resource> findResources​(ResourceResolver resourceResolver, java.lang.String query, java.lang.String language)
      Searches for resources using the given query formulated in the given language.
      static Resource getAbsoluteParent​(Resource current, java.lang.String level)
      Method for retrieving an absolute parent resource.
      static Resource getCAConfigResource​(Resource resource, java.lang.String bucket, java.lang.String name)
      Method for retrieving the CA Config resource for a specified resource
      static java.util.Iterator<Resource> getCAConfigResources​(Resource resource, java.lang.String bucket, java.lang.String name)
      Method for retrieving the CA Config resources for a specified resource
      static java.util.Iterator<Resource> getParents​(Resource current, java.lang.String startDepth)
      Function for retrieving all of the parent resources of a specified resource, returning them in hierarchy order.
      static Resource getRelativeResource​(Resource base, java.lang.String path)
      Gets the resource at the relative path to the provided resource.
      static Resource getResource​(ResourceResolver resolver, java.lang.String path)
      Method allow for the retrieval of resources.
      static <E> E getValue​(ValueMap properties, java.lang.String key, java.lang.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.
      static boolean hasChildren​(Resource resource)
      Method for checking whether or not a resource has child resources.
      static java.util.Iterator<Resource> listChildren​(Resource resource)
      Method for allowing the invocation of the Sling Resource listChildren method.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SlingFunctions

        public SlingFunctions()
    • Method Detail

      • adaptTo

        public static java.lang.Object adaptTo​(Adaptable adaptable,
                                               java.lang.String adapter)
                                        throws java.lang.ClassNotFoundException
        Adapt the adaptable to the adapter class.
        Parameters:
        adaptable - the adaptable instance
        adapter - the class to which to adapt the adaptable
        Returns:
        the adapted class instance
        Throws:
        java.lang.ClassNotFoundException - the adapter class was not found by the Classloader
      • encode

        public static java.lang.String encode​(java.lang.String value,
                                              java.lang.String mode)
        XSS encodes the specified text using the specified mode.
        Parameters:
        value - The text to encode
        mode - The XSS mode to use, see XSSSupport for the list of available modes
        Returns:
        the encoded text
      • findResources

        public static java.util.Iterator<Resource> findResources​(ResourceResolver resourceResolver,
                                                                 java.lang.String query,
                                                                 java.lang.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 query
        query - 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 Resource getAbsoluteParent​(Resource current,
                                                       java.lang.String level)
        Method for retrieving an absolute parent resource.
        Parameters:
        current - the current resource
        level - the absolute level for the parent resource to retrieve
        Returns:
        the parent resource at the level
      • getCAConfigResource

        public static final Resource getCAConfigResource​(Resource resource,
                                                         java.lang.String bucket,
                                                         java.lang.String name)
        Method for retrieving the CA Config resource for a specified resource
        Parameters:
        resource - the resource for which to retrieve the CA Config resource
        bucket - the bucket name of the configuration to retrieve
        name - the configuration name to retrieve
        Returns:
        the config resource
      • getCAConfigResources

        public static final java.util.Iterator<Resource> getCAConfigResources​(Resource resource,
                                                                              java.lang.String bucket,
                                                                              java.lang.String name)
        Method for retrieving the CA Config resources for a specified resource
        Parameters:
        resource - the resource for which to retrieve the CA Config resources
        bucket - the bucket name of the configuration to retrieve
        name - the configuration name to retrieve
        Returns:
        the config resources
      • getParents

        public static final java.util.Iterator<Resource> getParents​(Resource current,
                                                                    java.lang.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 parents
        startDepth - 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 Resource getRelativeResource​(Resource base,
                                                   java.lang.String path)
        Gets the resource at the relative path to the provided resource.
        Parameters:
        base - the resource relative to which to find the path
        path - the relative path at which to find the resource
        Returns:
        the resource
      • getResource

        public static final Resource getResource​(ResourceResolver resolver,
                                                 java.lang.String path)
        Method allow for the retrieval of resources.
        Parameters:
        resolver - the current resource resolver
        path - the path of the resource to retrieve
        Returns:
        the resource at the path or null
      • getValue

        public static final <E> E getValue​(ValueMap properties,
                                           java.lang.String key,
                                           java.lang.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 value
        key - the key for the value to retrieve
        defaultOrType - 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​(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 java.util.Iterator<Resource> listChildren​(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()