Class ResourceTag

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

    public class ResourceTag
    extends org.apache.commons.jelly.TagSupport

    A tag for resolving resources on the class path and creating corresponding URI strings.

    Sometimes an application ships with data like properties files, style sheets, etc., which is stored on the class path. Per default, such data is resolved using the getResource() method of ClassLoader. In environments with complex class loader structures, it is not trivial to get the correct class loader; for this purpose, JGUIraffe defines the ClassLoaderProvider interface. With this tag it is possible to shield application code from the mechanism of resolving a resource with the correct class loader. The idea is to use this tag to do the resolving and store the resulting URL string in a Jelly variable. This variable can then be used when declaring a bean as constructor argument or property. Thus, beans get initialized with correctly resolved URLs without having to no the details of this process.

    In its most simple form this tag is passed a resource name and the name of the target variable:

     <di:resource resource="myResource" var="url"/>
     

    It is also possible to specify the class loader to be used for the resolving operation by its name:

     <di:resource resource="myResource" classLoader="myLoader"
         var="url" />
     

    A single variable can be used as target for multiple resolve operations. In this case, the URL strings are concatenated with a configurable delimiter string. The example below shows how two resources a resolved resulting in a string with their corresponding URLs using a comma as delimiter:

     <di:resource resource="myResource1" var="url"
       delimiter=","/>
     <di:resource resource="myResource2" var="url"
       delimiter=","/>
     

    The following attributes are supported:

    Attribute Description Optional
    resource The name of the resource to be resolved on the class path. If this resource cannot be resolved, the tag throws an exception. No
    var The name of the variable in the Jelly context which stores the result, i.e. the resolved URI string. This variable is overwritten if it exists unless the delimiter attribute is used (see below). No
    classLoader The name of the class loader to be used for resolving the resource name. Yes
    delimiter When using this attribute multiple resolve operations use the same output variable. If the specified variable does not have a value yet, it is assigned the resolved URI string. Otherwise, the URI string is added to the variable using the delimiter string defined here. Yes

    Since:
    1.3
    Version:
    $Id$
    Author:
    Oliver Heger
    • Field Summary

      • Fields inherited from class org.apache.commons.jelly.TagSupport

        body, context, hasTrimmed, parent, shouldTrim
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceTag()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void doTag​(org.apache.commons.jelly.XMLOutput output)
      This implementation contains the actual logic of this tag.
      String getClassLoader()
      Returns the name of the class loader to be used for resolving the resource.
      String getDelimiter()
      Returns the delimiter to be used for concatenating the results of multiple resolve operations.
      String getResource()
      Returns the name of the resource to be resolved.
      String getVar()
      Returns the name of the target variable.
      void setClassLoader​(String classLoader)
      Set method for the classLoader attribute.
      void setDelimiter​(String delimiter)
      Set method for the delimiter attribute.
      void setResource​(String resource)
      Set method for the resource attribute.
      void setVar​(String var)
      Set method for the var attribute.
      • Methods inherited from class org.apache.commons.jelly.TagSupport

        findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
    • Constructor Detail

      • ResourceTag

        public ResourceTag()
    • Method Detail

      • setResource

        public void setResource​(String resource)
        Set method for the resource attribute.
        Parameters:
        resource - the resource name
      • getResource

        public String getResource()
        Returns the name of the resource to be resolved.
        Returns:
        the resource name
      • setVar

        public void setVar​(String var)
        Set method for the var attribute.
        Parameters:
        var - the name of the target variable
      • getVar

        public String getVar()
        Returns the name of the target variable.
        Returns:
        the name of the target variable
      • setClassLoader

        public void setClassLoader​(String classLoader)
        Set method for the classLoader attribute.
        Parameters:
        classLoader - the name of the class loader to be used
      • getClassLoader

        public String getClassLoader()
        Returns the name of the class loader to be used for resolving the resource.
        Returns:
        the class loader name
      • setDelimiter

        public void setDelimiter​(String delimiter)
        Set method for the delimiter attribute.
        Parameters:
        delimiter - the delimiter
      • getDelimiter

        public String getDelimiter()
        Returns the delimiter to be used for concatenating the results of multiple resolve operations.
        Returns:
        the delimiter
      • doTag

        public void doTag​(org.apache.commons.jelly.XMLOutput output)
                   throws org.apache.commons.jelly.JellyTagException
        This implementation contains the actual logic of this tag.
        Throws:
        org.apache.commons.jelly.JellyTagException