org.apache.commons.jelly.tags.xml
Class SetTag

java.lang.Object
  extended by org.apache.commons.jelly.TagSupport
      extended by org.apache.commons.jelly.xpath.XPathTagSupport
          extended by org.apache.commons.jelly.tags.xml.SetTag
All Implemented Interfaces:
org.apache.commons.jelly.Tag

public class SetTag
extends org.apache.commons.jelly.xpath.XPathTagSupport

A tag which defines a variable from an XPath expression. This function creates a variable of type List or Node (for example Element or Attribute). Thus, the variable created from xml:set can be used from the other xml library functions.

Version:
$Revision: 155420 $
Author:
James Strachan

Field Summary
private  java.lang.Boolean asString
           
private  java.lang.String delim
           
private  java.lang.String delimiter
           
private  org.apache.commons.logging.Log log
          The Log to which logging calls will be made.
private static int RETURN_DELIMITED_STRING_LIST
           
private static int RETURN_FIRST_AS_STRING
           
private static int RETURN_FIRST_NODE
           
private static int RETURN_NODE_LIST
           
private static int RETURN_STRING_LIST
           
private  org.jaxen.XPath select
          The XPath expression to evaluate.
private  java.lang.Boolean single
           
private  java.lang.String var
          The variable name to export.
private  org.apache.commons.jelly.xpath.XPathComparator xpCmp
          Xpath comparator for sorting
 
Fields inherited from class org.apache.commons.jelly.TagSupport
body, context, hasTrimmed, parent, shouldTrim
 
Constructor Summary
SetTag()
           
 
Method Summary
private  int determineReturnType()
           
 void doTag(org.apache.commons.jelly.XMLOutput output)
           
private  java.lang.String joinDelimitedElements(java.util.List values)
           
private  java.util.List nodeListToStringList(java.util.List values)
           
 void setAsString(boolean asString)
          If set to true, will ensure that the (XPath) text-value of the selected node is taken instead of the node itself.
 void setDelim(java.lang.String delim)
          If set, returns a string delimited by this delimiter.
 void setDescending(boolean descending)
          Set whether to sort ascending or descending.
 void setSelect(org.jaxen.XPath select)
          Sets the XPath expression to evaluate.
 void setSingle(boolean single)
          If set to true will only take the first element matching.
 void setSort(org.jaxen.XPath sortXPath)
          Sets the xpath expression to use to sort selected nodes.
 void setVar(java.lang.String var)
          Sets the variable name to define for this expression
private  java.lang.String singleValueAsString(java.lang.Object value)
           
private  java.util.List valueAsList(java.lang.Object value)
           
private  java.lang.Object valueAsSingle(java.lang.Object value)
           
 
Methods inherited from class org.apache.commons.jelly.xpath.XPathTagSupport
getXPathContext
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RETURN_NODE_LIST

private static final int RETURN_NODE_LIST
See Also:
Constant Field Values

RETURN_FIRST_NODE

private static final int RETURN_FIRST_NODE
See Also:
Constant Field Values

RETURN_STRING_LIST

private static final int RETURN_STRING_LIST
See Also:
Constant Field Values

RETURN_DELIMITED_STRING_LIST

private static final int RETURN_DELIMITED_STRING_LIST
See Also:
Constant Field Values

RETURN_FIRST_AS_STRING

private static final int RETURN_FIRST_AS_STRING
See Also:
Constant Field Values

log

private org.apache.commons.logging.Log log
The Log to which logging calls will be made.


var

private java.lang.String var
The variable name to export.


select

private org.jaxen.XPath select
The XPath expression to evaluate.


xpCmp

private org.apache.commons.jelly.xpath.XPathComparator xpCmp
Xpath comparator for sorting


single

private java.lang.Boolean single

asString

private java.lang.Boolean asString

delimiter

private java.lang.String delimiter

delim

private java.lang.String delim
Constructor Detail

SetTag

public SetTag()
Method Detail

doTag

public void doTag(org.apache.commons.jelly.XMLOutput output)
           throws org.apache.commons.jelly.MissingAttributeException,
                  org.apache.commons.jelly.JellyTagException
Throws:
org.apache.commons.jelly.MissingAttributeException
org.apache.commons.jelly.JellyTagException

valueAsList

private java.util.List valueAsList(java.lang.Object value)

valueAsSingle

private java.lang.Object valueAsSingle(java.lang.Object value)

singleValueAsString

private java.lang.String singleValueAsString(java.lang.Object value)

nodeListToStringList

private java.util.List nodeListToStringList(java.util.List values)

joinDelimitedElements

private java.lang.String joinDelimitedElements(java.util.List values)

determineReturnType

private int determineReturnType()

setVar

public void setVar(java.lang.String var)
Sets the variable name to define for this expression


setSelect

public void setSelect(org.jaxen.XPath select)
Sets the XPath expression to evaluate.


setSingle

public void setSingle(boolean single)
If set to true will only take the first element matching. It then guarantees that the result is of type Node thereby making sure that, for example, when an element is selected, one can directly call such methods as setAttribute.
If set to false, guarantees that a list is returned. If set to false, guarantees that a list is returned.


setAsString

public void setAsString(boolean asString)
If set to true, will ensure that the (XPath) text-value of the selected node is taken instead of the node itself. This ensures that, thereafter, string manipulations can be performed on the result.


setDelim

public void setDelim(java.lang.String delim)
If set, returns a string delimited by this delimiter. Implies asString to be true.


setSort

public void setSort(org.jaxen.XPath sortXPath)
             throws org.jaxen.JaxenException
Sets the xpath expression to use to sort selected nodes. Ignored if single is true.

Throws:
org.jaxen.JaxenException

setDescending

public void setDescending(boolean descending)
Set whether to sort ascending or descending.