Class ClientlibLink


  • public class ClientlibLink
    extends Object
    Represents data for linking to an actually referred file / client library / category of client libraries.

    Since this is kept alive during the processing of the request by RendererContext and we don't want to keep references to the corresponding Sling Resources around for longer than needed, this does not contain a reference to the resource, just the path. In the case of files this however means that we have already to put in the correct minified selector according to RendererContext.useMinifiedFiles(), since there might or might not be a minified or unminified sibling and we don't want to re-resolve the Resource to determine this. To make things consistent, we do this always.

    • Field Detail

      • LINK_PROPERTIES

        public static final String[] LINK_PROPERTIES
        List of supported additional properties for links etc.
      • path

        public final String path
        Full path to the resource, the category if this refers to category, or an external URI.
      • hash

        public final String hash
        An optional hash that is encoded in the URL to ensure that each change of a resource will lead to a new URL avoiding caching problems. Used only on Clientlibs / categories since external URLs and file URLs don't support the used format.
    • Constructor Detail

      • ClientlibLink

        protected ClientlibLink​(Clientlib.Type type,
                                ClientlibLink.Kind kind,
                                String path,
                                Map<String,​String> properties,
                                String hash)
        Creates a new link.
        Parameters:
        type - the type of the linked resource - js, css, ...
        kind - the kind of linked resource - clientlib, file, ...
        path - the path / category name / url to the linked resource
        properties - additional properties used in rendering
        hash - optional hash for the resource to be encoded in the URL for clientlibs / - categories.
      • ClientlibLink

        public ClientlibLink​(Clientlib.Type type,
                             ClientlibLink.Kind kind,
                             String path,
                             Map<String,​String> properties)
        Creates a new link.
        Parameters:
        type - the type of the linked resource - js, css, ...
        kind - the kind of linked resource - clientlib, file, ...
        path - the path / category name / url to the linked resource
        properties - additional properties used in rendering
    • Method Detail

      • withHash

        public ClientlibLink withHash​(String newHash)
        Creates a new link with parameters as this except hash.
        Parameters:
        newHash - new nullable hash for the resource to be encoded in the URL for clientlibs / - categories.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getUrl

        public String getUrl​(org.apache.sling.api.SlingHttpServletRequest request,
                             RendererContext context)
        Determines the URL we render into the page. We don't want to access resources here, so at least for files we need already to know the exact path with .min or not.

        Cases:

        Parameters:
        request - the request
        context - the context
        Returns:
        the url