Package org.zkoss.idom.input
Class SAXHandler
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.zkoss.idom.input.SAXHandler
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler,DeclHandler,LexicalHandler
The 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe namespaces in between startPrefixMapping and endPrefixMapping.protected DocumentThe Document being created.protected IDOMFactoryThe iDOM factory.protected booleanIndicator of whether we are in a CDATA.protected booleanIndicator of whether we are in a DTD.protected LocatorLocator.The Group stack. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddToCurrentGroup(Item vtx) Adds the item to the current group; also attach the locator.protected final voidattachLocator(Item vtx) Attaches the locator to the item.voidvoidcharacters(char[] ch, int start, int length) voidcomment(char[] ch, int start, int length) protected InputSourcedefaultResolveEntity(String publicId, String systemId) The default entity resolver.voidelementDecl(String name, String model) voidendCDATA()voidvoidendDTD()voidendElement(String nsURI, String lname, String tname) voidvoidendPrefixMapping(String prefix) voidvoidexternalEntityDecl(String name, String pubId, String sysId) voidfinal DocumentGets the document being created.final EntityResolverGets the org.xml.sax.EntityResolver.final ErrorHandlerGets the org.xml.sax.ErrorHandler.final IDOMFactoryGets the iDOM factory.protected final GroupReturns the top group, or null if not available.voidignorableWhitespace(char[] ch, int start, int length) voidinternalEntityDecl(String name, String value) final booleanIndicates 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.final booleanTests whether to expand entity reference nodes.final booleanIndicates whether or not the factory is configured to produce parsers which ignores comments.final booleanTests whether to ignore whitespaces in element content.voidnotationDecl(String name, String publicID, String systemID) protected final voidpopGroup()Pops out the current group, and the one under it becomes the new current group.voidprocessingInstruction(String target, String data) protected final voidAdds a new group to the current group as a child, and pushes the new group to be the new current group.resolveEntity(String publicId, String systemId) final 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(Locator locator) final voidSpecifies the org.xml.sax.EntityResolver to be used to resolve entities present in the XML document to be parsed.final voidSpecifies the org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.final voidsetExpandEntityReferences(boolean expand) Sets whether to expand entities during parsing.final voidsetIDOMFactory(IDOMFactory factory) Sets the iDOM factory.final voidsetIgnoringComments(boolean ignoreComments) Specifies that the parser produced by this code will ignore comments.final voidsetIgnoringElementContentWhitespace(boolean ignore) Sets whether the parser should eliminate whitespace in element content.voidvoidvoidvoidstartElement(String nsURI, String lname, String tname, Attributes attrs) voidstartEntity(String name) voidstartPrefixMapping(String prefix, String uri) voidunparsedEntityDecl(String name, String pubId, String sysId, String notationName) voidMethods inherited from class org.xml.sax.helpers.DefaultHandler
skippedEntityMethods 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
-
_factory
The iDOM factory. -
_doc
The Document being created. -
_loc
Locator. -
_inDTD
protected boolean _inDTDIndicator of whether we are in a DTD. -
_inCData
protected boolean _inCDataIndicator of whether we are in a CDATA. -
_stack
The Group stack. The top one is the current group being processed. -
_declNamespaces
The namespaces in between startPrefixMapping and endPrefixMapping.
-
-
Constructor Details
-
SAXHandler
Constructor.- Parameters:
factory- the iDOM factory; null for DefaultIDOMFactory.
-
SAXHandler
public SAXHandler()Constructor.
-
-
Method Details
-
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
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
Gets the org.xml.sax.ErrorHandler.- Returns:
- the error handler; null to use the default implementation
-
setEntityResolver
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
Gets the org.xml.sax.EntityResolver.- Returns:
- the entity resolver; null to use the default implementation
-
getDocument
Gets the document being created. Called to retrieve the iDOM tree after parsed. -
getIDOMFactory
Gets the iDOM factory. Null for DefaultIDOMFactory.THE. -
setIDOMFactory
Sets the iDOM factory. Null for DefaultIDOMFactory.THE. -
attachLocator
Attaches the locator to the item. -
getTopGroup
Returns the top group, or null if not available. -
addToCurrentGroup
Adds the item to the current group; also attach the locator. -
pushGroup
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
- Specified by:
externalEntityDeclin interfaceDeclHandler- Throws:
SAXException
-
internalEntityDecl
- Specified by:
internalEntityDeclin interfaceDeclHandler- Throws:
SAXException
-
attributeDecl
public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws SAXException - Specified by:
attributeDeclin interfaceDeclHandler- Throws:
SAXException
-
elementDecl
- Specified by:
elementDeclin interfaceDeclHandler- Throws:
SAXException
-
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
-
startDocument
- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException
-
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
-
startElement
public void startElement(String nsURI, String lname, String tname, Attributes attrs) 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
-
ignorableWhitespace
- Specified by:
ignorableWhitespacein interfaceContentHandler- Overrides:
ignorableWhitespacein classDefaultHandler- Throws:
SAXException
-
notationDecl
- Specified by:
notationDeclin interfaceDTDHandler- Overrides:
notationDeclin classDefaultHandler- Throws:
SAXException
-
unparsedEntityDecl
public void unparsedEntityDecl(String name, String pubId, String sysId, String notationName) throws SAXException - Specified by:
unparsedEntityDeclin interfaceDTDHandler- Overrides:
unparsedEntityDeclin classDefaultHandler- Throws:
SAXException
-
resolveEntity
- Specified by:
resolveEntityin interfaceEntityResolver- Overrides:
resolveEntityin classDefaultHandler- Throws:
SAXException
-
defaultResolveEntity
The 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:
SAXException
-
warning
- Specified by:
warningin interfaceErrorHandler- Overrides:
warningin classDefaultHandler- Throws:
SAXException
-
error
- Specified by:
errorin interfaceErrorHandler- Overrides:
errorin classDefaultHandler- Throws:
SAXException
-
fatalError
- Specified by:
fatalErrorin interfaceErrorHandler- Overrides:
fatalErrorin classDefaultHandler- Throws:
SAXException
-