org.tinyjee.maven.dim.utils
Class PositioningDocumentBuilder
java.lang.Object
org.tinyjee.maven.dim.utils.AbstractPositioningDocumentBuilder
org.tinyjee.maven.dim.utils.PositioningDocumentBuilder
public class PositioningDocumentBuilder
- extends AbstractPositioningDocumentBuilder
Creates a Document
builder that adds user-data into the parsed DOM nodes that covers line number and column information.
The purpose of this implementation is to get positions of selected elements in order to allow snippet selection via XPath.
This implementation is roughly based on the examples found at:
- http://stackoverflow.com/questions/2798376/is-there-a-way-to-parse-xml-via-sax-dom-with-line-numbers-available-per-node
- http://stackoverflow.com/questions/4915422/get-line-number-from-xml-node-java
- Author:
- Juergen_Kellerer, 2011-10-12
- See Also:
PositioningJsonDocumentBuilder
Constructor Summary |
PositioningDocumentBuilder(boolean namespaceAware)
Creates a new document builder that adds line and column number to the user data sections of resulting element nodes. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PositioningDocumentBuilder
public PositioningDocumentBuilder(boolean namespaceAware)
- Creates a new document builder that adds line and column number to the user data sections of resulting element nodes.
- Parameters:
namespaceAware
- whether XML processing is namespace aware.
getSaxParserFactory
public SAXParserFactory getSaxParserFactory()
getTransformerFactory
public TransformerFactory getTransformerFactory()
parse
public Document parse(URL systemId)
throws SAXException,
IOException,
TransformerException,
ParserConfigurationException
- Parses the given XML document.
- Specified by:
parse
in class AbstractPositioningDocumentBuilder
- Parameters:
systemId
- the URL of the document to parse.
- Returns:
- a parsed document with line and column numbers being included for elements.
- Throws:
SAXException
- If SAX parses cannot be created.
IOException
- If reading fails.
TransformerException
- If XML transformation is unavailable.
ParserConfigurationException
- If parsers are not configured correctly.
parse
public Document parse(URL systemIdUrl,
Reader reader)
throws SAXException,
IOException,
TransformerException,
ParserConfigurationException
- Description copied from class:
AbstractPositioningDocumentBuilder
- Parses the given URL to a
Document
.
- Specified by:
parse
in class AbstractPositioningDocumentBuilder
- Parameters:
systemIdUrl
- the URL of the document to parse.reader
- a reader containing the content to parse.
- Returns:
- the parsed document.
- Throws:
SAXException
IOException
TransformerException
ParserConfigurationException