gnu.xml.util

Class DomParser

Implemented Interfaces:
XMLReader

public final class DomParser
extends Object
implements XMLReader

This parser emits SAX2 parsing events as it traverses a DOM tree, using any conformant implementation of DOM. It exposes all SAX1 features, and the following SAX2 features and properties (as identified by standard URIs which are not fully provided here). Note that if a Level 1 DOM implementation is given, then this behaves as if namespaces were disabled, and namespace prefixes were enabled.
NameNotes
Features ... URL prefix is http://xml.org/sax/features/
(URL)/external-general-entitiesfalse (does no parsing)
(URL)/external-parameter-entitiesfalse (does no parsing)
(URL)/namespacesValue is fixed at true
(URL)/namespace-prefixesValue is settable, defaulting to false (xmlns attributes hidden, and names aren't prefixed)
(URL)/string-interningValue is fixed at false (DOM provides no guarantees as to interning)
(URL)/validationfalse (does no parsing)
(URL)/lexical-handler/parameter-entitiesfalse (DOM doesn't do parameter entities)
Properties ... URL prefix is http://xml.org/sax/properties/
(URL)/dom-nodeThis property may be set before parsing to hold a DOM Document node; any arguments given to parse methods are ignored. When retrieved during a parse, this value contains the "current" DOM node.
(URL)/declaration-handlerA declaration handler may be provided. Declaration of external general entities is exposed, but not parameter entities; none of the entity names reported here will begin with "%".
(URL)/lexical-handlerA lexical handler may be provided. While the start and end of any external subset are reported, expansion of other parameter entities (e.g. inside attribute list declarations) is not exposed. Expansion of general entities within attributes is also not exposed (see below).

The consequences of modifying a DOM document tree as it is being walked by this "parser" are unspecified; don't do it!

Constructor Summary

DomParser()
Constructs an unitialized SAX2 parser.
DomParser(Node node)
Constructs an SAX2 parser initialized to traverse the specified DOM tree.

Method Summary

ContentHandler
getContentHandler()
SAX2: Returns the object used to report the logical content of an XML document.
DTDHandler
getDTDHandler()
SAX2: Returns the object used to process declarations related to notations and unparsed entities.
EntityResolver
getEntityResolver()
SAX2: Returns the object used when resolving external entities during parsing (both general and parameter entities).
ErrorHandler
getErrorHandler()
SAX2: Returns the object used to receive callbacks for XML errors of all levels (fatal, nonfatal, warning).
boolean
getFeature(String name)
SAX2: Tells whether this parser supports the specified feature.
Object
getProperty(String name)
SAX2: Returns the specified property.
void
parse(String uri)
SAX1: Parses the previously provided DOM document (the input parameter is ignored).
void
parse(InputSource input)
SAX1: Parses the previously provided DOM document (the input parameter is ignored).
void
setContentHandler(ContentHandler handler)
SAX2: Assigns the object used to report the logical content of an XML document.
void
setDTDHandler(DTDHandler handler)
SAX1: Provides an object which may be used to intercept declarations related to notations and unparsed entities.
void
setEntityResolver(EntityResolver resolver)
SAX1: Provides an object which may be used when resolving external entities during parsing (both general and parameter entities).
void
setErrorHandler(ErrorHandler handler)
SAX1: Provides an object which receives callbacks for XML errors of all levels (fatal, nonfatal, warning).
void
setFeature(String name, boolean state)
SAX2: Sets the state of features supported in this parser.
void
setLocale(Locale locale)
SAX1: Identifies the locale which the parser should use for the diagnostics it provides.
void
setProperty(String name, Object state)
SAX2: Assigns the specified property.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

DomParser

public DomParser()
Constructs an unitialized SAX2 parser.

DomParser

public DomParser(Node node)
Constructs an SAX2 parser initialized to traverse the specified DOM tree. If the node is a document, the startDocument() and endDocument() calls bracket the calls exposing children.

Method Details

getContentHandler

public ContentHandler getContentHandler()
SAX2: Returns the object used to report the logical content of an XML document.
Specified by:
getContentHandler in interface XMLReader

getDTDHandler

public DTDHandler getDTDHandler()
SAX2: Returns the object used to process declarations related to notations and unparsed entities.
Specified by:
getDTDHandler in interface XMLReader

getEntityResolver

public EntityResolver getEntityResolver()
SAX2: Returns the object used when resolving external entities during parsing (both general and parameter entities).
Specified by:
getEntityResolver in interface XMLReader

getErrorHandler

public ErrorHandler getErrorHandler()
SAX2: Returns the object used to receive callbacks for XML errors of all levels (fatal, nonfatal, warning).
Specified by:
getErrorHandler in interface XMLReader

getFeature

public boolean getFeature(String name)
            throws SAXNotRecognizedException,
                   SAXNotSupportedException
SAX2: Tells whether this parser supports the specified feature.
Specified by:
getFeature in interface XMLReader

getProperty

public Object getProperty(String name)
            throws SAXNotRecognizedException,
                   SAXNotSupportedException
SAX2: Returns the specified property. At this time only the declaration and lexical handlers, and current the "DOM" node, are supported.
Specified by:
getProperty in interface XMLReader

parse

public void parse(String uri)
            throws SAXException
SAX1: Parses the previously provided DOM document (the input parameter is ignored). When this returns, that same document may be parsed again without needing a "reset".
Specified by:
parse in interface XMLReader
Parameters:
uri - ignored (pass an empty string)
Throws:
SAXException - as defined in the specification for org.xml.sax.Parser.parse()

parse

public void parse(InputSource input)
            throws SAXException
SAX1: Parses the previously provided DOM document (the input parameter is ignored). When this returns, that same document may be parsed again without needing a "reset".
Specified by:
parse in interface XMLReader
Parameters:
input - ignored
Throws:
SAXException - as defined in the specification for org.xml.sax.Parser.parse()

setContentHandler

public void setContentHandler(ContentHandler handler)
SAX2: Assigns the object used to report the logical content of an XML document.
Specified by:
setContentHandler in interface XMLReader

setDTDHandler

public void setDTDHandler(DTDHandler handler)
SAX1: Provides an object which may be used to intercept declarations related to notations and unparsed entities.
Specified by:
setDTDHandler in interface XMLReader

setEntityResolver

public void setEntityResolver(EntityResolver resolver)
SAX1: Provides an object which may be used when resolving external entities during parsing (both general and parameter entities).
Specified by:
setEntityResolver in interface XMLReader

setErrorHandler

public void setErrorHandler(ErrorHandler handler)
SAX1: Provides an object which receives callbacks for XML errors of all levels (fatal, nonfatal, warning).
Specified by:
setErrorHandler in interface XMLReader

setFeature

public void setFeature(String name,
                       boolean state)
            throws SAXNotRecognizedException,
                   SAXNotSupportedException
SAX2: Sets the state of features supported in this parser. Only the namespace support features are mutable.
Specified by:
setFeature in interface XMLReader

setLocale

public void setLocale(Locale locale)
            throws SAXException
SAX1: Identifies the locale which the parser should use for the diagnostics it provides.
Throws:
SAXException - as defined in the specification for org.xml.sax.Parser.setLocale()

setProperty

public void setProperty(String name,
                        Object state)
            throws SAXNotRecognizedException,
                   SAXNotSupportedException
SAX2: Assigns the specified property. At this time only declaration and lexical handlers, and the initial DOM document, are supported. These must not be changed to values of the wrong type. Like SAX1 handlers, these handlers may be changed at any time. Like SAX1 input source or document URI, the initial DOM document may not be changed during a parse.
Specified by:
setProperty in interface XMLReader

DomParser.java -- Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.