org.apache.commons.jelly.impl

## Class TagScript

- java.lang.Object
- - org.apache.commons.jelly.impl.TagScript

All Implemented Interfaces:
  Script

Direct Known Subclasses:
  StaticTagScript

    public class TagScript
    extends Object
    implements Script

`TagScript` is a Script that evaluates a custom tag.

Note that this class should be re-entrant and used concurrently by multiple threads.

Version:
  $Revision: 227285 $
Author:
  James Strachan

### Field Summary

Fields
`protected Map<String,ExpressionAttribute>` `attributes` The attribute expressions that are created

### Constructor Summary

Constructors
Constructor and Description
`TagScript()`
`TagScript(TagFactory tagFactory)`

### Method Summary

Methods
`void` `addAttribute(String name, Expression expression)` Add an initialization attribute for the tag.
`void` `addAttribute(String name, String prefix, String nsURI, Expression expression)` Add an initialization attribute for the tag.
`protected void` `applyLocation(LocationAware locationAware)`
`protected void` `clearTag()` Flushes the current cached tag so that it will be created, lazily, next invocation
`Script` `compile()` Compiles the tags body
`protected void` `configureTag(Tag tag, JellyContext context)` Compiles a newly created tag if required, sets its parent and body.
`protected Object` `convertType(Object value, Class requiredType)` Converts the given value to the required type.
`protected JellyException` `createJellyException(String reason)` Creates a new Jelly exception, adorning it with location information
`protected JellyException` `createJellyException(String reason, Exception cause)` Creates a new Jelly exception, adorning it with location information
`protected Tag` `createTag()` Factory method to create a new Tag instance.
`protected void` `endNamespacePrefixes(XMLOutput output)` End the new namespace prefixes mapped for the current element
`protected Expression` `getAttribute(String name)` Retrieves the expression of the given attribute name.
`protected String` `getBodyText(JellyContext context, boolean shouldEscape)` Evaluates the body and obtains it as a string.
`int` `getColumnNumber()`
`String` `getElementName()`
`String` `getFileName()`
`int` `getLineNumber()`
`String` `getLocalName()` Returns the local, non namespaced XML name of this tag
`Map` `getNamespaceContext()` Returns the namespace context of this tag.
`String` `getNsUri()`
`TagScript` `getParent()` Returns the parent.
`Attributes` `getSaxAttributes()` Returns the SAX attributes of this tag
`URL` `getScriptURL()` Base URL from which the script (that uses this tag) is loaded.
`Tag` `getTag(JellyContext context)`
`Script` `getTagBody()` Returns the tagBody.
`TagFactory` `getTagFactory()` Returns the Factory of Tag instances.
`protected void` `handleException(Error e)` A helper method to handle this non-Jelly exception.
`protected void` `handleException(Exception e)` A helper method to handle this non-Jelly exception.
`protected void` `handleException(JellyException e)` A helper method to handle this Jelly exception.
`protected void` `handleException(JellyTagException e)` A helper method to handle this Jelly exception.
`static TagScript` `newInstance(Class tagClass)`
`void` `run(JellyContext context, XMLOutput output)` Evaluates the body of a tag
`void` `setColumnNumber(int columnNumber)` Sets the column number of the tag
`protected void` `setContextURLs(JellyContext context)` Set the context's root and current URL if not present
`void` `setElementName(String elementName)` Sets the element name which caused the problem
`void` `setFileName(String fileName)` Sets the Jelly file which caused the problem
`void` `setLineNumber(int lineNumber)` Sets the line number of the tag
`void` `setLocalName(String localName)` Sets the local, non namespaced name of this tag.
`void` `setLocator(Locator locator)` Configures this TagScript from the SAX Locator, setting the column and line numbers
`void` `setNsUri(String nsUri)`
`void` `setParent(TagScript parent)` Sets the parent.
`void` `setSaxAttributes(Attributes saxAttributes)` Sets the SAX attributes of this tag
`protected void` `setTag(Tag tag, JellyContext context)` Allows the script to set the tag instance to be used, such as in a StaticTagScript when a StaticTag is switched with a DynamicTag
`void` `setTagBody(Script tagBody)` Sets the tagBody.
`void` `setTagFactory(TagFactory tagFactory)` Sets the Factory of Tag instances.
`void` `setTagNamespacesMap(Map tagNamespacesMap)` Sets the optional namespaces prefix -> URI map of the namespaces attached to this Tag
`protected void` `startNamespacePrefixes(XMLOutput output)` Output the new namespace prefixes used for this element
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### attributes

    protected Map<String,ExpressionAttribute> attributes

