Top Description Fields Constructors Methods
org.dom4j.io

public Class SAXContentHandler

extends DefaultHandler
implements LexicalHandler, DeclHandler, DTDHandler
Class Inheritance
All Implemented Interfaces
org.xml.sax.DTDHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler
Known Direct Subclasses
org.dom4j.io.SAXModifyContentHandler
Imports
java.lang.reflect.Method, java.util.ArrayList, .HashMap, .List, .Map, org.dom4j.Branch, .Document, .DocumentFactory, .DocumentType, .Element, .ElementHandler, .Namespace, .QName, org.dom4j.dtd.*, org.dom4j.tree.AbstractElement, .NamespaceStack, org.xml.sax.Attributes, .DTDHandler, .EntityResolver, .InputSource, .Locator, .SAXException, .SAXParseException, org.xml.sax.ext.DeclHandler, .LexicalHandler, .Locator2, org.xml.sax.helpers.DefaultHandler

SAXContentHandler builds a dom4j tree via SAX events.

Author
James Strachan
Version
$Revision: 1.61 $

Field Summary

Modifier and TypeField and Description
private StringBuffer
cdataText

buffer to hold contents of cdata section across multiple characters events

private Element
currentElement

The current element we are on

private int
declaredNamespaceIndex

The number of namespaces that are declared in the current scope

private Document
document

The document that is being built

private DocumentFactory
documentFactory

The factory used to create new Document instances

private ElementHandler
elementHandler

the ElementHandler called as the elements are complete

private ElementStack
elementStack

stack of Element objects

private String
entity

The name of the current entity

private int
entityLevel

The number of levels deep we are inside a startEntity/endEntity call

private EntityResolver
entityResolver

The entity resolver

private List<Decl>
externalDTDDeclarations

external DTD declarations

private boolean
ignoreComments

Should we ignore comments

private boolean
includeExternalDTDDeclarations

Should external DTD declarations be expanded into a List in the DTD

private boolean
includeInternalDTDDeclarations

Should internal DTD declarations be expanded into a List in the DTD

private InputSource
private boolean
insideCDATASection

Flag used to indicate that we are inside a CDATA section

private boolean
insideDTDSection

Flag used to indicate that we are inside a DTD section

private List<Decl>
internalDTDDeclarations

internal DTD declarations

private boolean
internalDTDsubset

Are we in an internal DTD subset?

private Locator
locator

the Locator

private boolean
mergeAdjacentText

Whether adjacent text nodes should be merged

private NamespaceStack
namespaceStack

stack of Namespace and QName objects

private boolean
stripWhitespaceText

Holds value of property stripWhitespaceText.

private StringBuffer
textBuffer

Buffer used to concatenate text together

private boolean
textInTextBuffer

Have we added text to the buffer

Constructor Summary

AccessConstructor and Description
public
public
public
SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler)

public
SAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler, ElementStack elementStack)

Method Summary

Modifier and TypeMethod and Description
protected void
addAttributes(Element
DOCUMENT ME!
element
,
Attributes
DOCUMENT ME!
attributes
)

Add all the attributes to the given elements

