Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 1156
نمايش فراداده

DefaultHandlerorg.xml.sax.helpers

Java 1.4

This helper class implements the four commonly-used SAX handler interfaces from the org.xml.sax package and defines stub implementations for all of their methods. It is usually easier to subclass DefaultHandler and override the desired methods than it is to implement all of the interfaces (and all of their methods) from scratch. DefaultHandler implements ContentHandler, ErrorHandler, EntityResolver and DTDHandler, so you can pass an instance of this class, (or of a subclass you define) to the setContentHandler( ), setErrorHandler( ), setEntityResolver( ), and setDTDHandler( ) methods of an XMLReader. You can also pass an instance of a DefaultHandler subclass directly to one of the parse( ) methods of a javax.xml.parsers.SAXParser. The SAXParser will take care of calling the four relevant methods of its internal XMLReader.

All but two of the methods of DefaultHandler have empty bodies and do nothing. The exceptions are resolveEntity( ) which simply returns null to tell the parser to resolve the entity itself, and fatalError( ) which throws the SAXParseException object that is passed to it.

Figure 22-15. org.xml.sax.helpers.DefaultHandler

public class

DefaultHandler implements org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler { // Public Constructors public

DefaultHandler ( ); // Methods Implementing ContentHandler public void

characters (char[ ]

ch , int

start , int

length ) throws org.xml.sax.SAXException; empty public void

endDocument ( ) throws org.xml.sax.SAXException; empty public void

endElement (String

uri , String

localName , String

qName ) throws org.xml.sax.SAXException; empty public void

endPrefixMapping (String

prefix ) throws org.xml.sax.SAXException; empty public void

ignorableWhitespace (char[ ]

ch , int

start , int

length ) throws org.xml.sax.SAXException; empty public void

processingInstruction (String

target , String

data ) throws org.xml.sax.SAXException; empty public void

setDocumentLocator (org.xml.sax.Locator

locator ); empty public void

skippedEntity (String

name ) throws org.xml.sax.SAXException; empty public void

startDocument ( ) throws org.xml.sax.SAXException; empty public void

startElement (String

uri , String

localName , String

qName , org.xml.sax.Attributes

attributes ) throws org.xml.sax.SAXException; empty public void

startPrefixMapping (String

prefix , String

uri ) throws org.xml.sax.SAXException; empty // Methods Implementing DTDHandler public void

notationDecl (String

name , String

publicId , String

systemId ) throws org.xml.sax.SAXException; empty public void

unparsedEntityDecl (String

name , String

publicId , String

systemId , String

notationName ) throws org.xml.sax.SAXException; empty // Methods Implementing EntityResolver public org.xml.sax.InputSource

resolveEntity (String

publicId , String

systemId ) throws java.io.IOException, org.xml.sax.SAXException; constant // Methods Implementing ErrorHandler public void

error (org.xml.sax.SAXParseException

e ) throws org.xml.sax.SAXException; empty public void

fatalError (org.xml.sax.SAXParseException

e ) throws org.xml.sax.SAXException; public void

warning (org.xml.sax.SAXParseException

e ) throws org.xml.sax.SAXException; empty }

Subclasses

org.xml.sax.ext.DefaultHandler2

Passed To

javax.xml.parsers.SAXParser.parse( )