Class SlingFunctions


  • public class SlingFunctions
    extends Object
    Class containing the TagLib Functions for Sling.
    • Constructor Detail

      • SlingFunctions

        public SlingFunctions()
    • Method Detail

      • adaptTo

        public static Object adaptTo​(Adaptable adaptable,
                                     String adapter)
                              throws 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:
        ClassNotFoundException - the adapter class was not found by the Classloader
      • encode

        public static String encode​(String value,
                                    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 Iterator<Resource> findResources​(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 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,
                                                       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,
                                                         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 resource
        bucket - the bucket name of the configuration to retrieve
        name - the configuration name to retrieve
        Returns:
        the config resource
      • getCAConfigResources

        public static final Iterator<Resource> getCAConfigResources​(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 resources
        bucket - the bucket name of the configuration to retrieve
        name - the configuration name to retrieve
        Returns:
        the config resources
      • getParents

        public static final Iterator<Resource> getParents​(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 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,
                                                   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,
                                                 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,
                                           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 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 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()