This adapter class behaves like a SAX2 XMLReader object, but gets its input from the SAX1 Parser object that is passed to the constructor. In order to make this work, it implements the deprecated SAX1 DocumentHandler interface so that it can receive events from the Parser . ParserAdapter provides its own layer of namespace processing to convert a namespace-unaware Parser into a namespace-aware XMLReader . This class is useful when working you are working with a legacy API that supplies a SAX1 Parser object, but want to work with that parser using the SAX2 XMLReader API: to use it, simply pass the Parser object to the ParserAdapter( ) constructor and use the resulting object as you would use any other XMLReader object. There is not perfect congruence between the SAX1 and SAX2 APIs, and a Parser cannot be perfectly adapted to a XMLReader . In particular, a ParserAdapter will never call the skippedEntity( ) handler method because the SAX1 Parser API does not provide notification of skipped entities. Also, it does not attempt to determine whether two namespace-prefixed attributes of an element actually resolve to the same attribute. See also XMLReaderAdapter , an adapter that works in the reverse direction to make a SAX2 parser behave like a SAX1 parser. Figure 22-17. org.xml.sax.helpers.ParserAdapterpublic class ParserAdapter implements org.xml.sax.DocumentHandler, org.xml.sax.XMLReader { // Public Constructors public ParserAdapter ( ) throws org.xml.sax.SAXException; public ParserAdapter (org.xml.sax.Parser parser ); // Methods Implementing DocumentHandler public void characters (char[ ] ch , int start , int length ) throws org.xml.sax.SAXException; public void endDocument ( ) throws org.xml.sax.SAXException; public void endElement (String qName ) throws org.xml.sax.SAXException; public void ignorableWhitespace (char[ ] ch , int start , int length ) throws org.xml.sax.SAXException; public void processingInstruction (String target , String data ) throws org.xml.sax.SAXException; public void setDocumentLocator (org.xml.sax.Locator locator ); public void startDocument ( ) throws org.xml.sax.SAXException; public void startElement (String qName , org.xml.sax.AttributeList qAtts ) throws org.xml.sax.SAXException; // Methods Implementing XMLReader public org.xml.sax.ContentHandler getContentHandler ( ); public org.xml.sax.DTDHandler getDTDHandler ( ); public org.xml.sax.EntityResolver getEntityResolver ( ); public org.xml.sax.ErrorHandler getErrorHandler ( ); public boolean getFeature (String name ) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException; public Object getProperty (String name ) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException; public void parse (String systemId ) throws java.io.IOException, org.xml.sax.SAXException; public void parse (org.xml.sax.InputSource input ) throws java.io.IOException, org.xml.sax.SAXException; public void setContentHandler (org.xml.sax.ContentHandler handler ); public void setDTDHandler (org.xml.sax.DTDHandler handler ); public void setEntityResolver (org.xml.sax.EntityResolver resolver ); public void setErrorHandler (org.xml.sax.ErrorHandler handler ); public void setFeature (String name , boolean value ) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException; public void setProperty (String name , Object value ) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException; } |