Class ClientlibLink
- java.lang.Object
-
- com.composum.sling.clientlibs.handle.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 toRendererContext.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClientlibLink.Kind
The kind of resource we link to:ClientlibLink.Kind.CATEGORY
,ClientlibLink.Kind.CLIENTLIB
,ClientlibLink.Kind.FILE
,ClientlibLink.Kind.EXTERNALURI
.
-
Field Summary
Fields Modifier and Type Field Description 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.ClientlibLink.Kind
kind
Kind ofClientlibElement
this was created for.static String[]
LINK_PROPERTIES
List of supported additional properties for links etc.String
path
Full path to the resource, the category if this refers to category, or an external URI.static String
PROP_REL
Name of the additional property to set the link relation in case ofClientlib.Type.link
orClientlib.Type.img
.Map<String,String>
properties
Additional properties, e.g.Clientlib.Type
type
Resource-type of the link.
-
Constructor Summary
Constructors Modifier Constructor Description ClientlibLink(Clientlib.Type type, ClientlibLink.Kind kind, String path, Map<String,String> properties)
Creates a new link.protected
ClientlibLink(Clientlib.Type type, ClientlibLink.Kind kind, String path, Map<String,String> properties, String hash)
Creates a new link.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
static ClientlibLink
forCategory(Clientlib.Type type, String category)
String
getUrl(org.apache.sling.api.SlingHttpServletRequest request, RendererContext context)
Determines the URL we render into the page.int
hashCode()
String
toString()
ClientlibLink
withHash(String newHash)
Creates a new link with parameters as this except hash.
-
-
-
Field Detail
-
PROP_REL
public static final String PROP_REL
Name of the additional property to set the link relation in case ofClientlib.Type.link
orClientlib.Type.img
.- See Also:
- Constant Field Values
-
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.
-
type
public final Clientlib.Type type
Resource-type of the link.
-
kind
public final ClientlibLink.Kind kind
Kind ofClientlibElement
this was created for.
-
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 resourceproperties
- additional properties used in renderinghash
- 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 resourceproperties
- 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.
-
forCategory
public static ClientlibLink forCategory(Clientlib.Type type, String category)
-
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:
- Clientlib category: refers to the
ClientlibCategoryServlet
, parameterized by type and minified according toRendererContext.useMinifiedFiles()
. - Clientlib: path to the client library plus minified and type.
- File:
- Parameters:
request
- the requestcontext
- the context- Returns:
- the url
- Clientlib category: refers to the
-
-