001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xml.parsers;
030:
031: import com.caucho.xml.QDOMImplementation;
032: import com.caucho.xml.Xml;
033: import com.caucho.xml.XmlParser;
034:
035: import org.w3c.dom.DOMImplementation;
036: import org.w3c.dom.Document;
037: import org.xml.sax.EntityResolver;
038: import org.xml.sax.ErrorHandler;
039: import org.xml.sax.InputSource;
040: import org.xml.sax.SAXException;
041:
042: import javax.xml.parsers.DocumentBuilder;
043: import java.io.IOException;
044: import java.io.InputStream;
045:
046: /**
047: * JAXP document builder factory for strict XML parsing.
048: */
049: public class AbstractDocumentBuilder extends DocumentBuilder {
050: // The parser implementation.
051: protected XmlParser _parser;
052:
053: public DOMImplementation getDOMImplementation() {
054: return new QDOMImplementation();
055: }
056:
057: /**
058: * Parses the document based on an input source.
059: *
060: * @param is the SAX input source
061: *
062: * @return the parsed document
063: */
064: public Document parse(InputSource is) throws IOException,
065: SAXException {
066: return _parser.parseDocument(is);
067: }
068:
069: /**
070: * Parses the document based on an input stream.
071: *
072: * @param is the input stream.
073: *
074: * @return the parsed document
075: */
076: public Document parse(InputStream is) throws IOException,
077: SAXException {
078: return _parser.parseDocument(is);
079: }
080:
081: /**
082: * Parses the document based on an input stream.
083: *
084: * @param is the input stream.
085: * @param systemId the stream's URL.
086: *
087: * @return the parsed document
088: */
089: public Document parse(InputStream is, String systemId)
090: throws IOException, SAXException {
091: return _parser.parseDocument(is, systemId);
092: }
093:
094: public boolean isNamespaceAware() {
095: return _parser.isNamespaceAware();
096: }
097:
098: public boolean isValidating() {
099: return false;
100: }
101:
102: /**
103: * Sets the callback to lookup included files.
104: *
105: * @param er the callback object to find included files.
106: */
107: public void setEntityResolver(EntityResolver er) {
108: _parser.setEntityResolver(er);
109: }
110:
111: public void setErrorHandler(ErrorHandler eh) {
112: _parser.setErrorHandler(eh);
113: }
114:
115: public Document newDocument() {
116: return Xml.createDocument();
117: }
118: }
|