--- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/XMLCatalogResolver.java 2017-06-20 10:53:18.954343385 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,596 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * 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.xerces.internal.util; - -import java.io.IOException; - -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.ext.EntityResolver2; - -import org.w3c.dom.ls.LSInput; -import org.w3c.dom.ls.LSResourceResolver; - -import javax.xml.parsers.SAXParserFactory; - -import com.sun.org.apache.xerces.internal.dom.DOMInputImpl; -import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl; - -import com.sun.org.apache.xerces.internal.xni.XNIException; -import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; - -import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; -import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; - -import com.sun.org.apache.xml.internal.resolver.Catalog; -import com.sun.org.apache.xml.internal.resolver.CatalogManager; -import com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader; -import com.sun.org.apache.xml.internal.resolver.readers.SAXCatalogReader; - -/** - *
The catalog resolver handles the resolution of external - * identifiers and URI references through XML catalogs. This - * component supports XML catalogs defined by the - * - * OASIS XML Catalogs Specification. It encapsulates the - * XML Commons resolver. - * An instance of this class may be registered on the parser - * as a SAX entity resolver, as a DOM LSResourceResolver or - * as an XNI entity resolver by setting the property - * (http://apache.org/xml/properties/internal/entity-resolver).
- * - *It is intended that this class may be used standalone to perform - * catalog resolution outside of a parsing context. It may be shared - * between several parsers and the application.
- * - * @deprecated This class and the JDK internal Catalog API in package - * {@code com.sun.org.apache.xml.internal.resolver} - * is encapsulated in JDK 9. The entire implementation under the package is now - * deprecated and subject to removal in a future release. Users of the API should - * migrate to the {@linkplain javax.xml.catalog new public API}. - *- * The new Catalog API is supported throughout the JDK XML Processors, which allows - * the use of Catalog by simply setting a path to a Catalog file as a property. - * - * @author Michael Glavassevich, IBM - * - */ -@Deprecated(since="9", forRemoval=true) -public class XMLCatalogResolver - implements XMLEntityResolver, EntityResolver2, LSResourceResolver { - - /** Internal catalog manager for Apache catalogs. **/ - private CatalogManager fResolverCatalogManager = null; - - /** Internal catalog structure. **/ - private Catalog fCatalog = null; - - /** An array of catalog URIs. **/ - private String [] fCatalogsList = null; - - /** - * Indicates whether the list of catalogs has - * changed since it was processed. - */ - private boolean fCatalogsChanged = true; - - /** Application specified prefer public setting. **/ - private boolean fPreferPublic = true; - - /** - * Indicates whether the application desires that - * the parser or some other component performing catalog - * resolution should use the literal system identifier - * instead of the expanded system identifier. - */ - private boolean fUseLiteralSystemId = true; - - /** - *
Constructs a catalog resolver with a default configuration.
- */ - public XMLCatalogResolver () { - this(null, true); - } - - /** - *Constructs a catalog resolver with the given - * list of entry files.
- * - * @param catalogs an ordered array list of absolute URIs - */ - public XMLCatalogResolver (String [] catalogs) { - this(catalogs, true); - } - - /** - *Constructs a catalog resolver with the given - * list of entry files and the preference for whether - * system or public matches are preferred.
- * - * @param catalogs an ordered array list of absolute URIs - * @param preferPublic the prefer public setting - */ - public XMLCatalogResolver (String [] catalogs, boolean preferPublic) { - init(catalogs, preferPublic); - } - - /** - *Returns the initial list of catalog entry files.
- * - * @return the initial list of catalog entry files - */ - public final synchronized String [] getCatalogList () { - return (fCatalogsList != null) - ? (String[]) fCatalogsList.clone() : null; - } - - /** - *Sets the initial list of catalog entry files. - * If there were any catalog mappings cached from - * the previous list they will be replaced by catalog - * mappings from the new list the next time the catalog - * is queried.
- * - * @param catalogs an ordered array list of absolute URIs - */ - public final synchronized void setCatalogList (String [] catalogs) { - fCatalogsChanged = true; - fCatalogsList = (catalogs != null) - ? (String[]) catalogs.clone() : null; - } - - /** - *Forces the cache of catalog mappings to be cleared.
- */ - public final synchronized void clear () { - fCatalog = null; - } - - /** - *Returns the preference for whether system or public
- * matches are preferred. This is used in the absence
- * of any occurence of the prefer
attribute
- * on the catalog
entry of a catalog. If this
- * property has not yet been explicitly set its value is
- * true
.
Sets the preference for whether system or public
- * matches are preferred. This is used in the absence
- * of any occurence of the prefer
attribute
- * on the catalog
entry of a catalog.
Returns the preference for whether the literal system
- * identifier should be used when resolving system
- * identifiers when both it and the expanded system
- * identifier are available. If this property has not yet
- * been explicitly set its value is true
.
Sets the preference for whether the literal system - * identifier should be used when resolving system - * identifiers when both it and the expanded system - * identifier are available.
- * - *The literal system identifier is the URI as it was - * provided before absolutization. It may be embedded within - * an entity. It may be provided externally or it may be the - * result of redirection. For example, redirection may - * have come from the protocol level through HTTP or from - * an application's entity resolver.
- * - *The expanded system identifier is an absolute URI - * which is the result of resolving the literal system - * identifier against a base URI.
- * - * @param useLiteralSystemId the preference for using - * literal system identifers for catalog resolution - */ - public final void setUseLiteralSystemId (boolean useLiteralSystemId) { - fUseLiteralSystemId = useLiteralSystemId; - } - - /** - *Resolves an external entity. If the entity cannot be
- * resolved, this method should return null
. This
- * method returns an input source if an entry was found in the
- * catalog for the given external identifier. It should be
- * overrided if other behaviour is required.
null
if none was supplied
- * @param systemId the system identifier
- *
- * @throws SAXException any SAX exception, possibly wrapping another exception
- * @throws IOException thrown if some i/o error occurs
- */
- public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException, IOException {
-
- String resolvedId = null;
- if (publicId != null && systemId != null) {
- resolvedId = resolvePublic(publicId, systemId);
- }
- else if (systemId != null) {
- resolvedId = resolveSystem(systemId);
- }
-
- if (resolvedId != null) {
- InputSource source = new InputSource(resolvedId);
- source.setPublicId(publicId);
- return source;
- }
- return null;
- }
-
- /**
- * Resolves an external entity. If the entity cannot be
- * resolved, this method should return null
. This
- * method returns an input source if an entry was found in the
- * catalog for the given external identifier. It should be
- * overrided if other behaviour is required.
null
if none was supplied
- * @param baseURI the URI with respect to which relative systemIDs are interpreted.
- * @param systemId the system identifier
- *
- * @throws SAXException any SAX exception, possibly wrapping another exception
- * @throws IOException thrown if some i/o error occurs
- */
- public InputSource resolveEntity(String name, String publicId,
- String baseURI, String systemId) throws SAXException, IOException {
-
- String resolvedId = null;
-
- if (!getUseLiteralSystemId() && baseURI != null) {
- // Attempt to resolve the system identifier against the base URI.
- try {
- URI uri = new URI(new URI(baseURI), systemId);
- systemId = uri.toString();
- }
- // Ignore the exception. Fallback to the literal system identifier.
- catch (URI.MalformedURIException ex) {}
- }
-
- if (publicId != null && systemId != null) {
- resolvedId = resolvePublic(publicId, systemId);
- }
- else if (systemId != null) {
- resolvedId = resolveSystem(systemId);
- }
-
- if (resolvedId != null) {
- InputSource source = new InputSource(resolvedId);
- source.setPublicId(publicId);
- return source;
- }
- return null;
- }
-
- /**
- * Locates an external subset for documents which do not explicitly
- * provide one. This method always returns null
. It
- * should be overrided if other behaviour is required.
Resolves a resource using the catalog. This method interprets that - * the namespace URI corresponds to uri entries in the catalog. - * Where both a namespace and an external identifier exist, the namespace - * takes precedence.
- * - * @param type the type of the resource being resolved - * @param namespaceURI the namespace of the resource being resolved, - * ornull
if none was supplied
- * @param publicId the public identifier of the resource being resolved,
- * or null
if none was supplied
- * @param systemId the system identifier of the resource being resolved,
- * or null
if none was supplied
- * @param baseURI the absolute base URI of the resource being parsed,
- * or null
if there is no base URI
- */
- public LSInput resolveResource(String type, String namespaceURI,
- String publicId, String systemId, String baseURI) {
-
- String resolvedId = null;
-
- try {
- // The namespace is useful for resolving namespace aware
- // grammars such as XML schema. Let it take precedence over
- // the external identifier if one exists.
- if (namespaceURI != null) {
- resolvedId = resolveURI(namespaceURI);
- }
-
- if (!getUseLiteralSystemId() && baseURI != null) {
- // Attempt to resolve the system identifier against the base URI.
- try {
- URI uri = new URI(new URI(baseURI), systemId);
- systemId = uri.toString();
- }
- // Ignore the exception. Fallback to the literal system identifier.
- catch (URI.MalformedURIException ex) {}
- }
-
- // Resolve against an external identifier if one exists. This
- // is useful for resolving DTD external subsets and other
- // external entities. For XML schemas if there was no namespace
- // mapping we might be able to resolve a system identifier
- // specified as a location hint.
- if (resolvedId == null) {
- if (publicId != null && systemId != null) {
- resolvedId = resolvePublic(publicId, systemId);
- }
- else if (systemId != null) {
- resolvedId = resolveSystem(systemId);
- }
- }
- }
- // Ignore IOException. It cannot be thrown from this method.
- catch (IOException ex) {}
-
- if (resolvedId != null) {
- return new DOMInputImpl(publicId, resolvedId, baseURI);
- }
- return null;
- }
-
-
- /**
- * Resolves an external entity. If the entity cannot be
- * resolved, this method should return null
. This
- * method only calls resolveIdentifier
and returns
- * an input source if an entry was found in the catalog. It
- * should be overrided if other behaviour is required.
Resolves an identifier using the catalog. This method interprets that - * the namespace of the identifier corresponds to uri entries in the catalog. - * Where both a namespace and an external identifier exist, the namespace - * takes precedence.
- * - * @param resourceIdentifier the identifier to resolve - * - * @throws XNIException thrown on general error - * @throws IOException thrown if some i/o error occurs - */ - public String resolveIdentifier(XMLResourceIdentifier resourceIdentifier) - throws IOException, XNIException { - - String resolvedId = null; - - // The namespace is useful for resolving namespace aware - // grammars such as XML schema. Let it take precedence over - // the external identifier if one exists. - String namespace = resourceIdentifier.getNamespace(); - if (namespace != null) { - resolvedId = resolveURI(namespace); - } - - // Resolve against an external identifier if one exists. This - // is useful for resolving DTD external subsets and other - // external entities. For XML schemas if there was no namespace - // mapping we might be able to resolve a system identifier - // specified as a location hint. - if (resolvedId == null) { - String publicId = resourceIdentifier.getPublicId(); - String systemId = getUseLiteralSystemId() - ? resourceIdentifier.getLiteralSystemId() - : resourceIdentifier.getExpandedSystemId(); - if (publicId != null && systemId != null) { - resolvedId = resolvePublic(publicId, systemId); - } - else if (systemId != null) { - resolvedId = resolveSystem(systemId); - } - } - return resolvedId; - } - - /** - *Returns the URI mapping in the catalog for the given
- * external identifier or null
if no mapping
- * exists. If the system identifier is an URN in the
- * publicid
namespace it is converted into
- * a public identifier by URN "unwrapping" as specified
- * in the XML Catalogs specification.
null
if no mapping
- * was found in the catalog
- *
- * @throws IOException if an i/o error occurred while reading
- * the catalog
- */
- public final synchronized String resolveSystem (String systemId)
- throws IOException {
-
- if (fCatalogsChanged) {
- parseCatalogs();
- fCatalogsChanged = false;
- }
- return (fCatalog != null)
- ? fCatalog.resolveSystem(systemId) : null;
- }
-
- /**
- * Returns the URI mapping in the catalog for the given
- * external identifier or null
if no mapping
- * exists. Public identifiers are normalized before
- * comparison.
null
if no mapping
- * was found in the catalog
- *
- * @throws IOException if an i/o error occurred while reading
- * the catalog
- */
- public final synchronized String resolvePublic (String publicId, String systemId)
- throws IOException {
-
- if (fCatalogsChanged) {
- parseCatalogs();
- fCatalogsChanged = false;
- }
- return (fCatalog != null)
- ? fCatalog.resolvePublic(publicId, systemId) : null;
- }
-
- /**
- * Returns the URI mapping in the catalog for the given URI
- * reference or null
if no mapping exists.
- * URI comparison is case sensitive. If the URI reference
- * is an URN in the publicid
namespace
- * it is converted into a public identifier by URN "unwrapping"
- * as specified in the XML Catalogs specification and then
- * resolution is performed following the semantics of
- * external identifier resolution.
null
if no mapping
- * was found in the catalog
- *
- * @throws IOException if an i/o error occurred while reading
- * the catalog
- */
- public final synchronized String resolveURI (String uri)
- throws IOException {
-
- if (fCatalogsChanged) {
- parseCatalogs();
- fCatalogsChanged = false;
- }
- return (fCatalog != null)
- ? fCatalog.resolveURI(uri) : null;
- }
-
- /**
- * Initialization. Create a CatalogManager and set all
- * the properties upfront. This prevents JVM wide system properties
- * or a property file somewhere in the environment from affecting
- * the behaviour of this catalog resolver.
- */
- private void init (String [] catalogs, boolean preferPublic) {
- fCatalogsList = (catalogs != null) ? (String[]) catalogs.clone() : null;
- fPreferPublic = preferPublic;
- fResolverCatalogManager = new CatalogManager();
- fResolverCatalogManager.setAllowOasisXMLCatalogPI(false);
- fResolverCatalogManager.setCatalogClassName("com.sun.org.apache.xml.internal.resolver.Catalog");
- fResolverCatalogManager.setCatalogFiles("");
- fResolverCatalogManager.setIgnoreMissingProperties(true);
- fResolverCatalogManager.setPreferPublic(fPreferPublic);
- fResolverCatalogManager.setRelativeCatalogs(false);
- fResolverCatalogManager.setUseStaticCatalog(false);
- fResolverCatalogManager.setVerbosity(0);
- }
-
- /**
- * Instruct the Catalog
to parse each of the
- * catalogs in the list. Only the first catalog will actually be
- * parsed immediately. The others will be queued and read if
- * they are needed later.
- */
- private void parseCatalogs () throws IOException {
- if (fCatalogsList != null) {
- fCatalog = new Catalog(fResolverCatalogManager);
- attachReaderToCatalog(fCatalog);
- for (int i = 0; i < fCatalogsList.length; ++i) {
- String catalog = fCatalogsList[i];
- if (catalog != null && catalog.length() > 0) {
- fCatalog.parseCatalog(catalog);
- }
- }
- }
- else {
- fCatalog = null;
- }
- }
-
- /**
- * Attaches the reader to the catalog.
- */
- private void attachReaderToCatalog (Catalog catalog) {
-
- SAXParserFactory spf = new SAXParserFactoryImpl();
- spf.setNamespaceAware(true);
- spf.setValidating(false);
-
- SAXCatalogReader saxReader = new SAXCatalogReader(spf);
- saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName, "catalog",
- "com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader");
- catalog.addReader("application/xml", saxReader);
- }
-}
--- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/Catalog.java 2017-06-20 10:53:19.162353758 -0700
+++ /dev/null 2017-06-17 22:58:47.330661897 -0700
@@ -1,2258 +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;
-
-import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
-import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
-import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
-import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
-import com.sun.org.apache.xml.internal.resolver.readers.CatalogReader;
-import com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader;
-import com.sun.org.apache.xml.internal.resolver.readers.SAXCatalogReader;
-import com.sun.org.apache.xml.internal.resolver.readers.TR9401CatalogReader;
-import java.io.DataInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Vector;
-import javax.xml.parsers.SAXParserFactory;
-
-/**
- * Represents OASIS Open Catalog files.
- *
- * This class implements the semantics of OASIS Open Catalog files - * (defined by - * OASIS Technical - * Resolution 9401:1997 (Amendment 2 to TR 9401)).
- * - *The primary purpose of the Catalog is to associate resources in the - * document with local system identifiers. Some entities - * (document types, XML entities, and notations) have names and all of them - * can have either public or system identifiers or both. (In XML, only a - * notation can have a public identifier without a system identifier, but - * the methods implemented in this class obey the Catalog semantics - * from the SGML - * days when system identifiers were optional.)
- * - *The system identifiers returned by the resolution methods in this - * class are valid, i.e. usable by, and in fact constructed by, the - * java.net.URL class. Unfortunately, this class seems to behave in - * somewhat non-standard ways and the system identifiers returned may - * not be directly usable in a browser or filesystem context. - * - *
This class recognizes all of the Catalog entries defined in - * TR9401:1997:
- * - *Note that BASE entries are treated as described by RFC2396. In - * particular, this has the counter-intuitive property that after a BASE - * entry identifing "http://example.com/a/b/c" as the base URI, - * the relative URI "foo" is resolved to the absolute URI - * "http://example.com/a/b/foo". You must provide the trailing slash if - * you do not want the final component of the path to be discarded as a - * filename would in a URI for a resource: "http://example.com/a/b/c/". - *
- * - *Note that subordinate catalogs (all catalogs except the first, - * including CATALOG and DELEGATE* catalogs) are only loaded if and when - * they are required.
- * - *This class relies on classes which implement the CatalogReader - * interface to actually load catalog files. This allows the catalog - * semantics to be implemented for TR9401 text-based catalogs, XML - * catalogs, or any number of other storage formats.
- * - *Additional catalogs may also be loaded with the - * {@link #parseCatalog} method.
- * - *Change Log:
- *Rewrite to use CatalogReaders.
Allow quoted components in xml.catalog.files - * so that URLs containing colons can be used on Unix. - * The string passed to xml.catalog.files can now have the form:
- *- * unquoted-path-with-no-sep-chars:"double-quoted path with or without sep chars":'single-quoted path with or without sep chars' - *- *
(Where ":" is the separater character in this example.)
- *If an unquoted path contains an embedded double or single quote - * character, no special processig is performed on that character. No - * path can contain separater characters, double, and single quotes - * simultaneously.
- *Fix bug in calculation of BASE entries: if - * a catalog contains multiple BASE entries, each is relative to the preceding - * base, not the default base URI of the catalog.
- *Fixed a bug in the calculation of the list of subordinate catalogs. - * This bug caused an infinite loop where parsing would alternately process - * two catalogs indefinitely.
- *- * The new Catalog API is supported throughout the JDK XML Processors, which allows - * the use of Catalog by simply setting a path to a Catalog file as a property. - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - * @version 1.0 - * - *
Derived from public domain code originally published by Arbortext, - * Inc.
- */ -@Deprecated(since="9", forRemoval=true) -public class Catalog { - /** The BASE Catalog Entry type. */ - public static final int BASE = CatalogEntry.addEntryType("BASE", 1); - - /** The CATALOG Catalog Entry type. */ - public static final int CATALOG = CatalogEntry.addEntryType("CATALOG", 1); - - /** The DOCUMENT Catalog Entry type. */ - public static final int DOCUMENT = CatalogEntry.addEntryType("DOCUMENT", 1); - - /** The OVERRIDE Catalog Entry type. */ - public static final int OVERRIDE = CatalogEntry.addEntryType("OVERRIDE", 1); - - /** The SGMLDECL Catalog Entry type. */ - public static final int SGMLDECL = CatalogEntry.addEntryType("SGMLDECL", 1); - - /** The DELEGATE_PUBLIC Catalog Entry type. */ - public static final int DELEGATE_PUBLIC = CatalogEntry.addEntryType("DELEGATE_PUBLIC", 2); - - /** The DELEGATE_SYSTEM Catalog Entry type. */ - public static final int DELEGATE_SYSTEM = CatalogEntry.addEntryType("DELEGATE_SYSTEM", 2); - - /** The DELEGATE_URI Catalog Entry type. */ - public static final int DELEGATE_URI = CatalogEntry.addEntryType("DELEGATE_URI", 2); - - /** The DOCTYPE Catalog Entry type. */ - public static final int DOCTYPE = CatalogEntry.addEntryType("DOCTYPE", 2); - - /** The DTDDECL Catalog Entry type. */ - public static final int DTDDECL = CatalogEntry.addEntryType("DTDDECL", 2); - - /** The ENTITY Catalog Entry type. */ - public static final int ENTITY = CatalogEntry.addEntryType("ENTITY", 2); - - /** The LINKTYPE Catalog Entry type. */ - public static final int LINKTYPE = CatalogEntry.addEntryType("LINKTYPE", 2); - - /** The NOTATION Catalog Entry type. */ - public static final int NOTATION = CatalogEntry.addEntryType("NOTATION", 2); - - /** The PUBLIC Catalog Entry type. */ - public static final int PUBLIC = CatalogEntry.addEntryType("PUBLIC", 2); - - /** The SYSTEM Catalog Entry type. */ - public static final int SYSTEM = CatalogEntry.addEntryType("SYSTEM", 2); - - /** The URI Catalog Entry type. */ - public static final int URI = CatalogEntry.addEntryType("URI", 2); - - /** The REWRITE_SYSTEM Catalog Entry type. */ - public static final int REWRITE_SYSTEM = CatalogEntry.addEntryType("REWRITE_SYSTEM", 2); - - /** The REWRITE_URI Catalog Entry type. */ - public static final int REWRITE_URI = CatalogEntry.addEntryType("REWRITE_URI", 2); - /** The SYSTEM_SUFFIX Catalog Entry type. */ - public static final int SYSTEM_SUFFIX = CatalogEntry.addEntryType("SYSTEM_SUFFIX", 2); - /** The URI_SUFFIX Catalog Entry type. */ - public static final int URI_SUFFIX = CatalogEntry.addEntryType("URI_SUFFIX", 2); - - /** - * The base URI for relative system identifiers in the catalog. - * This may be changed by BASE entries in the catalog. - */ - protected URL base; - - /** The base URI of the Catalog file currently being parsed. */ - protected URL catalogCwd; - - /** The catalog entries currently known to the system. */ - protected Vector catalogEntries = new Vector(); - - /** The default initial override setting. */ - protected boolean default_override = true; - - /** The catalog manager in use for this instance. */ - protected CatalogManager catalogManager = CatalogManager.getStaticManager(); - - /** - * A vector of catalog files to be loaded. - * - *This list is initially established by
- * loadSystemCatalogs
when
- * it parses the system catalog list, but CATALOG entries may
- * contribute to it during the course of parsing.
This two-level system is actually necessary to correctly implement - * the semantics of the CATALOG entry. If one catalog file includes - * another with a CATALOG entry, the included catalog logically - * occurs at the end of the including catalog, and after any - * preceding CATALOG entries. In other words, the CATALOG entry - * cannot insert anything into the middle of a catalog file.
- * - *When processing reaches the end of each catalog files, any
- * elements on this vector are added to the front of the
- * catalogFiles
vector.
The semantics of Catalog resolution are such that each - * catalog is effectively a list of Catalogs (in other words, - * a recursive list of Catalog instances).
- * - *Catalogs that are processed as the result of CATALOG or - * DELEGATE* entries are subordinate to the catalog that contained - * them, but they may in turn have subordinate catalogs.
- * - *Catalogs are only loaded when they are needed, so this vector - * initially contains a list of Catalog filenames (URLs). If, during - * processing, one of these catalogs has to be loaded, the resulting - * Catalog object is placed in the vector, effectively caching it - * for the next query.
- */ - protected Vector catalogs = new Vector(); - - /** - * A vector of DELEGATE* Catalog entries constructed during - * processing of the Catalog. - * - *This two-level system has two purposes; first, it allows - * us to sort the DELEGATE* entries by the length of the partial - * public identifier so that a linear search encounters them in - * the correct order and second, it puts them all at the end of - * the Catalog.
- * - *When processing reaches the end of each catalog file, any
- * elements on this vector are added to the end of the
- * catalogEntries
vector. This assures that matching
- * PUBLIC keywords are encountered before DELEGATE* entries.
This hash maps MIME types to elements in the readerArr - * vector. This allows the Catalog to quickly locate the reader - * for a particular MIME type.
- */ - protected MapThis vector contains all of the readers in the order that they - * were added. In the event that a catalog is read from a file, where - * the MIME type is unknown, each reader is attempted in turn until - * one succeeds.
- */ - protected Vector readerArr = new Vector(); - - /** - * Constructs an empty Catalog. - * - *The constructor interrogates the relevant system properties - * using the default (static) CatalogManager - * and initializes the catalog data structures.
- */ - public Catalog() { - // nop; - } - - /** - * Constructs an empty Catalog with a specific CatalogManager. - * - *The constructor interrogates the relevant system properties - * using the specified Catalog Manager - * and initializes the catalog data structures.
- */ - public Catalog(CatalogManager manager) { - catalogManager = manager; - } - - /** - * Return the CatalogManager used by this catalog. - * - */ - public CatalogManager getCatalogManager() { - return catalogManager; - } - - /** - * Establish the CatalogManager used by this catalog. - * - */ - public void setCatalogManager(CatalogManager manager) { - catalogManager = manager; - } - - /** - * Setup readers. - */ - public void setupReaders() { - SAXParserFactory spf = catalogManager.useServicesMechanism() ? - SAXParserFactory.newInstance() : new SAXParserFactoryImpl(); - spf.setNamespaceAware(true); - spf.setValidating(false); - - SAXCatalogReader saxReader = new SAXCatalogReader(spf); - - saxReader.setCatalogParser(null, "XMLCatalog", - "com.sun.org.apache.xml.internal.resolver.readers.XCatalogReader"); - - saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName, - "catalog", - "com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader"); - - addReader("application/xml", saxReader); - - TR9401CatalogReader textReader = new TR9401CatalogReader(); - addReader("text/plain", textReader); - } - - /** - * Add a new CatalogReader to the Catalog. - * - *This method allows you to add a new CatalogReader to the - * catalog. The reader will be associated with the specified mimeType. - * You can only have one reader per mimeType.
- * - *In the absence of a mimeType (e.g., when reading a catalog - * directly from a file on the local system), the readers are attempted - * in the order that you add them to the Catalog.
- * - *Note that subordinate catalogs (created by CATALOG or - * DELEGATE* entries) get a copy of the set of readers present in - * the primary catalog when they are created. Readers added subsequently - * will not be available. For this reason, it is best to add all - * of the readers before the first call to parse a catalog.
- * - * @param mimeType The MIME type associated with this reader. - * @param reader The CatalogReader to use. - */ - public void addReader(String mimeType, CatalogReader reader) { - if (readerMap.containsKey(mimeType)) { - Integer pos = readerMap.get(mimeType); - readerArr.set(pos, reader); - } else { - readerArr.add(reader); - Integer pos = readerArr.size()-1; - readerMap.put(mimeType, pos); - } - } - - /** - * Copies the reader list from the current Catalog to a new Catalog. - * - *This method is used internally when constructing a new catalog. - * It copies the current reader associations over to the new catalog. - *
- * - * @param newCatalog The new Catalog. - */ - protected void copyReaders(Catalog newCatalog) { - // Have to copy the readers in the right order...convert hash to arr - Vector mapArr = new Vector(readerMap.size()); - - // Pad the mapArr out to the right length - for (int count = 0; count < readerMap.size(); count++) { - mapArr.add(null); - } - - for (Map.EntryThis method constructs a new instance of the running Catalog - * class (which might be a subtype of com.sun.org.apache.xml.internal.resolver.Catalog). - * All new catalogs are managed by the same CatalogManager. - *
- * - *N.B. All Catalog subtypes should call newCatalog() to construct - * a new Catalog. Do not simply use "new Subclass()" since that will - * confuse future subclasses.
- */ - protected Catalog newCatalog() { - String catalogClass = this.getClass().getName(); - - try { - Catalog c = (Catalog) (Class.forName(catalogClass).newInstance()); - c.setCatalogManager(catalogManager); - copyReaders(c); - return c; - } catch (ClassNotFoundException cnfe) { - catalogManager.debug.message(1, "Class Not Found Exception: " + catalogClass); - } catch (IllegalAccessException iae) { - catalogManager.debug.message(1, "Illegal Access Exception: " + catalogClass); - } catch (InstantiationException ie) { - catalogManager.debug.message(1, "Instantiation Exception: " + catalogClass); - } catch (ClassCastException cce) { - catalogManager.debug.message(1, "Class Cast Exception: " + catalogClass); - } catch (Exception e) { - catalogManager.debug.message(1, "Other Exception: " + catalogClass); - } - - Catalog c = new Catalog(); - c.setCatalogManager(catalogManager); - copyReaders(c); - return c; - } - - /** - * Returns the current base URI. - */ - public String getCurrentBase() { - return base.toString(); - } - - /** - * Returns the default override setting associated with this - * catalog. - * - *All catalog files loaded by this catalog will have the - * initial override setting specified by this default.
- */ - public String getDefaultOverride() { - if (default_override) { - return "yes"; - } else { - return "no"; - } - } - - /** - * Load the system catalog files. - * - *The method adds all of the - * catalogs specified in the xml.catalog.files property - * to the Catalog list.
- * - * @throws MalformedURLException One of the system catalogs is - * identified with a filename that is not a valid URL. - * @throws IOException One of the system catalogs cannot be read. - */ - public void loadSystemCatalogs() - throws MalformedURLException, IOException { - - Vector catalogs = catalogManager.getCatalogFiles(); - if (catalogs != null) { - for (int count = 0; count < catalogs.size(); count++) { - catalogFiles.addElement(catalogs.elementAt(count)); - } - } - - if (catalogFiles.size() > 0) { - // This is a little odd. The parseCatalog() method expects - // a filename, but it adds that name to the end of the - // catalogFiles vector, and then processes that vector. - // This allows the system to handle CATALOG entries - // correctly. - // - // In this init case, we take the last element off the - // catalogFiles vector and pass it to parseCatalog. This - // will "do the right thing" in the init case, and allow - // parseCatalog() to do the right thing in the non-init - // case. Honest. - // - String catfile = (String) catalogFiles.lastElement(); - catalogFiles.removeElement(catfile); - parseCatalog(catfile); - } - } - - /** - * Parse a catalog file, augmenting internal data structures. - * - * @param fileName The filename of the catalog file to process - * - * @throws MalformedURLException The fileName cannot be turned into - * a valid URL. - * @throws IOException Error reading catalog file. - */ - public synchronized void parseCatalog(String fileName) - throws MalformedURLException, IOException { - - default_override = catalogManager.getPreferPublic(); - catalogManager.debug.message(4, "Parse catalog: " + fileName); - - // Put the file into the list of catalogs to process... - // In all cases except the case when initCatalog() is the - // caller, this will be the only catalog initially in the list... - catalogFiles.addElement(fileName); - - // Now process all the pending catalogs... - parsePendingCatalogs(); - } - - /** - * Parse a catalog file, augmenting internal data structures. - * - *Catalogs retrieved over the net may have an associated MIME type. - * The MIME type can be used to select an appropriate reader.
- * - * @param mimeType The MIME type of the catalog file. - * @param is The InputStream from which the catalog should be read - * - * @throws CatalogException Failed to load catalog - * mimeType. - * @throws IOException Error reading catalog file. - */ - public synchronized void parseCatalog(String mimeType, InputStream is) - throws IOException, CatalogException { - - default_override = catalogManager.getPreferPublic(); - catalogManager.debug.message(4, "Parse " + mimeType + " catalog on input stream"); - - CatalogReader reader = null; - - if (readerMap.containsKey(mimeType)) { - int arrayPos = ((Integer) readerMap.get(mimeType)).intValue(); - reader = (CatalogReader) readerArr.get(arrayPos); - } - - if (reader == null) { - String msg = "No CatalogReader for MIME type: " + mimeType; - catalogManager.debug.message(2, msg); - throw new CatalogException(CatalogException.UNPARSEABLE, msg); - } - - reader.readCatalog(this, is); - - // Now process all the pending catalogs... - parsePendingCatalogs(); - } - - /** - * Parse a catalog document, augmenting internal data structures. - * - *This method supports catalog files stored in jar files: e.g., - * jar:file:///path/to/filename.jar!/path/to/catalog.xml". That URI - * doesn't survive transmogrification through the URI processing that - * the parseCatalog(String) performs and passing it as an input stream - * doesn't set the base URI appropriately.
- * - *Written by Stefan Wachter (2002-09-26)
- * - * @param aUrl The URL of the catalog document to process - * - * @throws IOException Error reading catalog file. - */ - public synchronized void parseCatalog(URL aUrl) throws IOException { - catalogCwd = aUrl; - base = aUrl; - - default_override = catalogManager.getPreferPublic(); - catalogManager.debug.message(4, "Parse catalog: " + aUrl.toString()); - - DataInputStream inStream = null; - boolean parsed = false; - - for (int count = 0; !parsed && count < readerArr.size(); count++) { - CatalogReader reader = (CatalogReader) readerArr.get(count); - - try { - inStream = new DataInputStream(aUrl.openStream()); - } catch (FileNotFoundException fnfe) { - // No catalog; give up! - break; - } - - try { - reader.readCatalog(this, inStream); - parsed=true; - } catch (CatalogException ce) { - if (ce.getExceptionType() == CatalogException.PARSE_FAILED) { - // give up! - break; - } else { - // try again! - } - } - - try { - inStream.close(); - } catch (IOException e) { - //nop - } - } - - if (parsed) parsePendingCatalogs(); - } - - /** - * Parse all of the pending catalogs. - * - *Catalogs may refer to other catalogs, this method parses - * all of the currently pending catalog files.
- */ - protected synchronized void parsePendingCatalogs() - throws MalformedURLException, IOException { - - if (!localCatalogFiles.isEmpty()) { - // Move all the localCatalogFiles into the front of - // the catalogFiles queue - Vector newQueue = new Vector(); - Enumeration q = localCatalogFiles.elements(); - while (q.hasMoreElements()) { - newQueue.addElement(q.nextElement()); - } - - // Put the rest of the catalogs on the end of the new list - for (int curCat = 0; curCat < catalogFiles.size(); curCat++) { - String catfile = (String) catalogFiles.elementAt(curCat); - newQueue.addElement(catfile); - } - - catalogFiles = newQueue; - localCatalogFiles.clear(); - } - - // Suppose there are no catalog files to process, but the - // single catalog already parsed included some delegate - // entries? Make sure they don't get lost. - if (catalogFiles.isEmpty() && !localDelegate.isEmpty()) { - Enumeration e = localDelegate.elements(); - while (e.hasMoreElements()) { - catalogEntries.addElement(e.nextElement()); - } - localDelegate.clear(); - } - - // Now process all the files on the catalogFiles vector. This - // vector can grow during processing if CATALOG entries are - // encountered in the catalog - while (!catalogFiles.isEmpty()) { - String catfile = (String) catalogFiles.elementAt(0); - try { - catalogFiles.remove(0); - } catch (ArrayIndexOutOfBoundsException e) { - // can't happen - } - - if (catalogEntries.size() == 0 && catalogs.size() == 0) { - // We haven't parsed any catalogs yet, let this - // catalog be the first... - try { - parseCatalogFile(catfile); - } catch (CatalogException ce) { - System.out.println("FIXME: " + ce.toString()); - } - } else { - // This is a subordinate catalog. We save its name, - // but don't bother to load it unless it's necessary. - catalogs.addElement(catfile); - } - - if (!localCatalogFiles.isEmpty()) { - // Move all the localCatalogFiles into the front of - // the catalogFiles queue - Vector newQueue = new Vector(); - Enumeration q = localCatalogFiles.elements(); - while (q.hasMoreElements()) { - newQueue.addElement(q.nextElement()); - } - - // Put the rest of the catalogs on the end of the new list - for (int curCat = 0; curCat < catalogFiles.size(); curCat++) { - catfile = (String) catalogFiles.elementAt(curCat); - newQueue.addElement(catfile); - } - - catalogFiles = newQueue; - localCatalogFiles.clear(); - } - - if (!localDelegate.isEmpty()) { - Enumeration e = localDelegate.elements(); - while (e.hasMoreElements()) { - catalogEntries.addElement(e.nextElement()); - } - localDelegate.clear(); - } - } - - // We've parsed them all, reinit the vector... - catalogFiles.clear(); - } - - /** - * Parse a single catalog file, augmenting internal data structures. - * - * @param fileName The filename of the catalog file to process - * - * @throws MalformedURLException The fileName cannot be turned into - * a valid URL. - * @throws IOException Error reading catalog file. - */ - protected synchronized void parseCatalogFile(String fileName) - throws MalformedURLException, IOException, CatalogException { - - CatalogEntry entry; - - // The base-base is the cwd. If the catalog file is specified - // with a relative path, this assures that it gets resolved - // properly... - try { - // tack on a basename because URLs point to files not dirs - catalogCwd = FileURL.makeURL("basename"); - } catch (MalformedURLException e) { - catalogManager.debug.message(1, "Malformed URL on cwd", "user.dir"); - catalogCwd = null; - } - - // The initial base URI is the location of the catalog file - try { - base = new URL(catalogCwd, fixSlashes(fileName)); - } catch (MalformedURLException e) { - try { - base = new URL("file:" + fixSlashes(fileName)); - } catch (MalformedURLException e2) { - catalogManager.debug.message(1, "Malformed URL on catalog filename", - fixSlashes(fileName)); - base = null; - } - } - - catalogManager.debug.message(2, "Loading catalog", fileName); - catalogManager.debug.message(4, "Default BASE", base.toString()); - - fileName = base.toString(); - - DataInputStream inStream = null; - boolean parsed = false; - boolean notFound = false; - - for (int count = 0; !parsed && count < readerArr.size(); count++) { - CatalogReader reader = (CatalogReader) readerArr.get(count); - - try { - notFound = false; - inStream = new DataInputStream(base.openStream()); - } catch (FileNotFoundException fnfe) { - // No catalog; give up! - notFound = true; - break; - } - - try { - reader.readCatalog(this, inStream); - parsed = true; - } catch (CatalogException ce) { - if (ce.getExceptionType() == CatalogException.PARSE_FAILED) { - // give up! - break; - } else { - // try again! - } - } - - try { - inStream.close(); - } catch (IOException e) { - //nop - } - } - - if (!parsed) { - if (notFound) { - catalogManager.debug.message(3, "Catalog does not exist", fileName); - } else { - catalogManager.debug.message(1, "Failed to parse catalog", fileName); - } - } - } - - /** - * Cleanup and process a Catalog entry. - * - *This method processes each Catalog entry, changing mapped - * relative system identifiers into absolute ones (based on the current - * base URI), and maintaining other information about the current - * catalog.
- * - * @param entry The CatalogEntry to process. - */ - public void addEntry(CatalogEntry entry) { - int type = entry.getEntryType(); - - if (type == BASE) { - String value = entry.getEntryArg(0); - URL newbase = null; - - if (base == null) { - catalogManager.debug.message(5, "BASE CUR", "null"); - } else { - catalogManager.debug.message(5, "BASE CUR", base.toString()); - } - catalogManager.debug.message(4, "BASE STR", value); - - try { - value = fixSlashes(value); - newbase = new URL(base, value); - } catch (MalformedURLException e) { - try { - newbase = new URL("file:" + value); - } catch (MalformedURLException e2) { - catalogManager.debug.message(1, "Malformed URL on base", value); - newbase = null; - } - } - - if (newbase != null) { - base = newbase; - } - - catalogManager.debug.message(5, "BASE NEW", base.toString()); - } else if (type == CATALOG) { - String fsi = makeAbsolute(entry.getEntryArg(0)); - - catalogManager.debug.message(4, "CATALOG", fsi); - - localCatalogFiles.addElement(fsi); - } else if (type == PUBLIC) { - String publicid = PublicId.normalize(entry.getEntryArg(0)); - String systemid = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(0, publicid); - entry.setEntryArg(1, systemid); - - catalogManager.debug.message(4, "PUBLIC", publicid, systemid); - - catalogEntries.addElement(entry); - } else if (type == SYSTEM) { - String systemid = normalizeURI(entry.getEntryArg(0)); - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "SYSTEM", systemid, fsi); - - catalogEntries.addElement(entry); - } else if (type == URI) { - String uri = normalizeURI(entry.getEntryArg(0)); - String altURI = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(1, altURI); - - catalogManager.debug.message(4, "URI", uri, altURI); - - catalogEntries.addElement(entry); - } else if (type == DOCUMENT) { - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(0))); - entry.setEntryArg(0, fsi); - - catalogManager.debug.message(4, "DOCUMENT", fsi); - - catalogEntries.addElement(entry); - } else if (type == OVERRIDE) { - catalogManager.debug.message(4, "OVERRIDE", entry.getEntryArg(0)); - - catalogEntries.addElement(entry); - } else if (type == SGMLDECL) { - // meaningless in XML - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(0))); - entry.setEntryArg(0, fsi); - - catalogManager.debug.message(4, "SGMLDECL", fsi); - - catalogEntries.addElement(entry); - } else if (type == DELEGATE_PUBLIC) { - String ppi = PublicId.normalize(entry.getEntryArg(0)); - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(0, ppi); - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "DELEGATE_PUBLIC", ppi, fsi); - - addDelegate(entry); - } else if (type == DELEGATE_SYSTEM) { - String psi = normalizeURI(entry.getEntryArg(0)); - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(0, psi); - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "DELEGATE_SYSTEM", psi, fsi); - - addDelegate(entry); - } else if (type == DELEGATE_URI) { - String pui = normalizeURI(entry.getEntryArg(0)); - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(0, pui); - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "DELEGATE_URI", pui, fsi); - - addDelegate(entry); - } else if (type == REWRITE_SYSTEM) { - String psi = normalizeURI(entry.getEntryArg(0)); - String rpx = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(0, psi); - entry.setEntryArg(1, rpx); - - catalogManager.debug.message(4, "REWRITE_SYSTEM", psi, rpx); - - catalogEntries.addElement(entry); - } else if (type == REWRITE_URI) { - String pui = normalizeURI(entry.getEntryArg(0)); - String upx = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(0, pui); - entry.setEntryArg(1, upx); - - catalogManager.debug.message(4, "REWRITE_URI", pui, upx); - - catalogEntries.addElement(entry); - } else if (type == SYSTEM_SUFFIX) { - String pui = normalizeURI(entry.getEntryArg(0)); - String upx = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(0, pui); - entry.setEntryArg(1, upx); - - catalogManager.debug.message(4, "SYSTEM_SUFFIX", pui, upx); - - catalogEntries.addElement(entry); - } else if (type == URI_SUFFIX) { - String pui = normalizeURI(entry.getEntryArg(0)); - String upx = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(0, pui); - entry.setEntryArg(1, upx); - - catalogManager.debug.message(4, "URI_SUFFIX", pui, upx); - - catalogEntries.addElement(entry); - } else if (type == DOCTYPE) { - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "DOCTYPE", entry.getEntryArg(0), fsi); - - catalogEntries.addElement(entry); - } else if (type == DTDDECL) { - // meaningless in XML - String fpi = PublicId.normalize(entry.getEntryArg(0)); - entry.setEntryArg(0, fpi); - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "DTDDECL", fpi, fsi); - - catalogEntries.addElement(entry); - } else if (type == ENTITY) { - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "ENTITY", entry.getEntryArg(0), fsi); - - catalogEntries.addElement(entry); - } else if (type == LINKTYPE) { - // meaningless in XML - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "LINKTYPE", entry.getEntryArg(0), fsi); - - catalogEntries.addElement(entry); - } else if (type == NOTATION) { - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "NOTATION", entry.getEntryArg(0), fsi); - - catalogEntries.addElement(entry); - } else { - catalogEntries.addElement(entry); - } - } - - /** - * Handle unknown CatalogEntry types. - * - *This method exists to allow subclasses to deal with unknown - * entry types.
- */ - public void unknownEntry(Vector strings) { - if (strings != null && strings.size() > 0) { - String keyword = (String) strings.elementAt(0); - catalogManager.debug.message(2, "Unrecognized token parsing catalog", keyword); - } - } - - /** - * Parse all subordinate catalogs. - * - *This method recursively parses all of the subordinate catalogs. - * If this method does not throw an exception, you can be confident that - * no subsequent call to any resolve*() method will either, with two - * possible exceptions:
- * - *Delegated catalogs are re-parsed each time they are needed - * (because a variable list of them may be needed in each case, - * depending on the length of the matching partial public identifier).
- *But they are parsed by this method, so as long as they don't - * change or disappear while the program is running, they shouldn't - * generate errors later if they don't generate errors now.
- *If you add new catalogs with parseCatalog
, they
- * won't be loaded until they are needed or until you call
- * parseAllCatalogs
again.
On the other hand, if you don't call this method, you may - * successfully parse documents without having to load all possible - * catalogs.
- * - * @throws MalformedURLException The filename (URL) for a - * subordinate or delegated catalog is not a valid URL. - * @throws IOException Error reading some subordinate or delegated - * catalog file. - */ - public void parseAllCatalogs() - throws MalformedURLException, IOException { - - // Parse all the subordinate catalogs - for (int catPos = 0; catPos < catalogs.size(); catPos++) { - Catalog c = null; - - try { - c = (Catalog) catalogs.elementAt(catPos); - } catch (ClassCastException e) { - String catfile = (String) catalogs.elementAt(catPos); - c = newCatalog(); - - c.parseCatalog(catfile); - catalogs.setElementAt(c, catPos); - c.parseAllCatalogs(); - } - } - - // Parse all the DELEGATE catalogs - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == DELEGATE_PUBLIC - || e.getEntryType() == DELEGATE_SYSTEM - || e.getEntryType() == DELEGATE_URI) { - Catalog dcat = newCatalog(); - dcat.parseCatalog(e.getEntryArg(1)); - } - } - } - - - /** - * Return the applicable DOCTYPE system identifier. - * - * @param entityName The name of the entity (element) for which - * a doctype is required. - * @param publicId The nominal public identifier for the doctype - * (as provided in the source document). - * @param systemId The nominal system identifier for the doctype - * (as provided in the source document). - * - * @return The system identifier to use for the doctype. - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public String resolveDoctype(String entityName, - String publicId, - String systemId) - throws MalformedURLException, IOException { - String resolved = null; - - catalogManager.debug.message(3, "resolveDoctype(" - +entityName+","+publicId+","+systemId+")"); - - systemId = normalizeURI(systemId); - - if (publicId != null && publicId.startsWith("urn:publicid:")) { - publicId = PublicId.decodeURN(publicId); - } - - if (systemId != null && systemId.startsWith("urn:publicid:")) { - systemId = PublicId.decodeURN(systemId); - if (publicId != null && !publicId.equals(systemId)) { - catalogManager.debug.message(1, "urn:publicid: system identifier differs from public identifier; using public identifier"); - systemId = null; - } else { - publicId = systemId; - systemId = null; - } - } - - if (systemId != null) { - // If there's a SYSTEM entry in this catalog, use it - resolved = resolveLocalSystem(systemId); - if (resolved != null) { - return resolved; - } - } - - if (publicId != null) { - // If there's a PUBLIC entry in this catalog, use it - resolved = resolveLocalPublic(DOCTYPE, - entityName, - publicId, - systemId); - if (resolved != null) { - return resolved; - } - } - - // If there's a DOCTYPE entry in this catalog, use it - boolean over = default_override; - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == OVERRIDE) { - over = e.getEntryArg(0).equalsIgnoreCase("YES"); - continue; - } - - if (e.getEntryType() == DOCTYPE - && e.getEntryArg(0).equals(entityName)) { - if (over || systemId == null) { - return e.getEntryArg(1); - } - } - } - - // Otherwise, look in the subordinate catalogs - return resolveSubordinateCatalogs(DOCTYPE, - entityName, - publicId, - systemId); - } - - /** - * Return the applicable DOCUMENT entry. - * - * @return The system identifier to use for the doctype. - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public String resolveDocument() - throws MalformedURLException, IOException { - // If there's a DOCUMENT entry, return it - - catalogManager.debug.message(3, "resolveDocument"); - - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == DOCUMENT) { - return e.getEntryArg(0); - } - } - - return resolveSubordinateCatalogs(DOCUMENT, - null, null, null); - } - - /** - * Return the applicable ENTITY system identifier. - * - * @param entityName The name of the entity for which - * a system identifier is required. - * @param publicId The nominal public identifier for the entity - * (as provided in the source document). - * @param systemId The nominal system identifier for the entity - * (as provided in the source document). - * - * @return The system identifier to use for the entity. - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public String resolveEntity(String entityName, - String publicId, - String systemId) - throws MalformedURLException, IOException { - String resolved = null; - - catalogManager.debug.message(3, "resolveEntity(" - +entityName+","+publicId+","+systemId+")"); - - systemId = normalizeURI(systemId); - - if (publicId != null && publicId.startsWith("urn:publicid:")) { - publicId = PublicId.decodeURN(publicId); - } - - if (systemId != null && systemId.startsWith("urn:publicid:")) { - systemId = PublicId.decodeURN(systemId); - if (publicId != null && !publicId.equals(systemId)) { - catalogManager.debug.message(1, "urn:publicid: system identifier differs from public identifier; using public identifier"); - systemId = null; - } else { - publicId = systemId; - systemId = null; - } - } - - if (systemId != null) { - // If there's a SYSTEM entry in this catalog, use it - resolved = resolveLocalSystem(systemId); - if (resolved != null) { - return resolved; - } - } - - if (publicId != null) { - // If there's a PUBLIC entry in this catalog, use it - resolved = resolveLocalPublic(ENTITY, - entityName, - publicId, - systemId); - if (resolved != null) { - return resolved; - } - } - - // If there's a ENTITY entry in this catalog, use it - boolean over = default_override; - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == OVERRIDE) { - over = e.getEntryArg(0).equalsIgnoreCase("YES"); - continue; - } - - if (e.getEntryType() == ENTITY - && e.getEntryArg(0).equals(entityName)) { - if (over || systemId == null) { - return e.getEntryArg(1); - } - } - } - - // Otherwise, look in the subordinate catalogs - return resolveSubordinateCatalogs(ENTITY, - entityName, - publicId, - systemId); - } - - /** - * Return the applicable NOTATION system identifier. - * - * @param notationName The name of the notation for which - * a doctype is required. - * @param publicId The nominal public identifier for the notation - * (as provided in the source document). - * @param systemId The nominal system identifier for the notation - * (as provided in the source document). - * - * @return The system identifier to use for the notation. - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public String resolveNotation(String notationName, - String publicId, - String systemId) - throws MalformedURLException, IOException { - String resolved = null; - - catalogManager.debug.message(3, "resolveNotation(" - +notationName+","+publicId+","+systemId+")"); - - systemId = normalizeURI(systemId); - - if (publicId != null && publicId.startsWith("urn:publicid:")) { - publicId = PublicId.decodeURN(publicId); - } - - if (systemId != null && systemId.startsWith("urn:publicid:")) { - systemId = PublicId.decodeURN(systemId); - if (publicId != null && !publicId.equals(systemId)) { - catalogManager.debug.message(1, "urn:publicid: system identifier differs from public identifier; using public identifier"); - systemId = null; - } else { - publicId = systemId; - systemId = null; - } - } - - if (systemId != null) { - // If there's a SYSTEM entry in this catalog, use it - resolved = resolveLocalSystem(systemId); - if (resolved != null) { - return resolved; - } - } - - if (publicId != null) { - // If there's a PUBLIC entry in this catalog, use it - resolved = resolveLocalPublic(NOTATION, - notationName, - publicId, - systemId); - if (resolved != null) { - return resolved; - } - } - - // If there's a NOTATION entry in this catalog, use it - boolean over = default_override; - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == OVERRIDE) { - over = e.getEntryArg(0).equalsIgnoreCase("YES"); - continue; - } - - if (e.getEntryType() == NOTATION - && e.getEntryArg(0).equals(notationName)) { - if (over || systemId == null) { - return e.getEntryArg(1); - } - } - } - - // Otherwise, look in the subordinate catalogs - return resolveSubordinateCatalogs(NOTATION, - notationName, - publicId, - systemId); - } - - /** - * Return the applicable PUBLIC or SYSTEM identifier. - * - *This method searches the Catalog and returns the system - * identifier specified for the given system or - * public identifiers. If - * no appropriate PUBLIC or SYSTEM entry is found in the Catalog, - * null is returned.
- * - * @param publicId The public identifier to locate in the catalog. - * Public identifiers are normalized before comparison. - * @param systemId The nominal system identifier for the entity - * in question (as provided in the source document). - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - * - * @return The system identifier to use. - * Note that the nominal system identifier is not returned if a - * match is not found in the catalog, instead null is returned - * to indicate that no match was found. - */ - public String resolvePublic(String publicId, String systemId) - throws MalformedURLException, IOException { - - catalogManager.debug.message(3, "resolvePublic("+publicId+","+systemId+")"); - - systemId = normalizeURI(systemId); - - if (publicId != null && publicId.startsWith("urn:publicid:")) { - publicId = PublicId.decodeURN(publicId); - } - - if (systemId != null && systemId.startsWith("urn:publicid:")) { - systemId = PublicId.decodeURN(systemId); - if (publicId != null && !publicId.equals(systemId)) { - catalogManager.debug.message(1, "urn:publicid: system identifier differs from public identifier; using public identifier"); - systemId = null; - } else { - publicId = systemId; - systemId = null; - } - } - - // If there's a SYSTEM entry in this catalog, use it - if (systemId != null) { - String resolved = resolveLocalSystem(systemId); - if (resolved != null) { - return resolved; - } - } - - // If there's a PUBLIC entry in this catalog, use it - String resolved = resolveLocalPublic(PUBLIC, - null, - publicId, - systemId); - if (resolved != null) { - return resolved; - } - - // Otherwise, look in the subordinate catalogs - return resolveSubordinateCatalogs(PUBLIC, - null, - publicId, - systemId); - } - - /** - * Return the applicable PUBLIC or SYSTEM identifier. - * - *This method searches the Catalog and returns the system - * identifier specified for the given system or public identifiers. - * If no appropriate PUBLIC or SYSTEM entry is found in the Catalog, - * delegated Catalogs are interrogated.
- * - *There are four possible cases:
- * - *If a SYSTEM entry exists in the Catalog - * for the system ID specified, return the mapped value.
- * - *On Windows-based operating systems, the comparison between - * the system identifier provided and the SYSTEM entries in the - * Catalog is case-insensitive.
- * - * @param systemId The system ID to locate in the catalog. - * - * @return The resolved system identifier. - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public String resolveSystem(String systemId) - throws MalformedURLException, IOException { - - catalogManager.debug.message(3, "resolveSystem("+systemId+")"); - - systemId = normalizeURI(systemId); - - if (systemId != null && systemId.startsWith("urn:publicid:")) { - systemId = PublicId.decodeURN(systemId); - return resolvePublic(systemId, null); - } - - // If there's a SYSTEM entry in this catalog, use it - if (systemId != null) { - String resolved = resolveLocalSystem(systemId); - if (resolved != null) { - return resolved; - } - } - - // Otherwise, look in the subordinate catalogs - return resolveSubordinateCatalogs(SYSTEM, - null, - null, - systemId); - } - - /** - * Return the applicable SYSTEM system identifier in this - * catalog. - * - *If a SYSTEM entry exists in the catalog file - * for the system ID specified, return the mapped value.
- * - * @param systemId The system ID to locate in the catalog - * - * @return The mapped system identifier or null - */ - protected String resolveLocalSystem(String systemId) - throws MalformedURLException, IOException { - - String osname = SecuritySupport.getSystemProperty("os.name"); - boolean windows = (osname.indexOf("Windows") >= 0); - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == SYSTEM - && (e.getEntryArg(0).equals(systemId) - || (windows - && e.getEntryArg(0).equalsIgnoreCase(systemId)))) { - return e.getEntryArg(1); - } - } - - // If there's a REWRITE_SYSTEM entry in this catalog, use it - en = catalogEntries.elements(); - String startString = null; - String prefix = null; - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - - if (e.getEntryType() == REWRITE_SYSTEM) { - String p = (String) e.getEntryArg(0); - if (p.length() <= systemId.length() - && p.equals(systemId.substring(0, p.length()))) { - // Is this the longest prefix? - if (startString == null - || p.length() > startString.length()) { - startString = p; - prefix = e.getEntryArg(1); - } - } - } - } - - if (prefix != null) { - // return the systemId with the new prefix - return prefix + systemId.substring(startString.length()); - } - - // If there's a SYSTEM_SUFFIX entry in this catalog, use it - en = catalogEntries.elements(); - String suffixString = null; - String suffixURI = null; - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - - if (e.getEntryType() == SYSTEM_SUFFIX) { - String p = (String) e.getEntryArg(0); - if (p.length() <= systemId.length() - && systemId.endsWith(p)) { - // Is this the longest prefix? - if (suffixString == null - || p.length() > suffixString.length()) { - suffixString = p; - suffixURI = e.getEntryArg(1); - } - } - } - } - - if (suffixURI != null) { - // return the systemId for the suffix - return suffixURI; - } - - // If there's a DELEGATE_SYSTEM entry in this catalog, use it - en = catalogEntries.elements(); - Vector delCats = new Vector(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - - if (e.getEntryType() == DELEGATE_SYSTEM) { - String p = (String) e.getEntryArg(0); - if (p.length() <= systemId.length() - && p.equals(systemId.substring(0, p.length()))) { - // delegate this match to the other catalog - - delCats.addElement(e.getEntryArg(1)); - } - } - } - - if (delCats.size() > 0) { - Enumeration enCats = delCats.elements(); - - if (catalogManager.debug.getDebug() > 1) { - catalogManager.debug.message(2, "Switching to delegated catalog(s):"); - while (enCats.hasMoreElements()) { - String delegatedCatalog = (String) enCats.nextElement(); - catalogManager.debug.message(2, "\t" + delegatedCatalog); - } - } - - Catalog dcat = newCatalog(); - - enCats = delCats.elements(); - while (enCats.hasMoreElements()) { - String delegatedCatalog = (String) enCats.nextElement(); - dcat.parseCatalog(delegatedCatalog); - } - - return dcat.resolveSystem(systemId); - } - - return null; - } - - /** - * Return the applicable URI. - * - *If a URI entry exists in the Catalog - * for the URI specified, return the mapped value.
- * - *URI comparison is case sensitive.
- * - * @param uri The URI to locate in the catalog. - * - * @return The resolved URI. - * - * @throws MalformedURLException The system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public String resolveURI(String uri) - throws MalformedURLException, IOException { - - catalogManager.debug.message(3, "resolveURI("+uri+")"); - - uri = normalizeURI(uri); - - if (uri != null && uri.startsWith("urn:publicid:")) { - uri = PublicId.decodeURN(uri); - return resolvePublic(uri, null); - } - - // If there's a URI entry in this catalog, use it - if (uri != null) { - String resolved = resolveLocalURI(uri); - if (resolved != null) { - return resolved; - } - } - - // Otherwise, look in the subordinate catalogs - return resolveSubordinateCatalogs(URI, - null, - null, - uri); - } - - /** - * Return the applicable URI in this catalog. - * - *If a URI entry exists in the catalog file - * for the URI specified, return the mapped value.
- * - * @param uri The URI to locate in the catalog - * - * @return The mapped URI or null - */ - protected String resolveLocalURI(String uri) - throws MalformedURLException, IOException { - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == URI - && (e.getEntryArg(0).equals(uri))) { - return e.getEntryArg(1); - } - } - - // If there's a REWRITE_URI entry in this catalog, use it - en = catalogEntries.elements(); - String startString = null; - String prefix = null; - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - - if (e.getEntryType() == REWRITE_URI) { - String p = (String) e.getEntryArg(0); - if (p.length() <= uri.length() - && p.equals(uri.substring(0, p.length()))) { - // Is this the longest prefix? - if (startString == null - || p.length() > startString.length()) { - startString = p; - prefix = e.getEntryArg(1); - } - } - } - } - - if (prefix != null) { - // return the uri with the new prefix - return prefix + uri.substring(startString.length()); - } - - // If there's a URI_SUFFIX entry in this catalog, use it - en = catalogEntries.elements(); - String suffixString = null; - String suffixURI = null; - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - - if (e.getEntryType() == URI_SUFFIX) { - String p = (String) e.getEntryArg(0); - if (p.length() <= uri.length() - && uri.endsWith(p)) { - // Is this the longest prefix? - if (suffixString == null - || p.length() > suffixString.length()) { - suffixString = p; - suffixURI = e.getEntryArg(1); - } - } - } - } - - if (suffixURI != null) { - // return the uri for the suffix - return suffixURI; - } - - // If there's a DELEGATE_URI entry in this catalog, use it - en = catalogEntries.elements(); - Vector delCats = new Vector(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - - if (e.getEntryType() == DELEGATE_URI) { - String p = (String) e.getEntryArg(0); - if (p.length() <= uri.length() - && p.equals(uri.substring(0, p.length()))) { - // delegate this match to the other catalog - - delCats.addElement(e.getEntryArg(1)); - } - } - } - - if (delCats.size() > 0) { - Enumeration enCats = delCats.elements(); - - if (catalogManager.debug.getDebug() > 1) { - catalogManager.debug.message(2, "Switching to delegated catalog(s):"); - while (enCats.hasMoreElements()) { - String delegatedCatalog = (String) enCats.nextElement(); - catalogManager.debug.message(2, "\t" + delegatedCatalog); - } - } - - Catalog dcat = newCatalog(); - - enCats = delCats.elements(); - while (enCats.hasMoreElements()) { - String delegatedCatalog = (String) enCats.nextElement(); - dcat.parseCatalog(delegatedCatalog); - } - - return dcat.resolveURI(uri); - } - - return null; - } - - /** - * Search the subordinate catalogs, in order, looking for a match. - * - *This method searches the Catalog and returns the system - * identifier specified for the given entity type with the given - * name, public, and system identifiers. In some contexts, these - * may be null.
- * - * @param entityType The CatalogEntry type for which this query is - * being conducted. This is necessary in order to do the approprate - * query on a subordinate catalog. - * @param entityName The name of the entity being searched for, if - * appropriate. - * @param publicId The public identifier of the entity in question - * (as provided in the source document). - * @param systemId The nominal system identifier for the entity - * in question (as provided in the source document). This parameter is - * overloaded for the URI entry type. - * - * @throws MalformedURLException The formal system identifier of a - * delegated catalog cannot be turned into a valid URL. - * @throws IOException Error reading delegated catalog file. - * - * @return The system identifier to use. - * Note that the nominal system identifier is not returned if a - * match is not found in the catalog, instead null is returned - * to indicate that no match was found. - */ - protected synchronized String resolveSubordinateCatalogs(int entityType, - String entityName, - String publicId, - String systemId) - throws MalformedURLException, IOException { - - for (int catPos = 0; catPos < catalogs.size(); catPos++) { - Catalog c = null; - - try { - c = (Catalog) catalogs.elementAt(catPos); - } catch (ClassCastException e) { - String catfile = (String) catalogs.elementAt(catPos); - c = newCatalog(); - - try { - c.parseCatalog(catfile); - } catch (MalformedURLException mue) { - catalogManager.debug.message(1, "Malformed Catalog URL", catfile); - } catch (FileNotFoundException fnfe) { - catalogManager.debug.message(1, "Failed to load catalog, file not found", - catfile); - } catch (IOException ioe) { - catalogManager.debug.message(1, "Failed to load catalog, I/O error", catfile); - } - - catalogs.setElementAt(c, catPos); - } - - String resolved = null; - - // Ok, now what are we supposed to call here? - if (entityType == DOCTYPE) { - resolved = c.resolveDoctype(entityName, - publicId, - systemId); - } else if (entityType == DOCUMENT) { - resolved = c.resolveDocument(); - } else if (entityType == ENTITY) { - resolved = c.resolveEntity(entityName, - publicId, - systemId); - } else if (entityType == NOTATION) { - resolved = c.resolveNotation(entityName, - publicId, - systemId); - } else if (entityType == PUBLIC) { - resolved = c.resolvePublic(publicId, systemId); - } else if (entityType == SYSTEM) { - resolved = c.resolveSystem(systemId); - } else if (entityType == URI) { - resolved = c.resolveURI(systemId); - } - - if (resolved != null) { - return resolved; - } - } - - return null; - } - - // ----------------------------------------------------------------- - - /** - * Replace backslashes with forward slashes. (URLs always use - * forward slashes.) - * - * @param sysid The input system identifier. - * @return The same system identifier with backslashes turned into - * forward slashes. - */ - protected String fixSlashes (String sysid) { - return sysid.replace('\\', '/'); - } - - /** - * Construct an absolute URI from a relative one, using the current - * base URI. - * - * @param sysid The (possibly relative) system identifier - * @return The system identifier made absolute with respect to the - * current {@link #base}. - */ - protected String makeAbsolute(String sysid) { - URL local = null; - - sysid = fixSlashes(sysid); - - try { - local = new URL(base, sysid); - } catch (MalformedURLException e) { - catalogManager.debug.message(1, "Malformed URL on system identifier", sysid); - } - - if (local != null) { - return local.toString(); - } else { - return sysid; - } - } - - - /** - * Perform character normalization on a URI reference. - * - * @param uriref The URI reference - * @return The normalized URI reference. - */ - protected String normalizeURI(String uriref) { - if (uriref == null) { - return null; - } - final int length = uriref.length(); - for (int i = 0; i < length; ++i) { - char c = uriref.charAt(i); - if ((c <= 0x20) // ctrl - || (c > 0x7F) // high ascii - || (c == 0x22) // " - || (c == 0x3C) // < - || (c == 0x3E) // > - || (c == 0x5C) // \ - || (c == 0x5E) // ^ - || (c == 0x60) // ` - || (c == 0x7B) // { - || (c == 0x7C) // | - || (c == 0x7D) // } - || (c == 0x7F)) { - return normalizeURI(uriref, i); - } - } - return uriref; - } - - /** - * Perform character normalization on a URI reference. - * - * @param uriref The URI reference - * @param index The index of the first character which requires escaping. - * @return The normalized URI reference. - */ - private String normalizeURI(String uriref, int index) { - final StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < index; ++i) { - buffer.append(uriref.charAt(i)); - } - final byte[] bytes; - try { - bytes = uriref.substring(index).getBytes("UTF-8"); - } - catch (UnsupportedEncodingException uee) { - // this can't happen - catalogManager.debug.message(1, "UTF-8 is an unsupported encoding!?"); - return uriref; - } - for (int count = 0; count < bytes.length; ++count) { - int ch = bytes[count] & 0xFF; - if ((ch <= 0x20) // ctrl - || (ch > 0x7F) // high ascii - || (ch == 0x22) // " - || (ch == 0x3C) // < - || (ch == 0x3E) // > - || (ch == 0x5C) // \ - || (ch == 0x5E) // ^ - || (ch == 0x60) // ` - || (ch == 0x7B) // { - || (ch == 0x7C) // | - || (ch == 0x7D) // } - || (ch == 0x7F)) { - writeEncodedByte(ch, buffer); - } - else { - buffer.append((char) bytes[count]); - } - } - return buffer.toString(); - } - - /** - * Perform %-encoding on a single byte. - * - * @param b The 8-bit integer that represents the byte. (Bytes are signed - * but encoding needs to look at the bytes unsigned.) - * @return The %-encoded string for the byte in question. - */ - protected String encodedByte(int b) { - StringBuilder buffer = new StringBuilder(3); - writeEncodedByte(b, buffer); - return buffer.toString(); - } - - /** - * Perform %-encoding on a single byte. - * - * @param b The 8-bit integer that represents the byte. (Bytes are signed - * but encoding needs to look at the bytes unsigned.) - * @param buffer The target for the %-encoded string for the byte in question. - */ - private void writeEncodedByte(int b, StringBuilder buffer) { - String hex = Integer.toHexString(b).toUpperCase(Locale.ENGLISH); - if (hex.length() < 2) { - buffer.append("%0"); - buffer.append(hex); - } - else { - buffer.append('%'); - buffer.append(hex); - } - } - - // ----------------------------------------------------------------- - - /** - * Add to the current list of delegated catalogs. - * - *This method always constructs the {@link #localDelegate} - * vector so that it is ordered by length of partial - * public identifier.
- * - * @param entry The DELEGATE catalog entry - */ - protected void addDelegate(CatalogEntry entry) { - int pos = 0; - String partial = entry.getEntryArg(0); - - Enumeration local = localDelegate.elements(); - while (local.hasMoreElements()) { - CatalogEntry dpe = (CatalogEntry) local.nextElement(); - String dp = dpe.getEntryArg(0); - if (dp.equals(partial)) { - // we already have this prefix - return; - } - if (dp.length() > partial.length()) { - pos++; - } - if (dp.length() < partial.length()) { - break; - } - } - - // now insert partial into the vector at [pos] - if (localDelegate.size() == 0) { - localDelegate.addElement(entry); - } else { - localDelegate.insertElementAt(entry, pos); - } - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/CatalogEntry.java 2017-06-20 10:53:19.398365526 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,251 +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; - -import java.util.Map; -import java.util.Vector; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Represents a Catalog entry. - * - *Instances of this class represent individual entries - * in a Catalog.
- * - *Each catalog entry has a unique name and is associated with - * an arbitrary number of arguments (all strings). For example, the - * TR9401 catalog entry "PUBLIC" has two arguments, a public identifier - * and a system identifier. Each entry has a unique numeric type, - * assigned automatically when the entry type is created.
- * - *The number and type of catalog entries is maintained - * statically. Catalog classes, or their subclasses, can add - * new entry types, but all Catalog objects share the same global pool - * of types.
- * - *Initially there are no valid entries.
- * - * @see Catalog - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public class CatalogEntry { - /** The nextEntry is the ordinal number of the next entry type. */ - static AtomicInteger nextEntry = new AtomicInteger(0); - - /** - * The entryTypes vector maps catalog entry names - * (e.g., 'BASE' or 'SYSTEM') to their type (1, 2, etc.). - * Names are case sensitive. - */ - static final MapCatalogs sometimes need to adjust the catlog entry parameters, - * for example to make a relative URI absolute with respect to the - * current base URI. But in general, this function should only be - * called shortly after object creation to do some sort of cleanup. - * Catalog entries should not mutate over time.
- * - * @param argNum The argument number (arguments are numbered from 0). - * @throws ArrayIndexOutOfBoundsException if an invalid argument - * number is provided. - */ - public void setEntryArg(int argNum, String newspec) - throws ArrayIndexOutOfBoundsException { - args.set(argNum, newspec); - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/CatalogException.java 2017-06-20 10:53:19.602375699 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,165 +0,0 @@ -/* - * 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; - -/** - * Signal Catalog exception. - * - *This exception is thrown if an error occurs loading a - * catalog file.
- * - * @see Catalog - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public class CatalogException extends Exception { - - private static final long serialVersionUID = 4007157171817798450L; - - /** A wrapper around another exception */ - public static final int WRAPPER = 1; - /** An invalid entry */ - public static final int INVALID_ENTRY = 2; - /** An invalid entry type */ - public static final int INVALID_ENTRY_TYPE = 3; - /** Could not instantiate an XML parser */ - public static final int NO_XML_PARSER = 4; - /** Unknown XML format */ - public static final int UNKNOWN_FORMAT = 5; - /** Unparseable XML catalog (not XML)*/ - public static final int UNPARSEABLE = 6; - /** XML but parse failed */ - public static final int PARSE_FAILED = 7; - /** Text catalog ended in mid-comment */ - public static final int UNENDED_COMMENT = 8; - - /** - * The embedded exception if tunnelling, or null. - */ - private final Exception exception; - private final int exceptionType; - - /** - * Create a new CatalogException. - * - * @param type The exception type - * @param message The error or warning message. - */ - public CatalogException (int type, String message) { - super(message); - this.exceptionType = type; - this.exception = null; - } - - /** - * Create a new CatalogException. - * - * @param type The exception type - */ - public CatalogException (int type) { - super("Catalog Exception " + type); - this.exceptionType = type; - this.exception = null; - } - - /** - * Create a new CatalogException wrapping an existing exception. - * - *The existing exception will be embedded in the new - * one, and its message will become the default message for - * the CatalogException.
- * - * @param e The exception to be wrapped in a CatalogException. - */ - public CatalogException (Exception e) { - super(); - this.exceptionType = WRAPPER; - this.exception = e; - } - - /** - * Create a new CatalogException from an existing exception. - * - *The existing exception will be embedded in the new - * one, but the new exception will have its own message.
- * - * @param message The detail message. - * @param e The exception to be wrapped in a CatalogException. - */ - public CatalogException (String message, Exception e) { - super(message); - this.exceptionType = WRAPPER; - this.exception = e; - } - - /** - * Return a detail message for this exception. - * - *If there is an embedded exception, and if the CatalogException - * has no detail message of its own, this method will return - * the detail message from the embedded exception.
- * - * @return The error or warning message. - */ - public String getMessage () - { - String message = super.getMessage(); - - if (message == null && exception != null) { - return exception.getMessage(); - } else { - return message; - } - } - - /** - * Return the embedded exception, if any. - * - * @return The embedded exception, or null if there is none. - */ - public Exception getException () - { - return exception; - } - - /** - * Return the exception type - * - * @return The exception type - */ - public int getExceptionType () - { - return exceptionType; - } - - /** - * Override toString to pick up any embedded exception. - * - * @return A string representation of this exception. - */ - public String toString () - { - if (exception != null) { - return exception.toString(); - } else { - return super.toString(); - } - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/CatalogManager.java 2017-06-20 10:53:19.810386071 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,870 +0,0 @@ -/* - * 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; - -import com.sun.org.apache.xerces.internal.utils.SecuritySupport; -import com.sun.org.apache.xml.internal.resolver.helpers.BootstrapResolver; -import com.sun.org.apache.xml.internal.resolver.helpers.Debug; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.MissingResourceException; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; -import java.util.StringTokenizer; -import java.util.Vector; -import sun.reflect.misc.ReflectUtil; - -/** - * CatalogManager provides an interface to the catalog properties. - * - *Properties can come from two places: from system properties or - * from a CatalogManager.properties file. This class provides a transparent - * interface to both, with system properties preferred over property file values.
- * - *The following table summarizes the properties:
- * - *System Property | - *CatalogManager.properties Property |
- * Description | - *
xml.catalog.ignoreMissing | - *- * | If true, a missing CatalogManager.properties file or missing properties - * within that file will not generate warning messages. See also the - * ignoreMissingProperties method. | - *
xml.catalog.files | - *catalogs | - *The |
- *
- * | relative-catalogs | - *If false, relative catalog URIs are made absolute with respect to the base URI of
- * the CatalogManager.properties file. This setting only applies to catalog
- * URIs obtained from the catalogs property |
- *
xml.catalog.verbosity | - *verbosity | - *If non-zero, the Catalog classes will print informative and debugging messages. - * The higher the number, the more messages. | - *
xml.catalog.prefer | - *prefer | - *Which identifier is preferred, "public" or "system"? | - *
xml.catalog.staticCatalog | - *static-catalog | - *Should a single catalog be constructed for all parsing, or should a different - * catalog be created for each parser? | - *
xml.catalog.allowPI | - *allow-oasis-xml-catalog-pi | - *If the source document contains "oasis-xml-catalog" processing instructions, - * should they be used? | - *
xml.catalog.className | - *catalog-class-name | - *If you're using the convenience classes - * com.sun.org.apache.xml.internal.resolver.tools.*), this setting - * allows you to specify an alternate class name to use for the underlying - * catalog. | - *
- * The new Catalog API is supported throughout the JDK XML Processors, which allows - * the use of Catalog by simply setting a path to a Catalog file as a property. - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - * @version 1.0 - */ -@Deprecated(since="9", forRemoval=true) -public class CatalogManager { - private static final String pFiles = "xml.catalog.files"; - private static final String pVerbosity = "xml.catalog.verbosity"; - private static final String pPrefer = "xml.catalog.prefer"; - private static final String pStatic = "xml.catalog.staticCatalog"; - private static final String pAllowPI = "xml.catalog.allowPI"; - private static final String pClassname = "xml.catalog.className"; - private static final String pIgnoreMissing = "xml.catalog.ignoreMissing"; - - /** A static CatalogManager instance for sharing */ - private static final CatalogManager staticManager = new CatalogManager(); - - /** The bootstrap resolver to use when loading XML Catalogs. */ - private BootstrapResolver bResolver = new BootstrapResolver(); - - /** Flag to ignore missing property files and/or properties */ - private boolean ignoreMissingProperties - = (SecuritySupport.getSystemProperty(pIgnoreMissing) != null - || SecuritySupport.getSystemProperty(pFiles) != null); - - /** Holds the resources after they are loaded from the file. */ - private ResourceBundle resources; - - /** The name of the CatalogManager properties file. */ - private String propertyFile = "CatalogManager.properties"; - - /** The location of the propertyFile */ - private URL propertyFileURI = null; - - /** Default catalog files list. */ - private String defaultCatalogFiles = "./xcatalog"; - - /** Current catalog files list. */ - private String catalogFiles = null; - - /** Did the catalogFiles come from the properties file? */ - private boolean fromPropertiesFile = false; - - /** Default verbosity level if there is no property setting for it. */ - private int defaultVerbosity = 1; - - /** Current verbosity level. */ - private Integer verbosity = null; - - /** Default preference setting. */ - private boolean defaultPreferPublic = true; - - /** Current preference setting. */ - private Boolean preferPublic = null; - - /** Default setting of the static catalog flag. */ - private boolean defaultUseStaticCatalog = true; - - /** Current setting of the static catalog flag. */ - private Boolean useStaticCatalog = null; - - /** The static catalog used by this manager. */ - private static volatile Catalog staticCatalog = null; - - /** Default setting of the oasisXMLCatalogPI flag. */ - private boolean defaultOasisXMLCatalogPI = true; - - /** Current setting of the oasisXMLCatalogPI flag. */ - private Boolean oasisXMLCatalogPI = null; - - /** Default setting of the relativeCatalogs flag. */ - private boolean defaultRelativeCatalogs = true; - - /** Current setting of the relativeCatalogs flag. */ - private Boolean relativeCatalogs = null; - - /** Current catalog class name. */ - private String catalogClassName = null; - /** - * Indicates whether implementation parts should use - * service loader (or similar). - * Note the default value (false) is the safe option.. - */ - private boolean useServicesMechanism; - - /** The manager's debug object. Used for printing debugging messages. - * - *
This field is public so that objects that have access to this - * CatalogManager can use this debug object.
- */ - public Debug debug = null; - - /** Constructor. */ - public CatalogManager() { - init(); - } - - /** Constructor that specifies an explicit property file. */ - public CatalogManager(String propertyFile) { - this.propertyFile = propertyFile; - init(); - } - - private void init() { - debug = new Debug(); - // Note that we don't setDebug() here; we do that lazily. Either the - // user will set it explicitly, or we'll do it automagically if they - // read from the propertyFile for some other reason. That way, there's - // no attempt to read from the file before the caller has had a chance - // to avoid it. - if (System.getSecurityManager() == null) { - useServicesMechanism = true; - } - // Make sure verbosity is set by xml.catalog.verbosity sysprop - // setting, if defined. - queryVerbosityFromSysProp(); - } - - /** Set the bootstrap resolver - * @param resolver the bootstrap resolver - */ - public void setBootstrapResolver(BootstrapResolver resolver) { - bResolver = resolver; - } - - /** Get the bootstrap resolver - * @return the bootstrap resolver - */ - public BootstrapResolver getBootstrapResolver() { - return bResolver; - } - - /** Query system property for verbosity level. */ - private void queryVerbosityFromSysProp() { - String verbStr = SecuritySupport.getSystemProperty(pVerbosity); - if (verbStr != null) { - try { - int verb = Integer.parseInt(verbStr.trim()); - verbosity = new Integer(verb); - debug.setDebug(verb); - } catch (Exception e) { - System.err.println("Cannot parse verbosity: \"" + verbStr + "\""); - } - } - } - - /** - * Load the properties from the propertyFile and build the - * resources from it. - */ - private synchronized void readProperties() { - try { - propertyFileURI = CatalogManager.class.getResource("/"+propertyFile); - InputStream in = - CatalogManager.class.getResourceAsStream("/"+propertyFile); - if (in==null) { - if (!ignoreMissingProperties) { - System.err.println("Cannot find "+propertyFile); - // there's no reason to give this warning more than once - ignoreMissingProperties = true; - } - return; - } - resources = new PropertyResourceBundle(in); - } catch (MissingResourceException mre) { - if (!ignoreMissingProperties) { - System.err.println("Cannot read "+propertyFile); - } - } catch (java.io.IOException e) { - if (!ignoreMissingProperties) { - System.err.println("Failure trying to read "+propertyFile); - } - } - - // This is a bit of a hack. After we've successfully read the properties, - // use them to set the default debug level, if the user hasn't already set - // the default debug level. - if (verbosity == null) { - try { - String verbStr = resources.getString("verbosity"); - int verb = Integer.parseInt(verbStr.trim()); - debug.setDebug(verb); - verbosity = new Integer(verb); - } catch (Exception e) { - // nop - } - } - } - - /** - * Allow access to the static CatalogManager - */ - public static CatalogManager getStaticManager() { - return staticManager; - } - - /** - * How are missing properties handled? - * - *If true, missing or unreadable property files will - * not be reported. Otherwise, a message will be sent to System.err. - *
- */ - public boolean getIgnoreMissingProperties() { - return ignoreMissingProperties; - } - - /** - * How should missing properties be handled? - * - *If ignore is true, missing or unreadable property files will - * not be reported. Otherwise, a message will be sent to System.err. - *
- */ - public void setIgnoreMissingProperties(boolean ignore) { - ignoreMissingProperties = ignore; - } - - /** - * How are missing properties handled? - * - *If ignore is true, missing or unreadable property files will - * not be reported. Otherwise, a message will be sent to System.err. - *
- * - * @deprecated No longer static; use get/set methods. - */ - public void ignoreMissingProperties(boolean ignore) { - setIgnoreMissingProperties(ignore); - } - - /** - * Obtain the verbosity setting from the properties. - * - * @return The verbosity level from the propertyFile or the - * defaultVerbosity. - */ - private int queryVerbosity () { - String defaultVerbStr = Integer.toString(defaultVerbosity); - - String verbStr = SecuritySupport.getSystemProperty(pVerbosity); - - if (verbStr == null) { - if (resources==null) readProperties(); - if (resources != null) { - try { - verbStr = resources.getString("verbosity"); - } catch (MissingResourceException e) { - verbStr = defaultVerbStr; - } - } else { - verbStr = defaultVerbStr; - } - } - - int verb = defaultVerbosity; - - try { - verb = Integer.parseInt(verbStr.trim()); - } catch (Exception e) { - System.err.println("Cannot parse verbosity: \"" + verbStr + "\""); - } - - // This is a bit of a hack. After we've successfully got the verbosity, - // we have to use it to set the default debug level, - // if the user hasn't already set the default debug level. - if (verbosity == null) { - debug.setDebug(verb); - verbosity = new Integer(verb); - } - - return verb; - } - - /** - * What is the current verbosity? - */ - public int getVerbosity() { - if (verbosity == null) { - verbosity = new Integer(queryVerbosity()); - } - - return verbosity.intValue(); - } - - /** - * Set the current verbosity. - */ - public void setVerbosity (int verbosity) { - this.verbosity = new Integer(verbosity); - debug.setDebug(verbosity); - } - - /** - * What is the current verbosity? - * - * @deprecated No longer static; use get/set methods. - */ - public int verbosity () { - return getVerbosity(); - } - - /** - * Obtain the relativeCatalogs setting from the properties. - * - * @return The relativeCatalogs setting from the propertyFile or the - * defaultRelativeCatalogs. - */ - private boolean queryRelativeCatalogs () { - if (resources==null) readProperties(); - - if (resources==null) return defaultRelativeCatalogs; - - try { - String allow = resources.getString("relative-catalogs"); - return (allow.equalsIgnoreCase("true") - || allow.equalsIgnoreCase("yes") - || allow.equalsIgnoreCase("1")); - } catch (MissingResourceException e) { - return defaultRelativeCatalogs; - } - } - - /** - * Get the relativeCatalogs setting. - * - *This property is used when the catalogFiles property is - * interrogated. If true, then relative catalog entry file names - * are returned. If false, relative catalog entry file names are - * made absolute with respect to the properties file before returning - * them.
- * - *This property
In the properties, a value of 'yes', 'true', or '1' is considered - * true, anything else is false.
- * - * @return The relativeCatalogs setting from the propertyFile or the - * defaultRelativeCatalogs. - */ - public boolean getRelativeCatalogs () { - if (relativeCatalogs == null) { - relativeCatalogs = queryRelativeCatalogs() ? Boolean.TRUE : Boolean.FALSE; - } - - return relativeCatalogs.booleanValue(); - } - - /** - * Set the relativeCatalogs setting. - * - * @see #getRelativeCatalogs() - */ - public void setRelativeCatalogs (boolean relative) { - relativeCatalogs = relative ? Boolean.TRUE : Boolean.FALSE; - } - - /** - * Get the relativeCatalogs setting. - * - * @deprecated No longer static; use get/set methods. - */ - public boolean relativeCatalogs () { - return getRelativeCatalogs(); - } - - /** - * Obtain the list of catalog files from the properties. - * - * @return A semicolon delimited list of catlog file URIs - */ - private String queryCatalogFiles () { - String catalogList = SecuritySupport.getSystemProperty(pFiles); - fromPropertiesFile = false; - - if (catalogList == null) { - if (resources == null) readProperties(); - if (resources != null) { - try { - catalogList = resources.getString("catalogs"); - fromPropertiesFile = true; - } catch (MissingResourceException e) { - System.err.println(propertyFile + ": catalogs not found."); - catalogList = null; - } - } - } - - if (catalogList == null) { - catalogList = defaultCatalogFiles; - } - - return catalogList; - } - - /** - * Return the current list of catalog files. - * - * @return A vector of the catalog file names or null if no catalogs - * are available in the properties. - */ - public Vector getCatalogFiles() { - if (catalogFiles == null) { - catalogFiles = queryCatalogFiles(); - } - - StringTokenizer files = new StringTokenizer(catalogFiles, ";"); - Vector catalogs = new Vector(); - while (files.hasMoreTokens()) { - String catalogFile = files.nextToken(); - URL absURI = null; - - if (fromPropertiesFile && !relativeCatalogs()) { - try { - absURI = new URL(propertyFileURI, catalogFile); - catalogFile = absURI.toString(); - } catch (MalformedURLException mue) { - absURI = null; - } - } - - catalogs.add(catalogFile); - } - - return catalogs; - } - - /** - * Set the list of catalog files. - */ - public void setCatalogFiles(String fileList) { - catalogFiles = fileList; - fromPropertiesFile = false; - } - - /** - * Return the current list of catalog files. - * - * @return A vector of the catalog file names or null if no catalogs - * are available in the properties. - * - * @deprecated No longer static; use get/set methods. - */ - public Vector catalogFiles() { - return getCatalogFiles(); - } - - /** - * Obtain the preferPublic setting from the properties. - * - *In the properties, a value of 'public' is true, - * anything else is false.
- * - * @return True if prefer is public or the - * defaultPreferSetting. - */ - private boolean queryPreferPublic () { - String prefer = SecuritySupport.getSystemProperty(pPrefer); - - if (prefer == null) { - if (resources==null) readProperties(); - if (resources==null) return defaultPreferPublic; - try { - prefer = resources.getString("prefer"); - } catch (MissingResourceException e) { - return defaultPreferPublic; - } - } - - if (prefer == null) { - return defaultPreferPublic; - } - - return (prefer.equalsIgnoreCase("public")); - } - - /** - * Return the current prefer public setting. - * - * @return True if public identifiers are preferred. - */ - public boolean getPreferPublic () { - if (preferPublic == null) { - preferPublic = queryPreferPublic() ? Boolean.TRUE : Boolean.FALSE; - } - return preferPublic.booleanValue(); - } - - /** - * Set the prefer public setting. - */ - public void setPreferPublic (boolean preferPublic) { - this.preferPublic = preferPublic ? Boolean.TRUE : Boolean.FALSE; - } - - /** - * Return the current prefer public setting. - * - * @return True if public identifiers are preferred. - * - * @deprecated No longer static; use get/set methods. - */ - public boolean preferPublic () { - return getPreferPublic(); - } - - /** - * Obtain the static-catalog setting from the properties. - * - *In the properties, a value of 'yes', 'true', or '1' is considered - * true, anything else is false.
- * - * @return The static-catalog setting from the propertyFile or the - * defaultUseStaticCatalog. - */ - private boolean queryUseStaticCatalog () { - String staticCatalog = SecuritySupport.getSystemProperty(pStatic); - - if (staticCatalog == null) { - if (resources==null) readProperties(); - if (resources==null) return defaultUseStaticCatalog; - try { - staticCatalog = resources.getString("static-catalog"); - } catch (MissingResourceException e) { - return defaultUseStaticCatalog; - } - } - - if (staticCatalog == null) { - return defaultUseStaticCatalog; - } - - return (staticCatalog.equalsIgnoreCase("true") - || staticCatalog.equalsIgnoreCase("yes") - || staticCatalog.equalsIgnoreCase("1")); - } - - /** - * Get the current use static catalog setting. - */ - public boolean getUseStaticCatalog() { - if (useStaticCatalog == null) { - useStaticCatalog = queryUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE; - } - - return useStaticCatalog.booleanValue(); - } - - /** - * Set the use static catalog setting. - */ - public void setUseStaticCatalog(boolean useStatic) { - useStaticCatalog = useStatic ? Boolean.TRUE : Boolean.FALSE; - } - - /** - * Get the current use static catalog setting. - * - * @deprecated No longer static; use get/set methods. - */ - public boolean staticCatalog() { - return getUseStaticCatalog(); - } - - /** - * Get a new catalog instance. - * - * This method always returns a new instance of the underlying catalog class. - */ - public Catalog getPrivateCatalog() { - Catalog catalog = staticCatalog; - - if (useStaticCatalog == null) { - useStaticCatalog = getUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE; - } - - if (catalog == null || !useStaticCatalog.booleanValue()) { - - try { - String catalogClassName = getCatalogClassName(); - - if (catalogClassName == null) { - catalog = new Catalog(); - } else { - try { - catalog = (Catalog) ReflectUtil.forName(catalogClassName).newInstance(); - } catch (ClassNotFoundException cnfe) { - debug.message(1,"Catalog class named '" - + catalogClassName - + "' could not be found. Using default."); - catalog = new Catalog(); - } catch (ClassCastException cnfe) { - debug.message(1,"Class named '" - + catalogClassName - + "' is not a Catalog. Using default."); - catalog = new Catalog(); - } - } - - catalog.setCatalogManager(this); - catalog.setupReaders(); - catalog.loadSystemCatalogs(); - } catch (Exception ex) { - ex.printStackTrace(); - } - - if (useStaticCatalog.booleanValue()) { - staticCatalog = catalog; - } - } - - return catalog; - } - - /** - * Get a catalog instance. - * - * If this manager uses static catalogs, the same static catalog will - * always be returned. Otherwise a new catalog will be returned. - */ - public Catalog getCatalog() { - Catalog catalog = staticCatalog; - - if (useStaticCatalog == null) { - useStaticCatalog = getUseStaticCatalog() ? Boolean.TRUE : Boolean.FALSE; - } - - if (catalog == null || !useStaticCatalog.booleanValue()) { - catalog = getPrivateCatalog(); - if (useStaticCatalog.booleanValue()) { - staticCatalog = catalog; - } - } - - return catalog; - } - - /** - *Obtain the oasisXMLCatalogPI setting from the properties.
- * - *In the properties, a value of 'yes', 'true', or '1' is considered - * true, anything else is false.
- * - * @return The oasisXMLCatalogPI setting from the propertyFile or the - * defaultOasisXMLCatalogPI. - */ - public boolean queryAllowOasisXMLCatalogPI () { - String allow = SecuritySupport.getSystemProperty(pAllowPI); - - if (allow == null) { - if (resources==null) readProperties(); - if (resources==null) return defaultOasisXMLCatalogPI; - try { - allow = resources.getString("allow-oasis-xml-catalog-pi"); - } catch (MissingResourceException e) { - return defaultOasisXMLCatalogPI; - } - } - - if (allow == null) { - return defaultOasisXMLCatalogPI; - } - - return (allow.equalsIgnoreCase("true") - || allow.equalsIgnoreCase("yes") - || allow.equalsIgnoreCase("1")); - } - - /** - * Get the current XML Catalog PI setting. - */ - public boolean getAllowOasisXMLCatalogPI () { - if (oasisXMLCatalogPI == null) { - oasisXMLCatalogPI = queryAllowOasisXMLCatalogPI() ? Boolean.TRUE : Boolean.FALSE; - } - - return oasisXMLCatalogPI.booleanValue(); - } - - public boolean useServicesMechanism() { - return useServicesMechanism; - } - /** - * Set the XML Catalog PI setting - */ - public void setAllowOasisXMLCatalogPI(boolean allowPI) { - oasisXMLCatalogPI = allowPI ? Boolean.TRUE : Boolean.FALSE; - } - - /** - * Get the current XML Catalog PI setting. - * - * @deprecated No longer static; use get/set methods. - */ - public boolean allowOasisXMLCatalogPI() { - return getAllowOasisXMLCatalogPI(); - } - - /** - * Obtain the Catalog class name setting from the properties. - * - */ - public String queryCatalogClassName () { - String className = SecuritySupport.getSystemProperty(pClassname); - - if (className == null) { - if (resources==null) readProperties(); - if (resources==null) return null; - try { - return resources.getString("catalog-class-name"); - } catch (MissingResourceException e) { - return null; - } - } - - return className; - } - - /** - * Get the current Catalog class name. - */ - public String getCatalogClassName() { - if (catalogClassName == null) { - catalogClassName = queryCatalogClassName(); - } - - return catalogClassName; - } - - /** - * Set the Catalog class name. - */ - public void setCatalogClassName(String className) { - catalogClassName = className; - } - - /** - * Get the current Catalog class name. - * - * @deprecated No longer static; use get/set methods. - */ - public String catalogClassName() { - return getCatalogClassName(); - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/Resolver.java 2017-06-20 10:53:20.034397242 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,697 +0,0 @@ -/* - * 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; - -import java.io.IOException; -import java.io.InputStream; -import java.io.FileNotFoundException; -import java.util.Enumeration; -import java.util.Vector; -import java.net.URL; -import java.net.URLConnection; -import java.net.MalformedURLException; -import javax.xml.parsers.SAXParserFactory; -import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl; -import com.sun.org.apache.xerces.internal.utils.SecuritySupport; -import com.sun.org.apache.xml.internal.resolver.readers.SAXCatalogReader; -import com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader; -import com.sun.org.apache.xml.internal.resolver.readers.TR9401CatalogReader; - -/** - * An extension to OASIS Open Catalog files, this class supports - * suffix-based matching and an external RFC2483 resolver. - * - * @see Catalog - * @deprecated The JDK internal Catalog API in package - * {@code com.sun.org.apache.xml.internal.resolver} - * is encapsulated in JDK 9. The entire implementation under the package is now - * deprecated and subject to removal in a future release. Users of the API - * should migrate to the {@linkplain javax.xml.catalog new public API}. - *- * The new Catalog API is supported throughout the JDK XML Processors, which allows - * the use of Catalog by simply setting a path to a Catalog file as a property. - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - * @version 1.0 - */ -@Deprecated(since="9", forRemoval=true) -public class Resolver extends Catalog { - /** - * The URISUFFIX Catalog Entry type. - * - *
URI suffix entries match URIs that end in a specified suffix.
- */ - public static final int URISUFFIX = CatalogEntry.addEntryType("URISUFFIX", 2); - - /** - * The SYSTEMSUFFIX Catalog Entry type. - * - *System suffix entries match system identifiers that end in a - * specified suffix.
- */ - public static final int SYSTEMSUFFIX = CatalogEntry.addEntryType("SYSTEMSUFFIX", 2); - - /** - * The RESOLVER Catalog Entry type. - * - *A hook for providing support for web-based backup resolvers.
- */ - public static final int RESOLVER = CatalogEntry.addEntryType("RESOLVER", 1); - - /** - * The SYSTEMREVERSE Catalog Entry type. - * - *This is a bit of a hack. There's no actual SYSTEMREVERSE entry, - * but this entry type is used to indicate that a reverse lookup is - * being performed. (This allows the Resolver to implement - * RFC2483 I2N and I2NS.) - */ - public static final int SYSTEMREVERSE - = CatalogEntry.addEntryType("SYSTEMREVERSE", 1); - - /** - * Setup readers. - */ - public void setupReaders() { - SAXParserFactory spf = catalogManager.useServicesMechanism() ? - SAXParserFactory.newInstance() : new SAXParserFactoryImpl(); - spf.setNamespaceAware(true); - spf.setValidating(false); - - SAXCatalogReader saxReader = new SAXCatalogReader(spf); - - saxReader.setCatalogParser(null, "XCatalog", - "com.sun.org.apache.xml.internal.resolver.readers.XCatalogReader"); - - saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName, - "catalog", - "com.sun.org.apache.xml.internal.resolver.readers.ExtendedXMLCatalogReader"); - - addReader("application/xml", saxReader); - - TR9401CatalogReader textReader = new TR9401CatalogReader(); - addReader("text/plain", textReader); - } - - /** - * Cleanup and process a Catalog entry. - * - *
This method processes each Catalog entry, changing mapped - * relative system identifiers into absolute ones (based on the current - * base URI), and maintaining other information about the current - * catalog.
- * - * @param entry The CatalogEntry to process. - */ - public void addEntry(CatalogEntry entry) { - int type = entry.getEntryType(); - - if (type == URISUFFIX) { - String suffix = normalizeURI(entry.getEntryArg(0)); - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "URISUFFIX", suffix, fsi); - } else if (type == SYSTEMSUFFIX) { - String suffix = normalizeURI(entry.getEntryArg(0)); - String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1))); - - entry.setEntryArg(1, fsi); - - catalogManager.debug.message(4, "SYSTEMSUFFIX", suffix, fsi); - } - - super.addEntry(entry); - } - - /** - * Return the applicable URI. - * - *If a URI entry exists in the Catalog - * for the URI specified, return the mapped value.
- * - *In the Resolver (as opposed to the Catalog) class, if the - * URI isn't found by the usual algorithm, URISUFFIX entries are - * considered.
- * - *URI comparison is case sensitive.
- * - * @param uri The URI to locate in the catalog. - * - * @return The resolved URI. - * - * @throws MalformedURLException The system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public String resolveURI(String uri) - throws MalformedURLException, IOException { - - String resolved = super.resolveURI(uri); - if (resolved != null) { - return resolved; - } - - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == RESOLVER) { - resolved = resolveExternalSystem(uri, e.getEntryArg(0)); - if (resolved != null) { - return resolved; - } - } else if (e.getEntryType() == URISUFFIX) { - String suffix = e.getEntryArg(0); - String result = e.getEntryArg(1); - - if (suffix.length() <= uri.length() - && uri.substring(uri.length()-suffix.length()).equals(suffix)) { - return result; - } - } - } - - // Otherwise, look in the subordinate catalogs - return resolveSubordinateCatalogs(Catalog.URI, - null, - null, - uri); - } - - /** - * Return the applicable SYSTEM system identifier, resorting - * to external RESOLVERs if necessary. - * - *If a SYSTEM entry exists in the Catalog - * for the system ID specified, return the mapped value.
- * - *In the Resolver (as opposed to the Catalog) class, if the - * URI isn't found by the usual algorithm, SYSTEMSUFFIX entries are - * considered.
- * - *On Windows-based operating systems, the comparison between - * the system identifier provided and the SYSTEM entries in the - * Catalog is case-insensitive.
- * - * @param systemId The system ID to locate in the catalog. - * - * @return The system identifier to use for systemId. - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public String resolveSystem(String systemId) - throws MalformedURLException, IOException { - - String resolved = super.resolveSystem(systemId); - if (resolved != null) { - return resolved; - } - - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == RESOLVER) { - resolved = resolveExternalSystem(systemId, e.getEntryArg(0)); - if (resolved != null) { - return resolved; - } - } else if (e.getEntryType() == SYSTEMSUFFIX) { - String suffix = e.getEntryArg(0); - String result = e.getEntryArg(1); - - if (suffix.length() <= systemId.length() - && systemId.substring(systemId.length()-suffix.length()).equals(suffix)) { - return result; - } - } - } - - return resolveSubordinateCatalogs(Catalog.SYSTEM, - null, - null, - systemId); - } - - /** - * Return the applicable PUBLIC or SYSTEM identifier, resorting - * to external resolvers if necessary. - * - *This method searches the Catalog and returns the system - * identifier specified for the given system or - * public identifiers. If - * no appropriate PUBLIC or SYSTEM entry is found in the Catalog, - * null is returned.
- * - *Note that a system or public identifier in the current catalog - * (or subordinate catalogs) will be used in preference to an - * external resolver. Further, if a systemId is present, the external - * resolver(s) will be queried for that before the publicId.
- * - * @param publicId The public identifier to locate in the catalog. - * Public identifiers are normalized before comparison. - * @param systemId The nominal system identifier for the entity - * in question (as provided in the source document). - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - * - * @return The system identifier to use. - * Note that the nominal system identifier is not returned if a - * match is not found in the catalog, instead null is returned - * to indicate that no match was found. - */ - public String resolvePublic(String publicId, String systemId) - throws MalformedURLException, IOException { - - String resolved = super.resolvePublic(publicId, systemId); - if (resolved != null) { - return resolved; - } - - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == RESOLVER) { - if (systemId != null) { - resolved = resolveExternalSystem(systemId, - e.getEntryArg(0)); - if (resolved != null) { - return resolved; - } - } - resolved = resolveExternalPublic(publicId, e.getEntryArg(0)); - if (resolved != null) { - return resolved; - } - } - } - - return resolveSubordinateCatalogs(Catalog.PUBLIC, - null, - publicId, - systemId); - } - - /** - * Query an external RFC2483 resolver for a system identifier. - * - * @param systemId The system ID to locate. - * @param resolver The name of the resolver to use. - * - * @return The system identifier to use for the systemId. - */ - protected String resolveExternalSystem(String systemId, String resolver) - throws MalformedURLException, IOException { - Resolver r = queryResolver(resolver, "i2l", systemId, null); - if (r != null) { - return r.resolveSystem(systemId); - } else { - return null; - } - } - - /** - * Query an external RFC2483 resolver for a public identifier. - * - * @param publicId The system ID to locate. - * @param resolver The name of the resolver to use. - * - * @return The system identifier to use for the systemId. - */ - protected String resolveExternalPublic(String publicId, String resolver) - throws MalformedURLException, IOException { - Resolver r = queryResolver(resolver, "fpi2l", publicId, null); - if (r != null) { - return r.resolvePublic(publicId, null); - } else { - return null; - } - } - - /** - * Query an external RFC2483 resolver. - * - * @param resolver The URL of the RFC2483 resolver. - * @param command The command to send the resolver. - * @param arg1 The first argument to the resolver. - * @param arg2 The second argument to the resolver, usually null. - * - * @return The Resolver constructed. - */ - protected Resolver queryResolver(String resolver, - String command, - String arg1, - String arg2) { - InputStream iStream = null; - String RFC2483 = resolver + "?command=" + command - + "&format=tr9401&uri=" + arg1 - + "&uri2=" + arg2; - String line = null; - - try { - URL url = new URL(RFC2483); - - URLConnection urlCon = url.openConnection(); - - urlCon.setUseCaches(false); - - Resolver r = (Resolver) newCatalog(); - - String cType = urlCon.getContentType(); - - // I don't care about the character set or subtype - if (cType.indexOf(";") > 0) { - cType = cType.substring(0, cType.indexOf(";")); - } - - r.parseCatalog(cType, urlCon.getInputStream()); - - return r; - } catch (CatalogException cex) { - if (cex.getExceptionType() == CatalogException.UNPARSEABLE) { - catalogManager.debug.message(1, "Unparseable catalog: " + RFC2483); - } else if (cex.getExceptionType() - == CatalogException.UNKNOWN_FORMAT) { - catalogManager.debug.message(1, "Unknown catalog format: " + RFC2483); - } - return null; - } catch (MalformedURLException mue) { - catalogManager.debug.message(1, "Malformed resolver URL: " + RFC2483); - return null; - } catch (IOException ie) { - catalogManager.debug.message(1, "I/O Exception opening resolver: " + RFC2483); - return null; - } - } - - /** - * Append two vectors, returning the result. - * - * @param vec The first vector - * @param appvec The vector to be appended - * @return The vector vec, with appvec's elements appended to it - */ - private Vector appendVector(Vector vec, Vector appvec) { - if (appvec != null) { - for (int count = 0; count < appvec.size(); count++) { - vec.addElement(appvec.elementAt(count)); - } - } - return vec; - } - - /** - * Find the URNs for a given system identifier in all catalogs. - * - * @param systemId The system ID to locate. - * - * @return A vector of URNs that map to the systemId. - */ - public Vector resolveAllSystemReverse(String systemId) - throws MalformedURLException, IOException { - Vector resolved = new Vector(); - - // If there's a SYSTEM entry in this catalog, use it - if (systemId != null) { - Vector localResolved = resolveLocalSystemReverse(systemId); - resolved = appendVector(resolved, localResolved); - } - - // Otherwise, look in the subordinate catalogs - Vector subResolved = resolveAllSubordinateCatalogs(SYSTEMREVERSE, - null, - null, - systemId); - - return appendVector(resolved, subResolved); - } - - /** - * Find the URN for a given system identifier. - * - * @param systemId The system ID to locate. - * - * @return A (single) URN that maps to the systemId. - */ - public String resolveSystemReverse(String systemId) - throws MalformedURLException, IOException { - Vector resolved = resolveAllSystemReverse(systemId); - if (resolved != null && resolved.size() > 0) { - return (String) resolved.elementAt(0); - } else { - return null; - } - } - - /** - * Return the applicable SYSTEM system identifiers. - * - *If one or more SYSTEM entries exists in the Catalog - * for the system ID specified, return the mapped values.
- * - *The caller is responsible for doing any necessary - * normalization of the system identifier before calling - * this method. For example, a relative system identifier in - * a document might be converted to an absolute system identifier - * before attempting to resolve it.
- * - *Note that this function will force all subordinate catalogs - * to be loaded.
- * - *On Windows-based operating systems, the comparison between - * the system identifier provided and the SYSTEM entries in the - * Catalog is case-insensitive.
- * - * @param systemId The system ID to locate in the catalog. - * - * @return The system identifier to use for the notation. - * - * @throws MalformedURLException The formal system identifier of a - * subordinate catalog cannot be turned into a valid URL. - * @throws IOException Error reading subordinate catalog file. - */ - public Vector resolveAllSystem(String systemId) - throws MalformedURLException, IOException { - Vector resolutions = new Vector(); - - // If there are SYSTEM entries in this catalog, start with them - if (systemId != null) { - Vector localResolutions = resolveAllLocalSystem(systemId); - resolutions = appendVector(resolutions, localResolutions); - } - - // Then look in the subordinate catalogs - Vector subResolutions = resolveAllSubordinateCatalogs(SYSTEM, - null, - null, - systemId); - resolutions = appendVector(resolutions, subResolutions); - - if (resolutions.size() > 0) { - return resolutions; - } else { - return null; - } - } - - /** - * Return all applicable SYSTEM system identifiers in this - * catalog. - * - *If one or more SYSTEM entries exists in the catalog file - * for the system ID specified, return the mapped values.
- * - * @param systemId The system ID to locate in the catalog - * - * @return A vector of the mapped system identifiers or null - */ - private Vector resolveAllLocalSystem(String systemId) { - Vector map = new Vector(); - String osname = SecuritySupport.getSystemProperty("os.name"); - boolean windows = (osname.indexOf("Windows") >= 0); - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == SYSTEM - && (e.getEntryArg(0).equals(systemId) - || (windows - && e.getEntryArg(0).equalsIgnoreCase(systemId)))) { - map.addElement(e.getEntryArg(1)); - } - } - if (map.size() == 0) { - return null; - } else { - return map; - } - } - - /** - * Find the URNs for a given system identifier in the current catalog. - * - * @param systemId The system ID to locate. - * - * @return A vector of URNs that map to the systemId. - */ - private Vector resolveLocalSystemReverse(String systemId) { - Vector map = new Vector(); - String osname = SecuritySupport.getSystemProperty("os.name"); - boolean windows = (osname.indexOf("Windows") >= 0); - Enumeration en = catalogEntries.elements(); - while (en.hasMoreElements()) { - CatalogEntry e = (CatalogEntry) en.nextElement(); - if (e.getEntryType() == SYSTEM - && (e.getEntryArg(1).equals(systemId) - || (windows - && e.getEntryArg(1).equalsIgnoreCase(systemId)))) { - map.addElement(e.getEntryArg(0)); - } - } - if (map.size() == 0) { - return null; - } else { - return map; - } - } - - /** - * Search the subordinate catalogs, in order, looking for all - * match. - * - *This method searches the Catalog and returns all of the system - * identifiers specified for the given entity type with the given - * name, public, and system identifiers. In some contexts, these - * may be null.
- * - * @param entityType The CatalogEntry type for which this query is - * being conducted. This is necessary in order to do the approprate - * query on a subordinate catalog. - * @param entityName The name of the entity being searched for, if - * appropriate. - * @param publicId The public identifier of the entity in question - * (as provided in the source document). - * @param systemId The nominal system identifier for the entity - * in question (as provided in the source document). - * - * @throws MalformedURLException The formal system identifier of a - * delegated catalog cannot be turned into a valid URL. - * @throws IOException Error reading delegated catalog file. - * - * @return The system identifier to use. - * Note that the nominal system identifier is not returned if a - * match is not found in the catalog, instead null is returned - * to indicate that no match was found. - */ - private synchronized Vector resolveAllSubordinateCatalogs(int entityType, - String entityName, - String publicId, - String systemId) - throws MalformedURLException, IOException { - - Vector resolutions = new Vector(); - - for (int catPos = 0; catPos < catalogs.size(); catPos++) { - Resolver c = null; - - try { - c = (Resolver) catalogs.elementAt(catPos); - } catch (ClassCastException e) { - String catfile = (String) catalogs.elementAt(catPos); - c = (Resolver) newCatalog(); - - try { - c.parseCatalog(catfile); - } catch (MalformedURLException mue) { - catalogManager.debug.message(1, "Malformed Catalog URL", catfile); - } catch (FileNotFoundException fnfe) { - catalogManager.debug.message(1, "Failed to load catalog, file not found", - catfile); - } catch (IOException ioe) { - catalogManager.debug.message(1, "Failed to load catalog, I/O error", catfile); - } - - catalogs.setElementAt(c, catPos); - } - - String resolved = null; - - // Ok, now what are we supposed to call here? - if (entityType == DOCTYPE) { - resolved = c.resolveDoctype(entityName, - publicId, - systemId); - if (resolved != null) { - // Only find one DOCTYPE resolution - resolutions.addElement(resolved); - return resolutions; - } - } else if (entityType == DOCUMENT) { - resolved = c.resolveDocument(); - if (resolved != null) { - // Only find one DOCUMENT resolution - resolutions.addElement(resolved); - return resolutions; - } - } else if (entityType == ENTITY) { - resolved = c.resolveEntity(entityName, - publicId, - systemId); - if (resolved != null) { - // Only find one ENTITY resolution - resolutions.addElement(resolved); - return resolutions; - } - } else if (entityType == NOTATION) { - resolved = c.resolveNotation(entityName, - publicId, - systemId); - if (resolved != null) { - // Only find one NOTATION resolution - resolutions.addElement(resolved); - return resolutions; - } - } else if (entityType == PUBLIC) { - resolved = c.resolvePublic(publicId, systemId); - if (resolved != null) { - // Only find one PUBLIC resolution - resolutions.addElement(resolved); - return resolutions; - } - } else if (entityType == SYSTEM) { - Vector localResolutions = c.resolveAllSystem(systemId); - resolutions = appendVector(resolutions, localResolutions); - break; - } else if (entityType == SYSTEMREVERSE) { - Vector localResolutions = c.resolveAllSystemReverse(systemId); - resolutions = appendVector(resolutions, localResolutions); - } - } - - if (resolutions != null) { - return resolutions; - } else { - return null; - } - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/helpers/BootstrapResolver.java 2017-06-20 10:53:20.266408811 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,207 +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.helpers; - -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import javax.xml.transform.URIResolver; -import javax.xml.transform.sax.SAXSource; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; - -/** - * A simple bootstrapping resolver. - * - *This class is used as the entity resolver when reading XML Catalogs. - * It searches for the OASIS XML Catalog DTD, Relax NG Grammar and W3C XML Schema - * as resources (e.g., in the resolver jar file).
- * - *If you have your own DTDs or schemas, you can extend this class and - * set the BootstrapResolver in your CatalogManager.
- * - * @see com.sun.org.apache.xml.internal.resolver.CatalogManager - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public class BootstrapResolver implements EntityResolver, URIResolver { - /** URI of the W3C XML Schema for OASIS XML Catalog files. */ - public static final String xmlCatalogXSD = "http://www.oasis-open.org/committees/entity/release/1.0/catalog.xsd"; - - /** URI of the RELAX NG Grammar for OASIS XML Catalog files. */ - public static final String xmlCatalogRNG = "http://www.oasis-open.org/committees/entity/release/1.0/catalog.rng"; - - /** Public identifier for OASIS XML Catalog files. */ - public static final String xmlCatalogPubId = "-//OASIS//DTD XML Catalogs V1.0//EN"; - - /** System identifier for OASIS XML Catalog files. */ - public static final String xmlCatalogSysId = "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"; - - /** Public identifier for legacy Apache XCatalog files. There is no official system identifier for XCatalog files. */ - public static final String xCatalogPubId = "-//DTD XCatalog//EN"; - - /** Private hash used for public identifiers. */ - private final MapThis class defines a set of static methods that can be called - * to produce debugging messages. Messages have an associated "debug - * level" and messages below the current setting are not displayed.
- * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public class Debug { - /** The internal debug level. */ - protected int debug = 0; - - /** Constructor */ - public Debug() { - // nop - } - - /** Set the debug level for future messages. */ - public void setDebug(int newDebug) { - debug = newDebug; - } - - /** Get the current debug level. */ - public int getDebug() { - return debug; - } - - /** - * Print debug message (if the debug level is high enough). - * - *Prints "the message"
- * - * @param level The debug level of this message. This message - * will only be - * displayed if the current debug level is at least equal to this - * value. - * @param message The text of the message. - */ - public void message(int level, String message) { - if (debug >= level) { - System.out.println(message); - } - } - - /** - * Print debug message (if the debug level is high enough). - * - *Prints "the message: spec"
- * - * @param level The debug level of this message. This message - * will only be - * displayed if the current debug level is at least equal to this - * value. - * @param message The text of the message. - * @param spec An argument to the message. - */ - public void message(int level, String message, String spec) { - if (debug >= level) { - System.out.println(message + ": " + spec); - } - } - - /** - * Print debug message (if the debug level is high enough). - * - *Prints "the message: spec1" and "spec2" indented on the next line.
- * - * @param level The debug level of this message. This message - * will only be - * displayed if the current debug level is at least equal to this - * value. - * @param message The text of the message. - * @param spec1 An argument to the message. - * @param spec2 Another argument to the message. - */ - public void message(int level, String message, - String spec1, String spec2) { - if (debug >= level) { - System.out.println(message + ": " + spec1); - System.out.println("\t" + spec2); - } - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/helpers/FileURL.java 2017-06-20 10:53:20.678429357 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,87 +0,0 @@ -/* - * 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.helpers; - -import java.net.URL; -import java.net.MalformedURLException; -import java.io.File; - -/** - * Static method for dealing with file: URLs. - * - *This class defines a static method that can be used to construct - * an appropriate file: URL from parts. It's defined here so that it - * can be reused throught the resolver.
- * - *(Yes, I'd rather have called this class FileURI, but - * given that a jave.net.URL is returned, it seemed...even more - * confusing.)
- * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - * @version 1.0 - */ -public abstract class FileURL { - protected FileURL() { } - - /** - * Construct a file: URL for a path name. - * - *URLs in the file: scheme can be constructed for paths on - * the local file system. Several possibilities need to be considered: - *
- * - *This method is declared static so that other classes - * can use it directly.
- * - * @param pathname The path name component for which to construct a URL. - * - * @return The appropriate file: URL. - * - * @throws MalformedURLException if the pathname can't be turned into - * a proper URL. - */ - public static URL makeURL(String pathname) throws MalformedURLException { - /*if (pathname.startsWith("/")) { - return new URL("file://" + pathname); - } - - String userdir = System.getProperty("user.dir"); - userdir.replace('\\', '/'); - - if (userdir.endsWith("/")) { - return new URL("file:///" + userdir + pathname); - } else { - return new URL("file:///" + userdir + "/" + pathname); - } - */ - File file = new File(pathname); - return file.toURI().toURL(); - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/helpers/Namespaces.java 2017-06-20 10:53:21.062448505 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,110 +0,0 @@ -/* - * 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.helpers; - -import org.w3c.dom.*; - -/** - * Static Namespace query methods. - * - *This class defines a set of static methods that can be called - * to analyze the namespace properties of DOM nodes.
- * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public class Namespaces { - /** - * Returns the "prefix" part of a QName or the empty string (not - * null) if the name has no prefix. - * - * @param element The QName of an element. - * @return The prefix part of the element name. - */ - public static String getPrefix(Element element) { - String name = element.getTagName(); - String prefix = ""; - - final int indexOfColon = name.indexOf(':'); - if (indexOfColon > 0) { - prefix = name.substring(0, indexOfColon); - } - - return prefix; - } - - /** - * Returns the "localname" part of a QName, which is the whole - * name if it has no prefix. - * - * @param element The QName of an element. - * @return The local part of a QName. - */ - public static String getLocalName(Element element) { - String name = element.getTagName(); - - final int indexOfColon = name.indexOf(':'); - if (indexOfColon > 0) { - name = name.substring(indexOfColon + 1); - } - - return name; - } - - /** - * Returns the namespace URI for the specified prefix at the - * specified context node. - * - * @param node The context node. - * @param prefix The prefix. - * @return The namespace URI associated with the prefix, or - * null if no namespace declaration exists for the prefix. - */ - public static String getNamespaceURI(Node node, String prefix) { - if (node == null || node.getNodeType() != Node.ELEMENT_NODE) { - return null; - } - - if (prefix.length() == 0) { - if (((Element) node).hasAttribute("xmlns")) { - return ((Element) node).getAttribute("xmlns"); - } - } else { - String nsattr = "xmlns:" + prefix; - if (((Element) node).hasAttribute(nsattr)) { - return ((Element) node).getAttribute(nsattr); - } - } - - return getNamespaceURI(node.getParentNode(), prefix); - } - - /** - * Returns the namespace URI for the namespace to which the - * element belongs. - * - * @param element The element. - * @return The namespace URI associated with the namespace of the - * element, or null if no namespace declaration exists for it. - */ - public static String getNamespaceURI(Element element) { - String prefix = getPrefix(element); - return getNamespaceURI(element, prefix); - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/helpers/PublicId.java 2017-06-20 10:53:21.302460473 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,169 +0,0 @@ -/* - * 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.helpers; - -/** - * Static methods for dealing with public identifiers. - * - *This class defines a set of static methods that can be called - * to handle public identifiers.
- * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public abstract class PublicId { - - protected PublicId() {} - - /** - * Normalize a public identifier. - * - *Public identifiers must be normalized according to the following - * rules before comparisons between them can be made:
- * - *This method is declared static so that other classes - * can use it directly.
- * - * @param publicId The unnormalized public identifier. - * - * @return The normalized identifier. - */ - public static String normalize(String publicId) { - String normal = publicId.replace('\t', ' '); - normal = normal.replace('\r', ' '); - normal = normal.replace('\n', ' '); - normal = normal.trim(); - - int pos; - - while ((pos = normal.indexOf(" ")) >= 0) { - normal = normal.substring(0, pos) + normal.substring(pos+1); - } - return normal; - } - - /** - * Encode a public identifier as a "publicid" URN. - * - *This method is declared static so that other classes - * can use it directly.
- * - * @param publicId The unnormalized public identifier. - * - * @return The normalized identifier. - */ - public static String encodeURN(String publicId) { - String urn = PublicId.normalize(publicId); - - urn = PublicId.stringReplace(urn, "%", "%25"); - urn = PublicId.stringReplace(urn, ";", "%3B"); - urn = PublicId.stringReplace(urn, "'", "%27"); - urn = PublicId.stringReplace(urn, "?", "%3F"); - urn = PublicId.stringReplace(urn, "#", "%23"); - urn = PublicId.stringReplace(urn, "+", "%2B"); - urn = PublicId.stringReplace(urn, " ", "+"); - urn = PublicId.stringReplace(urn, "::", ";"); - urn = PublicId.stringReplace(urn, ":", "%3A"); - urn = PublicId.stringReplace(urn, "//", ":"); - urn = PublicId.stringReplace(urn, "/", "%2F"); - - StringBuilder buffer = new StringBuilder(13 + urn.length()); - buffer.append("urn:publicid:"); - buffer.append(urn); - return buffer.toString(); - } - - /** - * Decode a "publicid" URN into a public identifier. - * - *This method is declared static so that other classes - * can use it directly.
- * - * @param urn The urn:publicid: URN - * - * @return The normalized identifier. - */ - public static String decodeURN(String urn) { - String publicId; - if (urn.startsWith("urn:publicid:")) { - publicId = urn.substring(13); - } - else { - return urn; - } - - final boolean hasEscape = (publicId.indexOf('%') >= 0); - if (hasEscape) { - publicId = PublicId.stringReplace(publicId, "%2F", "/"); - } - publicId = PublicId.stringReplace(publicId, ":", "//"); - if (hasEscape) { - publicId = PublicId.stringReplace(publicId, "%3A", ":"); - } - publicId = PublicId.stringReplace(publicId, ";", "::"); - publicId = PublicId.stringReplace(publicId, "+", " "); - if (hasEscape) { - publicId = PublicId.stringReplace(publicId, "%2B", "+"); - publicId = PublicId.stringReplace(publicId, "%23", "#"); - publicId = PublicId.stringReplace(publicId, "%3F", "?"); - publicId = PublicId.stringReplace(publicId, "%27", "'"); - publicId = PublicId.stringReplace(publicId, "%3B", ";"); - publicId = PublicId.stringReplace(publicId, "%25", "%"); - } - - return publicId; - } - - /** - * Replace one string with another. - */ - private static String stringReplace(String str, - String oldStr, - String newStr) { - int pos = str.indexOf(oldStr); - if (pos >= 0) { - final StringBuilder buffer = new StringBuilder(); - final int oldStrLength = oldStr.length(); - int start = 0; - do { - for (int i = start; i < pos; ++i) { - buffer.append(str.charAt(i)); - } - buffer.append(newStr); - start = pos + oldStrLength; - pos = str.indexOf(oldStr, start); - } - while (pos >= 0); - final int strLength = str.length(); - for (int i = start; i < strLength; ++i) { - buffer.append(str.charAt(i)); - } - return buffer.toString(); - } - return str; - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/CatalogReader.java 2017-06-20 10:53:21.510470846 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,75 +0,0 @@ -/* - * 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 java.io.IOException; -import java.net.MalformedURLException; -import com.sun.org.apache.xml.internal.resolver.CatalogException; - -import java.io.InputStream; -import com.sun.org.apache.xml.internal.resolver.Catalog; - -/** - * The CatalogReader interface. - * - *The Catalog class requires that classes implement this interface - * in order to be used to read catalogs. Examples of CatalogReaders - * include the TextCatalogReader, the SAXCatalogReader, and the - * DOMCatalogReader.
- * - * @see Catalog - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public interface CatalogReader { - /** - * Read a catalog from a file. - * - *This class reads a catalog from a URL.
- * - * @param catalog The catalog for which this reader is called. - * @param fileUrl The URL of a document to be read. - * @throws MalformedURLException if the specified URL cannot be - * turned into a URL object. - * @throws IOException if the URL cannot be read. - * @throws UnknownCatalogFormatException if the catalog format is - * not recognized. - * @throws UnparseableCatalogException if the catalog cannot be parsed. - * (For example, if it is supposed to be XML and isn't well-formed.) - */ - public void readCatalog(Catalog catalog, String fileUrl) - throws MalformedURLException, IOException, CatalogException; - - /** - * Read a catalog from an input stream. - * - *This class reads a catalog from an input stream.
- * - * @param catalog The catalog for which this reader is called. - * @param is The input stream that is to be read. - * @throws IOException if the URL cannot be read. - * @throws UnknownCatalogFormatException if the catalog format is - * not recognized. - * @throws UnparseableCatalogException if the catalog cannot be parsed. - * (For example, if it is supposed to be XML and isn't well-formed.) - */ - public void readCatalog(Catalog catalog, InputStream is) - throws IOException, CatalogException; -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/DOMCatalogParser.java 2017-06-20 10:53:21.722481418 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,47 +0,0 @@ -/* - * 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 org.w3c.dom.Node; - -/** - * The DOMCatalogParser interface. - * - *This interface must be implemented in order for a class to - * participate as a parser for the DOMCatalogReader. - * - * @see Catalog - * @see DOMCatalogReader - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public interface DOMCatalogParser { - /** - * Parse a DOM node as a catalog entry. - * - *
This method is expected to analyze the specified node and - * construct appropriate catalog entry(ies) from it.
- * - * @param catalog The catalog for which this node is being considered. - * @param node The DOM Node from the catalog. - */ - public void parseCatalogEntry(Catalog catalog, Node node); -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/DOMCatalogReader.java 2017-06-20 10:53:21.934491990 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,240 +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.helpers.Namespaces; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.HashMap; -import java.util.Map; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.w3c.dom.*; -import org.xml.sax.SAXException; -import sun.reflect.misc.ReflectUtil; - -/** - * A DOM-based CatalogReader. - * - *This class is used to read XML Catalogs using the DOM. This reader - * has an advantage over the SAX-based reader that it can analyze the - * DOM tree rather than simply a series of SAX events. It has the disadvantage - * that it requires all of the code necessary to build and walk a DOM - * 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 DOMCatalogReader 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 DOMCatalogReader implements CatalogReader { - /** - * 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 MapThis method associates the specified parserClass with the - * namespaceURI/rootElement names specified.
- * - * @param namespaceURI The namespace URI. Not the prefix. - * @param rootElement The name of the root element. - * @param parserClass The name of the parserClass to instantiate - * for this kind of catalog. - */ - public void setCatalogParser(String namespaceURI, - String rootElement, - String parserClass) { - if (namespaceURI == null) { - namespaceMap.put(rootElement, parserClass); - } else { - namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass); - } - } - - /** - * Get the name of the parser class for a given catalog type. - * - *This method returns the parserClass associated with the - * namespaceURI/rootElement names specified.
- * - * @param namespaceURI The namespace URI. Not the prefix. - * @param rootElement The name of the root element. - * @return The parser class. - */ - public String getCatalogParser(String namespaceURI, - String rootElement) { - if (namespaceURI == null) { - return namespaceMap.get(rootElement); - } else { - return namespaceMap.get("{"+namespaceURI+"}"+rootElement); - } - } - - /** - * Null constructor; something for subclasses to call. - */ - public DOMCatalogReader() { } - - /** - * Read a catalog from an input stream. - * - *This class reads a catalog from an input stream:
- * - *startElement
method recognizes elements
- * from the plain catalog format and instantiates CatalogEntry
- * objects for them.
- *
- * @param namespaceURI The namespace name of the element.
- * @param localName The local name of the element.
- * @param qName The QName of the element.
- * @param atts The list of attributes on the element.
- *
- * @see CatalogEntry
- */
- public void startElement (String namespaceURI,
- String localName,
- String qName,
- Attributes atts)
- throws SAXException {
-
- // Check before calling the super because super will report our
- // namespace as an extension namespace, but that doesn't count
- // for this element.
- boolean inExtension = inExtensionNamespace();
-
- super.startElement(namespaceURI, localName, qName, atts);
-
- int entryType = -1;
- Vector entryArgs = new Vector();
-
- if (namespaceURI != null && extendedNamespaceName.equals(namespaceURI)
- && !inExtension) {
- // This is an Extended XML Catalog entry
-
- if (atts.getValue("xml:base") != null) {
- String baseURI = atts.getValue("xml:base");
- entryType = Catalog.BASE;
- entryArgs.add(baseURI);
- baseURIStack.push(baseURI);
-
- debug.message(4, "xml:base", baseURI);
-
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry (base)", localName);
- }
- }
-
- entryType = -1;
- entryArgs = new Vector();
- } else {
- baseURIStack.push(baseURIStack.peek());
- }
-
- if (localName.equals("uriSuffix")) {
- if (checkAttributes(atts, "suffix", "uri")) {
- entryType = Resolver.URISUFFIX;
- entryArgs.add(atts.getValue("suffix"));
- entryArgs.add(atts.getValue("uri"));
-
- debug.message(4, "uriSuffix",
- atts.getValue("suffix"),
- atts.getValue("uri"));
- }
- } else if (localName.equals("systemSuffix")) {
- if (checkAttributes(atts, "suffix", "uri")) {
- entryType = Resolver.SYSTEMSUFFIX;
- entryArgs.add(atts.getValue("suffix"));
- entryArgs.add(atts.getValue("uri"));
-
- debug.message(4, "systemSuffix",
- atts.getValue("suffix"),
- atts.getValue("uri"));
- }
- } else {
- // This is equivalent to an invalid catalog entry type
- debug.message(1, "Invalid catalog entry type", localName);
- }
-
- if (entryType >= 0) {
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry", localName);
- }
- }
- }
- }
- }
-
- /** The SAX endElement
method does nothing. */
- public void endElement (String namespaceURI,
- String localName,
- String qName)
- throws SAXException {
-
- super.endElement(namespaceURI, localName, qName);
-
- // Check after popping the stack so we don't erroneously think we
- // are our own extension namespace...
- boolean inExtension = inExtensionNamespace();
-
- int entryType = -1;
- Vector entryArgs = new Vector();
-
- if (namespaceURI != null
- && (extendedNamespaceName.equals(namespaceURI))
- && !inExtension) {
-
- String popURI = (String) baseURIStack.pop();
- String baseURI = (String) baseURIStack.peek();
-
- if (!baseURI.equals(popURI)) {
- entryType = Catalog.BASE;
- entryArgs.add(baseURI);
-
- debug.message(4, "(reset) xml:base", baseURI);
-
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry (rbase)", localName);
- }
- }
- }
- }
- }
-}
--- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/OASISXMLCatalogReader.java 2017-06-20 10:53:22.354512934 -0700
+++ /dev/null 2017-06-17 22:58:47.330661897 -0700
@@ -1,546 +0,0 @@
-/*
- * 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.CatalogEntry;
-import com.sun.org.apache.xml.internal.resolver.CatalogException;
-import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
-import java.util.Enumeration;
-import java.util.Stack;
-import java.util.Vector;
-import javax.xml.parsers.SAXParserFactory;
-import org.w3c.dom.*;
-import org.xml.sax.*;
-
-/**
- * Parse OASIS Entity Resolution Technical Committee
- * XML Catalog files.
- *
- * @see Catalog
- *
- * @author Norman Walsh
- * Norman.Walsh@Sun.COM
- *
- */
-public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalogParser {
- /** The catalog object needs to be stored by the object so that
- * SAX callbacks can use it.
- */
- protected Catalog catalog = null;
-
- /** The namespace name of OASIS ERTC catalogs */
- public static final String namespaceName = "urn:oasis:names:tc:entity:xmlns:xml:catalog";
-
- /** The namespace name of OASIS ERTC TR9401 catalog extension */
- public static final String tr9401NamespaceName = "urn:oasis:names:tc:entity:xmlns:tr9401:catalog";
-
- protected Stack baseURIStack = new Stack();
- protected Stack overrideStack = new Stack();
- protected Stack namespaceStack = new Stack();
-
- /** Set the current catalog. */
- public void setCatalog (Catalog catalog) {
- this.catalog = catalog;
- debug = catalog.getCatalogManager().debug;
- }
-
- /** Get the current catalog. */
- public Catalog getCatalog () {
- return catalog;
- }
-
- /** Default constructor */
- public OASISXMLCatalogReader() {
- super();
- }
-
- /** Constructor allowing for providing custom SAX parser factory */
- public OASISXMLCatalogReader(SAXParserFactory parserFactory, Catalog catalog) {
- super(parserFactory);
- setCatalog(catalog);
- }
-
- /**
- * Are we in an extension namespace?
- *
- * @return true if the current stack of open namespaces includes
- * an extension namespace.
- */
- protected boolean inExtensionNamespace() {
- boolean inExtension = false;
-
- Enumeration elements = namespaceStack.elements();
- while (!inExtension && elements.hasMoreElements()) {
- String ns = (String) elements.nextElement();
- if (ns == null) {
- inExtension = true;
- } else {
- inExtension = (!ns.equals(tr9401NamespaceName)
- && !ns.equals(namespaceName));
- }
- }
-
- return inExtension;
- }
-
- // ----------------------------------------------------------------------
- // Implement the SAX ContentHandler interface
-
- /** The SAX setDocumentLocator
method does nothing. */
- public void setDocumentLocator (Locator locator) {
- return;
- }
-
- /** The SAX startDocument
*/
- public void startDocument ()
- throws SAXException {
- baseURIStack.push(catalog.getCurrentBase());
- overrideStack.push(catalog.getDefaultOverride());
- return;
- }
-
- /** The SAX endDocument
method does nothing. */
- public void endDocument ()
- throws SAXException {
- return;
- }
-
- /**
- * The SAX startElement
method recognizes elements
- * from the plain catalog format and instantiates CatalogEntry
- * objects for them.
- *
- * @param namespaceURI The namespace name of the element.
- * @param localName The local name of the element.
- * @param qName The QName of the element.
- * @param atts The list of attributes on the element.
- *
- * @see CatalogEntry
- */
- public void startElement (String namespaceURI,
- String localName,
- String qName,
- Attributes atts)
- throws SAXException {
-
- int entryType = -1;
- Vector entryArgs = new Vector();
-
- namespaceStack.push(namespaceURI);
-
- boolean inExtension = inExtensionNamespace();
-
- if (namespaceURI != null && namespaceName.equals(namespaceURI)
- && !inExtension) {
- // This is an XML Catalog entry
-
- if (atts.getValue("xml:base") != null) {
- String baseURI = atts.getValue("xml:base");
- entryType = Catalog.BASE;
- entryArgs.add(baseURI);
- baseURIStack.push(baseURI);
-
- debug.message(4, "xml:base", baseURI);
-
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry (base)", localName);
- }
- }
-
- entryType = -1;
- entryArgs = new Vector();
-
- } else {
- baseURIStack.push(baseURIStack.peek());
- }
-
- if ((localName.equals("catalog") || localName.equals("group"))
- && atts.getValue("prefer") != null) {
- String override = atts.getValue("prefer");
-
- if (override.equals("public")) {
- override = "yes";
- } else if (override.equals("system")) {
- override = "no";
- } else {
- debug.message(1,
- "Invalid prefer: must be 'system' or 'public'",
- localName);
- override = catalog.getDefaultOverride();
- }
-
- entryType = Catalog.OVERRIDE;
- entryArgs.add(override);
- overrideStack.push(override);
-
- debug.message(4, "override", override);
-
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry (override)", localName);
- }
- }
-
- entryType = -1;
- entryArgs = new Vector();
-
- } else {
- overrideStack.push(overrideStack.peek());
- }
-
- if (localName.equals("delegatePublic")) {
- if (checkAttributes(atts, "publicIdStartString", "catalog")) {
- entryType = Catalog.DELEGATE_PUBLIC;
- entryArgs.add(atts.getValue("publicIdStartString"));
- entryArgs.add(atts.getValue("catalog"));
-
- debug.message(4, "delegatePublic",
- PublicId.normalize(atts.getValue("publicIdStartString")),
- atts.getValue("catalog"));
- }
- } else if (localName.equals("delegateSystem")) {
- if (checkAttributes(atts, "systemIdStartString", "catalog")) {
- entryType = Catalog.DELEGATE_SYSTEM;
- entryArgs.add(atts.getValue("systemIdStartString"));
- entryArgs.add(atts.getValue("catalog"));
-
- debug.message(4, "delegateSystem",
- atts.getValue("systemIdStartString"),
- atts.getValue("catalog"));
- }
- } else if (localName.equals("delegateURI")) {
- if (checkAttributes(atts, "uriStartString", "catalog")) {
- entryType = Catalog.DELEGATE_URI;
- entryArgs.add(atts.getValue("uriStartString"));
- entryArgs.add(atts.getValue("catalog"));
-
- debug.message(4, "delegateURI",
- atts.getValue("uriStartString"),
- atts.getValue("catalog"));
- }
- } else if (localName.equals("rewriteSystem")) {
- if (checkAttributes(atts, "systemIdStartString", "rewritePrefix")) {
- entryType = Catalog.REWRITE_SYSTEM;
- entryArgs.add(atts.getValue("systemIdStartString"));
- entryArgs.add(atts.getValue("rewritePrefix"));
-
- debug.message(4, "rewriteSystem",
- atts.getValue("systemIdStartString"),
- atts.getValue("rewritePrefix"));
- }
- } else if (localName.equals("systemSuffix")) {
- if (checkAttributes(atts, "systemIdSuffix", "uri")) {
- entryType = Catalog.SYSTEM_SUFFIX;
- entryArgs.add(atts.getValue("systemIdSuffix"));
- entryArgs.add(atts.getValue("uri"));
-
- debug.message(4, "systemSuffix",
- atts.getValue("systemIdSuffix"),
- atts.getValue("uri"));
- }
- } else if (localName.equals("rewriteURI")) {
- if (checkAttributes(atts, "uriStartString", "rewritePrefix")) {
- entryType = Catalog.REWRITE_URI;
- entryArgs.add(atts.getValue("uriStartString"));
- entryArgs.add(atts.getValue("rewritePrefix"));
-
- debug.message(4, "rewriteURI",
- atts.getValue("uriStartString"),
- atts.getValue("rewritePrefix"));
- }
- } else if (localName.equals("uriSuffix")) {
- if (checkAttributes(atts, "uriSuffix", "uri")) {
- entryType = Catalog.URI_SUFFIX;
- entryArgs.add(atts.getValue("uriSuffix"));
- entryArgs.add(atts.getValue("uri"));
-
- debug.message(4, "uriSuffix",
- atts.getValue("uriSuffix"),
- atts.getValue("uri"));
- }
- } else if (localName.equals("nextCatalog")) {
- if (checkAttributes(atts, "catalog")) {
- entryType = Catalog.CATALOG;
- entryArgs.add(atts.getValue("catalog"));
-
- debug.message(4, "nextCatalog", atts.getValue("catalog"));
- }
- } else if (localName.equals("public")) {
- if (checkAttributes(atts, "publicId", "uri")) {
- entryType = Catalog.PUBLIC;
- entryArgs.add(atts.getValue("publicId"));
- entryArgs.add(atts.getValue("uri"));
-
- debug.message(4, "public",
- PublicId.normalize(atts.getValue("publicId")),
- atts.getValue("uri"));
- }
- } else if (localName.equals("system")) {
- if (checkAttributes(atts, "systemId", "uri")) {
- entryType = Catalog.SYSTEM;
- entryArgs.add(atts.getValue("systemId"));
- entryArgs.add(atts.getValue("uri"));
-
- debug.message(4, "system",
- atts.getValue("systemId"),
- atts.getValue("uri"));
- }
- } else if (localName.equals("uri")) {
- if (checkAttributes(atts, "name", "uri")) {
- entryType = Catalog.URI;
- entryArgs.add(atts.getValue("name"));
- entryArgs.add(atts.getValue("uri"));
-
- debug.message(4, "uri",
- atts.getValue("name"),
- atts.getValue("uri"));
- }
- } else if (localName.equals("catalog")) {
- // nop, start of catalog
- } else if (localName.equals("group")) {
- // nop, a group
- } else {
- // This is equivalent to an invalid catalog entry type
- debug.message(1, "Invalid catalog entry type", localName);
- }
-
- if (entryType >= 0) {
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry", localName);
- }
- }
- }
- }
-
- if (namespaceURI != null && tr9401NamespaceName.equals(namespaceURI)
- && !inExtension) {
- // This is a TR9401 Catalog entry
-
- if (atts.getValue("xml:base") != null) {
- String baseURI = atts.getValue("xml:base");
- entryType = Catalog.BASE;
- entryArgs.add(baseURI);
- baseURIStack.push(baseURI);
-
- debug.message(4, "xml:base", baseURI);
-
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry (base)", localName);
- }
- }
-
- entryType = -1;
- entryArgs = new Vector();
-
- } else {
- baseURIStack.push(baseURIStack.peek());
- }
-
- if (localName.equals("doctype")) {
- entryType = Catalog.DOCTYPE;
- entryArgs.add(atts.getValue("name"));
- entryArgs.add(atts.getValue("uri"));
- } else if (localName.equals("document")) {
- entryType = Catalog.DOCUMENT;
- entryArgs.add(atts.getValue("uri"));
- } else if (localName.equals("dtddecl")) {
- entryType = Catalog.DTDDECL;
- entryArgs.add(atts.getValue("publicId"));
- entryArgs.add(atts.getValue("uri"));
- } else if (localName.equals("entity")) {
- entryType = Catalog.ENTITY;
- entryArgs.add(atts.getValue("name"));
- entryArgs.add(atts.getValue("uri"));
- } else if (localName.equals("linktype")) {
- entryType = Catalog.LINKTYPE;
- entryArgs.add(atts.getValue("name"));
- entryArgs.add(atts.getValue("uri"));
- } else if (localName.equals("notation")) {
- entryType = Catalog.NOTATION;
- entryArgs.add(atts.getValue("name"));
- entryArgs.add(atts.getValue("uri"));
- } else if (localName.equals("sgmldecl")) {
- entryType = Catalog.SGMLDECL;
- entryArgs.add(atts.getValue("uri"));
- } else {
- // This is equivalent to an invalid catalog entry type
- debug.message(1, "Invalid catalog entry type", localName);
- }
-
- if (entryType >= 0) {
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry", localName);
- }
- }
- }
- }
- }
-
- public boolean checkAttributes (Attributes atts, String attName) {
- if (atts.getValue(attName) == null) {
- debug.message(1, "Error: required attribute " + attName + " missing.");
- return false;
- } else {
- return true;
- }
- }
-
- public boolean checkAttributes (Attributes atts,
- String attName1,
- String attName2) {
- return checkAttributes(atts, attName1)
- && checkAttributes(atts, attName2);
- }
-
- /** The SAX endElement
*/
- public void endElement (String namespaceURI,
- String localName,
- String qName)
- throws SAXException {
-
- int entryType = -1;
- Vector entryArgs = new Vector();
-
- boolean inExtension = inExtensionNamespace();
-
- if (namespaceURI != null
- && !inExtension
- && (namespaceName.equals(namespaceURI)
- || tr9401NamespaceName.equals(namespaceURI))) {
-
- String popURI = (String) baseURIStack.pop();
- String baseURI = (String) baseURIStack.peek();
-
- if (!baseURI.equals(popURI)) {
- entryType = Catalog.BASE;
- entryArgs.add(baseURI);
-
- debug.message(4, "(reset) xml:base", baseURI);
-
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry (rbase)", localName);
- }
- }
- }
- }
-
- if (namespaceURI != null && namespaceName.equals(namespaceURI)
- && !inExtension) {
- if (localName.equals("catalog") || localName.equals("group")) {
- String popOverride = (String) overrideStack.pop();
- String override = (String) overrideStack.peek();
-
- if (!override.equals(popOverride)) {
- entryType = Catalog.OVERRIDE;
- entryArgs.add(override);
- overrideStack.push(override);
-
- debug.message(4, "(reset) override", override);
-
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry (roverride)", localName);
- }
- }
- }
- }
- }
-
- namespaceStack.pop();
-
- return;
- }
-
- /** The SAX characters
method does nothing. */
- public void characters (char ch[], int start, int length)
- throws SAXException {
- return;
- }
-
- /** The SAX ignorableWhitespace
method does nothing. */
- public void ignorableWhitespace (char ch[], int start, int length)
- throws SAXException {
- return;
- }
-
- /** The SAX processingInstruction
method does nothing. */
- public void processingInstruction (String target, String data)
- throws SAXException {
- return;
- }
-
- /** The SAX skippedEntity
method does nothing. */
- public void skippedEntity (String name)
- throws SAXException {
- return;
- }
-
- /** The SAX startPrefixMapping
method does nothing. */
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
- return;
- }
-
- /** The SAX endPrefixMapping
method does nothing. */
- public void endPrefixMapping(String prefix)
- throws SAXException {
- return;
- }
-
-}
--- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/SAXCatalogParser.java 2017-06-20 10:53:22.582524304 -0700
+++ /dev/null 2017-06-17 22:58:47.330661897 -0700
@@ -1,39 +0,0 @@
-/*
- * 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 org.xml.sax.*;
-
-/**
- * The SAXCatalogParser interface.
- *
- * This interface must be implemented in order for a class to - * participate as a parser for the SAXCatalogReader. - * - * @see Catalog - * @see SAXCatalogReader - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public interface SAXCatalogParser extends ContentHandler, DocumentHandler { - /** Set the Catalog for which parsing is being performed. */ - public void setCatalog(Catalog catalog); -} --- 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);
- }
- }
-}
--- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/SAXParserHandler.java 2017-06-20 10:53:23.074548839 -0700
+++ /dev/null 2017-06-17 22:58:47.330661897 -0700
@@ -1,144 +0,0 @@
-/*
- * 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 java.io.IOException;
-
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
-
-/**
- * An entity-resolving DefaultHandler.
- *
- * This class provides a SAXParser DefaultHandler that performs - * entity resolution. - *
- * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - */ -public class SAXParserHandler extends DefaultHandler { - private EntityResolver er = null; - private ContentHandler ch = null; - - public SAXParserHandler() { - super(); - } - - public void setEntityResolver(EntityResolver er) { - this.er = er; - } - - public void setContentHandler(ContentHandler ch) { - this.ch = ch; - } - - // Entity Resolver - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException { - - if (er != null) { - try { - return er.resolveEntity(publicId, systemId); - } catch (IOException e) { - System.out.println("resolveEntity threw IOException!"); - return null; - } - } else { - return null; - } - } - - // Content Handler - public void characters(char[] ch, int start, int length) - throws SAXException { - if (this.ch != null) { - this.ch.characters(ch, start, length); - } - } - - public void endDocument() - throws SAXException { - if (ch != null) { - ch.endDocument(); - } - } - - public void endElement(String namespaceURI, String localName, String qName) - throws SAXException { - if (ch != null) { - ch.endElement(namespaceURI, localName, qName); - } - } - - public void endPrefixMapping(String prefix) - throws SAXException { - if (ch != null) { - ch.endPrefixMapping(prefix); - } - } - - public void ignorableWhitespace(char[] ch, int start, int length) - throws SAXException { - if (this.ch != null) { - this.ch.ignorableWhitespace(ch, start, length); - } - } - - public void processingInstruction(String target, String data) - throws SAXException { - if (ch != null) { - ch.processingInstruction(target, data); - } - } - - public void setDocumentLocator(Locator locator) { - if (ch != null) { - ch.setDocumentLocator(locator); - } - } - - public void skippedEntity(String name) - throws SAXException { - if (ch != null) { - ch.skippedEntity(name); - } - } - - public void startDocument() - throws SAXException { - if (ch != null) { - ch.startDocument(); - } - } - - public void startElement(String namespaceURI, String localName, - String qName, Attributes atts) - throws SAXException { - if (ch != null) { - ch.startElement(namespaceURI, localName, qName, atts); - } - } - - public void startPrefixMapping(String prefix, String uri) - throws SAXException { - if (ch != null) { - ch.startPrefixMapping(prefix, uri); - } - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/TR9401CatalogReader.java 2017-06-20 10:53:23.290559610 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,138 +0,0 @@ -/* - * 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.CatalogEntry; -import com.sun.org.apache.xml.internal.resolver.CatalogException; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.util.Locale; -import java.util.Vector; - -/** - * Parses OASIS Open Catalog files. - * - *This class reads OASIS Open Catalog files, returning a stream - * of tokens.
- * - *This code interrogates the following non-standard system properties:
- * - *Sets the debug level. A value of 0 is assumed if the - * property is not set or is not a number.
nextEntry
.
- *
- * In a TR9401 Catalog the 'DELEGATE' entry delegates public - * identifiers. There is no delegate entry for system identifiers - * or URIs.
- * - * @param catalog The Catalog to populate - * @param is The input stream from which to read the TR9401 Catalog - * - * @throws MalformedURLException Improper fileUrl - * @throws IOException Error reading catalog file - */ - public void readCatalog(Catalog catalog, InputStream is) - throws MalformedURLException, IOException { - - catfile = is; - - if (catfile == null) { - return; - } - - Vector unknownEntry = null; - - try { - while (true) { - String token = nextToken(); - - if (token == null) { - if (unknownEntry != null) { - catalog.unknownEntry(unknownEntry); - unknownEntry = null; - } - catfile.close(); - catfile = null; - return; - } - - String entryToken = null; - if (caseSensitive) { - entryToken = token; - } else { - entryToken = token.toUpperCase(Locale.ENGLISH); - } - - if (entryToken.equals("DELEGATE")) { - entryToken = "DELEGATE_PUBLIC"; - } - - try { - int type = CatalogEntry.getEntryType(entryToken); - int numArgs = CatalogEntry.getEntryArgCount(type); - Vector args = new Vector(); - - if (unknownEntry != null) { - catalog.unknownEntry(unknownEntry); - unknownEntry = null; - } - - for (int count = 0; count < numArgs; count++) { - args.addElement(nextToken()); - } - - catalog.addEntry(new CatalogEntry(entryToken, args)); - } catch (CatalogException cex) { - if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { - if (unknownEntry == null) { - unknownEntry = new Vector(); - } - unknownEntry.addElement(token); - } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { - catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token); - unknownEntry = null; - } else if (cex.getExceptionType() == CatalogException.UNENDED_COMMENT) { - catalog.getCatalogManager().debug.message(1, cex.getMessage()); - } - } - } - } catch (CatalogException cex2) { - if (cex2.getExceptionType() == CatalogException.UNENDED_COMMENT) { - catalog.getCatalogManager().debug.message(1, cex2.getMessage()); - } - } - - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/TextCatalogReader.java 2017-06-20 10:53:23.526571379 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,298 +0,0 @@ -/* - * 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.CatalogEntry; -import com.sun.org.apache.xml.internal.resolver.CatalogException; -import com.sun.org.apache.xml.internal.resolver.readers.CatalogReader; -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.util.Locale; -import java.util.Stack; -import java.util.Vector; - -/** - * Parses plain text Catalog files. - * - *This class reads plain text Open Catalog files.
- * - * @see Catalog - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - */ -public class TextCatalogReader implements CatalogReader { - /** The input stream used to read the catalog */ - protected InputStream catfile = null; - - /** - * Character lookahead stack. Reading a catalog sometimes requires - * up to two characters of lookahead. - */ - protected int[] stack = new int[3]; - - /** - * Token stack. Recognizing an unexpected catalog entry requires - * the ability to "push back" a token. - */ - protected Stack tokenStack = new Stack(); - - /** The current position on the lookahead stack */ - protected int top = -1; - - /** Are keywords in the catalog case sensitive? */ - protected boolean caseSensitive = false; - - /** - * Construct a CatalogReader object. - */ - public TextCatalogReader() { } - - public void setCaseSensitive(boolean isCaseSensitive) { - caseSensitive = isCaseSensitive; - } - - public boolean getCaseSensitive() { - return caseSensitive; - } - - /** - * Start parsing a text catalog file. The file is - * actually read and parsed - * as needed bynextEntry
.
- *
- * @param fileUrl The URL or filename of the catalog file to process
- *
- * @throws MalformedURLException Improper fileUrl
- * @throws IOException Error reading catalog file
- */
- public void readCatalog(Catalog catalog, String fileUrl)
- throws MalformedURLException, IOException {
- URL catURL = null;
-
- try {
- catURL = new URL(fileUrl);
- } catch (MalformedURLException e) {
- catURL = new URL("file:///" + fileUrl);
- }
-
- URLConnection urlCon = catURL.openConnection();
- try {
- readCatalog(catalog, urlCon.getInputStream());
- } catch (FileNotFoundException e) {
- catalog.getCatalogManager().debug.message(1, "Failed to load catalog, file not found",
- catURL.toString());
- }
- }
-
- public void readCatalog(Catalog catalog, InputStream is)
- throws MalformedURLException, IOException {
-
- catfile = is;
-
- if (catfile == null) {
- return;
- }
-
- Vector unknownEntry = null;
-
- try {
- while (true) {
- String token = nextToken();
-
- if (token == null) {
- if (unknownEntry != null) {
- catalog.unknownEntry(unknownEntry);
- unknownEntry = null;
- }
- catfile.close();
- catfile = null;
- return;
- }
-
- String entryToken = null;
- if (caseSensitive) {
- entryToken = token;
- } else {
- entryToken = token.toUpperCase(Locale.ENGLISH);
- }
-
- try {
- int type = CatalogEntry.getEntryType(entryToken);
- int numArgs = CatalogEntry.getEntryArgCount(type);
- Vector args = new Vector();
-
- if (unknownEntry != null) {
- catalog.unknownEntry(unknownEntry);
- unknownEntry = null;
- }
-
- for (int count = 0; count < numArgs; count++) {
- args.addElement(nextToken());
- }
-
- catalog.addEntry(new CatalogEntry(entryToken, args));
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- if (unknownEntry == null) {
- unknownEntry = new Vector();
- }
- unknownEntry.addElement(token);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", token);
- unknownEntry = null;
- } else if (cex.getExceptionType() == CatalogException.UNENDED_COMMENT) {
- catalog.getCatalogManager().debug.message(1, cex.getMessage());
- }
- }
- }
- } catch (CatalogException cex2) {
- if (cex2.getExceptionType() == CatalogException.UNENDED_COMMENT) {
- catalog.getCatalogManager().debug.message(1, cex2.getMessage());
- }
- }
- }
-
- /**
- * The destructor.
- *
- * Makes sure the catalog file is closed.
- */ - protected void finalize() { - if (catfile != null) { - try { - catfile.close(); - } catch (IOException e) { - // whatever... - } - } - catfile = null; - } - - // ----------------------------------------------------------------- - - /** - * Return the next token in the catalog file. - * - *FYI: This code does not throw any sort of exception for
- * a file that contains an n
- *
- * @return The Catalog file token from the input stream.
- * @throws IOException If an error occurs reading from the stream.
- */
- protected String nextToken() throws IOException, CatalogException {
- String token = "";
- int ch, nextch;
-
- if (!tokenStack.empty()) {
- return (String) tokenStack.pop();
- }
-
- // Skip over leading whitespace and comments
- while (true) {
- // skip leading whitespace
- ch = catfile.read();
- while (ch <= ' ') { // all ctrls are whitespace
- ch = catfile.read();
- if (ch < 0) {
- return null;
- }
- }
-
- // now 'ch' is the current char from the file
- nextch = catfile.read();
- if (nextch < 0) {
- return null;
- }
-
- if (ch == '-' && nextch == '-') {
- // we've found a comment, skip it...
- ch = ' ';
- nextch = nextChar();
- while ((ch != '-' || nextch != '-') && nextch > 0) {
- ch = nextch;
- nextch = nextChar();
- }
-
- if (nextch < 0) {
- throw new CatalogException(CatalogException.UNENDED_COMMENT,
- "Unterminated comment in catalog file; EOF treated as end-of-comment.");
- }
-
- // Ok, we've found the end of the comment,
- // loop back to the top and start again...
- } else {
- stack[++top] = nextch;
- stack[++top] = ch;
- break;
- }
- }
-
- ch = nextChar();
- if (ch == '"' || ch == '\'') {
- int quote = ch;
- while ((ch = nextChar()) != quote) {
- char[] chararr = new char[1];
- chararr[0] = (char) ch;
- String s = new String(chararr);
- token = token.concat(s);
- }
- return token;
- } else {
- // return the next whitespace or comment delimited
- // string
- while (ch > ' ') {
- nextch = nextChar();
- if (ch == '-' && nextch == '-') {
- stack[++top] = ch;
- stack[++top] = nextch;
- return token;
- } else {
- char[] chararr = new char[1];
- chararr[0] = (char) ch;
- String s = new String(chararr);
- token = token.concat(s);
- ch = nextch;
- }
- }
- return token;
- }
- }
-
- /**
- * Return the next logical character from the input stream.
- *
- * @return The next (logical) character from the input stream. The
- * character may be buffered from a previous lookahead.
- *
- * @throws IOException If an error occurs reading from the stream.
- */
- protected int nextChar() throws IOException {
- if (top < 0) {
- return catfile.read();
- } else {
- return stack[top--];
- }
- }
-}
--- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/readers/XCatalogReader.java 2017-06-20 10:53:23.738581951 -0700
+++ /dev/null 2017-06-17 22:58:47.330661897 -0700
@@ -1,208 +0,0 @@
-/*
- * 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 java.util.Vector;
-import com.sun.org.apache.xml.internal.resolver.Catalog;
-import com.sun.org.apache.xml.internal.resolver.CatalogEntry;
-import com.sun.org.apache.xml.internal.resolver.CatalogException;
-import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
-
-import org.xml.sax.*;
-
-import javax.xml.parsers.*;
-
-/**
- * Parse "XCatalog" XML Catalog files, this is the XML Catalog format
- * developed by John Cowan and supported by Apache.
- *
- * @see Catalog
- *
- * @author Norman Walsh
- * Norman.Walsh@Sun.COM
- *
- */
-public class XCatalogReader extends SAXCatalogReader implements SAXCatalogParser {
- /** The catalog object needs to be stored by the object so that
- * SAX callbacks can use it.
- */
- protected Catalog catalog = null;
-
- /** Set the current catalog. */
- public void setCatalog (Catalog catalog) {
- this.catalog = catalog;
- debug = catalog.getCatalogManager().debug;
- }
-
- /** Get the current catalog. */
- public Catalog getCatalog () {
- return catalog;
- }
-
- /** Default constructor */
- public XCatalogReader() {
- super();
- }
-
- /** Constructor allowing for providing custom SAX parser factory */
- public XCatalogReader(SAXParserFactory parserFactory, Catalog catalog) {
- super(parserFactory);
- setCatalog(catalog);
- }
-
- // ----------------------------------------------------------------------
- // Implement the SAX ContentHandler interface
-
- /** The SAX setDocumentLocator
method does nothing. */
- public void setDocumentLocator (Locator locator) {
- return;
- }
-
- /** The SAX startDocument
method does nothing. */
- public void startDocument ()
- throws SAXException {
- return;
- }
-
- /** The SAX endDocument
method does nothing. */
- public void endDocument ()
- throws SAXException {
- return;
- }
-
- /**
- * The SAX startElement
method recognizes elements
- * from the plain catalog format and instantiates CatalogEntry
- * objects for them.
- *
- * @param namespaceURI The namespace name of the element.
- * @param localName The local name of the element.
- * @param qName The QName of the element.
- * @param atts The list of attributes on the element.
- *
- * @see CatalogEntry
- */
- public void startElement (String namespaceURI,
- String localName,
- String qName,
- Attributes atts)
- throws SAXException {
-
- int entryType = -1;
- Vector entryArgs = new Vector();
-
- if (localName.equals("Base")) {
- entryType = Catalog.BASE;
- entryArgs.add(atts.getValue("HRef"));
-
- debug.message(4, "Base", atts.getValue("HRef"));
- } else if (localName.equals("Delegate")) {
- entryType = Catalog.DELEGATE_PUBLIC;
- entryArgs.add(atts.getValue("PublicID"));
- entryArgs.add(atts.getValue("HRef"));
-
- debug.message(4, "Delegate",
- PublicId.normalize(atts.getValue("PublicID")),
- atts.getValue("HRef"));
- } else if (localName.equals("Extend")) {
- entryType = Catalog.CATALOG;
- entryArgs.add(atts.getValue("HRef"));
-
- debug.message(4, "Extend", atts.getValue("HRef"));
- } else if (localName.equals("Map")) {
- entryType = Catalog.PUBLIC;
- entryArgs.add(atts.getValue("PublicID"));
- entryArgs.add(atts.getValue("HRef"));
-
- debug.message(4, "Map",
- PublicId.normalize(atts.getValue("PublicID")),
- atts.getValue("HRef"));
- } else if (localName.equals("Remap")) {
- entryType = Catalog.SYSTEM;
- entryArgs.add(atts.getValue("SystemID"));
- entryArgs.add(atts.getValue("HRef"));
-
- debug.message(4, "Remap",
- atts.getValue("SystemID"),
- atts.getValue("HRef"));
- } else if (localName.equals("XCatalog")) {
- // nop, start of catalog
- } else {
- // This is equivalent to an invalid catalog entry type
- debug.message(1, "Invalid catalog entry type", localName);
- }
-
- if (entryType >= 0) {
- try {
- CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
- catalog.addEntry(ce);
- } catch (CatalogException cex) {
- if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
- debug.message(1, "Invalid catalog entry type", localName);
- } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
- debug.message(1, "Invalid catalog entry", localName);
- }
- }
- }
- }
-
- /** The SAX endElement
method does nothing. */
- public void endElement (String namespaceURI,
- String localName,
- String qName)
- throws SAXException {
- return;
- }
-
- /** The SAX characters
method does nothing. */
- public void characters (char ch[], int start, int length)
- throws SAXException {
- return;
- }
-
- /** The SAX ignorableWhitespace
method does nothing. */
- public void ignorableWhitespace (char ch[], int start, int length)
- throws SAXException {
- return;
- }
-
- /** The SAX processingInstruction
method does nothing. */
- public void processingInstruction (String target, String data)
- throws SAXException {
- return;
- }
-
- /** The SAX skippedEntity
method does nothing. */
- public void skippedEntity (String name)
- throws SAXException {
- return;
- }
-
- /** The SAX startPrefixMapping
method does nothing. */
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
- return;
- }
-
- /** The SAX endPrefixMapping
method does nothing. */
- public void endPrefixMapping(String prefix)
- throws SAXException {
- return;
- }
-
-}
--- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/tools/CatalogResolver.java 2017-06-20 10:53:23.950592522 -0700
+++ /dev/null 2017-06-17 22:58:47.330661897 -0700
@@ -1,349 +0,0 @@
-/*
- * 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.tools;
-
-import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.MalformedURLException;
-
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.InputSource;
-import org.xml.sax.EntityResolver;
-
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.Source;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.TransformerException;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
-
-import com.sun.org.apache.xml.internal.resolver.Catalog;
-import com.sun.org.apache.xml.internal.resolver.CatalogManager;
-import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
-
-/**
- * A SAX EntityResolver/JAXP URIResolver that uses catalogs.
- *
- *
This class implements both a SAX EntityResolver and a JAXP URIResolver. - *
- * - *This resolver understands OASIS TR9401 catalogs, XCatalogs, and the - * current working draft of the OASIS Entity Resolution Technical - * Committee specification.
- * - * @see Catalog - * @see org.xml.sax.EntityResolver - * @see javax.xml.transform.URIResolver - * @deprecated The JDK internal Catalog API in package - * {@code com.sun.org.apache.xml.internal.resolver} - * is encapsulated in JDK 9. The entire implementation under the package is now - * deprecated and subject to removal in a future release. Users of the API - * should migrate to the {@linkplain javax.xml.catalog new public API}. - *
- * The new Catalog API is supported throughout the JDK XML Processors, which allows
- * the use of Catalog by simply setting a path to a Catalog file as a property.
- *
- * @author Norman Walsh
- * Norman.Walsh@Sun.COM
- *
- * @version 1.0
- */
-@Deprecated(since="9", forRemoval=true)
-public class CatalogResolver implements EntityResolver, URIResolver {
- /** Make the parser Namespace aware? */
- public boolean namespaceAware = true;
-
- /** Make the parser validating? */
- public boolean validating = false;
-
- /** The underlying catalog */
- private Catalog catalog = null;
-
- /** The catalog manager */
- private CatalogManager catalogManager = CatalogManager.getStaticManager();
-
- /** Constructor */
- public CatalogResolver() {
- initializeCatalogs(false);
- }
-
- /** Constructor */
- public CatalogResolver(boolean privateCatalog) {
- initializeCatalogs(privateCatalog);
- }
-
- /** Constructor */
- public CatalogResolver(CatalogManager manager) {
- catalogManager = manager;
- initializeCatalogs(!catalogManager.getUseStaticCatalog());
- }
-
- /** Initialize catalog */
- private void initializeCatalogs(boolean privateCatalog) {
- catalog = catalogManager.getCatalog();
- }
-
- /** Return the underlying catalog */
- public Catalog getCatalog() {
- return catalog;
- }
-
- /**
- * Implements the guts of the resolveEntity
method
- * for the SAX interface.
- *
- *
Presented with an optional public identifier and a system - * identifier, this function attempts to locate a mapping in the - * catalogs.
- * - *If such a mapping is found, it is returned. If no mapping is - * found, null is returned.
- * - * @param publicId The public identifier for the entity in question. - * This may be null. - * - * @param systemId The system identifier for the entity in question. - * XML requires a system identifier on all external entities, so this - * value is always specified. - * - * @return The resolved identifier (a URI reference). - */ - public String getResolvedEntity (String publicId, String systemId) { - String resolved = null; - - if (catalog == null) { - catalogManager.debug.message(1, "Catalog resolution attempted with null catalog; ignored"); - return null; - } - - if (systemId != null) { - try { - resolved = catalog.resolveSystem(systemId); - } catch (MalformedURLException me) { - catalogManager.debug.message(1, "Malformed URL exception trying to resolve", - publicId); - resolved = null; - } catch (IOException ie) { - catalogManager.debug.message(1, "I/O exception trying to resolve", publicId); - resolved = null; - } - } - - if (resolved == null) { - if (publicId != null) { - try { - resolved = catalog.resolvePublic(publicId, systemId); - } catch (MalformedURLException me) { - catalogManager.debug.message(1, "Malformed URL exception trying to resolve", - publicId); - } catch (IOException ie) { - catalogManager.debug.message(1, "I/O exception trying to resolve", publicId); - } - } - - if (resolved != null) { - catalogManager.debug.message(2, "Resolved public", publicId, resolved); - } - } else { - catalogManager.debug.message(2, "Resolved system", systemId, resolved); - } - - return resolved; - } - - /** - * Implements theresolveEntity
method
- * for the SAX interface.
- *
- * Presented with an optional public identifier and a system - * identifier, this function attempts to locate a mapping in the - * catalogs.
- * - *If such a mapping is found, the resolver attempts to open - * the mapped value as an InputSource and return it. Exceptions are - * ignored and null is returned if the mapped value cannot be opened - * as an input source.
- * - *If no mapping is found (or an error occurs attempting to open - * the mapped value as an input source), null is returned and the system - * will use the specified system identifier as if no entityResolver - * was specified.
- * - * @param publicId The public identifier for the entity in question. - * This may be null. - * - * @param systemId The system identifier for the entity in question. - * XML requires a system identifier on all external entities, so this - * value is always specified. - * - * @return An InputSource for the mapped identifier, or null. - */ - public InputSource resolveEntity (String publicId, String systemId) { - String resolved = getResolvedEntity(publicId, systemId); - - if (resolved != null) { - try { - InputSource iSource = new InputSource(resolved); - iSource.setPublicId(publicId); - - // Ideally this method would not attempt to open the - // InputStream, but there is a bug (in Xerces, at least) - // that causes the parser to mistakenly open the wrong - // system identifier if the returned InputSource does - // not have a byteStream. - // - // It could be argued that we still shouldn't do this here, - // but since the purpose of calling the entityResolver is - // almost certainly to open the input stream, it seems to - // do little harm. - // - URL url = new URL(resolved); - InputStream iStream = url.openStream(); - iSource.setByteStream(iStream); - - return iSource; - } catch (Exception e) { - catalogManager.debug.message(1, - "Failed to create InputSource (" - + e.toString() - + ")", resolved); - return null; - } - } - - return null; - } - - /** JAXP URIResolver API */ - public Source resolve(String href, String base) - throws TransformerException { - - String uri = href; - String fragment = null; - int hashPos = href.indexOf("#"); - if (hashPos >= 0) { - uri = href.substring(0, hashPos); - fragment = href.substring(hashPos+1); - } - - String result = null; - - try { - result = catalog.resolveURI(href); - } catch (Exception e) { - // nop; - } - - if (result == null) { - try { - URL url = null; - - if (base==null) { - url = new URL(uri); - result = url.toString(); - } else { - URL baseURL = new URL(base); - url = (href.length()==0 ? baseURL : new URL(baseURL, uri)); - result = url.toString(); - } - } catch (java.net.MalformedURLException mue) { - // try to make an absolute URI from the current base - String absBase = makeAbsolute(base); - if (!absBase.equals(base)) { - // don't bother if the absBase isn't different! - return resolve(href, absBase); - } else { - throw new TransformerException("Malformed URL " - + href + "(base " + base + ")", - mue); - } - } - } - - catalogManager.debug.message(2, "Resolved URI", href, result); - - SAXSource source = new SAXSource(); - source.setInputSource(new InputSource(result)); - setEntityResolver(source); - return source; - } - - /** - *Establish an entityResolver for newly resolved URIs.
- * - *This is called from the URIResolver to set an EntityResolver - * on the SAX parser to be used for new XML documents that are - * encountered as a result of the document() function, xsl:import, - * or xsl:include. This is done because the XSLT processor calls - * out to the SAXParserFactory itself to create a new SAXParser to - * parse the new document. The new parser does not automatically - * inherit the EntityResolver of the original (although arguably - * it should). See below:
- * - * "If an application wants to set the ErrorHandler or - * EntityResolver for an XMLReader used during a transformation, - * it should use a URIResolver to return the SAXSource which - * provides (with getXMLReader) a reference to the XMLReader" - * - *...quoted from page 118 of the Java API for XML - * Processing 1.1 specification
- * - */ - private void setEntityResolver(SAXSource source) throws TransformerException { - XMLReader reader = source.getXMLReader(); - if (reader == null) { - SAXParserFactory spFactory = catalogManager.useServicesMechanism() ? - SAXParserFactory.newInstance() : new SAXParserFactoryImpl(); - spFactory.setNamespaceAware(true); - try { - reader = spFactory.newSAXParser().getXMLReader(); - } - catch (ParserConfigurationException ex) { - throw new TransformerException(ex); - } - catch (SAXException ex) { - throw new TransformerException(ex); - } - } - reader.setEntityResolver(this); - source.setXMLReader(reader); - } - - /** Attempt to construct an absolute URI */ - private String makeAbsolute(String uri) { - if (uri == null) { - uri = ""; - } - - try { - URL url = new URL(uri); - return url.toString(); - } catch (MalformedURLException mue) { - try { - URL fileURL = FileURL.makeURL(uri); - return fileURL.toString(); - } catch (MalformedURLException mue2) { - // bail - return uri; - } - } - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/tools/ResolvingParser.java 2017-06-20 10:53:24.158602895 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,434 +0,0 @@ -/* - * 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.tools; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.MalformedURLException; -import java.util.Locale; - -import org.xml.sax.Parser; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.ErrorHandler; -import org.xml.sax.DTDHandler; -import org.xml.sax.DocumentHandler; -import org.xml.sax.AttributeList; -import org.xml.sax.EntityResolver; -import org.xml.sax.SAXException; - -import javax.xml.parsers.SAXParserFactory; -import javax.xml.parsers.SAXParser; - -import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl; -import com.sun.org.apache.xml.internal.resolver.Catalog; -import com.sun.org.apache.xml.internal.resolver.CatalogManager; -import com.sun.org.apache.xml.internal.resolver.helpers.FileURL; - -/** - * A SAX Parser that performs catalog-based entity resolution. - * - *This class implements a SAX Parser that performs entity resolution - * using the CatalogResolver. The actual, underlying parser is obtained - * from a SAXParserFactory.
- * - * - * @deprecated This interface has been replaced by the - * {@link com.sun.org.apache.xml.internal.resolver.tools.ResolvingXMLReader} for SAX2. - * @see CatalogResolver - * @see org.xml.sax.Parser - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - * @version 1.0 - */ -public class ResolvingParser - implements Parser, DTDHandler, DocumentHandler, EntityResolver { - - /** Suppress explanatory message? - * - * @see #parse(InputSource) - */ - private static final boolean suppressExplanation = false; - - /** The underlying parser. */ - private SAXParser saxParser = null; - - /** The underlying reader. */ - private Parser parser = null; - - /** The underlying DocumentHandler. */ - private DocumentHandler documentHandler = null; - - /** The underlying DTDHandler. */ - private DTDHandler dtdHandler = null; - - /** The manager for the underlying resolver. */ - private CatalogManager catalogManager = CatalogManager.getStaticManager(); - - /** The underlying catalog resolver. */ - private CatalogResolver catalogResolver = null; - - /** A separate resolver for oasis-xml-pi catalogs. */ - private CatalogResolver piCatalogResolver = null; - - /** Are we in the prolog? Is an oasis-xml-catalog PI valid now? */ - private boolean allowXMLCatalogPI = false; - - /** The base URI of the input document, if known. */ - private URL baseURL = null; - - /** Constructor. */ - public ResolvingParser() { - initParser(); - } - - /** Constructor. */ - public ResolvingParser(CatalogManager manager) { - catalogManager = manager; - initParser(); - } - - /** Initialize the parser. */ - private void initParser() { - catalogResolver = new CatalogResolver(catalogManager); - SAXParserFactory spf = catalogManager.useServicesMechanism() ? - SAXParserFactory.newInstance() : new SAXParserFactoryImpl(); - spf.setNamespaceAware(true); - spf.setValidating(false); - - try { - saxParser = spf.newSAXParser(); - parser = saxParser.getParser(); - documentHandler = null; - dtdHandler = null; - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - /** Return the Catalog being used. */ - public Catalog getCatalog() { - return catalogResolver.getCatalog(); - } - - /** - * SAX Parser API. - * - *Note that the JAXP 1.1ea2 parser crashes with an InternalError if - * it encounters a system identifier that appears to be a relative URI - * that begins with a slash. For example, the declaration:
- * - *- * <!DOCTYPE book SYSTEM "/path/to/dtd/on/my/system/docbookx.dtd"> - *- * - *
would cause such an error. As a convenience, this method catches - * that error and prints an explanation. (Unfortunately, it's not possible - * to identify the particular system identifier that causes the problem.) - *
- * - *The underlying error is forwarded after printing the explanatory
- * message. The message is only every printed once and if
- * suppressExplanation
is set to false
before
- * parsing, it will never be printed.
The purpose of this class is to implement an entity resolver. - * Attempting to set a different one is pointless (and ignored).
- */ - public void setEntityResolver(EntityResolver resolver) { - // nop - } - - /** SAX Parser API. */ - public void setErrorHandler(ErrorHandler handler) { - parser.setErrorHandler(handler); - } - - /** SAX Parser API. */ - public void setLocale(Locale locale) throws SAXException { - parser.setLocale(locale); - } - - /** SAX DocumentHandler API. */ - public void characters(char[] ch, int start, int length) - throws SAXException { - if (documentHandler != null) { - documentHandler.characters(ch,start,length); - } - } - - /** SAX DocumentHandler API. */ - public void endDocument() throws SAXException { - if (documentHandler != null) { - documentHandler.endDocument(); - } - } - - /** SAX DocumentHandler API. */ - public void endElement(String name) throws SAXException { - if (documentHandler != null) { - documentHandler.endElement(name); - } - } - - /** SAX DocumentHandler API. */ - public void ignorableWhitespace(char[] ch, int start, int length) - throws SAXException { - if (documentHandler != null) { - documentHandler.ignorableWhitespace(ch,start,length); - } - } - - /** SAX DocumentHandler API. */ - public void processingInstruction(String target, String pidata) - throws SAXException { - - if (target.equals("oasis-xml-catalog")) { - URL catalog = null; - String data = pidata; - - int pos = data.indexOf("catalog="); - if (pos >= 0) { - data = data.substring(pos+8); - if (data.length() > 1) { - String quote = data.substring(0,1); - data = data.substring(1); - pos = data.indexOf(quote); - if (pos >= 0) { - data = data.substring(0, pos); - try { - if (baseURL != null) { - catalog = new URL(baseURL, data); - } else { - catalog = new URL(data); - } - } catch (MalformedURLException mue) { - // nevermind - } - } - } - } - - if (allowXMLCatalogPI) { - if (catalogManager.getAllowOasisXMLCatalogPI()) { - catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata); - - if (catalog != null) { - try { - catalogManager.debug.message(4,"oasis-xml-catalog", catalog.toString()); - - if (piCatalogResolver == null) { - piCatalogResolver = new CatalogResolver(true); - } - - piCatalogResolver.getCatalog().parseCatalog(catalog.toString()); - } catch (Exception e) { - catalogManager.debug.message(3, "Exception parsing oasis-xml-catalog: " - + catalog.toString()); - } - } else { - catalogManager.debug.message(3, "PI oasis-xml-catalog unparseable: " + pidata); - } - } else { - catalogManager.debug.message(4,"PI oasis-xml-catalog ignored: " + pidata); - } - } else { - catalogManager.debug.message(3, "PI oasis-xml-catalog occurred in an invalid place: " - + pidata); - } - } else { - if (documentHandler != null) { - documentHandler.processingInstruction(target, pidata); - } - } - } - - /** SAX DocumentHandler API. */ - public void setDocumentLocator(Locator locator) { - if (documentHandler != null) { - documentHandler.setDocumentLocator(locator); - } - } - - /** SAX DocumentHandler API. */ - public void startDocument() throws SAXException { - if (documentHandler != null) { - documentHandler.startDocument(); - } - } - - /** SAX DocumentHandler API. */ - public void startElement(String name, AttributeList atts) - throws SAXException { - allowXMLCatalogPI = false; - if (documentHandler != null) { - documentHandler.startElement(name,atts); - } - } - - /** SAX DTDHandler API. */ - public void notationDecl (String name, String publicId, String systemId) - throws SAXException { - allowXMLCatalogPI = false; - if (dtdHandler != null) { - dtdHandler.notationDecl(name,publicId,systemId); - } - } - - /** SAX DTDHandler API. */ - public void unparsedEntityDecl (String name, - String publicId, - String systemId, - String notationName) - throws SAXException { - allowXMLCatalogPI = false; - if (dtdHandler != null) { - dtdHandler.unparsedEntityDecl (name, publicId, systemId, notationName); - } - } - - /** - * Implements theresolveEntity
method
- * for the SAX interface, using an underlying CatalogResolver
- * to do the real work.
- */
- public InputSource resolveEntity (String publicId, String systemId) {
- allowXMLCatalogPI = false;
- String resolved = catalogResolver.getResolvedEntity(publicId, systemId);
-
- if (resolved == null && piCatalogResolver != null) {
- resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
- }
-
- if (resolved != null) {
- try {
- InputSource iSource = new InputSource(resolved);
- iSource.setPublicId(publicId);
-
- // Ideally this method would not attempt to open the
- // InputStream, but there is a bug (in Xerces, at least)
- // that causes the parser to mistakenly open the wrong
- // system identifier if the returned InputSource does
- // not have a byteStream.
- //
- // It could be argued that we still shouldn't do this here,
- // but since the purpose of calling the entityResolver is
- // almost certainly to open the input stream, it seems to
- // do little harm.
- //
- URL url = new URL(resolved);
- InputStream iStream = url.openStream();
- iSource.setByteStream(iStream);
-
- return iSource;
- } catch (Exception e) {
- catalogManager.debug.message(1,
- "Failed to create InputSource ("
- + e.toString()
- + ")", resolved);
- return null;
- }
- } else {
- return null;
- }
- }
-
- /** Setup for parsing. */
- private void setupParse(String systemId) {
- allowXMLCatalogPI = true;
- parser.setEntityResolver(this);
- parser.setDocumentHandler(this);
- parser.setDTDHandler(this);
-
- URL cwd = null;
-
- try {
- cwd = FileURL.makeURL("basename");
- } catch (MalformedURLException mue) {
- cwd = null;
- }
-
- try {
- baseURL = new URL(systemId);
- } catch (MalformedURLException mue) {
- if (cwd != null) {
- try {
- baseURL = new URL(cwd, systemId);
- } catch (MalformedURLException mue2) {
- // give up
- baseURL = null;
- }
- } else {
- // give up
- baseURL = null;
- }
- }
- }
-
- /** Provide one possible explanation for an InternalError. */
- private void explain(String systemId) {
- if (!suppressExplanation) {
- System.out.println("Parser probably encountered bad URI in " + systemId);
- System.out.println("For example, replace '/some/uri' with 'file:/some/uri'.");
- }
- }
-}
--- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLFilter.java 2017-06-20 10:53:24.370613466 -0700
+++ /dev/null 2017-06-17 22:58:47.330661897 -0700
@@ -1,346 +0,0 @@
-/*
- * 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.tools;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.Attributes;
-import org.xml.sax.helpers.XMLFilterImpl;
-
-import com.sun.org.apache.xml.internal.resolver.Catalog;
-import com.sun.org.apache.xml.internal.resolver.CatalogManager;
-
-import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
-
-/**
- * A SAX XMLFilter that performs catalog-based entity resolution.
- *
- * This class implements a SAX XMLFilter that performs entity resolution - * using the CatalogResolver. The actual, underlying parser is obtained - * from a SAXParserFactory.
- * - * - * @see CatalogResolver - * @see org.xml.sax.XMLFilter - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - * @version 1.0 - */ -public class ResolvingXMLFilter extends XMLFilterImpl { - /** - * Suppress explanatory message? - * - * @see #parse(InputSource) - */ - private static boolean suppressExplanation = false; - - /** The manager for the underlying resolver. */ - CatalogManager catalogManager = CatalogManager.getStaticManager(); - - /** The underlying catalog resolver. */ - private CatalogResolver catalogResolver = null; - - /** A separate resolver for oasis-xml-pi catalogs. */ - private CatalogResolver piCatalogResolver = null; - - /** Are we in the prolog? Is an oasis-xml-catalog PI valid now? */ - private boolean allowXMLCatalogPI = false; - - /** The base URI of the input document, if known. */ - private URL baseURL = null; - - /** Construct an empty XML Filter with no parent. */ - public ResolvingXMLFilter() { - super(); - catalogResolver = new CatalogResolver(catalogManager); - } - - /** Construct an XML filter with the specified parent. */ - public ResolvingXMLFilter(XMLReader parent) { - super(parent); - catalogResolver = new CatalogResolver(catalogManager); - } - - /** Construct an XML filter with the specified parent. */ - public ResolvingXMLFilter(CatalogManager manager) { - super(); - catalogManager = manager; - catalogResolver = new CatalogResolver(catalogManager); - } - - /** Construct an XML filter with the specified parent. */ - public ResolvingXMLFilter(XMLReader parent, CatalogManager manager) { - super(parent); - catalogManager = manager; - catalogResolver = new CatalogResolver(catalogManager); - } - - /** - * Provide accessto the underlying Catalog. - */ - public Catalog getCatalog() { - return catalogResolver.getCatalog(); - } - - /** - * SAX XMLReader API. - * - *Note that the JAXP 1.1ea2 parser crashes with an InternalError if - * it encounters a system identifier that appears to be a relative URI - * that begins with a slash. For example, the declaration:
- * - *- * <!DOCTYPE book SYSTEM "/path/to/dtd/on/my/system/docbookx.dtd"> - *- * - *
would cause such an error. As a convenience, this method catches - * that error and prints an explanation. (Unfortunately, it's not possible - * to identify the particular system identifier that causes the problem.) - *
- * - *The underlying error is forwarded after printing the explanatory
- * message. The message is only every printed once and if
- * suppressExplanation
is set to false
before
- * parsing, it will never be printed.
resolveEntity
method
- * for the SAX interface, using an underlying CatalogResolver
- * to do the real work.
- */
- public InputSource resolveEntity (String publicId, String systemId) {
- allowXMLCatalogPI = false;
- String resolved = catalogResolver.getResolvedEntity(publicId, systemId);
-
- if (resolved == null && piCatalogResolver != null) {
- resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
- }
-
- if (resolved != null) {
- try {
- InputSource iSource = new InputSource(resolved);
- iSource.setPublicId(publicId);
-
- // Ideally this method would not attempt to open the
- // InputStream, but there is a bug (in Xerces, at least)
- // that causes the parser to mistakenly open the wrong
- // system identifier if the returned InputSource does
- // not have a byteStream.
- //
- // It could be argued that we still shouldn't do this here,
- // but since the purpose of calling the entityResolver is
- // almost certainly to open the input stream, it seems to
- // do little harm.
- //
- URL url = new URL(resolved);
- InputStream iStream = url.openStream();
- iSource.setByteStream(iStream);
-
- return iSource;
- } catch (Exception e) {
- catalogManager.debug.message(1,
- "Failed to create InputSource ("
- + e.toString()
- + ")", resolved);
- return null;
- }
- } else {
- return null;
- }
- }
-
- /** SAX DTDHandler API.
- *
- * Captured here only to detect the end of the prolog so that - * we can ignore subsequent oasis-xml-catalog PIs. Otherwise - * the events are just passed through.
- */ - public void notationDecl (String name, String publicId, String systemId) - throws SAXException { - allowXMLCatalogPI = false; - super.notationDecl(name,publicId,systemId); - } - - /** SAX DTDHandler API. - * - *Captured here only to detect the end of the prolog so that - * we can ignore subsequent oasis-xml-catalog PIs. Otherwise - * the events are just passed through.
- */ - public void unparsedEntityDecl (String name, - String publicId, - String systemId, - String notationName) - throws SAXException { - allowXMLCatalogPI = false; - super.unparsedEntityDecl (name, publicId, systemId, notationName); - } - - /** SAX ContentHandler API. - * - *Captured here only to detect the end of the prolog so that - * we can ignore subsequent oasis-xml-catalog PIs. Otherwise - * the events are just passed through.
- */ - public void startElement (String uri, String localName, String qName, - Attributes atts) - throws SAXException { - allowXMLCatalogPI = false; - super.startElement(uri,localName,qName,atts); - } - - /** SAX ContentHandler API. - * - *Detect and use the oasis-xml-catalog PI if it occurs.
- */ - public void processingInstruction(String target, String pidata) - throws SAXException { - if (target.equals("oasis-xml-catalog")) { - URL catalog = null; - String data = pidata; - - int pos = data.indexOf("catalog="); - if (pos >= 0) { - data = data.substring(pos+8); - if (data.length() > 1) { - String quote = data.substring(0,1); - data = data.substring(1); - pos = data.indexOf(quote); - if (pos >= 0) { - data = data.substring(0, pos); - try { - if (baseURL != null) { - catalog = new URL(baseURL, data); - } else { - catalog = new URL(data); - } - } catch (MalformedURLException mue) { - // nevermind - } - } - } - } - - if (allowXMLCatalogPI) { - if (catalogManager.getAllowOasisXMLCatalogPI()) { - catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata); - - if (catalog != null) { - try { - catalogManager.debug.message(4,"oasis-xml-catalog", catalog.toString()); - - if (piCatalogResolver == null) { - piCatalogResolver = new CatalogResolver(true); - } - - piCatalogResolver.getCatalog().parseCatalog(catalog.toString()); - } catch (Exception e) { - catalogManager.debug.message(3, "Exception parsing oasis-xml-catalog: " - + catalog.toString()); - } - } else { - catalogManager.debug.message(3, "PI oasis-xml-catalog unparseable: " + pidata); - } - } else { - catalogManager.debug.message(4,"PI oasis-xml-catalog ignored: " + pidata); - } - } else { - catalogManager.debug.message(3, "PI oasis-xml-catalog occurred in an invalid place: " - + pidata); - } - } else { - super.processingInstruction(target, pidata); - } - } - - /** Save the base URI of the document being parsed. */ - private void setupBaseURI(String systemId) { - URL cwd = null; - - try { - cwd = FileURL.makeURL("basename"); - } catch (MalformedURLException mue) { - cwd = null; - } - - try { - baseURL = new URL(systemId); - } catch (MalformedURLException mue) { - if (cwd != null) { - try { - baseURL = new URL(cwd, systemId); - } catch (MalformedURLException mue2) { - // give up - baseURL = null; - } - } else { - // give up - baseURL = null; - } - } - } - - /** Provide one possible explanation for an InternalError. */ - private void explain(String systemId) { - if (!suppressExplanation) { - System.out.println("XMLReader probably encountered bad URI in " + systemId); - System.out.println("For example, replace '/some/uri' with 'file:/some/uri'."); - } - suppressExplanation = true; - } -} --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLReader.java 2017-06-20 10:53:24.582624038 -0700 +++ /dev/null 2017-06-17 22:58:47.330661897 -0700 @@ -1,90 +0,0 @@ -/* - * 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.tools; - - -import javax.xml.parsers.*; - -import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl; -import com.sun.org.apache.xml.internal.resolver.*; - -/** - * A SAX XMLReader that performs catalog-based entity resolution. - * - *This class implements a SAX XMLReader that performs entity resolution - * using the CatalogResolver. The actual, underlying parser is obtained - * from a SAXParserFactory.
- * - * - * @see CatalogResolver - * @see org.xml.sax.XMLReader - * - * @author Norman Walsh - * Norman.Walsh@Sun.COM - * - * @version 1.0 - */ -public class ResolvingXMLReader extends ResolvingXMLFilter { - /** Make the parser Namespace aware? */ - private static final boolean namespaceAware = true; - - /** Make the parser validating? */ - private static final boolean validating = false; - - /** - * Construct a new reader from the JAXP factory. - * - *In order to do its job, a ResolvingXMLReader must in fact be - * a filter. So the only difference between this code and the filter - * code is that the constructor builds a new reader.
- */ - public ResolvingXMLReader() { - super(); - SAXParserFactory spf = catalogManager.useServicesMechanism() ? - SAXParserFactory.newInstance() : new SAXParserFactoryImpl(); - spf.setNamespaceAware(namespaceAware); - spf.setValidating(validating); - try { - SAXParser parser = spf.newSAXParser(); - setParent(parser.getXMLReader()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - /** - * Construct a new reader from the JAXP factory. - * - *In order to do its job, a ResolvingXMLReader must in fact be - * a filter. So the only difference between this code and the filter - * code is that the constructor builds a new reader.
- */ - public ResolvingXMLReader(CatalogManager manager) { - super(manager); - SAXParserFactory spf = catalogManager.useServicesMechanism() ? - SAXParserFactory.newInstance() : new SAXParserFactoryImpl(); - spf.setNamespaceAware(namespaceAware); - spf.setValidating(validating); - try { - SAXParser parser = spf.newSAXParser(); - setParent(parser.getXMLReader()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } -}