public class XmlPatternWorker.Library
extends java.lang.Object
Constructor and Description |
---|
Library() |
Modifier and Type | Method and Description |
---|---|
Aast |
createAst(int type,
java.lang.String text,
Aast parent)
General purpose XML AST creation function which can create a
XmlAst node using the given token type and text. |
XmlAst |
findElement(XmlAst parent,
java.lang.String name,
java.lang.Object[] attrPairs)
Given an XML AST node, attempt to find a child element with the
specified name, and whose attributes match the given attribute
name/value pairs.
|
java.lang.String |
getAttributeValue(Aast attrSet,
java.lang.String name)
Scan all attributes for the given AST set and return the one which
matches with the given name (case-sensitively).
|
java.lang.String |
makeSystemID(java.lang.String appendPath)
Compose a system ID for XML validation purposes.
|
XmlAst |
parse(java.lang.String filename,
boolean validate,
java.lang.String systemID)
Parse an XML document and return its data as an XML AST.
|
void |
persistTarget(XmlAst root,
java.lang.String filename,
boolean saveAst)
Convert the current target XML AST into a DOM and save it to file.
|
public Aast createAst(int type, java.lang.String text, Aast parent)
XmlAst
node using the given token type and text.
The created node will then be attached to the specified parent. This
is used in cases where the conversion is simple enough to drive
it completely from the rule set rather than from a custom worker.type
- The token type for the XML AST.text
- The text for the AST.parent
- The ID of the parent AST node.null
if the parent ID is invalid, if the type
is not valid or on any unexpected error during AST
creation.public void persistTarget(XmlAst root, java.lang.String filename, boolean saveAst) throws ConfigurationException, javax.xml.parsers.ParserConfigurationException, java.io.IOException
root
- Root of the XML AST.filename
- Project-relative filename for XML document file.saveAst
- true
to persist the intermediate, AST form of
the XML document. If true
, the AST is persisted
with an xast
extension, alongside the XML file.ConfigurationException
- if a project home directory has not been configured.javax.xml.parsers.ParserConfigurationException
- if the XML parser used to create the DOM has been
configured incorrectly.java.io.IOException
- if any I/O error occurs writing the DOM to file or
creating the necessary directories.public java.lang.String makeSystemID(java.lang.String appendPath) throws java.net.URISyntaxException, ConfigurationException
appendPath
- An optional, relative path to append to the end of the system ID.java.net.URISyntaxException
- if the URL for the enclosing jar file cannot be converted to a URI.ConfigurationException
- if there is a problem determining P2J_HOME.public XmlAst parse(java.lang.String filename, boolean validate, java.lang.String systemID) throws java.lang.Exception
filename
- Name of file at which XML document resides.validate
- true
to use a validating parser,
false
to parse the document without validation.systemID
- A base for resolving relative URIs. Used if validating with a system DOCTYPE
which specifies a relative URI for the DTD.javax.xml.parsers.ParserConfigurationException
- if the XML parser has been configured incorrectly.java.io.IOException
- if an I/O error occurs during parsing or stream cleanup.org.xml.sax.SAXException
- if an error occurs parsing the XML within the specified
file.java.lang.Exception
public XmlAst findElement(XmlAst parent, java.lang.String name, java.lang.Object[] attrPairs)
parent
- AST node whose children are iterated to find a match.name
- Name of the target element to be matched.attrPairs
- An array of strings which must contain an even number of
elements, representing interleaved attribute name/value
pairs. When iterated two indexes at a time, each ith
element represents an attribute's name, while the i +
1th element represents its value.null
if no such match is found.public java.lang.String getAttributeValue(Aast attrSet, java.lang.String name)
attrSet
- AST set which to be searchedname
- Target attribute name for which the value is retrieved.null
otherwaysXmlPatternWorker.matchAttribute(Aast, String, String)