--- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/SAXCatalogReader.java 2017-06-20 10:53:22.794534876 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,503 +0,0 @@ -/* - * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. - */ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.sun.org.apache.xml.internal.resolver.readers; - -import com.sun.org.apache.xml.internal.resolver.Catalog; -import com.sun.org.apache.xml.internal.resolver.CatalogException; -import com.sun.org.apache.xml.internal.resolver.CatalogManager; -import com.sun.org.apache.xml.internal.resolver.helpers.Debug; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import org.xml.sax.AttributeList; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.DocumentHandler; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.Parser; -import org.xml.sax.SAXException; -import sun.reflect.misc.ReflectUtil; - -/** - * A SAX-based CatalogReader. - * - *
This class is used to read XML Catalogs using the SAX. This reader - * has an advantage over the DOM-based reader in that it functions on - * the stream of SAX events. It has the disadvantage - * that it cannot look around in the tree.
- * - *Since the choice of CatalogReaders (in the InputStream case) can only - * be made on the basis of MIME type, the following problem occurs: only - * one CatalogReader can exist for all XML mime types. In order to get - * around this problem, the SAXCatalogReader relies on a set of external - * CatalogParsers to actually build the catalog.
- * - *The selection of CatalogParsers is made on the basis of the QName - * of the root element of the document.
- * - * @see Catalog - * @see CatalogReader - * @see SAXCatalogReader - * @see TextCatalogReader - * @see DOMCatalogParser - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public class SAXCatalogReader implements CatalogReader, ContentHandler, DocumentHandler { - /** The SAX Parser Factory */ - protected SAXParserFactory parserFactory = null; - - /** The SAX Parser Class */ - protected String parserClass = null; - - /** - * Mapping table from QNames to CatalogParser classes. - * - *Each key in this hash table has the form "elementname" - * or "{namespaceuri}elementname". The former is used if the - * namespace URI is null.
- */ - protected MapsetDocumentLocator
method. Does nothing. */
- public void setDocumentLocator (Locator locator) {
- if (saxParser != null) {
- saxParser.setDocumentLocator(locator);
- }
- }
-
- /** The SAX startDocument
method. Does nothing. */
- public void startDocument () throws SAXException {
- saxParser = null;
- abandonHope = false;
- return;
- }
-
- /** The SAX endDocument
method. Does nothing. */
- public void endDocument ()throws SAXException {
- if (saxParser != null) {
- saxParser.endDocument();
- }
- }
-
- /**
- * The SAX startElement
method.
- *
- * The catalog parser is selected based on the namespace of the - * first element encountered in the catalog.
- */ - public void startElement (String name, - AttributeList atts) - throws SAXException { - - if (abandonHope) { - return; - } - - if (saxParser == null) { - String prefix = ""; - if (name.indexOf(':') > 0) { - prefix = name.substring(0, name.indexOf(':')); - } - - String localName = name; - if (localName.indexOf(':') > 0) { - localName = localName.substring(localName.indexOf(':')+1); - } - - String namespaceURI = null; - if (prefix.length() == 0) { - namespaceURI = atts.getValue("xmlns"); - } else { - namespaceURI = atts.getValue("xmlns:" + prefix); - } - - String saxParserClass = getCatalogParser(namespaceURI, - localName); - - if (saxParserClass == null) { - abandonHope = true; - if (namespaceURI == null) { - debug.message(2, "No Catalog parser for " + name); - } else { - debug.message(2, "No Catalog parser for " - + "{" + namespaceURI + "}" - + name); - } - return; - } - - try { - saxParser = (SAXCatalogParser) - ReflectUtil.forName(saxParserClass).newInstance(); - - saxParser.setCatalog(catalog); - saxParser.startDocument(); - saxParser.startElement(name, atts); - } catch (ClassNotFoundException cnfe) { - saxParser = null; - abandonHope = true; - debug.message(2, cnfe.toString()); - } catch (InstantiationException ie) { - saxParser = null; - abandonHope = true; - debug.message(2, ie.toString()); - } catch (IllegalAccessException iae) { - saxParser = null; - abandonHope = true; - debug.message(2, iae.toString()); - } catch (ClassCastException cce ) { - saxParser = null; - abandonHope = true; - debug.message(2, cce.toString()); - } - } else { - saxParser.startElement(name, atts); - } - } - - /** - * The SAX2startElement
method.
- *
- * The catalog parser is selected based on the namespace of the - * first element encountered in the catalog.
- */ - public void startElement (String namespaceURI, - String localName, - String qName, - Attributes atts) - throws SAXException { - - if (abandonHope) { - return; - } - - if (saxParser == null) { - String saxParserClass = getCatalogParser(namespaceURI, - localName); - - if (saxParserClass == null) { - abandonHope = true; - if (namespaceURI == null) { - debug.message(2, "No Catalog parser for " + localName); - } else { - debug.message(2, "No Catalog parser for " - + "{" + namespaceURI + "}" - + localName); - } - return; - } - - try { - saxParser = (SAXCatalogParser) - ReflectUtil.forName(saxParserClass).newInstance(); - - saxParser.setCatalog(catalog); - saxParser.startDocument(); - saxParser.startElement(namespaceURI, localName, qName, atts); - } catch (ClassNotFoundException cnfe) { - saxParser = null; - abandonHope = true; - debug.message(2, cnfe.toString()); - } catch (InstantiationException ie) { - saxParser = null; - abandonHope = true; - debug.message(2, ie.toString()); - } catch (IllegalAccessException iae) { - saxParser = null; - abandonHope = true; - debug.message(2, iae.toString()); - } catch (ClassCastException cce ) { - saxParser = null; - abandonHope = true; - debug.message(2, cce.toString()); - } - } else { - saxParser.startElement(namespaceURI, localName, qName, atts); - } - } - - /** The SAXendElement
method. Does nothing. */
- public void endElement (String name) throws SAXException {
- if (saxParser != null) {
- saxParser.endElement(name);
- }
- }
-
- /** The SAX2 endElement
method. Does nothing. */
- public void endElement (String namespaceURI,
- String localName,
- String qName) throws SAXException {
- if (saxParser != null) {
- saxParser.endElement(namespaceURI, localName, qName);
- }
- }
-
- /** The SAX characters
method. Does nothing. */
- public void characters (char ch[], int start, int length)
- throws SAXException {
- if (saxParser != null) {
- saxParser.characters(ch, start, length);
- }
- }
-
- /** The SAX ignorableWhitespace
method. Does nothing. */
- public void ignorableWhitespace (char ch[], int start, int length)
- throws SAXException {
- if (saxParser != null) {
- saxParser.ignorableWhitespace(ch, start, length);
- }
- }
-
- /** The SAX processingInstruction
method. Does nothing. */
- public void processingInstruction (String target, String data)
- throws SAXException {
- if (saxParser != null) {
- saxParser.processingInstruction(target, data);
- }
- }
-
- /** The SAX startPrefixMapping
method. Does nothing. */
- public void startPrefixMapping (String prefix, String uri)
- throws SAXException {
- if (saxParser != null) {
- saxParser.startPrefixMapping (prefix, uri);
- }
- }
-
- /** The SAX endPrefixMapping
method. Does nothing. */
- public void endPrefixMapping (String prefix)
- throws SAXException {
- if (saxParser != null) {
- saxParser.endPrefixMapping (prefix);
- }
- }
-
- /** The SAX skippedentity
method. Does nothing. */
- public void skippedEntity (String name)
- throws SAXException {
- if (saxParser != null) {
- saxParser.skippedEntity(name);
- }
- }
-}