|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tools.ant.ProjectComponent org.apache.tools.ant.Task net.sf.fikin.ant.XPathTask
public class XPathTask
Execute XPath expressions against input XML/HTML data and return result.
Support XML or HTML inputs
Support writing to Project properties or a file
Support for multiple xpath expressions per single input
Example:
<xpath>
<input file="bin/test/ant/test1/in1.xml" />
<output property="p1" />
<forEach select="/root/id" >
<valueOf select="local-name(..)" />
<valueOf select="'/'" />
<valueOf select="local-name()" />
</forEach>
<forEach select="/root" >
<valueOf select="local-name()" />
<valueOf select="' count nested tags : '" />
<valueOf select="count(.)" />
</forEach>
</xpath>
<echo>${p1}</echo>
where for input file:
<root><id/></root>
would set property p1
to:
[echo] root/id root count nested tags : 1
Example:
<xpath>
<input>
<![CDATA[ <root><tag id="1"/><tag id="2"/></root> ]]>
</input>
<forEach select="/root/tag" >
<valueOf select="@id" />
</forEach>
<sequential>
<echo>@{node}</echo>
</sequential>
</xpath>
would print out:
[echo] 1
[echo] 2
created on Jan 3, 2007
Nested Class Summary | |
---|---|
class |
XPathTask.ForEach
Represents a for-each nested tag created on Jan 3, 2007 |
class |
XPathTask.Function
Represent a function tag created on Jan 3, 2007 |
class |
XPathTask.ListOfFunctions
Functions context handler used by XPath to resolve custom namespaces |
class |
XPathTask.ListOfNS
Namespace context handler used by XPath to resolve custom namespaces |
class |
XPathTask.Select
Represents a value-of nested tag created on Jan 3, 2007 |
Field Summary | |
---|---|
protected FactoryType |
factory
factory to use, if defined |
protected boolean |
failOnError
abort build when execution error, by default true |
protected java.util.Vector |
forEachs
list of for-each nested tags |
protected java.util.Vector |
functions
hold custom defined functions |
protected XHTMLInput |
input
input document |
protected org.apache.tools.ant.taskdefs.MacroDef |
macroDef
internal instance of MacroDef, corresponds to nested sequential tag |
protected org.apache.tools.ant.taskdefs.MacroInstance |
macroInstance
macro instance used to execute sequential if defined, internal member |
protected java.util.Vector |
namespaces
hold all defined namespaces |
protected DelimitedPrintWriter |
out
output writer, internal member |
protected Output |
output
output document |
protected int |
recordCnt
count how many records were discovered by forEach tags, internal member |
protected javax.xml.xpath.XPath |
xpath
xpath object to use for expression evaluations, internal member |
protected javax.xml.xpath.XPathFactory |
xpathFactory
xpathFactory to use, internal member |
Fields inherited from class org.apache.tools.ant.Task |
---|
description, location, target, taskName, taskType, wrapper |
Fields inherited from class org.apache.tools.ant.ProjectComponent |
---|
project |
Constructor Summary | |
---|---|
XPathTask()
|
Method Summary | |
---|---|
void |
addNamespace(Namespace ns)
add new namespace tag |
void |
check(org.apache.tools.ant.Task task)
test for input has been set and is consistent test output or sequential has been set and is consistent test namespaces are consistent test functions are consistent test for at least one for-each and it is consistent test factory if defined |
protected void |
closeOut()
close the output system : in this case closing out stream if
such has been used (and not macroInstance ) |
FactoryType |
createFactory()
create factory tag |
XPathTask.ForEach |
createForEach()
create new for-each tag |
XPathTask.Function |
createFunction()
create new function tag |
XHTMLInput |
createInput()
create xml/html/xhtml input tag |
Output |
createOutput()
create output tag |
java.lang.Object |
createSequential()
Create sequential task |
void |
execute()
execute the task |
protected void |
execute(org.w3c.dom.Node node,
java.util.List selects,
java.lang.StringBuffer appendTo)
execute xpath for each of Select elements in the vector |
protected void |
execute(org.w3c.dom.Node node,
XPathTask.ForEach fe)
execute xpath expression of this for-each |
protected void |
execute(org.w3c.dom.Node node,
XPathTask.Select select,
java.lang.StringBuffer appendTo)
execute the xpath expression and append it to the string buffer |
protected void |
execute(java.lang.String rowOfData)
either print the data to the output or execute the sequential with it |
protected void |
initOut()
Initialize the output system : this being out stream or
macroInstance |
protected javax.xml.xpath.XPathFactory |
newXPathFactory()
instantiate new xpath factory |
void |
setFailOnError(boolean failOnError)
abort build whenever execution error |
protected void |
setFunctions()
set functions the the xpath object |
protected void |
setNamespaces()
set namespaces the the xpath object |
Methods inherited from class org.apache.tools.ant.Task |
---|
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType |
Methods inherited from class org.apache.tools.ant.ProjectComponent |
---|
getProject, setProject |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean failOnError
protected java.util.Vector namespaces
protected java.util.Vector functions
protected org.apache.tools.ant.taskdefs.MacroDef macroDef
protected XHTMLInput input
protected Output output
protected java.util.Vector forEachs
protected FactoryType factory
protected javax.xml.xpath.XPathFactory xpathFactory
protected javax.xml.xpath.XPath xpath
protected DelimitedPrintWriter out
protected org.apache.tools.ant.taskdefs.MacroInstance macroInstance
protected int recordCnt
Constructor Detail |
---|
public XPathTask()
Method Detail |
---|
public void setFailOnError(boolean failOnError)
failOnError
- aborts build if set to true, by default true
public void addNamespace(Namespace ns)
ns
- is a new namespace tagpublic XPathTask.Function createFunction()
public XHTMLInput createInput()
public java.lang.Object createSequential()
Its code will be executed for each Node found in by for-each tags
One can refer to the combined value-of string (computed for that Node)
via the macro attribute @{node}
public Output createOutput()
public FactoryType createFactory()
public XPathTask.ForEach createForEach()
public void check(org.apache.tools.ant.Task task) throws org.apache.tools.ant.BuildException
org.apache.tools.ant.BuildException
public void execute() throws org.apache.tools.ant.BuildException
execute
in class org.apache.tools.ant.Task
org.apache.tools.ant.BuildException
protected void execute(org.w3c.dom.Node node, XPathTask.ForEach fe) throws org.apache.tools.ant.BuildException
node
- to use as rootfe
- is for-each xpath expression
org.apache.tools.ant.BuildException
protected void execute(org.w3c.dom.Node node, java.util.List selects, java.lang.StringBuffer appendTo) throws javax.xml.xpath.XPathExpressionException
node
- to use as baseselects
- is a list ofappendTo
- is a string buffer to append the evaluation result to
javax.xml.xpath.XPathExpressionException
protected void execute(org.w3c.dom.Node node, XPathTask.Select select, java.lang.StringBuffer appendTo) throws javax.xml.xpath.XPathExpressionException
node
- to use as baseselect
- is xpath to evaluateappendTo
- is a string buffer to append the evaluation result to
javax.xml.xpath.XPathExpressionException
protected void execute(java.lang.String rowOfData)
rowOfData
- protected void initOut()
out
stream or
macroInstance
To be called once before calling execute(String)
for first time
protected void closeOut()
out
stream if
such has been used (and not macroInstance
)
To be called at the end of the task execution i.e. execute()
protected javax.xml.xpath.XPathFactory newXPathFactory() throws org.apache.tools.ant.BuildException
org.apache.tools.ant.BuildException
protected void setNamespaces()
protected void setFunctions()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |