Package com.day.cq.commons
Class DownloadResource
java.lang.Object
org.apache.sling.api.resource.ResourceWrapper
com.day.cq.commons.DownloadResource
- Direct Known Subclasses:
Download,ImageResource
Provides convenience methods for rendering download paragraphs.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringname of the file node.static final Stringname of the description propertystatic final Stringname of the 'file name' property.static final Stringname of the file reference property.static final Stringname of the title property.Fields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING -
Constructor Summary
ConstructorsConstructorDescriptionDownloadResource(Resource resource) Creates a new download based on the given resource. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(String name, String value) Adds a tag attribute to this download.voidaddCssClass(String name) Adds a CSS class name to the respective attribute.voidaddQueryParam(String name, String value) Adds a query param to the 'query' attributevoidWrites this download as link tag to the given writerGet a property either from the overlaid map or the underlying properties.intGet a property and convert it to an integer.Returns a map of attributes.getData()Returns the property that contains the binary data of this download.Returns the image description as defined by getItemName(PN_DESCRIPTION) or overridden bysetDescription(String).getDescription(boolean escape) Returns the image description as defined by 'getItemName(PN_DESCRIPTION)' or overridden bysetDescription(String).Returns the extension.Returns the file name of this download as defined by the property with the name from 'getItemName(PN_FILE_NAME).Returns the file path.Returns the file reference.getHref()Returns the href attribute of this download.Deprecated.since 5.4 please use css classes for the icon, like "icon_xls.gif"Returns the icon type of this file.Returns the inner html object for the download link.getItemName(String name) Returns the name of the given item which is either the default or can be redefined bysetItemName(String, String).Returns the last modified of this image.Returns the mime type of this image.getQuery()Gets the query attributeReturns the selector string.Returns a string representation as HTML tag of this image.Returns the suffix.getTitle()Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden bysetTitle(String).getTitle(boolean escape) Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden bysetTitle(String).booleanChecks if this download has content.voidinit()Calculates all default values if 'source' isnullbooleanReturns if page is in UI Touch mode?voidSet a property to the overlaid map.voidsetDescription(String description) Sets the description.voidsetExtension(String extension) Sets the extension.voidsetFileName(String fileName) Sets the file name.voidsetFileNodePath(String fileNodePath) Sets the path to the file node.voidsetFileReference(String fileReference) Sets the file reference.voidSets the href attributevoidsetInnerHtml(Object innerHtml) Sets the inner html object for the download.voidsetIsInUITouchMode(boolean inUITouchMode) Page is in UI Touch mode?voidsetItemName(String key, String name) Defines the name of an item.voidSets the query attribute, overwrites any previously generated queries.voidsetSelector(String selector) Sets the selector string.voidSets the suffix.voidSets the title.Methods inherited from class org.apache.sling.api.resource.ResourceWrapper
adaptTo, getChild, getChildren, getName, getParent, getPath, getResource, getResourceMetadata, getResourceResolver, getResourceSuperType, getResourceType, getValueMap, hasChildren, isResourceType, listChildren, toString
-
Field Details
-
PN_REFERENCE
name of the file reference property. this can hold a path to a file or resource node, to a binary property or a uuid to a resource node.- See Also:
-
NN_FILE
name of the file node.- See Also:
-
PN_FILE_NAME
name of the 'file name' property.- See Also:
-
PN_TITLE
name of the title property.- See Also:
-
PN_DESCRIPTION
name of the description property- See Also:
-
-
Constructor Details
-
DownloadResource
Creates a new download based on the given resource. the file properties are considered to be 'on' the given resource.- Parameters:
resource- resource of the image- Throws:
IllegalArgumentException- if the given resource is not adaptable to node.
-
-
Method Details
-
isTouchAuthoringUIMode
public boolean isTouchAuthoringUIMode()Returns if page is in UI Touch mode?- Returns:
- if page is in UI Touch mode
-
setIsInUITouchMode
public void setIsInUITouchMode(boolean inUITouchMode) Page is in UI Touch mode?- Parameters:
inUITouchMode- value to set
-
get
Get a property either from the overlaid map or the underlying properties.- Parameters:
name- name of the property- Returns:
- string value of the property or an empty string
-
get
Get a property and convert it to an integer. If any exception occurs, return the default value.- Parameters:
name- name of the propertydefaultValue- default value- Returns:
- integer value
-
set
Set a property to the overlaid map.- Parameters:
name- name of the propertyvalue- value of the property
-
addAttribute
Adds a tag attribute to this download. The attributes are included whendrawingthe tag.- Parameters:
name- name of the attributevalue- value of the attribute
-
addCssClass
Adds a CSS class name to the respective attribute. If the class name is already present, nothing is added.- Parameters:
name- the class name
-
init
public void init()Calculates all default values if 'source' isnull -
getItemName
Returns the name of the given item which is either the default or can be redefined bysetItemName(String, String). If the name is not defined, the given name is returned. Example: Download.getItemName(Download.PN_FILE_NAME)- Parameters:
name- item name- Returns:
- defined item name
-
setItemName
Defines the name of an item.- Parameters:
key- key. egPN_FILE_NAME.name- redefined name
-
getFileReference
Returns the file reference.- Returns:
- the file reference.
-
setFileReference
Sets the file reference.- Parameters:
fileReference- the file reference.
-
getInnerHtml
Returns the inner html object for the download link.- Returns:
- the inner html or
nullif not defined.
-
setInnerHtml
Sets the inner html object for the download. If not inner html is defined the file name is used when drawing the download link.- Parameters:
innerHtml- the inner html object
-
getFileNodePath
Returns the file path. This defaults to the path of the node addressed by 'getItemName(NN_FILE)' or an empty string if that node does not exist.- Returns:
- path of the file node.
-
setFileNodePath
Sets the path to the file node. Set this to an empty string to disable fetching data from the respective node. the path can be relative to address a node relative to the image node.- Parameters:
fileNodePath- path of the file node.
-
getFileName
Returns the file name of this download as defined by the property with the name from 'getItemName(PN_FILE_NAME). this is an informative property and is not used for any logic. the file name is added per default as suffix to the link path.- Returns:
- file name.
-
setFileName
Sets the file name.- Parameters:
fileName- the file name
-
getTitle
Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden bysetTitle(String).- Returns:
- the title
-
getTitle
Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden bysetTitle(String).- Parameters:
escape- iftruethe string is HTML escaped- Returns:
- the title
-
setTitle
Sets the title.- Parameters:
title- the title.
-
getDescription
Returns the image description as defined by getItemName(PN_DESCRIPTION) or overridden bysetDescription(String).- Returns:
- the description
-
getDescription
Returns the image description as defined by 'getItemName(PN_DESCRIPTION)' or overridden bysetDescription(String).- Parameters:
escape- iftruethe string is HTML escaped- Returns:
- the description
-
setDescription
Sets the description.- Parameters:
description- the description.
-
getHref
Returns the href attribute of this download. the source is computed as follows:- if a selector is defined the path of the current resource concatenated with the selector, extension, and suffix is used.
- if a file node path is defined it is concatenated with the extension and suffix.
- if a file reference is defined it is concatenated with the suffix.
- Returns:
- the href attribute
-
setHref
Sets the href attribute- Parameters:
href- the href attribute
-
getQuery
Gets the query attribute- Returns:
- the query
-
setQuery
Sets the query attribute, overwrites any previously generated queries.- Parameters:
query- the query
-
addQueryParam
Adds a query param to the 'query' attribute- Parameters:
name- name of the paramvalue- value of the param
-
getExtension
Returns the extension. defaults to.res- Returns:
- the extension.
-
setExtension
Sets the extension.- Parameters:
extension- the extension.
-
getIconType
Returns the icon type of this file. Note: currently the mime type of the file is not respected but only the extension of the file name is used.- Returns:
- the icon type.
-
getIconPath
Deprecated.since 5.4 please use css classes for the icon, like "icon_xls.gif"Returns a path to an icon representing the file.- Returns:
- a path to an icon or
null.
-
getSuffix
Returns the suffix. defaults to""- Returns:
- the suffix.
-
setSuffix
Sets the suffix.- Parameters:
suffix- the suffix.
-
getSelector
Returns the selector string. defaults to an empty string. Note: in order to use a spool script, you need to defined the selector, otherwise the file will be addressed directly.- Returns:
- the selector string.
-
setSelector
Sets the selector string.- Parameters:
selector- the selector string.
-
hasContent
public boolean hasContent()Checks if this download has content. i.e. if there either an file or an file reference defined and they have binary data.- Returns:
trueif this download has content.
-
draw
Writes this download as link tag to the given writer- Parameters:
w- the writer- Throws:
IOException- if an I/O error occurs
-
getString
Returns a string representation as HTML tag of this image.- Returns:
- the HTML tag.
-
getMimeType
Returns the mime type of this image. This is a convenience method that gets the "jcr:mimeType" sibling property of the data property returned bygetData().- Returns:
- the mime type of the image or
nullif the image has no content. - Throws:
RepositoryException- if an error accessing the repository occurs.
-
getLastModified
Returns the last modified of this image. This is a convenience method that gets the "jcr:lastModified" sibling property of the data property returned bygetData().- Returns:
- the last modified of the image or
nullif the image has no content. - Throws:
RepositoryException- if an error accessing the repository occurs.
-
getData
Returns the property that contains the binary data of this download. This can either by a property addressed by the internal file resource or a property addressed by an external file reference.- Returns:
- binary property or
null - Throws:
RepositoryException- if an error accessing the repository occurs.
-
getAttributes
Returns a map of attributes.- Returns:
- the attributes map.
-