001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: package com.sun.xml.xsom.impl.parser;
021:
022: import com.sun.xml.xsom.parser.XMLParser;
023: import org.xml.sax.InputSource;
024: import org.xml.sax.SAXException;
025: import org.xml.sax.XMLReader;
026: import org.xml.sax.helpers.XMLFilterImpl;
027: import org.xml.sax.helpers.XMLReaderAdapter;
028:
029: import javax.xml.parsers.ParserConfigurationException;
030: import javax.xml.parsers.SAXParser;
031: import javax.xml.parsers.SAXParserFactory;
032: import java.io.IOException;
033:
034: /**
035: * {@link SAXParserFactory} implementation that ultimately
036: * uses {@link XMLParser} to parse documents.
037: *
038: * @author
039: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
040: */
041: public class SAXParserFactoryAdaptor extends SAXParserFactory {
042:
043: private final XMLParser parser;
044:
045: public SAXParserFactoryAdaptor(XMLParser _parser) {
046: this .parser = _parser;
047: }
048:
049: public SAXParser newSAXParser()
050: throws ParserConfigurationException, SAXException {
051: return new SAXParserImpl();
052: }
053:
054: public void setFeature(String name, boolean value) {
055: ;
056: }
057:
058: public boolean getFeature(String name) {
059: return false;
060: }
061:
062: private class SAXParserImpl extends SAXParser {
063: private final XMLReaderImpl reader = new XMLReaderImpl();
064:
065: /**
066: * @deprecated
067: */
068: public org.xml.sax.Parser getParser() throws SAXException {
069: return new XMLReaderAdapter(reader);
070: }
071:
072: public XMLReader getXMLReader() throws SAXException {
073: return reader;
074: }
075:
076: public boolean isNamespaceAware() {
077: return true;
078: }
079:
080: public boolean isValidating() {
081: return false;
082: }
083:
084: public void setProperty(String name, Object value) {
085: }
086:
087: public Object getProperty(String name) {
088: return null;
089: }
090: }
091:
092: private class XMLReaderImpl extends XMLFilterImpl {
093: public void parse(InputSource input) throws IOException,
094: SAXException {
095: parser.parse(input, this , this , this );
096: }
097:
098: public void parse(String systemId) throws IOException,
099: SAXException {
100: parser.parse(new InputSource(systemId), this, this, this);
101: }
102: }
103: }
|