Package nu.validator.saxtree
Class TreeBuilder
java.lang.Object
nu.validator.saxtree.TreeBuilder
- All Implemented Interfaces:
ContentHandler,LexicalHandler
Builds a SAX Tree representation of a document or a fragment
streamed as
ContentHandler and
LexicalHandler events. The start/end event matching
is expected to adhere to the SAX API contract. Things will
simply break if this is not the case. Fragments are expected to
omit startDocument() and endDocument()
calls.- Version:
- $Id$
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ParentNodeThe current node.private LocatorThe locator.private List<PrefixMapping> The prefix mappings for the next element to be inserted.private final booleanWhether to retain attribute objects. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a reusableTreeBuilderthat buildsDocuments and copies attributes.TreeBuilder(boolean fragment, boolean retainAttributes) The constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(char[] ch, int start, int length) voidcomment(char[] ch, int start, int length) voidendCDATA()voidvoidendDTD()voidendElement(String uri, String localName, String qName) voidvoidendPrefixMapping(String prefix) getRoot()Returns the root (Documentif building a full document orDocumentFragmentif building a fragment.).voidignorableWhitespace(char[] ch, int start, int length) voidprocessingInstruction(String target, String data) voidsetDocumentLocator(Locator locator) voidskippedEntity(String name) voidvoidvoidvoidstartElement(String uri, String localName, String qName, Attributes atts) voidstartEntity(String name) voidstartPrefixMapping(String prefix, String uri) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
locator
The locator. -
current
The current node. -
retainAttributes
private final boolean retainAttributesWhether to retain attribute objects. -
prefixMappings
The prefix mappings for the next element to be inserted.
-
-
Constructor Details
-
TreeBuilder
public TreeBuilder()Constructs a reusableTreeBuilderthat buildsDocuments and copies attributes. -
TreeBuilder
public TreeBuilder(boolean fragment, boolean retainAttributes) The constructor. The instance will be reusabe if building a full document and not reusable if building a fragment.- Parameters:
fragment- whether thisTreeBuildershould build aDocumentFragmentinstead of aDocument.retainAttributes- whether instances of theAttributesinterface passed tostartElementshould be retained (the alternative is copying).
-
-
Method Details
-
characters
- Specified by:
charactersin interfaceContentHandler- Throws:
SAXException- See Also:
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Throws:
SAXException- See Also:
-
endElement
- Specified by:
endElementin interfaceContentHandler- Throws:
SAXException- See Also:
-
endPrefixMapping
- Specified by:
endPrefixMappingin interfaceContentHandler- Throws:
SAXException- See Also:
-
ignorableWhitespace
- Specified by:
ignorableWhitespacein interfaceContentHandler- Throws:
SAXException- See Also:
-
processingInstruction
- Specified by:
processingInstructionin interfaceContentHandler- Throws:
SAXException- See Also:
-
setDocumentLocator
- Specified by:
setDocumentLocatorin interfaceContentHandler- See Also:
-
skippedEntity
- Specified by:
skippedEntityin interfaceContentHandler- Throws:
SAXException
-
startDocument
- Specified by:
startDocumentin interfaceContentHandler- Throws:
SAXException- See Also:
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException - Specified by:
startElementin interfaceContentHandler- Throws:
SAXException- See Also:
-
startPrefixMapping
- Specified by:
startPrefixMappingin interfaceContentHandler- Throws:
SAXException- See Also:
-
comment
- Specified by:
commentin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
endCDATA
- Specified by:
endCDATAin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
endDTD
- Specified by:
endDTDin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
endEntity
- Specified by:
endEntityin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
startCDATA
- Specified by:
startCDATAin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
startDTD
- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
startEntity
- Specified by:
startEntityin interfaceLexicalHandler- Throws:
SAXException- See Also:
-
getRoot
Returns the root (Documentif building a full document orDocumentFragmentif building a fragment.).- Returns:
- the root
-