com.day.cq.wcm.foundation
Class Download

java.lang.Object
  extended by com.day.cq.wcm.foundation.Download
Direct Known Subclasses:
Image

public class Download
extends Object

Provides convenience methods for rendering download paragraphs.


Field Summary
protected  Map<String,String> attrs
          map of tag attributes
static String NN_FILE
          name of the file node.
protected  Node node
          internal node
static String PN_DESCRIPTION
          name of the description property
static String PN_FILE_NAME
          name of the 'file name' property.
static String PN_REFERENCE
          name of the file reference property.
static String PN_TITLE
          name of the title property.
protected  org.apache.sling.api.resource.ValueMap properties
          internal properties
protected  org.apache.sling.api.resource.Resource resource
          internal resource
 
Constructor Summary
Download(org.apache.sling.api.resource.Resource resource)
          Creates a new download based on the given resource.
 
Method Summary
 void addAttribute(String name, String value)
          Adds a tag attribute to this download.
 void addCssClass(String name)
          Adds a CSS class name to the respective attribute.
 void draw(Writer w)
          Writes this download as link tag to the given writer
 String get(String name)
          Get a property either from the overlaid map or the underlying properties.
 int get(String name, int defaultValue)
          Get a property and convert it to an integer.
 Map<String,String> getAttributes()
          Returns a map of attributes.
 Property getData()
          Returns the property that contains the binary data of this download.
 String getDescription()
          Returns the image description as defined by getItemName(PN_DESCRIPTION) or overridden by setDescription(String).
 String getDescription(boolean escape)
          Returns the image description as defined by 'getItemName(PN_DESCRIPTION)' or overridden by setDescription(String).
 String getExtension()
          Returns the extension.
 String getFileName()
          Returns the file name of this download as defined by the property with the name from 'getItemName(PN_FILE_NAME).
 String getFileNodePath()
          Returns the file path.
 String getFileReference()
          Returns the file reference.
 String getHref()
          Returns the href attribute of this download.
 String getIconPath()
          Returns a path to an icon representing the file.
 String getIconType()
          Returns the icon type of this file.
 Object getInnerHtml()
          Returns the inner html object for the download link.
 String getItemName(String name)
          Returns the name of the given item which is either the default or can be redefined by setItemName(String, String).
 Calendar getLastModified()
          Returns the last modified of this image.
 String getMimeType()
          Returns the mime type of this image.
 org.apache.sling.api.resource.Resource getResource()
          Returns the underlying resource.
 String getSelector()
          Returns the selector string.
 String getString()
          Returns a string representation as HTML tag of this image.
 String getSuffix()
          Returns the suffix.
 String getTitle()
          Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden by setTitle(String).
 String getTitle(boolean escape)
          Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden by setTitle(String).
 boolean hasContent()
          Checks if this download has content.
 void init()
          Calculates all default values if 'source' is null
 void set(String name, String value)
          Set a property to the overlaid map.
 void setDescription(String description)
          Sets the description.
 void setExtension(String extension)
          Sets the extension.
 void setFileName(String fileName)
          Sets the file name.
 void setFileNodePath(String fileNodePath)
          Sets the path to the file node.
 void setFileReference(String fileReference)
          Sets the file reference.
 void setHref(String href)
          Sets the href attribute
 void setInnerHtml(Object innerHtml)
          Sets the inner html object for the download.
 void setItemName(String key, String name)
          Defines the name of an item.
 void setSelector(String selector)
          Sets the selector string.
 void setSuffix(String suffix)
          Sets the suffix.
 void setTitle(String title)
          Sets the title.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PN_REFERENCE

public static final String 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:
Constant Field Values

NN_FILE

public static final String NN_FILE
name of the file node.

See Also:
Constant Field Values

PN_FILE_NAME

public static final String PN_FILE_NAME
name of the 'file name' property.

See Also:
Constant Field Values

PN_TITLE

public static final String PN_TITLE
name of the title property.

See Also:
Constant Field Values

PN_DESCRIPTION

public static final String PN_DESCRIPTION
name of the description property

See Also:
Constant Field Values

resource

protected final org.apache.sling.api.resource.Resource resource
internal resource


properties

protected final org.apache.sling.api.resource.ValueMap properties
internal properties


node

protected final Node node
internal node


attrs

protected Map<String,String> attrs
map of tag attributes

Constructor Detail

Download