protected void
addDeclaredNamespaces(Element
DOCUMENT ME!
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(Decl
DOCUMENT ME!
declaration
)

Adds an internal DTD declaration to the list of declarations

protected void
addExternalDTDDeclaration(Decl
DOCUMENT ME!
declaration
)

Adds an external DTD declaration to the list of declarations

public void
attributeDecl(String
The name of the associated element.
eName
,
String
The name of the attribute.
aName
,
String
A string representing the attribute type.
type
,
String
A string representing the attribute default ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.
valueDefault
,
String
A string representing the attribute's default value, or null if there is none.
val
)

Implements org.xml.sax.ext.DeclHandler.attributeDecl.

Report an attribute type declaration.
public void
characters(char[]
The characters.
ch
,
int
The start position in the character array.
start
,
int
The number of characters to use from the character array.
end
)

Overrides org.xml.sax.helpers.DefaultHandler.characters.

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data inside an element.
public void
comment(char[]
An array holding the characters in the comment.
ch
,
int
The starting position in the array.
start
,
int
The number of characters to use from the array.
end
)

Implements org.xml.sax.ext.LexicalHandler.comment.

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

Returns:

the current document
createDocument
()

DOCUMENT ME!

protected ElementStack
public void
elementDecl(String
The element type name.
name
,
String
The content model as a normalized string.
model
)

Implements org.xml.sax.ext.DeclHandler.elementDecl.

Report an element type declaration.
public void
endCDATA()

Implements org.xml.sax.ext.LexicalHandler.endCDATA.

Report the end of a CDATA section.
public void
endDocument()

Overrides org.xml.sax.helpers.DefaultHandler.endDocument.

Implements org.xml.sax.ContentHandler.endDocument.

Receive notification of the end of the document.
public void
endDTD()

Implements org.xml.sax.ext.LexicalHandler.endDTD.

Report the end of DTD declarations.
public void
endElement(String
The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
namespaceURI
,
String
The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
String
The qualified name (with prefix), or the empty string if qualified names are not available.
qName
)

Overrides org.xml.sax.helpers.DefaultHandler.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.
public void
endEntity(String
The name of the entity that is ending.
name
)

Implements org.xml.sax.ext.LexicalHandler.endEntity.

Report the end of an entity.
public void
endPrefixMapping(String
The Namespace prefix being declared.
prefix
)

Overrides org.xml.sax.helpers.DefaultHandler.endPrefixMapping.

Implements org.xml.sax.ContentHandler.endPrefixMapping.

Receive notification of the end of a Namespace mapping.
public void
error(SAXParseException
DOCUMENT ME!
exception
)

Overrides org.xml.sax.helpers.DefaultHandler.error.

Implements org.xml.sax.ErrorHandler.error.

This method is called when an error is detected during parsing such as a validation error.
public void
externalEntityDecl(String
The name of the entity. If it is a parameter entity, the name will begin with '%'.
name
,
String
The declared public identifier of the entity, or null if none was declared.
publicId
,
String
The declared system identifier of the entity.
sysId
)

Implements org.xml.sax.ext.DeclHandler.externalEntityDecl.

Report a parsed external entity declaration.
public void
fatalError(SAXParseException
DOCUMENT ME!
exception
)

Overrides org.xml.sax.helpers.DefaultHandler.fatalError.

Implements org.xml.sax.ErrorHandler.fatalError.

This method is called when a fatal error occurs during parsing.
public Document

Returns:

the document that has been or is being built
getDocument
()

DOCUMENT ME!

public ElementStack
private String
public EntityResolver
public InputSource
public void
internalEntityDecl(String
The name of the entity. If it is a parameter entity, the name will begin with '%'.
name
,
String
The replacement text of the entity.
value
)

Implements org.xml.sax.ext.DeclHandler.internalEntityDecl.

Report an internal entity declaration.
protected boolean

Returns:

DOCUMENT ME!
isIgnorableEntity
(String
DOCUMENT ME!
name
)

a Strategy Method to determine if a given entity name is ignorable

public boolean

Returns:

boolean
isIgnoreComments
()

Returns whether we should ignore comments or not.

public boolean

Returns:

whether external DTD declarations should be expanded into the DocumentType object or not.
isIncludeExternalDTDDeclarations
()

DOCUMENT ME!

public boolean

Returns:

whether internal DTD declarations should be expanded into the DocumentType object or not.
isIncludeInternalDTDDeclarations
()

DOCUMENT ME!

public boolean

Returns:

Value of property mergeAdjacentText.
isMergeAdjacentText
()

Returns whether adjacent text nodes should be merged together.

public boolean

Returns:

Value of property stripWhitespaceText.
isStripWhitespaceText
()

Sets whether whitespace between element start and end tags should be ignored

public void
notationDecl(String
The notation name.
name
,
String
The notation's public identifier, or null if none was given.
publicId
,
String
The notation's system identifier, or null if none was given.
systemId
)

Overrides org.xml.sax.helpers.DefaultHandler.notationDecl.

Implements org.xml.sax.DTDHandler.notationDecl.

Receive notification of a notation declaration event.
public void
processingInstruction(String
The processing instruction target.
target
,
String
The processing instruction data, or null if none is supplied.
data
)

Overrides org.xml.sax.helpers.DefaultHandler.processingInstruction.

Implements org.xml.sax.ContentHandler.processingInstruction.

Receive notification of a processing instruction.
public void
setDocumentLocator(Locator
A locator for all SAX document events.
documentLocator
)

Overrides org.xml.sax.helpers.DefaultHandler.setDocumentLocator.

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Receive a Locator object for document events.
public void
public void
public void
setIgnoreComments(boolean
whether we should ignore comments or not.
ignoreComments
)

Sets whether we should ignore comments or not.

public void
setIncludeExternalDTDDeclarations(boolean
whether or not DTD declarations should be expanded and included into the DocumentType object.
include
)

Sets whether DTD external declarations should be expanded into the DocumentType object or not.

public void
setIncludeInternalDTDDeclarations(boolean
whether or not DTD declarations should be expanded and included into the DocumentType object.
include
)

Sets whether internal DTD declarations should be expanded into the DocumentType object or not.

public void
public void
setMergeAdjacentText(boolean
New value of property mergeAdjacentText.
mergeAdjacentText
)

Sets whether or not adjacent text nodes should be merged together when parsing.

public void
setStripWhitespaceText(boolean
New value of property stripWhitespaceText.
stripWhitespaceText
)

Sets whether whitespace between element start and end tags should be ignored.

public void
startCDATA()

Implements org.xml.sax.ext.LexicalHandler.startCDATA.

Report the start of a CDATA section.
public void
startDocument()

Overrides org.xml.sax.helpers.DefaultHandler.startDocument.

Implements org.xml.sax.ContentHandler.startDocument.

Receive notification of the beginning of the document.
public void
startDTD(String
The document type name.
name
,
String
The declared public identifier for the external DTD subset, or null if none was declared.
publicId
,
String
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.)
systemId
)

