Class DownloadResource

    • Constructor Detail

      • DownloadResource

        public DownloadResource​(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

      • 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

        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: Download.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:
        • 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

        public void setHref​(String href)
        Sets the href attribute
        Parameters:
        href - the href attribute
      • getQuery

        public String getQuery()
        Gets the query attribute
        Returns:
        the query
      • setQuery

        public void setQuery​(String query)
        Sets the query attribute, overwrites any previously generated queries.
        Parameters:
        query - the query
      • addQueryParam

        public void addQueryParam​(String name,
                                  String value)
        Adds a query param to the 'query' attribute
        Parameters:
        name - name of the param
        value - value of the param
      • 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

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

        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 "jcr:mimeType" sibling property of the data property returned by getData().
        Returns:
        the mime type of the image or null if the image has no content.
        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 "jcr:lastModified" sibling property of the data property returned by getData().
        Returns:
        the last modified of the image or null if the image has no content.
        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.