public Download(org.apache.sling.api.resource.Resource resource)
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 Detail

getResource

public org.apache.sling.api.resource.Resource getResource()
Returns the underlying resource.

Returns:
the resource

get

public String get(String name)
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

public int get(String name,
               int defaultValue)
Get a property and convert it to an integer. If any exception occurs, return the default value.

Parameters:
name - name of the property
defaultValue - default value
Returns:
integer value

set

public void set(String name,
                String value)
Set a property to the overlaid map.

Parameters:
name - name of the property
value - value of the property

addAttribute

public void addAttribute(String name,
                         String value)
Adds a tag attribute to this download. The attributes are included when drawing the tag.

Parameters:
name - name of the attribute
value - value of the attribute

addCssClass

public void addCssClass(String name)
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' is null


getItemName

public String getItemName(String name)
Returns the name of the given item which is either the default or can be redefined by setItemName(String, String). If the name is not defined, the given name is returned. Example: Donwload.getItemName(Download.PN_FILE_NAME)

Parameters:
name - item name
Returns:
defined item name

setItemName

public void setItemName(String key,
                        String name)
Defines the name of an item.

Parameters:
key - key. eg PN_FILE_NAME.
name - redefined name

getFileReference

public String getFileReference()
Returns the file reference.

Returns:
the file reference.

setFileReference

public void setFileReference(String fileReference)
Sets the file reference.

Parameters:
fileReference - the file reference.

getInnerHtml

public Object getInnerHtml()
Returns the inner html object for the download link.

Returns:
the inner html or null if not defined.

setInnerHtml

public void setInnerHtml(Object innerHtml)
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

public String 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

public void setFileNodePath(String fileNodePath)
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

public String 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

public void setFileName(String fileName)
Sets the file name.

Parameters:
fileName - the file name

getTitle

public String getTitle()
Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden by setTitle(String).

Returns:
the title

getTitle

public String getTitle(boolean escape)
Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden by setTitle(String).

Parameters:
escape - if true the string is HTML escaped
Returns:
the title

setTitle

public void setTitle(String title)
Sets the title.

Parameters:
title - the title.

getDescription

public String getDescription()
Returns the image description as defined by getItemName(PN_DESCRIPTION) or overridden by setDescription(String).

Returns:
the description

getDescription

public String getDescription(boolean escape)
Returns the image description as defined by 'getItemName(PN_DESCRIPTION)' or overridden by setDescription(String).

Parameters:
escape - if true the string is HTML escaped
Returns:
the description

setDescription

public void setDescription(String description)
Sets the description.

Parameters:
description - the description.

getHref

public String getHref()
Returns the href attribute of this download. the source is computed as follows:

Returns:
the href attribute

setHref

public void setHref(String href)
Sets the href attribute

Parameters:
href - the href attribute

getExtension

public String getExtension()
Returns the extension. defaults to .res

Returns:
the extension.

setExtension

public void setExtension(String extension)
Sets the extension.

Parameters:
extension - the extension.

getIconType

public String 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

public String getIconPath()
Returns a path to an icon representing the file.

Returns:
a path to an icon or null.

getSuffix

public String getSuffix()
Returns the suffix. defaults to ""

Returns:
the suffix.

setSuffix

public void setSuffix(String suffix)
Sets the suffix.

Parameters:
suffix - the suffix.

getSelector

public String 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

public void setSelector(String selector)
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:
true if this download has content.

draw

public void draw(Writer w)
          throws IOException
Writes this download as link tag to the given writer

Parameters:
w - the writer
Throws:
IOException - if an I/O error occurs

getString

public String getString()
Returns a string representation as HTML tag of this image.

Returns:
the HTML tag.

getMimeType

public String getMimeType()
                   throws RepositoryException
Returns the mime type of this image. This is a convenience method that gets the sibling property of the data property returned by getData().

Returns:
the mime type of the image
Throws:
RepositoryException - if an error accessing the repository occurs.

getLastModified

public Calendar getLastModified()
                         throws RepositoryException
Returns the last modified of this image. This is a convenience method that gets the sibling property of the data property returned by getData().

Returns:
the last modified of the image
Throws:
RepositoryException - if an error accessing the repository occurs.

getData

public Property getData()
                 throws RepositoryException
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

public Map<String,String> getAttributes()
Returns a map of attributes.

Returns:
the attributes map.


Copyright © 2009 Day Management AG. All Rights Reserved.