001: package com.rimfaxe.xml.xmlreader;
002:
003: import java.io.*;
004:
005: import javax.xml.parsers.*;
006: import org.xml.sax.*;
007: import org.xml.sax.helpers.XMLReaderAdapter;
008: import org.xml.sax.helpers.DefaultHandler;
009:
010: /** JAXP compatible XMLReader wrapper for Sparta.
011:
012: <blockquote><small> Copyright (C) 2002 Hewlett-Packard Company.
013: This file is part of Sparta, an XML Parser, DOM, and XPath library.
014: This library is free software; you can redistribute it and/or
015: modify it under the terms of the <a href="doc-files/LGPL.txt">GNU
016: Lesser General Public License</a> as published by the Free Software
017: Foundation; either version 2.1 of the License, or (at your option)
018: any later version. This library is distributed in the hope that it
019: will be useful, but WITHOUT ANY WARRANTY; without even the implied
020: warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
021: PURPOSE. </small></blockquote>
022: @version $Date: 2002/12/05 04:37:14 $ $Revision: 1.2 $
023: @author Sergio Marti
024: */
025:
026: public class SAXParserImpl extends SAXParser {
027:
028: private final XMLReaderImpl reader_;
029: private boolean nsAware_ = false;
030:
031: public SAXParserImpl(boolean nsAware) {
032: super ();
033: nsAware_ = nsAware;
034: reader_ = new XMLReaderImpl(nsAware);
035: }
036:
037: /** Returns the SAX parser that is encapsultated by the implementation
038: of this class.
039: @deprecated because org.xml.sax.Parser is deprecated
040: */
041: public org.xml.sax.Parser getParser() {
042: return new XMLReaderAdapter(reader_);
043: }
044:
045: // Returns the XMLReader that is encapsulated by the implementation of
046: // this class.
047: public XMLReader getXMLReader() {
048: return reader_;
049: }
050:
051: // Returns the particular property requested for in the underlying
052: // implementation of XMLReader.
053: public java.lang.Object getProperty(java.lang.String name) {
054: return reader_.getProperty(name);
055: }
056:
057: // Sets the particular property in the underlying implementation of
058: // XMLReader.
059: public void setProperty(java.lang.String name,
060: java.lang.Object value) {
061: reader_.setProperty(name, value);
062: }
063:
064: // Indicates whether or not this parser is configured to understand
065: // namespaces.
066: public boolean isNamespaceAware() {
067: return nsAware_;
068: }
069:
070: // Indicates whether or not this parser is configured to validate XML
071: // documents.
072: public boolean isValidating() {
073: return false;
074: }
075:
076: // Parse the content of the file specified as XML using the specified
077: // DefaultHandler.
078: public void parse(java.io.File f, DefaultHandler dh)
079: throws SAXException, IOException {
080: reader_.init(dh);
081: try {
082: Parser.parse(f, reader_);
083: } catch (ParseException pe) {
084: dh.fatalError(new SAXParseException(pe.getMessage(), "", f
085: .toString(), -1, -1, pe));
086: }
087: }
088:
089: // Parse the content given InputSource as XML using the specified
090: // DefaultHandler.
091: public void parse(InputSource is, DefaultHandler dh)
092: throws SAXException, IOException {
093: reader_.init(dh);
094: reader_.parse(is);
095: }
096:
097: // Parse the content of the given InputStream instance as XML using
098: // the specified DefaultHandler.
099: public void parse(java.io.InputStream is, DefaultHandler dh)
100: throws SAXException, IOException {
101: parse(new InputSource(is), dh);
102: }
103:
104: // Parse the content of the given InputStream instance as XML using
105: // the specified DefaultHandler.
106: public void parse(java.io.InputStream is, DefaultHandler dh,
107: java.lang.String systemId) throws SAXException, IOException {
108: reader_.init(dh);
109: try {
110: Parser.parse(systemId, is, reader_);
111: } catch (ParseException pe) {
112: dh.fatalError(new SAXParseException(pe.getMessage(), "",
113: systemId, -1, -1, pe));
114: }
115: }
116:
117: // Parse the content described by the giving Uniform Resource Identifier
118: // (URI) as XML using the specified DefaultHandler.
119: public void parse(java.lang.String uri, DefaultHandler dh)
120: throws SAXException, IOException {
121: reader_.init(dh);
122: reader_.parse(uri);
123: }
124:
125: }
|