## org.eclipse.jet
Class XPathContextExtender

    java.lang.Object
      org.eclipse.jet.AbstractContextExtender
          org.eclipse.jet.XPathContextExtender

All Implemented Interfaces:
  XPathVariableResolver

    public final class XPathContextExtender

extends AbstractContextExtender
implements XPathVariableResolver

Context Extender that understands XPath processing.

Constructor Summary
`XPathContextExtender(JET2Context context)` Deprecated. Use `getInstance(JET2Context)`. This method will be made private in the near future.

Method Summary
`void` `addCustomFunctions(XPathFunctionMetaData[] functionData)` Add the passed list of XPath function definitions to the XPath processor.
`java.lang.Object` `addElement(java.lang.Object parent, java.lang.String name)`
`java.lang.Object` `addTextElement(java.lang.Object parentElement, java.lang.String name, java.lang.String bodyContent)` Create a new text (simple) element whose content is set to `bodyContent`.
`java.lang.Object` `addTextElement(java.lang.Object parentElement, java.lang.String name, java.lang.String bodyContent, boolean asCData)` Create a new text (simple) element whose content is set to `bodyContent`.
`java.lang.Object` `copyElement(java.lang.Object srcElement, java.lang.Object tgtParent, java.lang.String name, boolean recursive)` Copy `srcElement` as a new element with the specified name under `tgtParent`.
`protected java.lang.Object` `createExtendedData(JET2Context context)` Called by the AbstractContextExtender constructor if the extender's data has not yet been created in the context.
`java.lang.Object` `currentXPathContextObject()`
`java.lang.Object` `getAttributeValue(java.lang.Object element, java.lang.String attributeName)` Return the value of the named attribute on the passed element.
`java.lang.String` `getContent(java.lang.Object object)` Return the string value of the passed object.
`static XPathContextExtender` `getInstance(JET2Context context)` Factory method for XPathContextExtenders
`void` `removeAttribute(java.lang.Object element, java.lang.String attributeName)` Remove the named attribute from the specified element.
`void` `removeElement(java.lang.Object element)`
`java.lang.Object[]` `resolve(java.lang.Object xpathContextObject, java.lang.String selectXPath)`
`java.lang.Object` `resolveAsObject(java.lang.Object contextObject, java.lang.String selectXPath)` Resolve the XPath expression, returning an object.
`java.lang.String` `resolveAsString(java.lang.Object xpathContextObject, java.lang.String selectXPath)` Resolve the given XPath expression as a string value.
`java.lang.String` `resolveDynamic(java.lang.String value)` Resolve dynamic XPath expressions {...} within the pass value
`java.lang.Object` `resolveSingle(java.lang.Object xpathContextObject, java.lang.String selectXPath)`
`boolean` `resolveTest(java.lang.Object xpathContext, java.lang.String testXPath)` Resolve an xpath expression as a boolean result according to the XPath rules.
`java.lang.Object` `resolveVariable(java.lang.String name)`
`boolean` `setAttribute(java.lang.Object element, java.lang.String name, java.lang.String bodyContent)`

Methods inherited from class org.eclipse.jet.AbstractContextExtender
`getContext, getExtendedData`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### XPathContextExtender

    public XPathContextExtender(JET2Context context)

  Deprecated. Use `getInstance(JET2Context)`. This method will be made private in the near future.

  Parameters:
    `context` -

Method Detail

### getInstance

    public static XPathContextExtender getInstance(JET2Context context)

  Factory method for XPathContextExtenders

  Parameters:
    `context` - the JET2Context that is extended
  Returns:
    an XPathContextExtender

### createExtendedData

    protected java.lang.Object createExtendedData(JET2Context context)

  Description copied from class: `AbstractContextExtender`
  Called by the AbstractContextExtender constructor if the extender's data has not yet been created in the context.

  Specified by:
    `createExtendedData` in class `AbstractContextExtender`
  Parameters:
    `context` - the context in which the data will be created.
  Returns:
    the extension data object.

### resolveVariable

    public java.lang.Object resolveVariable(java.lang.String name)

  Specified by:
    `resolveVariable` in interface `XPathVariableResolver`

### resolveAsString

    public java.lang.String resolveAsString(java.lang.Object xpathContextObject,
                                            java.lang.String selectXPath)
                                     throws JET2TagException

  Resolve the given XPath expression as a string value. Note that if the XPath expression returns an empty Node set, this method returns `null`

  Parameters:
    `xpathContextObject` - the xpath context
    `selectXPath` - the XPath expression
  Returns:
    the string value of the XPath expression, or `null` if the expression resulted in an empty node set.
  Throws:
    `JET2TagException` - if an error occurs during expression evaluation

### resolveSingle

    public java.lang.Object resolveSingle(java.lang.Object xpathContextObject,
                                          java.lang.String selectXPath)
                                   throws JET2TagException

  Throws:
    `JET2TagException`

### currentXPathContextObject

    public java.lang.Object currentXPathContextObject()

### resolve

    public java.lang.Object[] resolve(java.lang.Object xpathContextObject,
                                      java.lang.String selectXPath)
                               throws JET2TagException

  Throws:
    `JET2TagException`

