Class IconTag

  • All Implemented Interfaces:
    ConditionalTag, org.apache.commons.jelly.Tag

    public class IconTag
    extends FormBaseTag

    A tag for adding an icon to a component.

    This tag supports multiple ways for defining an icon:

    • By specifying an URL using the url attribute.
    • By specifying a resource name using the resource attribute. In this case the icon is searched on the class path. Per default, the current default class loader is used for resolving the resource name. If a different class loader is desired, its name (as registered at the current ClassLoaderProvider) can be specified using the resourceLoader attribute.
    • By specifying an arbitrary Locator pointing to the icon data using the locator attribute. This is actually the generic form of the ways described above. The locator is looked up by its name in the current bean context.
    • With the ref attribute an icon can be referenced that has already been created and stored in the Jelly context (e.g by another icon tag that had a var attribute (see below).
    Exactly one of these attributes must be present.

    The icon is created using the component manager. Then the tag searches for an enclosing tag that implements the IconSupport interface. If one is found, this tag is passed the icon. With the var attribute the name of a variable can be specified, which is assigned the icon. So it can be reused. At least one of the ways for storing an icon (the var attribute or an IconSupport tag) must be defined, otherwise an exception is thrown.

    Version:
    $Id: IconTag.java 211 2012-07-10 19:49:13Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • IconTag

        public IconTag()
    • Method Detail

      • getResource

        public String getResource()
        Returns the resource name of the icon.
        Returns:
        the resource name
      • setResource

        public void setResource​(String resource)
        Setter method for the resource attribute. Specifies the name under which the icon can be found on the classpath. Either this resource name or an URL must be specified.
        Parameters:
        resource - the resource name
      • getResourceLoader

        public String getResourceLoader()
        Returns the name of the class loader for resolving the resource name.
        Returns:
        the name of the class loader
        Since:
        1.2
      • setResourceLoader

        public void setResourceLoader​(String resourceLoader)
        Setter method for the resourceLoader attribute. Here the name of a class loader for resolving the resource name can be provided. A class loader with this name is looked up using the current ClassLoaderProvider. If no class loader has been specified, the default one is used.
        Parameters:
        resourceLoader - the name of the class loader for resolving class path resources
        Since:
        1.2
      • getUrl

        public String getUrl()
        Returns the URL that points to the icon.
        Returns:
        the URL
      • setUrl

        public void setUrl​(String url)
        Setter method for the URL attribute. Specifies an URL from which the icon can be loaded. Either this URL or a resource name must be specified.
        Parameters:
        url - the URL
      • getRef

        public String getRef()
        Returns the name of the variable that stores the icon.
        Returns:
        the name of a variable reference
      • setRef

        public void setRef​(String ref)
        Setter method for the var attribute. If no URL or resource name are specified, the icon can be obtained from a variable.
        Parameters:
        ref - the attribute's value
      • getVar

        public String getVar()
        Returns the name of the variable, to which the icon should be assigned.
        Returns:
        the name of a target variable
      • setVar

        public void setVar​(String var)
        Setter method of the var attribute.
        Parameters:
        var - the attribute's value
      • getLocator

        public String getLocator()
        Returns the name of the Locator, from which the icon should be obtained.
        Returns:
        the name of the Locator
      • setLocator

        public void setLocator​(String locator)
        Setter method of the locator attribute. With this attribute an arbitrary Locator can be specified, from which the icon data is loaded. The locator is looked up in the current bean context under the name specified here.
        Parameters:
        locator - the name of Locator with the icon data
      • process

        protected void process()
                        throws org.apache.commons.jelly.JellyTagException,
                               FormBuilderException
        Executes this tag. Tries to create the icon and set it on an enclosing IconSupport tag.
        Specified by:
        process in class FormBaseTag
        Throws:
        org.apache.commons.jelly.JellyTagException - if an error occurs
        FormBuilderException - if an error occurs
      • createIcon

        protected Object createIcon()
                             throws FormBuilderException
        Creates the icon. This method is called after all syntactic checks were successful. Here the icon must be created, depending on the defined attributes.
        Returns:
        the icon
        Throws:
        FormBuilderException - if an error occurs
      • fetchLocator

        protected Locator fetchLocator()
        Fetches the locator for the icon. This method is called by createIcon() when no reference attribute is specified, i.e. the icon has to be obtained from a locator. If the locator attribute is specified, the locator is looked up from the current bean context. Otherwise a locator is created from the other convenience attributes ( url or resource).
        Returns:
        the Locator that defines the icon