The attribute expressions that are created

### Constructor Detail

#### TagScript

    public TagScript()

#### TagScript

    public TagScript(TagFactory tagFactory)

### Method Detail

#### newInstance

    public static TagScript newInstance(Class tagClass)

Returns:
  a new TagScript based on whether the given Tag class is a bean tag or DynaTag

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### compile

    public Script compile()
                   throws JellyException

Compiles the tags body

Specified by:
  `compile` in interface `Script`
Throws:
  `JellyException`

#### setTagNamespacesMap

    public void setTagNamespacesMap(Map tagNamespacesMap)

Sets the optional namespaces prefix -> URI map of the namespaces attached to this Tag

#### setLocator

    public void setLocator(Locator locator)

Configures this TagScript from the SAX Locator, setting the column and line numbers

#### addAttribute

    public void addAttribute(String name,
                    Expression expression)

Add an initialization attribute for the tag. This method must be called after the setTag() method

#### addAttribute

    public void addAttribute(String name,
                    String prefix,
                    String nsURI,
                    Expression expression)

Add an initialization attribute for the tag. This method must be called after the setTag() method

#### run

    public void run(JellyContext context,
           XMLOutput output)
             throws JellyTagException

Evaluates the body of a tag

Specified by:
  `run` in interface `Script`
Throws:
  `JellyTagException`

#### setContextURLs

    protected void setContextURLs(JellyContext context)
                           throws JellyTagException

Set the context's root and current URL if not present

Parameters:
  `context` -
Throws:
  `JellyTagException`

#### getTag

    public Tag getTag(JellyContext context)
               throws JellyException

Returns:
  the tag to be evaluated, creating it lazily if required.
Throws:
  `JellyException`

#### getTagFactory

    public TagFactory getTagFactory()

Returns the Factory of Tag instances.

Returns:
  the factory

#### setTagFactory

    public void setTagFactory(TagFactory tagFactory)

Sets the Factory of Tag instances.

Parameters:
  `tagFactory` - The factory to set

#### getParent

    public TagScript getParent()

Returns the parent.

Returns:
  TagScript

#### getTagBody

    public Script getTagBody()

Returns the tagBody.

Returns:
  Script

#### setParent

    public void setParent(TagScript parent)

Sets the parent.

Parameters:
  `parent` - The parent to set

#### setTagBody

    public void setTagBody(Script tagBody)

Sets the tagBody.

Parameters:
  `tagBody` - The tagBody to set

#### getFileName

    public String getFileName()

Returns:
  the Jelly file which caused the problem

#### setFileName

    public void setFileName(String fileName)

Sets the Jelly file which caused the problem

#### getScriptURL

    public URL getScriptURL()

Base URL from which the script (that uses this tag) is loaded. Useful fo resolving other resources/scripts that are placed side-by-side.

#### getElementName

    public String getElementName()

Returns:
  the element name which caused the problem

#### setElementName

    public void setElementName(String elementName)

Sets the element name which caused the problem

#### getLineNumber

    public int getLineNumber()

Returns:
  the line number of the tag

#### setLineNumber

    public void setLineNumber(int lineNumber)

Sets the line number of the tag

#### getColumnNumber

    public int getColumnNumber()

Returns:
  the column number of the tag

#### setColumnNumber

    public void setColumnNumber(int columnNumber)

Sets the column number of the tag

#### getSaxAttributes

    public Attributes getSaxAttributes()

Returns the SAX attributes of this tag

Returns:
  Attributes