### resolveTest

    public boolean resolveTest(java.lang.Object xpathContext,
                               java.lang.String testXPath)
                        throws JET2TagException

  Resolve an xpath expression as a boolean result according to the XPath rules.

  TODO Add link to XPath 1.0 spec for clarification

  Parameters:
    `xpathContext` - the XPath context object
    `testXPath` - the XPath expression
  Returns:
    `true` or `false`
  Throws:
    `JET2TagException` - if an error occurs in evaluating the expression.

### setAttribute

    public boolean setAttribute(java.lang.Object element,
                                java.lang.String name,
                                java.lang.String bodyContent)
                         throws JET2TagException

  Throws:
    `JET2TagException`

### resolveDynamic

    public java.lang.String resolveDynamic(java.lang.String value)
                                    throws JET2TagException

  Resolve dynamic XPath expressions {...} within the pass value

  Parameters:
    `value` - a string containing zero or more dynamic xpath expressions
  Returns:
    the string with all dynamic xpath expressions resolved
  Throws:
    `JET2TagException` - if an Xpath evaluation error occurs

### addElement

    public java.lang.Object addElement(java.lang.Object parent,
                                       java.lang.String name)
                                throws JET2TagException

  Throws:
    `JET2TagException`

### removeElement

    public void removeElement(java.lang.Object element)
                       throws JET2TagException

  Throws:
    `JET2TagException`

### copyElement

    public java.lang.Object copyElement(java.lang.Object srcElement,
                                        java.lang.Object tgtParent,
                                        java.lang.String name,
                                        boolean recursive)
                                 throws JET2TagException

  Copy `srcElement` as a new element with the specified name under `tgtParent`. If `recursive` is `true`, then all the contained children of `srcElement` are copied, otherwise, only the element and its attributes are copied.

  Parameters:
    `srcElement` - the element to copy
    `tgtParent` - the parent element that will contain the copy
    `name` - the name of the copied element
    `recursive` - `true` if contained chidren are to be copied, too.
  Returns:
    the newly copied element
  Throws:
    `JET2TagException` - an error occurs

### addTextElement

    public java.lang.Object addTextElement(java.lang.Object parentElement,
                                           java.lang.String name,
                                           java.lang.String bodyContent)
                                    throws JET2TagException

  Create a new text (simple) element whose content is set to `bodyContent`.

  Parameters:
    `parentElement` - the parent of the new element.
    `name` - the name of the new element.
    `bodyContent` - the content.
  Returns:
    the new Element.
  Throws:
    `JET2TagException` - if the element cannot be added.

### addTextElement

    public java.lang.Object addTextElement(java.lang.Object parentElement,
                                           java.lang.String name,
                                           java.lang.String bodyContent,
                                           boolean asCData)
                                    throws JET2TagException

  Create a new text (simple) element whose content is set to `bodyContent`.

  Parameters:
    `parentElement` - the parent of the new element.
    `name` - the name of the new element.
    `bodyContent` - the content.
    `asCData` - if `true`, create the element as a CDATA section, of possible
  Returns:
    the new element.
  Throws:
    `JET2TagException` - if the element cannot be added.

### resolveAsObject

    public java.lang.Object resolveAsObject(java.lang.Object contextObject,
                                            java.lang.String selectXPath)
                                     throws JET2TagException

  Resolve the XPath expression, returning an object. Unlike the other resolve methods, this method performs no type conversions on the XPath results.

  Parameters:
    `contextObject` - the context object to which the XPath expression is relative.
    `selectXPath` - the XPath expression
  Returns:
    the result of the expression evaluation.
  Throws:
    `JET2TagException` - if an error occurs.

### getAttributeValue

    public java.lang.Object getAttributeValue(java.lang.Object element,
                                              java.lang.String attributeName)
                                       throws JET2TagException

  Return the value of the named attribute on the passed element.

  Parameters:
    `element` - the element containing the attribute
    `attributeName` - the attribute name
  Returns:
    the attribute value
  Throws:
    `JET2TagException`

### removeAttribute

    public void removeAttribute(java.lang.Object element,
                                java.lang.String attributeName)
                         throws JET2TagException

  Remove the named attribute from the specified element.

  Parameters:
    `element` - the element containing the attribute
    `attributeName` - the attribute to remove
  Throws:
    `JET2TagException` - if the attribute cannot be removed (because it is required), or if `element` is not a recognized element.

### getContent

    public java.lang.String getContent(java.lang.Object object)
                                throws JET2TagException

  Return the string value of the passed object. This equivalent to calling the XPath string() function on the passed object.

  Parameters:
    `object` - the object to examine.
  Returns:
    the string value.
  Throws:
    `JET2TagException` - if an error occurs.

### addCustomFunctions

    public void addCustomFunctions(XPathFunctionMetaData[] functionData)

  Add the passed list of XPath function definitions to the XPath processor.

  Parameters:
    `functionData` - possible empty array of `XPathFunctionMetaData` instances.

Copyright 2006 IBM Corporation and others. All Rights Reserved.