Implements org.xml.sax.ext.LexicalHandler.startDTD.

Report the start of DTD declarations, if any.
public void
startElement(String
The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
namespaceURI
,
String
The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
String
The qualified name (with prefix), or the empty string if qualified names are not available.
qualifiedName
,
Attributes
The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
attributes
)

Overrides org.xml.sax.helpers.DefaultHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Receive notification of the start of an element.
public void
startEntity(String
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]".
name
)

Implements org.xml.sax.ext.LexicalHandler.startEntity.

Report the beginning of some internal and external XML entities.
public void
startPrefixMapping(String
The Namespace prefix being declared.
prefix
,
String
The Namespace URI mapped to the prefix.
uri
)

Overrides org.xml.sax.helpers.DefaultHandler.startPrefixMapping.

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Receive notification of the start of a Namespace mapping.
public void
unparsedEntityDecl(String
The unparsed entity's name.
name
,
String
The entity's public identifier, or null if none was given.
publicId
,
String
The entity's system identifier.
systemId
,
String
The name of the associated notation.
notationName
)

Overrides org.xml.sax.helpers.DefaultHandler.unparsedEntityDecl.

Implements org.xml.sax.DTDHandler.unparsedEntityDecl.

Receive notification of an unparsed entity declaration event.
public void
warning(SAXParseException
DOCUMENT ME!
exception
)

Overrides org.xml.sax.helpers.DefaultHandler.warning.

Implements org.xml.sax.ErrorHandler.warning.

This method is called when a warning occurs during the parsing of the document.
Inherited from org.xml.sax.helpers.DefaultHandler:
ignorableWhitespaceresolveEntityskippedEntity