#### setSaxAttributes

    public void setSaxAttributes(Attributes saxAttributes)

Sets the SAX attributes of this tag

Parameters:
  `saxAttributes` - The saxAttributes to set

#### getLocalName

    public String getLocalName()

Returns the local, non namespaced XML name of this tag

Returns:
  String

#### setLocalName

    public void setLocalName(String localName)

Sets the local, non namespaced name of this tag.

Parameters:
  `localName` - The localName to set

#### getNsUri

    public String getNsUri()

#### setNsUri

    public void setNsUri(String nsUri)

#### getNamespaceContext

    public Map getNamespaceContext()

Returns the namespace context of this tag. This is all the prefixes in scope in the document where this tag is used which are mapped to their namespace URIs.

Returns:
  a Map with the keys are namespace prefixes and the values are namespace URIs.

#### createTag

    protected Tag createTag()
                     throws JellyException

Factory method to create a new Tag instance. The default implementation is to delegate to the TagFactory

Throws:
  `JellyException`

#### configureTag

    protected void configureTag(Tag tag,
                    JellyContext context)
                         throws JellyException

Compiles a newly created tag if required, sets its parent and body.

Throws:
  `JellyException`

#### clearTag

    protected void clearTag()

Flushes the current cached tag so that it will be created, lazily, next invocation

#### setTag

    protected void setTag(Tag tag,
              JellyContext context)

Allows the script to set the tag instance to be used, such as in a StaticTagScript when a StaticTag is switched with a DynamicTag

#### startNamespacePrefixes

    protected void startNamespacePrefixes(XMLOutput output)
                                   throws SAXException

Output the new namespace prefixes used for this element

Throws:
  `SAXException`

#### endNamespacePrefixes

    protected void endNamespacePrefixes(XMLOutput output)
                                 throws SAXException

End the new namespace prefixes mapped for the current element

Throws:
  `SAXException`

#### convertType

    protected Object convertType(Object value,
                     Class requiredType)
                          throws JellyException

Converts the given value to the required type.

Parameters:
  `value` - is the value to be converted. This will not be null
  `requiredType` - the type that the value should be converted to
Throws:
  `JellyException`

#### createJellyException

    protected JellyException createJellyException(String reason)

Creates a new Jelly exception, adorning it with location information

#### createJellyException

    protected JellyException createJellyException(String reason,
                                      Exception cause)

Creates a new Jelly exception, adorning it with location information

#### handleException

    protected void handleException(JellyTagException e)
                            throws JellyTagException

A helper method to handle this Jelly exception. This method adorns the JellyException with location information such as adding line number information etc.

Throws:
  `JellyTagException`

#### handleException

    protected void handleException(JellyException e)
                            throws JellyTagException

A helper method to handle this Jelly exception. This method adorns the JellyException with location information such as adding line number information etc.

Throws:
  `JellyTagException`

#### applyLocation

    protected void applyLocation(LocationAware locationAware)

#### handleException

    protected void handleException(Exception e)
                            throws JellyTagException

A helper method to handle this non-Jelly exception. This method will rethrow the exception, wrapped in a JellyException while adding line number information etc.

Throws:
  `JellyTagException`

#### handleException

    protected void handleException(Error e)
                            throws Error,
                                   JellyTagException

A helper method to handle this non-Jelly exception. This method will rethrow the exception, wrapped in a JellyException while adding line number information etc. Is this method wise?

Throws:
  `Error`
  `JellyTagException`

#### getAttribute

    protected Expression getAttribute(String name)

Retrieves the expression of the given attribute name. If no such attribute exists, this method returns `Expression.NULL` so that the caller doesn't have to do the null check.

#### getBodyText

    protected String getBodyText(JellyContext context,
                     boolean shouldEscape)
                          throws JellyTagException

Evaluates the body and obtains it as a string. Uses standard XMLOutput.createXMLOutput() to generate output unless the JellyContext contains a variable named org.apache.commons.jelly.XMLOutputFactory which is an object of that type.

Throws:
  `JellyTagException`