Class SAXContentHandler
- All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, DeclHandler, LexicalHandler
- Direct Known Subclasses:
SAXModifyContentHandler
SAXContentHandler builds a dom4j tree via SAX events.
- Version:
- $Revision: 1.61 $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringBufferbuffer to hold contents of cdata section across multiple characters eventsprivate ElementThe current element we are onprivate intThe number of namespaces that are declared in the current scopeprivate DocumentThe document that is being builtprivate DocumentFactoryThe factory used to create newDocumentinstancesprivate ElementHandlertheElementHandlercalled as the elements are completeprivate ElementStackstack ofElementobjectsprivate StringThe name of the current entityprivate intThe number of levels deep we are inside a startEntity/endEntity callprivate EntityResolverThe entity resolverexternal DTD declarationsprivate booleanShould we ignore commentsprivate booleanShould external DTD declarations be expanded into a List in the DTDprivate booleanShould internal DTD declarations be expanded into a List in the DTDprivate InputSourceprivate booleanFlag used to indicate that we are inside a CDATA sectionprivate booleanFlag used to indicate that we are inside a DTD sectioninternal DTD declarationsprivate booleanAre we in an internal DTD subset?private Locatorthe Locatorprivate booleanWhether adjacent text nodes should be mergedprivate NamespaceStackstack ofNamespaceandQNameobjectsprivate booleanHolds value of property stripWhitespaceText.private StringBufferBuffer used to concatenate text togetherprivate booleanHave we added text to the buffer -
Constructor Summary
ConstructorsConstructorDescriptionSAXContentHandler(DocumentFactory documentFactory) SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler) SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler, ElementStack elementStack) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAttributes(Element element, Attributes attributes) Add all the attributes to the given elementsprotected voidaddDeclaredNamespaces(Element element) Add all namespaces declared before the startElement() SAX event to the current element so that they are available to child elements and attributesprotected voidaddDTDDeclaration(Decl declaration) Adds an internal DTD declaration to the list of declarationsprotected voidaddExternalDTDDeclaration(Decl declaration) Adds an external DTD declaration to the list of declarationsvoidReport an attribute type declaration.voidcharacters(char[] ch, int start, int end) voidcomment(char[] ch, int start, int end) protected voidIf the current text buffer contains any text then create a new text node with it and add it to the current elementprotected DocumentDOCUMENT ME!protected ElementStackvoidelementDecl(String name, String model) Report an element type declaration.voidendCDATA()voidvoidendDTD()voidendElement(String namespaceURI, String localName, String qName) voidvoidendPrefixMapping(String prefix) voiderror(SAXParseException exception) This method is called when an error is detected during parsing such as a validation error.voidexternalEntityDecl(String name, String publicId, String sysId) Report a parsed external entity declaration.voidfatalError(SAXParseException exception) This method is called when a fatal error occurs during parsing.DOCUMENT ME!private StringvoidinternalEntityDecl(String name, String value) Report an internal entity declaration.protected booleanisIgnorableEntity(String name) a Strategy Method to determine if a given entity name is ignorablebooleanReturns whether we should ignore comments or not.booleanDOCUMENT ME!booleanDOCUMENT ME!booleanReturns whether adjacent text nodes should be merged together.booleanSets whether whitespace between element start and end tags should be ignoredvoidnotationDecl(String name, String publicId, String systemId) Receive notification of a notation declaration event.voidprocessingInstruction(String target, String data) voidsetDocumentLocator(Locator documentLocator) voidsetElementStack(ElementStack elementStack) voidsetEntityResolver(EntityResolver entityResolver) voidsetIgnoreComments(boolean ignoreComments) Sets whether we should ignore comments or not.voidsetIncludeExternalDTDDeclarations(boolean include) Sets whether DTD external declarations should be expanded into the DocumentType object or not.voidsetIncludeInternalDTDDeclarations(boolean include) Sets whether internal DTD declarations should be expanded into the DocumentType object or not.voidsetInputSource(InputSource inputSource) voidsetMergeAdjacentText(boolean mergeAdjacentText) Sets whether or not adjacent text nodes should be merged together when parsing.voidsetStripWhitespaceText(boolean stripWhitespaceText) Sets whether whitespace between element start and end tags should be ignored.voidvoidvoidvoidstartElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) voidstartEntity(String name) voidstartPrefixMapping(String prefix, String uri) voidunparsedEntityDecl(String name, String publicId, String systemId, String notationName) Receive notification of an unparsed entity declaration event.voidwarning(SAXParseException exception) This method is called when a warning occurs during the parsing of the document.Methods inherited from class DefaultHandler
ignorableWhitespace, resolveEntity, skippedEntityMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContentHandler
declaration
-
Field Details
-
documentFactory
The factory used to create newDocumentinstances -
document
The document that is being built -
elementStack
stack ofElementobjects -
namespaceStack
stack ofNamespaceandQNameobjects -
elementHandler
theElementHandlercalled as the elements are complete -
locator
the Locator -
entity
The name of the current entity -
insideDTDSection
private boolean insideDTDSectionFlag used to indicate that we are inside a DTD section -
insideCDATASection
private boolean insideCDATASectionFlag used to indicate that we are inside a CDATA section -
cdataText
buffer to hold contents of cdata section across multiple characters events -
internalDTDDeclarations
-
externalDTDDeclarations
-
declaredNamespaceIndex
private int declaredNamespaceIndexThe number of namespaces that are declared in the current scope -
entityResolver
The entity resolver -
inputSource
-
currentElement
The current element we are on -
includeInternalDTDDeclarations
private boolean includeInternalDTDDeclarationsShould internal DTD declarations be expanded into a List in the DTD -
includeExternalDTDDeclarations
private boolean includeExternalDTDDeclarationsShould external DTD declarations be expanded into a List in the DTD -
entityLevel
private int entityLevelThe number of levels deep we are inside a startEntity/endEntity call -
internalDTDsubset
private boolean internalDTDsubsetAre we in an internal DTD subset? -
mergeAdjacentText
private boolean mergeAdjacentTextWhether adjacent text nodes should be merged -
textInTextBuffer
private boolean textInTextBufferHave we added text to the buffer -
ignoreComments
private boolean ignoreCommentsShould we ignore comments -
textBuffer
Buffer used to concatenate text together -
stripWhitespaceText
private boolean stripWhitespaceTextHolds value of property stripWhitespaceText.
-
-
Constructor Details
-
SAXContentHandler
public SAXContentHandler() -
SAXContentHandler
-
SAXContentHandler
-
SAXContentHandler
public SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler, ElementStack elementStack)
-
-
Method Details
-
getDocument
-
setDocumentLocator
- Specified by:
setDocumentLocatorin interfaceContentHandler- Overrides:
setDocumentLocatorin classDefaultHandler
-
processingInstruction
- Specified by:
processingInstructionin interfaceContentHandler- Overrides:
processingInstructionin classDefaultHandler- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classDefaultHandler- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMappingin interfaceContentHandler- Overrides:
endPrefixMappingin classDefaultHandler- Throws:
SAXException
-
startDocument
- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) throws SAXException - Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException
-
endElement
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
characters
- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Throws:
SAXException
-
warning
This method is called when a warning occurs during the parsing of the document. This method does nothing.- Specified by:
warningin interfaceErrorHandler- Overrides:
warningin classDefaultHandler- Parameters:
exception- DOCUMENT ME!- Throws:
SAXException- DOCUMENT ME!
-
error
This method is called when an error is detected during parsing such as a validation error. This method rethrows the exception- Specified by:
errorin interfaceErrorHandler- Overrides:
errorin classDefaultHandler- Parameters:
exception- DOCUMENT ME!- Throws:
SAXException- DOCUMENT ME!
-
fatalError
This method is called when a fatal error occurs during parsing. This method rethrows the exception- Specified by:
fatalErrorin interfaceErrorHandler- Overrides:
fatalErrorin classDefaultHandler- Parameters:
exception- DOCUMENT ME!- Throws:
SAXException- DOCUMENT ME!
-
startDTD
- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException
-
endDTD
- Specified by:
endDTDin interfaceLexicalHandler- Throws:
SAXException
-
startEntity
- Specified by:
startEntityin interfaceLexicalHandler- Throws:
SAXException
-
endEntity
- Specified by:
endEntityin interfaceLexicalHandler- Throws:
SAXException
-
startCDATA
- Specified by:
startCDATAin interfaceLexicalHandler- Throws:
SAXException
-
endCDATA
- Specified by:
endCDATAin interfaceLexicalHandler- Throws:
SAXException
-
comment
- Specified by:
commentin interfaceLexicalHandler- Throws:
SAXException
-
elementDecl
Report an element type declaration.The content model will consist of the string "EMPTY", the string "ANY", or a parenthesised group, optionally followed by an occurrence indicator. The model will be normalized so that all parameter entities are fully resolved and all whitespace is removed,and will include the enclosing parentheses. Other normalization (such as removing redundant parentheses or simplifying occurrence indicators) is at the discretion of the parser.
- Specified by:
elementDeclin interfaceDeclHandler- Parameters:
name- The element type name.model- The content model as a normalized string.- Throws:
SAXException- The application may raise an exception.
-
attributeDecl
public void attributeDecl(String eName, String aName, String type, String valueDefault, String val) throws SAXException Report an attribute type declaration.Only the effective (first) declaration for an attribute will be reported. The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", a parenthesized token group with the separator "|" and all whitespace removed, or the word "NOTATION" followed by a space followed by a parenthesized token group with all whitespace removed.
Any parameter entities in the attribute value will be expanded, but general entities will not.
- Specified by:
attributeDeclin interfaceDeclHandler- Parameters:
eName- The name of the associated element.aName- The name of the attribute.type- A string representing the attribute type.valueDefault- A string representing the attribute default ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.val- A string representing the attribute's default value, or null if there is none.- Throws:
SAXException- The application may raise an exception.
-
internalEntityDecl
Report an internal entity declaration.Only the effective (first) declaration for each entity will be reported. All parameter entities in the value will be expanded, but general entities will not.
- Specified by:
internalEntityDeclin interfaceDeclHandler- Parameters:
name- The name of the entity. If it is a parameter entity, the name will begin with '%'.value- The replacement text of the entity.- Throws:
SAXException- The application may raise an exception.- See Also:
-
externalEntityDecl
Report a parsed external entity declaration.Only the effective (first) declaration for each entity will be reported.
- Specified by:
externalEntityDeclin interfaceDeclHandler- Parameters:
name- The name of the entity. If it is a parameter entity, the name will begin with '%'.publicId- The declared public identifier of the entity, or null if none was declared.sysId- The declared system identifier of the entity.- Throws:
SAXException- The application may raise an exception.- See Also:
-
notationDecl
Receive notification of a notation declaration event.It is up to the application to record the notation for later reference, if necessary.
At least one of publicId and systemId must be non-null. If a system identifier is present, and it is a URL, the SAX parser must resolve it fully before passing it to the application through this event.
There is no guarantee that the notation declaration will be reported before any unparsed entities that use it.
- Specified by:
notationDeclin interfaceDTDHandler- Overrides:
notationDeclin classDefaultHandler- Parameters:
name- The notation name.publicId- The notation's public identifier, or null if none was given.systemId- The notation's system identifier, or null if none was given.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
-
unparsedEntityDecl
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException Receive notification of an unparsed entity declaration event.Note that the notation name corresponds to a notation reported by the
notationDeclevent. It is up to the application to record the entity for later reference, if necessary.If the system identifier is a URL, the parser must resolve it fully before passing it to the application.
- Specified by:
unparsedEntityDeclin interfaceDTDHandler- Overrides:
unparsedEntityDeclin classDefaultHandler- Parameters:
name- The unparsed entity's name.publicId- The entity's public identifier, or null if none was given.systemId- The entity's system identifier.notationName- The name of the associated notation.- Throws:
SAXException- Any SAX exception, possibly wrapping another exception.- See Also:
-
getElementStack
-
setElementStack
-
getEntityResolver
-
setEntityResolver
-
getInputSource
-
setInputSource
-
isIncludeInternalDTDDeclarations
public boolean isIncludeInternalDTDDeclarations()DOCUMENT ME!- Returns:
- whether internal DTD declarations should be expanded into the DocumentType object or not.
-
setIncludeInternalDTDDeclarations
public void setIncludeInternalDTDDeclarations(boolean include) Sets whether internal DTD declarations should be expanded into the DocumentType object or not.- Parameters:
include- whether or not DTD declarations should be expanded and included into the DocumentType object.
-
isIncludeExternalDTDDeclarations
public boolean isIncludeExternalDTDDeclarations()DOCUMENT ME!- Returns:
- whether external DTD declarations should be expanded into the DocumentType object or not.
-
setIncludeExternalDTDDeclarations
public void setIncludeExternalDTDDeclarations(boolean include) Sets whether DTD external declarations should be expanded into the DocumentType object or not.- Parameters:
include- whether or not DTD declarations should be expanded and included into the DocumentType object.
-
isMergeAdjacentText
public boolean isMergeAdjacentText()Returns whether adjacent text nodes should be merged together.- Returns:
- Value of property mergeAdjacentText.
-
setMergeAdjacentText
public void setMergeAdjacentText(boolean mergeAdjacentText) Sets whether or not adjacent text nodes should be merged together when parsing.- Parameters:
mergeAdjacentText- New value of property mergeAdjacentText.
-
isStripWhitespaceText
public boolean isStripWhitespaceText()Sets whether whitespace between element start and end tags should be ignored- Returns:
- Value of property stripWhitespaceText.
-
setStripWhitespaceText
public void setStripWhitespaceText(boolean stripWhitespaceText) Sets whether whitespace between element start and end tags should be ignored.- Parameters:
stripWhitespaceText- New value of property stripWhitespaceText.
-
isIgnoreComments
public boolean isIgnoreComments()Returns whether we should ignore comments or not.- Returns:
- boolean
-
setIgnoreComments
public void setIgnoreComments(boolean ignoreComments) Sets whether we should ignore comments or not.- Parameters:
ignoreComments- whether we should ignore comments or not.
-
completeCurrentTextNode
protected void completeCurrentTextNode()If the current text buffer contains any text then create a new text node with it and add it to the current element -
createDocument
-
getEncoding
-
isIgnorableEntity
a Strategy Method to determine if a given entity name is ignorable- Parameters:
name- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
addDeclaredNamespaces
Add all namespaces declared before the startElement() SAX event to the current element so that they are available to child elements and attributes- Parameters:
element- DOCUMENT ME!
-
addAttributes
Add all the attributes to the given elements- Parameters:
element- DOCUMENT ME!attributes- DOCUMENT ME!
-
addDTDDeclaration
Adds an internal DTD declaration to the list of declarations- Parameters:
declaration- DOCUMENT ME!
-
addExternalDTDDeclaration
Adds an external DTD declaration to the list of declarations- Parameters:
declaration- DOCUMENT ME!
-
createElementStack
-