Package org.zkoss.idom.input
Class SAXHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.zkoss.idom.input.SAXHandler
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler,org.xml.sax.ext.DeclHandler,org.xml.sax.ext.LexicalHandler
public class SAXHandler extends org.xml.sax.helpers.DefaultHandler implements org.xml.sax.ext.LexicalHandler, org.xml.sax.ext.DeclHandlerThe SAX Handler. It implements ContentHandler, LexicalHandler and DeclHandler. It is the caller's job to set up this handler properly if required.This class doesn't depend on SAXBuilder, so it can be used in any other place, e.g., javax.xml.transform.sax.SAXResult.
- Author:
- tomyeh
- See Also:
SAXBuilder
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Namespace>_declNamespacesThe namespaces in between startPrefixMapping and endPrefixMapping.protected Document_docThe Document being created.protected IDOMFactory_factoryThe iDOM factory.protected boolean_inCDataIndicator of whether we are in a CDATA.protected boolean_inDTDIndicator of whether we are in a DTD.protected org.xml.sax.Locator_locLocator.protected java.util.Stack<Group>_stackThe Group stack.
-
Constructor Summary
Constructors Constructor Description SAXHandler()Constructor.SAXHandler(IDOMFactory factory)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddToCurrentGroup(Item vtx)Adds the item to the current group; also attach the locator.protected voidattachLocator(Item vtx)Attaches the locator to the item.voidattributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)voidcharacters(char[] ch, int start, int length)voidcomment(char[] ch, int start, int length)protected org.xml.sax.InputSourcedefaultResolveEntity(java.lang.String publicId, java.lang.String systemId)The default entity resolver.voidelementDecl(java.lang.String name, java.lang.String model)voidendCDATA()voidendDocument()voidendDTD()voidendElement(java.lang.String nsURI, java.lang.String lname, java.lang.String tname)voidendEntity(java.lang.String name)voidendPrefixMapping(java.lang.String prefix)voiderror(org.xml.sax.SAXParseException ex)voidexternalEntityDecl(java.lang.String name, java.lang.String pubId, java.lang.String sysId)voidfatalError(org.xml.sax.SAXParseException ex)DocumentgetDocument()Gets the document being created.org.xml.sax.EntityResolvergetEntityResolver()Gets the org.xml.sax.EntityResolver.org.xml.sax.ErrorHandlergetErrorHandler()Gets the org.xml.sax.ErrorHandler.IDOMFactorygetIDOMFactory()Gets the iDOM factory.protected GroupgetTopGroup()Returns the top group, or null if not available.voidignorableWhitespace(char[] ch, int start, int length)voidinternalEntityDecl(java.lang.String name, java.lang.String value)booleanisCoalescing()Indicates whether or not the factory is configured to produce parsers which converts CDATA to Text and appends it to the adjacent (if any) Text node.booleanisExpandEntityReferences()Tests whether to expand entity reference nodes.booleanisIgnoringComments()Indicates whether or not the factory is configured to produce parsers which ignores comments.booleanisIgnoringElementContentWhitespace()Tests whether to ignore whitespaces in element content.voidnotationDecl(java.lang.String name, java.lang.String publicID, java.lang.String systemID)protected voidpopGroup()Pops out the current group, and the one under it becomes the new current group.voidprocessingInstruction(java.lang.String target, java.lang.String data)protected voidpushGroup(Group group)Adds a new group to the current group as a child, and pushes the new group to be the new current group.org.xml.sax.InputSourceresolveEntity(java.lang.String publicId, java.lang.String systemId)voidsetCoalescing(boolean coalescing)Specifies that the parser produced by this code will convert CDATA to Text and append it to the adjacent (if any) text.voidsetDocumentLocator(org.xml.sax.Locator locator)voidsetEntityResolver(org.xml.sax.EntityResolver er)Specifies the org.xml.sax.EntityResolver to be used to resolve entities present in the XML document to be parsed.voidsetErrorHandler(org.xml.sax.ErrorHandler eh)Specifies the org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.voidsetExpandEntityReferences(boolean expand)Sets whether to expand entities during parsing.voidsetIDOMFactory(IDOMFactory factory)Sets the iDOM factory.voidsetIgnoringComments(boolean ignoreComments)Specifies that the parser produced by this code will ignore comments.voidsetIgnoringElementContentWhitespace(boolean ignore)Sets whether the parser should eliminate whitespace in element content.voidstartCDATA()voidstartDocument()voidstartDTD(java.lang.String name, java.lang.String pubId, java.lang.String sysId)voidstartElement(java.lang.String nsURI, java.lang.String lname, java.lang.String tname, org.xml.sax.Attributes attrs)voidstartEntity(java.lang.String name)voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)voidunparsedEntityDecl(java.lang.String name, java.lang.String pubId, java.lang.String sysId, java.lang.String notationName)voidwarning(org.xml.sax.SAXParseException ex)
-
-
-
Field Detail
-
_factory
protected IDOMFactory _factory
The iDOM factory.
-
_doc
protected Document _doc
The Document being created.
-
_loc
protected org.xml.sax.Locator _loc
Locator.
-
_inDTD
protected boolean _inDTD
Indicator of whether we are in a DTD.
-
_inCData
protected boolean _inCData
Indicator of whether we are in a CDATA.
-
_stack
protected java.util.Stack<Group> _stack
The Group stack. The top one is the current group being processed.
-
_declNamespaces
protected java.util.List<Namespace> _declNamespaces
The namespaces in between startPrefixMapping and endPrefixMapping.
-
-
Constructor Detail
-
SAXHandler
public SAXHandler(IDOMFactory factory)
Constructor.- Parameters:
factory- the iDOM factory; null for DefaultIDOMFactory.
-
SAXHandler
public SAXHandler()
Constructor.
-
-
Method Detail
-
isIgnoringElementContentWhitespace
public final boolean isIgnoringElementContentWhitespace()
Tests whether to ignore whitespaces in element content.
-
setIgnoringElementContentWhitespace
public final void setIgnoringElementContentWhitespace(boolean ignore)
Sets whether the parser should eliminate whitespace in element content. They are known as "ignorable whitespace". Only whitespace which is contained within element content that has an element only content model will be eliminated (see XML Rec 2.10).For this setting to take effect requires that validation be turned on.
Default: false.
- Parameters:
ignore- Whether to ignore whitespaces in element content.
-
isExpandEntityReferences
public final boolean isExpandEntityReferences()
Tests whether to expand entity reference nodes.
-
setExpandEntityReferences
public final void setExpandEntityReferences(boolean expand)
Sets whether to expand entities during parsing. A true means to expand entities as normal content. A false means to leave entities unexpanded asEntityReferenceobjects.Default: true.
- Parameters:
expand- whether entity expansion should occur.
-
isCoalescing
public final boolean isCoalescing()
Indicates whether or not the factory is configured to produce parsers which converts CDATA to Text and appends it to the adjacent (if any) Text node.Default: false.
- Returns:
- true if the factory is configured to produce parsers which converts CDATA nodes to Text nodes and appends it to the adjacent (if any) Text node; false otherwise.
-
setCoalescing
public final void setCoalescing(boolean coalescing)
Specifies that the parser produced by this code will convert CDATA to Text and append it to the adjacent (if any) text.Default: false.
-
isIgnoringComments
public final boolean isIgnoringComments()
Indicates whether or not the factory is configured to produce parsers which ignores comments.Default: false.
- Returns:
- true if the factory is configured to produce parsers which ignores comments; false otherwise.
-
setIgnoringComments
public final void setIgnoringComments(boolean ignoreComments)
Specifies that the parser produced by this code will ignore comments.Default: false.
-
setErrorHandler
public final void setErrorHandler(org.xml.sax.ErrorHandler eh)
Specifies the org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.Default: null -- to use the default implementation and behavior.
-
getErrorHandler
public final org.xml.sax.ErrorHandler getErrorHandler()
Gets the org.xml.sax.ErrorHandler.- Returns:
- the error handler; null to use the default implementation
-
setEntityResolver
public final void setEntityResolver(org.xml.sax.EntityResolver er)
Specifies the org.xml.sax.EntityResolver to be used to resolve entities present in the XML document to be parsed.Default: null -- to use the default implementation and behavior.
-
getEntityResolver
public final org.xml.sax.EntityResolver getEntityResolver()
Gets the org.xml.sax.EntityResolver.- Returns:
- the entity resolver; null to use the default implementation
-
getDocument
public final Document getDocument()
Gets the document being created. Called to retrieve the iDOM tree after parsed.
-
getIDOMFactory
public final IDOMFactory getIDOMFactory()
Gets the iDOM factory. Null for DefaultIDOMFactory.THE.
-
setIDOMFactory
public final void setIDOMFactory(IDOMFactory factory)
Sets the iDOM factory. Null for DefaultIDOMFactory.THE.
-
attachLocator
protected final void attachLocator(Item vtx)
Attaches the locator to the item.
-
getTopGroup
protected final Group getTopGroup()
Returns the top group, or null if not available.
-
addToCurrentGroup
protected final void addToCurrentGroup(Item vtx)
Adds the item to the current group; also attach the locator.
-
pushGroup
protected final void pushGroup(Group group)
Adds a new group to the current group as a child, and pushes the new group to be the new current group.
-
popGroup
protected final void popGroup()
Pops out the current group, and the one under it becomes the new current group.
-
externalEntityDecl
public void externalEntityDecl(java.lang.String name, java.lang.String pubId, java.lang.String sysId) throws org.xml.sax.SAXException- Specified by:
externalEntityDeclin interfaceorg.xml.sax.ext.DeclHandler- Throws:
org.xml.sax.SAXException
-
internalEntityDecl
public void internalEntityDecl(java.lang.String name, java.lang.String value) throws org.xml.sax.SAXException- Specified by:
internalEntityDeclin interfaceorg.xml.sax.ext.DeclHandler- Throws:
org.xml.sax.SAXException
-
attributeDecl
public void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value) throws org.xml.sax.SAXException- Specified by:
attributeDeclin interfaceorg.xml.sax.ext.DeclHandler- Throws:
org.xml.sax.SAXException
-
elementDecl
public void elementDecl(java.lang.String name, java.lang.String model) throws org.xml.sax.SAXException- Specified by:
elementDeclin interfaceorg.xml.sax.ext.DeclHandler- Throws:
org.xml.sax.SAXException
-
startDTD
public void startDTD(java.lang.String name, java.lang.String pubId, java.lang.String sysId) throws org.xml.sax.SAXException- Specified by:
startDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endDTD
public void endDTD() throws org.xml.sax.SAXException- Specified by:
endDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startEntity
public void startEntity(java.lang.String name) throws org.xml.sax.SAXException- Specified by:
startEntityin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endEntity
public void endEntity(java.lang.String name) throws org.xml.sax.SAXException- Specified by:
endEntityin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startCDATA
public void startCDATA() throws org.xml.sax.SAXException- Specified by:
startCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endCDATA
public void endCDATA() throws org.xml.sax.SAXException- Specified by:
endCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
comment
public void comment(char[] ch, int start, int length) throws org.xml.sax.SAXException- Specified by:
commentin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startDocument
public void startDocument() throws org.xml.sax.SAXException- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
startDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
endDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Overrides:
setDocumentLocatorin classorg.xml.sax.helpers.DefaultHandler
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Overrides:
processingInstructionin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
startPrefixMappingin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
endPrefixMappingin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startElement
public void startElement(java.lang.String nsURI, java.lang.String lname, java.lang.String tname, org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String nsURI, java.lang.String lname, java.lang.String tname) throws org.xml.sax.SAXException- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Overrides:
ignorableWhitespacein classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
notationDecl
public void notationDecl(java.lang.String name, java.lang.String publicID, java.lang.String systemID) throws org.xml.sax.SAXException- Specified by:
notationDeclin interfaceorg.xml.sax.DTDHandler- Overrides:
notationDeclin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
unparsedEntityDecl
public void unparsedEntityDecl(java.lang.String name, java.lang.String pubId, java.lang.String sysId, java.lang.String notationName) throws org.xml.sax.SAXException- Specified by:
unparsedEntityDeclin interfaceorg.xml.sax.DTDHandler- Overrides:
unparsedEntityDeclin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
resolveEntity
public org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException- Specified by:
resolveEntityin interfaceorg.xml.sax.EntityResolver- Overrides:
resolveEntityin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
defaultResolveEntity
protected org.xml.sax.InputSource defaultResolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXExceptionThe default entity resolver. It is used ifsetEntityResolver(org.xml.sax.EntityResolver)is not called. This implementation searches the class path under /metainfo/xml.For example, http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd is asked. It searches from classpath for /metainfo/xml/java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd and /metainfo/xml/portlet-app_1_0.xsd
- Throws:
org.xml.sax.SAXException
-
warning
public void warning(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException- Specified by:
warningin interfaceorg.xml.sax.ErrorHandler- Overrides:
warningin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
error
public void error(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException- Specified by:
errorin interfaceorg.xml.sax.ErrorHandler- Overrides:
errorin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
fatalError
public void fatalError(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException- Specified by:
fatalErrorin interfaceorg.xml.sax.ErrorHandler- Overrides:
fatalErrorin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
-