|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
org.dom4j.io.SAXContentHandler
SAXContentHandler
builds a dom4j tree via SAX events.
Constructor Summary | |
SAXContentHandler()
|
|
SAXContentHandler(DocumentFactory documentFactory)
|
|
SAXContentHandler(DocumentFactory documentFactory,
ElementHandler elementHandler)
|
|
SAXContentHandler(DocumentFactory documentFactory,
ElementHandler elementHandler,
org.dom4j.io.ElementStack elementStack)
|
Method Summary | |
protected void |
addAttributes(Element element,
Attributes attributes)
Add all the attributes to the given elements |
protected void |
addDeclaredNamespaces(Element element)
Add all namespaces declared before the startElement() SAX event to the current element so that they are available to child elements and attributes |
protected void |
addDTDDeclaration(java.lang.Object declaration)
Adds an internal DTD declaration to the list of declarations |
protected void |
addExternalDTDDeclaration(java.lang.Object declaration)
Adds an external DTD declaration to the list of declarations |
void |
attributeDecl(java.lang.String eName,
java.lang.String aName,
java.lang.String type,
java.lang.String valueDefault,
java.lang.String value)
Report an attribute type declaration. |
void |
characters(char[] ch,
int start,
int end)
Receive notification of character data inside an element. |
void |
comment(char[] ch,
int start,
int end)
Report an XML comment anywhere in the document. |
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 |
protected Document |
createDocument()
|
protected org.dom4j.io.ElementStack |
createElementStack()
|
void |
elementDecl(java.lang.String name,
java.lang.String model)
Report an element type declaration. |
void |
endCDATA()
Report the end of a CDATA section. |
void |
endDocument()
Receive notification of the end of the document. |
void |
endDTD()
Report the end of DTD declarations. |
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
Receive notification of the end of an element. |
void |
endEntity(java.lang.String name)
Report the end of an entity. |
void |
endPrefixMapping(java.lang.String prefix)
Receive notification of the end of a Namespace mapping. |
void |
error(SAXParseException exception)
This method is called when an error is detected during parsing such as a validation error. |
void |
externalEntityDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
Report a parsed external entity declaration. |
void |
fatalError(SAXParseException exception)
This method is called when a fatal error occurs during parsing. |
Document |
getDocument()
|
org.dom4j.io.ElementStack |
getElementStack()
|
EntityResolver |
getEntityResolver()
|
InputSource |
getInputSource()
|
void |
internalEntityDecl(java.lang.String name,
java.lang.String value)
Report an internal entity declaration. |
protected boolean |
isIgnorableEntity(java.lang.String name)
a Strategy Method to determine if a given entity name is ignorable |
boolean |
isIgnoreComments()
Returns whether we should ignore comments or not. |
boolean |
isIncludeExternalDTDDeclarations()
|
boolean |
isIncludeInternalDTDDeclarations()
|
boolean |
isMergeAdjacentText()
Returns whether adjacent text nodes should be merged together. |
boolean |
isStripWhitespaceText()
Sets whether whitespace between element start and end tags should be ignored |
void |
notationDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
Receive notification of a notation declaration event. |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Receive notification of a processing instruction. |
void |
setDocumentLocator(Locator locator)
Receive a Locator object for document events. |
void |
setElementStack(org.dom4j.io.ElementStack elementStack)
|
void |
setEntityResolver(EntityResolver entityResolver)
|
void |
setIgnoreComments(boolean ignoreComments)
Sets whether we should ignore comments or not. |
void |
setIncludeExternalDTDDeclarations(boolean includeExternalDTDDeclarations)
Sets whether DTD external declarations should be expanded into the DocumentType object or not. |
void |
setIncludeInternalDTDDeclarations(boolean includeInternalDTDDeclarations)
Sets whether internal DTD declarations should be expanded into the DocumentType object or not. |
void |
setInputSource(InputSource inputSource)
|
void |
setMergeAdjacentText(boolean mergeAdjacentText)
Sets whether or not adjacent text nodes should be merged together when parsing. |
void |
setStripWhitespaceText(boolean stripWhitespaceText)
Sets whether whitespace between element start and end tags should be ignored. |
void |
startCDATA()
Report the start of a CDATA section. |
void |
startDocument()
Receive notification of the beginning of the document. |
void |
startDTD(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
Report the start of DTD declarations, if any. |
void |
startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qualifiedName,
Attributes attributes)
Receive notification of the start of an element. |
void |
startEntity(java.lang.String name)
Report the beginning of some internal and external XML entities. |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
Receive notification of the start of a Namespace mapping. |
void |
unparsedEntityDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId,
java.lang.String notationName)
Receive notification of an unparsed entity declaration event. |
void |
warning(SAXParseException exception)
This method is called when a warning occurs during the parsing of the document. |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
ignorableWhitespace, resolveEntity, skippedEntity |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SAXContentHandler()
public SAXContentHandler(DocumentFactory documentFactory)
public SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler)
public SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler, org.dom4j.io.ElementStack elementStack)
Method Detail |
public Document getDocument()
public void setDocumentLocator(Locator locator)
DefaultHandler
By default, do nothing. Application writers may override this method in a subclass if they wish to store the locator for use with other document events.
setDocumentLocator
in interface ContentHandler
setDocumentLocator
in class DefaultHandler
locator
- A locator for all SAX document events.ContentHandler.setDocumentLocator(org.xml.sax.Locator)
,
Locator
public void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException
DefaultHandler
By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.
processingInstruction
in interface ContentHandler
processingInstruction
in class DefaultHandler
target
- The processing instruction target.data
- The processing instruction data, or null if
none is supplied.
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.processingInstruction(java.lang.String, java.lang.String)
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws SAXException
DefaultHandler
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each Namespace prefix scope (such as storing the prefix mapping).
startPrefixMapping
in interface ContentHandler
startPrefixMapping
in class DefaultHandler
prefix
- The Namespace prefix being declared.uri
- The Namespace URI mapped to the prefix.
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
public void endPrefixMapping(java.lang.String prefix) throws SAXException
DefaultHandler
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each prefix mapping.
endPrefixMapping
in interface ContentHandler
endPrefixMapping
in class DefaultHandler
prefix
- The Namespace prefix being declared.
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.endPrefixMapping(java.lang.String)
public void startDocument() throws SAXException
DefaultHandler
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the beginning of a document (such as allocating the root node of a tree or creating an output file).
startDocument
in interface ContentHandler
startDocument
in class DefaultHandler
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.startDocument()
public void endDocument() throws SAXException
DefaultHandler
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of a document (such as finalising a tree or closing an output file).
endDocument
in interface ContentHandler
endDocument
in class DefaultHandler
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.endDocument()
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName, Attributes attributes) throws SAXException
DefaultHandler
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).
startElement
in interface ContentHandler
startElement
in class DefaultHandler
namespaceURI
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.qualifiedName
- The qualified name (with prefix), or the
empty string if qualified names are not available.
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws SAXException
DefaultHandler
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).
endElement
in interface ContentHandler
endElement
in class DefaultHandler
namespaceURI
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.qName
- The qualified name (with prefix), or the
empty string if qualified names are not available.
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
public void characters(char[] ch, int start, int end) throws SAXException
DefaultHandler
By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).
characters
in interface ContentHandler
characters
in class DefaultHandler
ch
- The characters.start
- The start position in the character array.end
- The number of characters to use from the
character array.
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.characters(char[], int, int)
public void warning(SAXParseException exception) throws SAXException
warning
in interface ErrorHandler
warning
in class DefaultHandler
exception
- The warning information encoded as an exception.
SAXException
- Any SAX exception, possibly
wrapping another exception.ErrorHandler.warning(org.xml.sax.SAXParseException)
,
SAXParseException
public void error(SAXParseException exception) throws SAXException
error
in interface ErrorHandler
error
in class DefaultHandler
exception
- The warning information encoded as an exception.
SAXException
- Any SAX exception, possibly
wrapping another exception.ErrorHandler.warning(org.xml.sax.SAXParseException)
,
SAXParseException
public void fatalError(SAXParseException exception) throws SAXException
fatalError
in interface ErrorHandler
fatalError
in class DefaultHandler
exception
- The error information encoded as an exception.
SAXException
- Any SAX exception, possibly
wrapping another exception.ErrorHandler.fatalError(org.xml.sax.SAXParseException)
,
SAXParseException
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws SAXException
LexicalHandler
This method is intended to report the beginning of the DOCTYPE declaration; if the document has no DOCTYPE declaration, this method will not be invoked.
All declarations reported through
DTDHandler
or
DeclHandler
events must appear
between the startDTD and endDTD
events.
Declarations are assumed to belong to the internal DTD subset
unless they appear between startEntity
and endEntity
events. Comments and
processing instructions from the DTD should also be reported
between the startDTD and endDTD events, in their original
order of (logical) occurrence; they are not required to
appear in their correct locations relative to DTDHandler
or DeclHandler events, however.
Note that the start/endDTD events will appear within
the start/endDocument events from ContentHandler and
before the first
startElement
event.
startDTD
in interface LexicalHandler
name
- The document type name.publicId
- The declared public identifier for the
external DTD subset, or null if none was declared.systemId
- The declared system identifier for the
external DTD subset, or null if none was declared.
(Note that this is not resolved against the document
base URI.)
SAXException
- The application may raise an
exception.LexicalHandler.endDTD()
,
LexicalHandler.startEntity(java.lang.String)
public void endDTD() throws SAXException
LexicalHandler
This method is intended to report the end of the DOCTYPE declaration; if the document has no DOCTYPE declaration, this method will not be invoked.
endDTD
in interface LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)
public void startEntity(java.lang.String name) throws SAXException
LexicalHandler
The reporting of parameter entities (including
the external DTD subset) is optional, and SAX2 drivers that
report LexicalHandler events may not implement it; you can use the
http://xml.org/sax/features/lexical-handler/parameter-entities
feature to query or control the reporting of parameter entities.
General entities are reported with their regular names, parameter entities have '%' prepended to their names, and the external DTD subset has the pseudo-entity name "[dtd]".
When a SAX2 driver is providing these events, all other
events must be properly nested within start/end entity
events. There is no additional requirement that events from
DeclHandler
or
DTDHandler
be properly ordered.
Note that skipped entities will be reported through the
skippedEntity
event, which is part of the ContentHandler interface.
Because of the streaming event model that SAX uses, some entity boundaries cannot be reported under any circumstances:
These will be silently expanded, with no indication of where the original entity boundaries were.
Note also that the boundaries of character references (which are not really entities anyway) are not reported.
All start/endEntity events must be properly nested.
startEntity
in interface LexicalHandler
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%', and if it is the
external DTD subset, it will be "[dtd]".
SAXException
- The application may raise an exception.LexicalHandler.endEntity(java.lang.String)
,
DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)
,
DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
public void endEntity(java.lang.String name) throws SAXException
LexicalHandler
endEntity
in interface LexicalHandler
name
- The name of the entity that is ending.
SAXException
- The application may raise an exception.LexicalHandler.startEntity(java.lang.String)
public void startCDATA() throws SAXException
LexicalHandler
The contents of the CDATA section will be reported through
the regular characters
event; this event is intended only to report
the boundary.
startCDATA
in interface LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.endCDATA()
public void endCDATA() throws SAXException
LexicalHandler
endCDATA
in interface LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.startCDATA()
public void comment(char[] ch, int start, int end) throws SAXException
LexicalHandler
This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read). Comments in the DTD must be properly nested inside start/endDTD and start/endEntity events (if used).
comment
in interface LexicalHandler
ch
- An array holding the characters in the comment.start
- The starting position in the array.end
- The number of characters to use from the array.
SAXException
- The application may raise an exception.public void elementDecl(java.lang.String name, java.lang.String model) throws SAXException
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.
elementDecl
in interface DeclHandler
name
- The element type name.model
- The content model as a normalized string.
SAXException
- The application may raise an exception.public void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value) throws SAXException
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.
attributeDecl
in interface DeclHandler
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.value
- A string representing the attribute's default value,
or null if there is none.
SAXException
- The application may raise an exception.public void internalEntityDecl(java.lang.String name, java.lang.String value) throws SAXException
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.
internalEntityDecl
in interface DeclHandler
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.value
- The replacement text of the entity.
SAXException
- The application may raise an exception.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws SAXException
Only the effective (first) declaration for each entity will be reported.
externalEntityDecl
in interface DeclHandler
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.systemId
- The declared system identifier of the entity.
SAXException
- The application may raise an exception.internalEntityDecl(java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws SAXException
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.
notationDecl
in interface DTDHandler
notationDecl
in class DefaultHandler
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.
SAXException
- Any SAX exception, possibly
wrapping another exception.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
,
AttributeList
public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName) throws SAXException
Note that the notation name corresponds to a notation
reported by the notationDecl
event.
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.
unparsedEntityDecl
in interface DTDHandler
unparsedEntityDecl
in class DefaultHandler
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.
SAXException
- Any SAX exception, possibly
wrapping another exception.notationDecl(java.lang.String, java.lang.String, java.lang.String)
,
AttributeList
public org.dom4j.io.ElementStack getElementStack()
public void setElementStack(org.dom4j.io.ElementStack elementStack)
public EntityResolver getEntityResolver()
public void setEntityResolver(EntityResolver entityResolver)
public InputSource getInputSource()
public void setInputSource(InputSource inputSource)
public boolean isIncludeInternalDTDDeclarations()
public void setIncludeInternalDTDDeclarations(boolean includeInternalDTDDeclarations)
includeInternalDTDDeclarations
- whether or not DTD declarations should be expanded
and included into the DocumentType object.public boolean isIncludeExternalDTDDeclarations()
public void setIncludeExternalDTDDeclarations(boolean includeExternalDTDDeclarations)
includeExternalDTDDeclarations
- whether or not DTD declarations should be expanded
and included into the DocumentType object.public boolean isMergeAdjacentText()
public void setMergeAdjacentText(boolean mergeAdjacentText)
mergeAdjacentText
- New value of property mergeAdjacentText.public boolean isStripWhitespaceText()
public void setStripWhitespaceText(boolean stripWhitespaceText)
stripWhitespaceText
- New value of property stripWhitespaceText.public boolean isIgnoreComments()
public void setIgnoreComments(boolean ignoreComments)
ignoreComments
- whether we should ignore comments or not.protected void completeCurrentTextNode()
protected Document createDocument()
protected boolean isIgnorableEntity(java.lang.String name)
protected void addDeclaredNamespaces(Element element)
protected void addAttributes(Element element, Attributes attributes)
protected void addDTDDeclaration(java.lang.Object declaration)
protected void addExternalDTDDeclaration(java.lang.Object declaration)
protected org.dom4j.io.ElementStack createElementStack()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |