1/*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package jdk.internal.util.xml.impl;
27
28import java.io.IOException;
29import java.io.InputStream;
30import jdk.internal.org.xml.sax.InputSource;
31import jdk.internal.org.xml.sax.SAXException;
32import jdk.internal.org.xml.sax.XMLReader;
33import jdk.internal.org.xml.sax.helpers.DefaultHandler;
34import jdk.internal.util.xml.SAXParser;
35
36public class SAXParserImpl extends SAXParser {
37
38    private ParserSAX parser;
39
40    public SAXParserImpl() {
41        super();
42        parser = new ParserSAX();
43    }
44
45    /**
46     * Returns the {@link org.xml.sax.XMLReader} that is encapsulated by the
47     * implementation of this class.
48     *
49     * @return The XMLReader that is encapsulated by the
50     *         implementation of this class.
51     *
52     * @throws SAXException If any SAX errors occur during processing.
53     */
54    public XMLReader getXMLReader()
55            throws SAXException {
56        return parser;
57    }
58
59    /**
60     * Indicates whether or not this parser is configured to
61     * understand namespaces.
62     *
63     * @return true if this parser is configured to
64     *         understand namespaces; false otherwise.
65     */
66    public boolean isNamespaceAware() {
67        return parser.mIsNSAware;
68    }
69
70    /**
71     * Indicates whether or not this parser is configured to validate
72     * XML documents.
73     *
74     * @return true if this parser is configured to validate XML
75     *          documents; false otherwise.
76     */
77    public boolean isValidating() {
78        return false;
79    }
80
81    /**
82     * Parse the content of the given {@link java.io.InputStream}
83     * instance as XML using the specified
84     * {@link org.xml.sax.helpers.DefaultHandler}.
85     *
86     * @param src InputStream containing the content to be parsed.
87     * @param handler The SAX DefaultHandler to use.
88     * @exception IOException If any IO errors occur.
89     * @exception IllegalArgumentException If the given InputStream or handler is null.
90     * @exception SAXException If the underlying parser throws a
91     * SAXException while parsing.
92     * @see org.xml.sax.helpers.DefaultHandler
93     */
94    public void parse(InputStream src, DefaultHandler handler)
95        throws SAXException, IOException
96    {
97        parser.parse(src, handler);
98    }
99
100    /**
101     * Parse the content given {@link org.xml.sax.InputSource}
102     * as XML using the specified
103     * {@link org.xml.sax.helpers.DefaultHandler}.
104     *
105     * @param is The InputSource containing the content to be parsed.
106     * @param handler The SAX DefaultHandler to use.
107     * @exception IOException If any IO errors occur.
108     * @exception IllegalArgumentException If the InputSource or handler is null.
109     * @exception SAXException If the underlying parser throws a
110     * SAXException while parsing.
111     * @see org.xml.sax.helpers.DefaultHandler
112     */
113    public void parse(InputSource is, DefaultHandler handler)
114        throws SAXException, IOException
115    {
116        parser.parse(is, handler);
117    }
118}
119