- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.xml.sax.ext.DefaultHandler2
-
- All Implemented Interfaces:
- ContentHandler, DTDHandler, EntityResolver, ErrorHandler, DeclHandler, EntityResolver2, LexicalHandler
public class DefaultHandler2 extends DefaultHandler implements LexicalHandler, DeclHandler, EntityResolver2
This class extends the SAX2 base handler class to support the SAX2LexicalHandler
,DeclHandler
, andEntityResolver2
extensions. Except for overriding the original SAX1resolveEntity()
method the added handler methods just return. Subclassers may override everything on a method-by-method basis.This module, both source code and documentation, is in the Public Domain, and comes with NO WARRANTY.
Note: this class might yet learn that the ContentHandler.setDocumentLocator() call might be passed a
Locator2
object, and that the ContentHandler.startElement() call might be passed aAttributes2
object.- Since:
- SAX 2.0 (extensions 1.1 alpha)
-
-
Constructor Summary
Constructors Constructor and Description DefaultHandler2()
Constructs a handler which ignores all parsing events.
-
Method Summary
Methods Modifier and Type Method and Description void
attributeDecl(String eName, String aName, String type, String mode, String value)
Report an attribute type declaration.void
comment(char[] ch, int start, int length)
Report an XML comment anywhere in the document.void
elementDecl(String name, String model)
Report an element type declaration.void
endCDATA()
Report the end of a CDATA section.void
endDTD()
Report the end of DTD declarations.void
endEntity(String name)
Report the end of an entity.void
externalEntityDecl(String name, String publicId, String systemId)
Report a parsed external entity declaration.InputSource
getExternalSubset(String name, String baseURI)
Tells the parser that if no external subset has been declared in the document text, none should be used.void
internalEntityDecl(String name, String value)
Report an internal entity declaration.InputSource
resolveEntity(String publicId, String systemId)
InvokesEntityResolver2.resolveEntity()
with null entity name and base URI.InputSource
resolveEntity(String name, String publicId, String baseURI, String systemId)
Tells the parser to resolve the systemId against the baseURI and read the entity text from that resulting absolute URI.void
startCDATA()
Report the start of a CDATA section.void
startDTD(String name, String publicId, String systemId)
Report the start of DTD declarations, if any.void
startEntity(String name)
Report the beginning of some internal and external XML entities.-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning
-
-
-
-
Constructor Detail
-
DefaultHandler2
public DefaultHandler2()
Constructs a handler which ignores all parsing events.
-
-
Method Detail
-
startCDATA
public void startCDATA() throws SAXException
Description copied from interface:LexicalHandler
Report the start of a CDATA section.The contents of the CDATA section will be reported through the regular
characters
event; this event is intended only to report the boundary.- Specified by:
startCDATA
in interfaceLexicalHandler
- Throws:
SAXException
- The application may raise an exception.- See Also:
LexicalHandler.endCDATA()
-
endCDATA
public void endCDATA() throws SAXException
Description copied from interface:LexicalHandler
Report the end of a CDATA section.- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
- The application may raise an exception.- See Also:
LexicalHandler.startCDATA()
-
startDTD
public void startDTD(String name, String publicId, String systemId) throws SAXException
Description copied from interface:LexicalHandler
Report the start of DTD declarations, if any.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
orDeclHandler
events must appear between the startDTD andendDTD
events. Declarations are assumed to belong to the internal DTD subset unless they appear betweenstartEntity
andendEntity
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.- Specified by:
startDTD
in interfaceLexicalHandler
- Parameters:
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.)- Throws:
SAXException
- The application may raise an exception.- See Also:
LexicalHandler.endDTD()
,LexicalHandler.startEntity(java.lang.String)
-
endDTD
public void endDTD() throws SAXException
Description copied from interface:LexicalHandler
Report the end of DTD declarations.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.
- Specified by:
endDTD
in interfaceLexicalHandler
- Throws:
SAXException
- The application may raise an exception.- See Also:
LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)
-
startEntity
public void startEntity(String name) throws SAXException
Description copied from interface:LexicalHandler
Report the beginning of some internal and external XML entities.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
orDTDHandler
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:
- general entities within attribute values
- parameter entities within declarations
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.
- Specified by:
startEntity
in interfaceLexicalHandler
- Parameters:
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]".- Throws:
SAXException
- The application may raise an exception.- See Also:
LexicalHandler.endEntity(java.lang.String)
,DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)
,DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
-
endEntity
public void endEntity(String name) throws SAXException
Description copied from interface:LexicalHandler
Report the end of an entity.- Specified by:
endEntity
in interfaceLexicalHandler
- Parameters:
name
- The name of the entity that is ending.- Throws:
SAXException
- The application may raise an exception.- See Also:
LexicalHandler.startEntity(java.lang.String)
-
comment
public void comment(char[] ch, int start, int length) throws SAXException
Description copied from interface:LexicalHandler
Report an XML comment anywhere in the document.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).
- Specified by:
comment
in interfaceLexicalHandler
- Parameters:
ch
- An array holding the characters in the comment.start
- The starting position in the array.length
- The number of characters to use from the array.- Throws:
SAXException
- The application may raise an exception.
-
attributeDecl
public void attributeDecl(String eName, String aName, String type, String mode, String value) throws SAXException
Description copied from interface:DeclHandler
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.
The value will be the value as reported to applications, appropriately normalized and with entity and character references expanded.
- Specified by:
attributeDecl
in interfaceDeclHandler
- Parameters:
eName
- The name of the associated element.aName
- The name of the attribute.type
- A string representing the attribute type.mode
- A string representing the attribute defaulting mode ("#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.- Throws:
SAXException
- The application may raise an exception.
-
elementDecl
public void elementDecl(String name, String model) throws SAXException
Description copied from interface:DeclHandler
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:
elementDecl
in interfaceDeclHandler
- Parameters:
name
- The element type name.model
- The content model as a normalized string.- Throws:
SAXException
- The application may raise an exception.
-
externalEntityDecl
public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException
Description copied from interface:DeclHandler
Report a parsed external entity declaration.Only the effective (first) declaration for each entity will be reported.
If the system identifier is a URL, the parser must resolve it fully before passing it to the application.
- Specified by:
externalEntityDecl
in interfaceDeclHandler
- Parameters:
name
- The name of the entity. If it is a parameter entity, the name will begin with '%'.publicId
- The entity's public identifier, or null if none was given.systemId
- The entity's system identifier.- Throws:
SAXException
- The application may raise an exception.- See Also:
DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)
,DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
-
internalEntityDecl
public void internalEntityDecl(String name, String value) throws SAXException
Description copied from interface:DeclHandler
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:
internalEntityDecl
in 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:
DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
,DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
-
getExternalSubset
public InputSource getExternalSubset(String name, String baseURI) throws SAXException, IOException
Tells the parser that if no external subset has been declared in the document text, none should be used.- Specified by:
getExternalSubset
in interfaceEntityResolver2
- Parameters:
name
- Identifies the document root element. This name comes from a DOCTYPE declaration (where available) or from the actual root element.baseURI
- The document's base URI, serving as an additional hint for selecting the external subset. This is always an absolute URI, unless it is null because the XMLReader was given an InputSource without one.- Returns:
- An InputSource object describing the new external subset to be used by the parser, or null to indicate that no external subset is provided.
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- Probably indicating a failure to create a new InputStream or Reader, or an illegal URL.
-
resolveEntity
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException
Tells the parser to resolve the systemId against the baseURI and read the entity text from that resulting absolute URI. Note that because the olderDefaultHandler.resolveEntity()
, method is overridden to call this one, this method may sometimes be invoked with null name and baseURI, and with the systemId already absolutized.- Specified by:
resolveEntity
in interfaceEntityResolver2
- Parameters:
name
- Identifies the external entity being resolved. Either "[dtd]" for the external subset, or a name starting with "%" to indicate a parameter entity, or else the name of a general entity. This is never null when invoked by a SAX2 parser.publicId
- The public identifier of the external entity being referenced (normalized as required by the XML specification), or null if none was supplied.baseURI
- The URI with respect to which relative systemIDs are interpreted. This is always an absolute URI, unless it is null (likely because the XMLReader was given an InputSource without one). This URI is defined by the XML specification to be the one associated with the "<" starting the relevant declaration.systemId
- The system identifier of the external entity being referenced; either a relative or absolute URI. This is never null when invoked by a SAX2 parser; only declared entities, and any external subset, are resolved by such parsers.- Returns:
- An InputSource object describing the new input source to be used by the parser. Returning null directs the parser to resolve the system ID against the base URI and open a connection to resulting URI.
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- Probably indicating a failure to create a new InputStream or Reader, or an illegal URL.
-
resolveEntity
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
InvokesEntityResolver2.resolveEntity()
with null entity name and base URI. You only need to override that method to use this class.- Specified by:
resolveEntity
in interfaceEntityResolver
- Overrides:
resolveEntity
in classDefaultHandler
- Parameters:
publicId
- The public identifier, or null if none is available.systemId
- The system identifier provided in the XML document.- Returns:
- The new input source, or null to require the default behaviour.
- Throws:
SAXException
- Any SAX exception, possibly wrapping another exception.IOException
- A Java-specific IO exception, possibly the result of creating a new InputStream or Reader for the InputSource.- See Also:
EntityResolver.resolveEntity(java.lang.String, java.lang.String)
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-org/xml/sax/ext/defaulthandler2.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.