jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/Catalog.java
author joehw
Wed, 14 Sep 2016 13:18:17 -0700
changeset 41021 444f2b1bcc8c
parent 33351 6e177c9004fd
permissions -rw-r--r--
8165784: Deprecate the internal Catalog API in JDK 9 Reviewed-by: dfuchs, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
     1
/*
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
     2
 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
     3
 */
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
/*
26516
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
     5
 * Licensed to the Apache Software Foundation (ASF) under one or more
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
     6
 * contributor license agreements.  See the NOTICE file distributed with
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
     7
 * this work for additional information regarding copyright ownership.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
     8
 * The ASF licenses this file to You under the Apache License, Version 2.0
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
     9
 * (the "License"); you may not use this file except in compliance with
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    10
 * the License.  You may obtain a copy of the License at
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    11
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    13
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
 * limitations under the License.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.resolver;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    23
import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
    24
import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
26516
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    25
import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    26
import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    27
import com.sun.org.apache.xml.internal.resolver.readers.CatalogReader;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    28
import com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    29
import com.sun.org.apache.xml.internal.resolver.readers.SAXCatalogReader;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    30
import com.sun.org.apache.xml.internal.resolver.readers.TR9401CatalogReader;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    31
import java.io.DataInputStream;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    32
import java.io.FileNotFoundException;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    33
import java.io.IOException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    34
import java.io.InputStream;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    35
import java.io.UnsupportedEncodingException;
26516
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    36
import java.net.MalformedURLException;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    37
import java.net.URL;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    38
import java.util.Enumeration;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
    39
import java.util.HashMap;
26516
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
    40
import java.util.Locale;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
    41
import java.util.Map;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    42
import java.util.Vector;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    43
import javax.xml.parsers.SAXParserFactory;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    45
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    46
 * Represents OASIS Open Catalog files.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    48
 * <p>This class implements the semantics of OASIS Open Catalog files
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    49
 * (defined by
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    50
 * <a href="http://www.oasis-open.org/html/a401.htm">OASIS Technical
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    51
 * Resolution 9401:1997 (Amendment 2 to TR 9401)</a>).</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    52
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    53
 * <p>The primary purpose of the Catalog is to associate resources in the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
 * document with local system identifiers. Some entities
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    55
 * (document types, XML entities, and notations) have names and all of them
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    56
 * can have either public or system identifiers or both. (In XML, only a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    57
 * notation can have a public identifier without a system identifier, but
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    58
 * the methods implemented in this class obey the Catalog semantics
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
 * from the SGML
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
 * days when system identifiers were optional.)</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
 * <p>The system identifiers returned by the resolution methods in this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    63
 * class are valid, i.e. usable by, and in fact constructed by, the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    64
 * <tt>java.net.URL</tt> class. Unfortunately, this class seems to behave in
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
 * somewhat non-standard ways and the system identifiers returned may
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
 * not be directly usable in a browser or filesystem context.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
 * <p>This class recognizes all of the Catalog entries defined in
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
 * TR9401:1997:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
 * <ul>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
 * <li><b>BASE</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    73
 * changes the base URI for resolving relative system identifiers. The
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
 * initial base URI is the URI of the location of the catalog (which is,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
 * in turn, relative to the location of the current working directory
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
 * at startup, as returned by the <tt>user.dir</tt> system property).</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
 * <li><b>CATALOG</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
 * processes other catalog files. An included catalog occurs logically
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
 * at the end of the including catalog.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
 * <li><b>DELEGATE_PUBLIC</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
 * specifies alternate catalogs for some public identifiers. The delegated
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
 * catalogs are not loaded until they are needed, but they are cached
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
 * once loaded.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
 * <li><b>DELEGATE_SYSTEM</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
 * specifies alternate catalogs for some system identifiers. The delegated
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
 * catalogs are not loaded until they are needed, but they are cached
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
 * once loaded.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
 * <li><b>DELEGATE_URI</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    89
 * specifies alternate catalogs for some URIs. The delegated
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    90
 * catalogs are not loaded until they are needed, but they are cached
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    91
 * once loaded.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    92
 * <li><b>REWRITE_SYSTEM</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
 * specifies alternate prefix for a system identifier.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
 * <li><b>REWRITE_URI</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
 * specifies alternate prefix for a URI.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
 * <li><b>SYSTEM_SUFFIX</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    97
 * maps any system identifier that ends with a particular suffix to another
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    98
 * system identifier.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    99
 * <li><b>URI_SUFFIX</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
 * maps any URI that ends with a particular suffix to another URI.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   101
 * <li><b>DOCTYPE</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   102
 * associates the names of root elements with URIs. (In other words, an XML
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
 * processor might infer the doctype of an XML document that does not include
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   104
 * a doctype declaration by looking for the DOCTYPE entry in the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
 * catalog which matches the name of the root element of the document.)</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   106
 * <li><b>DOCUMENT</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   107
 * provides a default document.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   108
 * <li><b>DTDDECL</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   109
 * recognized and silently ignored. Not relevant for XML.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   110
 * <li><b>ENTITY</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   111
 * associates entity names with URIs.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   112
 * <li><b>LINKTYPE</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   113
 * recognized and silently ignored. Not relevant for XML.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   114
 * <li><b>NOTATION</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   115
 * associates notation names with URIs.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
 * <li><b>OVERRIDE</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
 * changes the override behavior. Initial behavior is set by the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   118
 * system property <tt>xml.catalog.override</tt>. The default initial
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   119
 * behavior is 'YES', that is, entries in the catalog override
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   120
 * system identifiers specified in the document.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   121
 * <li><b>PUBLIC</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   122
 * maps a public identifier to a system identifier.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   123
 * <li><b>SGMLDECL</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
 * recognized and silently ignored. Not relevant for XML.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
 * <li><b>SYSTEM</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   126
 * maps a system identifier to another system identifier.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   127
 * <li><b>URI</b>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   128
 * maps a URI to another URI.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   129
 * </ul>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
 * <p>Note that BASE entries are treated as described by RFC2396. In
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
 * particular, this has the counter-intuitive property that after a BASE
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
 * entry identifing "http://example.com/a/b/c" as the base URI,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   134
 * the relative URI "foo" is resolved to the absolute URI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   135
 * "http://example.com/a/b/foo". You must provide the trailing slash if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   136
 * you do not want the final component of the path to be discarded as a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   137
 * filename would in a URI for a resource: "http://example.com/a/b/c/".
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   138
 * </p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   139
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   140
 * <p>Note that subordinate catalogs (all catalogs except the first,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   141
 * including CATALOG and DELEGATE* catalogs) are only loaded if and when
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   142
 * they are required.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   143
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   144
 * <p>This class relies on classes which implement the CatalogReader
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   145
 * interface to actually load catalog files. This allows the catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   146
 * semantics to be implemented for TR9401 text-based catalogs, XML
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   147
 * catalogs, or any number of other storage formats.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   148
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   149
 * <p>Additional catalogs may also be loaded with the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   150
 * {@link #parseCatalog} method.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   151
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   152
 * <p><b>Change Log:</b></p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   153
 * <dl>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   154
 * <dt>2.0</dt>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   155
 * <dd><p>Rewrite to use CatalogReaders.</p></dd>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
 * <dt>1.1</dt>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   157
 * <dd><p>Allow quoted components in <tt>xml.catalog.files</tt>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   158
 * so that URLs containing colons can be used on Unix.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   159
 * The string passed to <tt>xml.catalog.files</tt> can now have the form:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   160
 * <pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   161
 * unquoted-path-with-no-sep-chars:"double-quoted path with or without sep chars":'single-quoted path with or without sep chars'
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   162
 * </pre>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   163
 * <p>(Where ":" is the separater character in this example.)</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   164
 * <p>If an unquoted path contains an embedded double or single quote
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   165
 * character, no special processig is performed on that character. No
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   166
 * path can contain separater characters, double, and single quotes
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   167
 * simultaneously.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   168
 * <p>Fix bug in calculation of BASE entries: if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   169
 * a catalog contains multiple BASE entries, each is relative to the preceding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   170
 * base, not the default base URI of the catalog.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   171
 * </dd>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   172
 * <dt>1.0.1</dt>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   173
 * <dd><p>Fixed a bug in the calculation of the list of subordinate catalogs.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   174
 * This bug caused an infinite loop where parsing would alternately process
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
 * two catalogs indefinitely.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
 * </dd>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
 * </dl>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   179
 * @see CatalogReader
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   180
 * @see CatalogEntry
41021
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   181
 * @deprecated The JDK internal Catalog API in package
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   182
 * {@code com.sun.org.apache.xml.internal.resolver}
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   183
 * is encapsulated in JDK 9. The entire implementation under the package is now
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   184
 * deprecated and subject to removal in a future release. Users of the API
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   185
 * should migrate to the {@linkplain javax.xml.catalog new public API}.
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   186
 * <p>
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   187
 * The new Catalog API is supported throughout the JDK XML Processors, which allows
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   188
 * the use of Catalog by simply setting a path to a Catalog file as a property.
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   189
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   190
 * @author Norman Walsh
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   191
 * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   192
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   193
 * @version 1.0
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   195
 * <p>Derived from public domain code originally published by Arbortext,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   196
 * Inc.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   197
 */
41021
444f2b1bcc8c 8165784: Deprecate the internal Catalog API in JDK 9
joehw
parents: 33351
diff changeset
   198
@Deprecated(since="9", forRemoval=true)
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
public class Catalog {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
  /** The BASE Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   201
  public static final int BASE     = CatalogEntry.addEntryType("BASE", 1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   202
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   203
  /** The CATALOG Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   204
  public static final int CATALOG  = CatalogEntry.addEntryType("CATALOG", 1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   206
  /** The DOCUMENT Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   207
  public static final int DOCUMENT = CatalogEntry.addEntryType("DOCUMENT", 1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   208
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   209
  /** The OVERRIDE Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   210
  public static final int OVERRIDE = CatalogEntry.addEntryType("OVERRIDE", 1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   211
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   212
  /** The SGMLDECL Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   213
  public static final int SGMLDECL = CatalogEntry.addEntryType("SGMLDECL", 1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   214
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
  /** The DELEGATE_PUBLIC Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   216
  public static final int DELEGATE_PUBLIC = CatalogEntry.addEntryType("DELEGATE_PUBLIC", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   217
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   218
  /** The DELEGATE_SYSTEM Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   219
  public static final int DELEGATE_SYSTEM = CatalogEntry.addEntryType("DELEGATE_SYSTEM", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   220
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
  /** The DELEGATE_URI Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   222
  public static final int DELEGATE_URI = CatalogEntry.addEntryType("DELEGATE_URI", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   223
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   224
  /** The DOCTYPE Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   225
  public static final int DOCTYPE  = CatalogEntry.addEntryType("DOCTYPE", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   226
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   227
  /** The DTDDECL Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   228
  public static final int DTDDECL  = CatalogEntry.addEntryType("DTDDECL", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   229
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   230
  /** The ENTITY Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   231
  public static final int ENTITY   = CatalogEntry.addEntryType("ENTITY", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   232
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   233
  /** The LINKTYPE Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   234
  public static final int LINKTYPE = CatalogEntry.addEntryType("LINKTYPE", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
  /** The NOTATION Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   237
  public static final int NOTATION = CatalogEntry.addEntryType("NOTATION", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   238
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   239
  /** The PUBLIC Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   240
  public static final int PUBLIC   = CatalogEntry.addEntryType("PUBLIC", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   241
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   242
  /** The SYSTEM Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   243
  public static final int SYSTEM   = CatalogEntry.addEntryType("SYSTEM", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   244
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   245
  /** The URI Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   246
  public static final int URI      = CatalogEntry.addEntryType("URI", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   247
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   248
  /** The REWRITE_SYSTEM Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   249
  public static final int REWRITE_SYSTEM = CatalogEntry.addEntryType("REWRITE_SYSTEM", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   250
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   251
  /** The REWRITE_URI Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   252
  public static final int REWRITE_URI = CatalogEntry.addEntryType("REWRITE_URI", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   253
  /** The SYSTEM_SUFFIX Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   254
  public static final int SYSTEM_SUFFIX = CatalogEntry.addEntryType("SYSTEM_SUFFIX", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   255
  /** The URI_SUFFIX Catalog Entry type. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   256
  public static final int URI_SUFFIX = CatalogEntry.addEntryType("URI_SUFFIX", 2);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   257
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   258
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   259
   * The base URI for relative system identifiers in the catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   260
   * This may be changed by BASE entries in the catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   261
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   262
  protected URL base;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   263
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   264
  /** The base URI of the Catalog file currently being parsed. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   265
  protected URL catalogCwd;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   266
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   267
  /** The catalog entries currently known to the system. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   268
  protected Vector catalogEntries = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   269
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   270
  /** The default initial override setting. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   271
  protected boolean default_override = true;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   272
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   273
  /** The catalog manager in use for this instance. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   274
  protected CatalogManager catalogManager = CatalogManager.getStaticManager();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   275
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   276
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   277
   * A vector of catalog files to be loaded.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   278
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   279
   * <p>This list is initially established by
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   280
   * <code>loadSystemCatalogs</code> when
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   281
   * it parses the system catalog list, but CATALOG entries may
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   282
   * contribute to it during the course of parsing.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   283
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   284
   * @see #loadSystemCatalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   285
   * @see #localCatalogFiles
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   286
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
  protected Vector catalogFiles = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   288
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   289
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   290
   * A vector of catalog files constructed during processing of
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   291
   * CATALOG entries in the current catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   292
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   293
   * <p>This two-level system is actually necessary to correctly implement
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   294
   * the semantics of the CATALOG entry. If one catalog file includes
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   295
   * another with a CATALOG entry, the included catalog logically
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   296
   * occurs <i>at the end</i> of the including catalog, and after any
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   297
   * preceding CATALOG entries. In other words, the CATALOG entry
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   298
   * cannot insert anything into the middle of a catalog file.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   299
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   300
   * <p>When processing reaches the end of each catalog files, any
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   301
   * elements on this vector are added to the front of the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   302
   * <code>catalogFiles</code> vector.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   303
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   304
   * @see #catalogFiles
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   305
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   306
  protected Vector localCatalogFiles = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   307
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   308
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   309
   * A vector of Catalogs.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   310
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   311
   * <p>The semantics of Catalog resolution are such that each
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   312
   * catalog is effectively a list of Catalogs (in other words,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   313
   * a recursive list of Catalog instances).</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   314
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   315
   * <p>Catalogs that are processed as the result of CATALOG or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   316
   * DELEGATE* entries are subordinate to the catalog that contained
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   317
   * them, but they may in turn have subordinate catalogs.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   318
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   319
   * <p>Catalogs are only loaded when they are needed, so this vector
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   320
   * initially contains a list of Catalog filenames (URLs). If, during
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   321
   * processing, one of these catalogs has to be loaded, the resulting
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   322
   * Catalog object is placed in the vector, effectively caching it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   323
   * for the next query.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   324
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   325
  protected Vector catalogs = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   326
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   327
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   328
   * A vector of DELEGATE* Catalog entries constructed during
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   329
   * processing of the Catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   330
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   331
   * <p>This two-level system has two purposes; first, it allows
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   332
   * us to sort the DELEGATE* entries by the length of the partial
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   333
   * public identifier so that a linear search encounters them in
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   334
   * the correct order and second, it puts them all at the end of
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   335
   * the Catalog.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   336
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   337
   * <p>When processing reaches the end of each catalog file, any
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   338
   * elements on this vector are added to the end of the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   339
   * <code>catalogEntries</code> vector. This assures that matching
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   340
   * PUBLIC keywords are encountered before DELEGATE* entries.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   341
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   342
  protected Vector localDelegate = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   343
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   344
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   345
   * A hash of CatalogReaders.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   346
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   347
   * <p>This hash maps MIME types to elements in the readerArr
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   348
   * vector. This allows the Catalog to quickly locate the reader
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   349
   * for a particular MIME type.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   350
   */
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
   351
  protected Map<String, Integer> readerMap = new HashMap<>();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   352
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   353
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   354
   * A vector of CatalogReaders.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   355
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   356
   * <p>This vector contains all of the readers in the order that they
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   357
   * were added. In the event that a catalog is read from a file, where
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   358
   * the MIME type is unknown, each reader is attempted in turn until
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   359
   * one succeeds.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   360
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   361
  protected Vector readerArr = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   362
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   363
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   364
   * Constructs an empty Catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   365
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   366
   * <p>The constructor interrogates the relevant system properties
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   367
   * using the default (static) CatalogManager
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   368
   * and initializes the catalog data structures.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   369
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   370
  public Catalog() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   371
    // nop;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   372
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   373
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   374
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   375
   * Constructs an empty Catalog with a specific CatalogManager.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   376
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   377
   * <p>The constructor interrogates the relevant system properties
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   378
   * using the specified Catalog Manager
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   379
   * and initializes the catalog data structures.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   380
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   381
  public Catalog(CatalogManager manager) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   382
    catalogManager = manager;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   383
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   384
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   385
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   386
   * Return the CatalogManager used by this catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   387
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   388
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   389
  public CatalogManager getCatalogManager() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   390
    return catalogManager;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   391
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   392
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   393
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   394
   * Establish the CatalogManager used by this catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   395
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   396
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   397
  public void setCatalogManager(CatalogManager manager) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   398
    catalogManager = manager;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   399
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   400
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   401
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   402
   * Setup readers.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   403
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   404
  public void setupReaders() {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   405
    SAXParserFactory spf = catalogManager.useServicesMechanism() ?
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   406
                    SAXParserFactory.newInstance() : new SAXParserFactoryImpl();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   407
    spf.setNamespaceAware(true);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   408
    spf.setValidating(false);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   409
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   410
    SAXCatalogReader saxReader = new SAXCatalogReader(spf);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   411
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   412
    saxReader.setCatalogParser(null, "XMLCatalog",
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   413
                               "com.sun.org.apache.xml.internal.resolver.readers.XCatalogReader");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   414
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   415
    saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   416
                               "catalog",
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   417
                               "com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   418
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   419
    addReader("application/xml", saxReader);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   420
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   421
    TR9401CatalogReader textReader = new TR9401CatalogReader();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   422
    addReader("text/plain", textReader);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   423
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   424
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   425
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   426
   * Add a new CatalogReader to the Catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   427
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   428
   * <p>This method allows you to add a new CatalogReader to the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   429
   * catalog. The reader will be associated with the specified mimeType.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   430
   * You can only have one reader per mimeType.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   431
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   432
   * <p>In the absence of a mimeType (e.g., when reading a catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   433
   * directly from a file on the local system), the readers are attempted
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   434
   * in the order that you add them to the Catalog.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   435
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   436
   * <p>Note that subordinate catalogs (created by CATALOG or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   437
   * DELEGATE* entries) get a copy of the set of readers present in
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   438
   * the primary catalog when they are created. Readers added subsequently
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   439
   * will not be available. For this reason, it is best to add all
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   440
   * of the readers before the first call to parse a catalog.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   441
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   442
   * @param mimeType The MIME type associated with this reader.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   443
   * @param reader The CatalogReader to use.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   444
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   445
  public void addReader(String mimeType, CatalogReader reader) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   446
    if (readerMap.containsKey(mimeType)) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
   447
      Integer pos = readerMap.get(mimeType);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
   448
      readerArr.set(pos, reader);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   449
    } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   450
      readerArr.add(reader);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
   451
      Integer pos = readerArr.size()-1;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   452
      readerMap.put(mimeType, pos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   453
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   454
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   455
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   456
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   457
   * Copies the reader list from the current Catalog to a new Catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   458
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   459
   * <p>This method is used internally when constructing a new catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   460
   * It copies the current reader associations over to the new catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   461
   * </p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   462
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   463
   * @param newCatalog The new Catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   464
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   465
  protected void copyReaders(Catalog newCatalog) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   466
    // Have to copy the readers in the right order...convert hash to arr
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   467
    Vector mapArr = new Vector(readerMap.size());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   468
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   469
    // Pad the mapArr out to the right length
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   470
    for (int count = 0; count < readerMap.size(); count++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   471
      mapArr.add(null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   472
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   473
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
   474
    for (Map.Entry<String, Integer> entry : readerMap.entrySet()) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
   475
        mapArr.set(entry.getValue().intValue(), entry.getKey());
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   476
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   477
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   478
    for (int count = 0; count < mapArr.size(); count++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   479
      String mimeType = (String) mapArr.get(count);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 26516
diff changeset
   480
      Integer pos = readerMap.get(mimeType);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   481
      newCatalog.addReader(mimeType,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   482
                           (CatalogReader)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   483
                           readerArr.get(pos.intValue()));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   484
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   485
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   486
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   487
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   488
   * Create a new Catalog object.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   489
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   490
   * <p>This method constructs a new instance of the running Catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   491
   * class (which might be a subtype of com.sun.org.apache.xml.internal.resolver.Catalog).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   492
   * All new catalogs are managed by the same CatalogManager.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   493
   * </p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   494
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   495
   * <p>N.B. All Catalog subtypes should call newCatalog() to construct
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   496
   * a new Catalog. Do not simply use "new Subclass()" since that will
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   497
   * confuse future subclasses.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   498
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   499
  protected Catalog newCatalog() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   500
    String catalogClass = this.getClass().getName();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   501
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   502
    try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   503
      Catalog c = (Catalog) (Class.forName(catalogClass).newInstance());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   504
      c.setCatalogManager(catalogManager);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   505
      copyReaders(c);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   506
      return c;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   507
    } catch (ClassNotFoundException cnfe) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   508
      catalogManager.debug.message(1, "Class Not Found Exception: " + catalogClass);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   509
    } catch (IllegalAccessException iae) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   510
      catalogManager.debug.message(1, "Illegal Access Exception: " + catalogClass);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   511
    } catch (InstantiationException ie) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   512
      catalogManager.debug.message(1, "Instantiation Exception: " + catalogClass);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   513
    } catch (ClassCastException cce) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   514
      catalogManager.debug.message(1, "Class Cast Exception: " + catalogClass);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   515
    } catch (Exception e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   516
      catalogManager.debug.message(1, "Other Exception: " + catalogClass);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   517
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   518
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   519
    Catalog c = new Catalog();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   520
    c.setCatalogManager(catalogManager);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   521
    copyReaders(c);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   522
    return c;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   523
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   524
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   525
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   526
   * Returns the current base URI.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   527
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   528
  public String getCurrentBase() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   529
    return base.toString();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   530
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   531
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   532
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   533
   * Returns the default override setting associated with this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   534
   * catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   535
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   536
   * <p>All catalog files loaded by this catalog will have the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   537
   * initial override setting specified by this default.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   538
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   539
  public String getDefaultOverride() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   540
    if (default_override) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   541
      return "yes";
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   542
    } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   543
      return "no";
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   544
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   545
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   546
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   547
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   548
   * Load the system catalog files.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   549
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   550
   * <p>The method adds all of the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   551
   * catalogs specified in the <tt>xml.catalog.files</tt> property
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   552
   * to the Catalog list.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   553
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   554
   * @throws MalformedURLException  One of the system catalogs is
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   555
   * identified with a filename that is not a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   556
   * @throws IOException One of the system catalogs cannot be read.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   557
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   558
  public void loadSystemCatalogs()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   559
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   560
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   561
    Vector catalogs = catalogManager.getCatalogFiles();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   562
    if (catalogs != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   563
      for (int count = 0; count < catalogs.size(); count++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   564
        catalogFiles.addElement(catalogs.elementAt(count));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   565
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   566
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   567
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   568
    if (catalogFiles.size() > 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   569
      // This is a little odd. The parseCatalog() method expects
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   570
      // a filename, but it adds that name to the end of the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   571
      // catalogFiles vector, and then processes that vector.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   572
      // This allows the system to handle CATALOG entries
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   573
      // correctly.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   574
      //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   575
      // In this init case, we take the last element off the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   576
      // catalogFiles vector and pass it to parseCatalog. This
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   577
      // will "do the right thing" in the init case, and allow
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   578
      // parseCatalog() to do the right thing in the non-init
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   579
      // case. Honest.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   580
      //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   581
      String catfile = (String) catalogFiles.lastElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   582
      catalogFiles.removeElement(catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   583
      parseCatalog(catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   584
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   585
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   586
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   587
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   588
   * Parse a catalog file, augmenting internal data structures.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   589
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   590
   * @param fileName The filename of the catalog file to process
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   591
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   592
   * @throws MalformedURLException The fileName cannot be turned into
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   593
   * a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   594
   * @throws IOException Error reading catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   595
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   596
  public synchronized void parseCatalog(String fileName)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   597
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   598
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   599
    default_override = catalogManager.getPreferPublic();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   600
    catalogManager.debug.message(4, "Parse catalog: " + fileName);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   601
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   602
    // Put the file into the list of catalogs to process...
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   603
    // In all cases except the case when initCatalog() is the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   604
    // caller, this will be the only catalog initially in the list...
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   605
    catalogFiles.addElement(fileName);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   606
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   607
    // Now process all the pending catalogs...
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   608
    parsePendingCatalogs();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   609
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   610
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   611
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   612
   * Parse a catalog file, augmenting internal data structures.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   613
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   614
   * <p>Catalogs retrieved over the net may have an associated MIME type.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   615
   * The MIME type can be used to select an appropriate reader.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   616
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   617
   * @param mimeType The MIME type of the catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   618
   * @param is The InputStream from which the catalog should be read
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   619
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   620
   * @throws CatalogException Failed to load catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   621
   * mimeType.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   622
   * @throws IOException Error reading catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   623
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   624
  public synchronized void parseCatalog(String mimeType, InputStream is)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   625
    throws IOException, CatalogException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   626
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   627
    default_override = catalogManager.getPreferPublic();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   628
    catalogManager.debug.message(4, "Parse " + mimeType + " catalog on input stream");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   629
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   630
    CatalogReader reader = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   631
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   632
    if (readerMap.containsKey(mimeType)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   633
      int arrayPos = ((Integer) readerMap.get(mimeType)).intValue();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   634
      reader = (CatalogReader) readerArr.get(arrayPos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   635
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   636
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   637
    if (reader == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   638
      String msg = "No CatalogReader for MIME type: " + mimeType;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   639
      catalogManager.debug.message(2, msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   640
      throw new CatalogException(CatalogException.UNPARSEABLE, msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   641
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   642
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   643
    reader.readCatalog(this, is);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   644
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   645
    // Now process all the pending catalogs...
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   646
    parsePendingCatalogs();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   647
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   648
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   649
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   650
   * Parse a catalog document, augmenting internal data structures.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   651
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   652
   * <p>This method supports catalog files stored in jar files: e.g.,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   653
   * jar:file:///path/to/filename.jar!/path/to/catalog.xml". That URI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   654
   * doesn't survive transmogrification through the URI processing that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   655
   * the parseCatalog(String) performs and passing it as an input stream
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   656
   * doesn't set the base URI appropriately.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   657
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   658
   * <p>Written by Stefan Wachter (2002-09-26)</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   659
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   660
   * @param aUrl The URL of the catalog document to process
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   661
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   662
   * @throws IOException Error reading catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   663
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   664
  public synchronized void parseCatalog(URL aUrl) throws IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   665
    catalogCwd = aUrl;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   666
    base = aUrl;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   667
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   668
    default_override = catalogManager.getPreferPublic();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   669
    catalogManager.debug.message(4, "Parse catalog: " + aUrl.toString());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   670
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   671
    DataInputStream inStream = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   672
    boolean parsed = false;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   673
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   674
    for (int count = 0; !parsed && count < readerArr.size(); count++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   675
      CatalogReader reader = (CatalogReader) readerArr.get(count);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   676
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   677
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   678
        inStream = new DataInputStream(aUrl.openStream());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   679
      } catch (FileNotFoundException fnfe) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   680
        // No catalog; give up!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   681
        break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   682
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   683
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   684
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   685
        reader.readCatalog(this, inStream);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   686
        parsed=true;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   687
      } catch (CatalogException ce) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   688
        if (ce.getExceptionType() == CatalogException.PARSE_FAILED) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   689
          // give up!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   690
          break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   691
        } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   692
          // try again!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   693
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   694
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   695
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   696
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   697
        inStream.close();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   698
      } catch (IOException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   699
        //nop
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   700
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   701
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   702
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   703
    if (parsed) parsePendingCatalogs();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   704
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   705
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   706
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   707
   * Parse all of the pending catalogs.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   708
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   709
   * <p>Catalogs may refer to other catalogs, this method parses
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   710
   * all of the currently pending catalog files.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   711
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   712
  protected synchronized void parsePendingCatalogs()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   713
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   714
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   715
    if (!localCatalogFiles.isEmpty()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   716
      // Move all the localCatalogFiles into the front of
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   717
      // the catalogFiles queue
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   718
      Vector newQueue = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   719
      Enumeration q = localCatalogFiles.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   720
      while (q.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   721
        newQueue.addElement(q.nextElement());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   722
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   723
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   724
      // Put the rest of the catalogs on the end of the new list
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   725
      for (int curCat = 0; curCat < catalogFiles.size(); curCat++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   726
        String catfile = (String) catalogFiles.elementAt(curCat);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   727
        newQueue.addElement(catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   728
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   729
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   730
      catalogFiles = newQueue;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   731
      localCatalogFiles.clear();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   732
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   733
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   734
    // Suppose there are no catalog files to process, but the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   735
    // single catalog already parsed included some delegate
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   736
    // entries? Make sure they don't get lost.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   737
    if (catalogFiles.isEmpty() && !localDelegate.isEmpty()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   738
      Enumeration e = localDelegate.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   739
      while (e.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   740
        catalogEntries.addElement(e.nextElement());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   741
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   742
      localDelegate.clear();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   743
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   744
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   745
    // Now process all the files on the catalogFiles vector. This
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   746
    // vector can grow during processing if CATALOG entries are
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   747
    // encountered in the catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   748
    while (!catalogFiles.isEmpty()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   749
      String catfile = (String) catalogFiles.elementAt(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   750
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   751
        catalogFiles.remove(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   752
      } catch (ArrayIndexOutOfBoundsException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   753
        // can't happen
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   754
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   755
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   756
      if (catalogEntries.size() == 0 && catalogs.size() == 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   757
        // We haven't parsed any catalogs yet, let this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   758
        // catalog be the first...
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   759
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   760
          parseCatalogFile(catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   761
        } catch (CatalogException ce) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   762
          System.out.println("FIXME: " + ce.toString());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   763
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   764
      } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   765
        // This is a subordinate catalog. We save its name,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   766
        // but don't bother to load it unless it's necessary.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   767
        catalogs.addElement(catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   768
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   769
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   770
      if (!localCatalogFiles.isEmpty()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   771
        // Move all the localCatalogFiles into the front of
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   772
        // the catalogFiles queue
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   773
        Vector newQueue = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   774
        Enumeration q = localCatalogFiles.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   775
        while (q.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   776
          newQueue.addElement(q.nextElement());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   777
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   778
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   779
        // Put the rest of the catalogs on the end of the new list
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   780
        for (int curCat = 0; curCat < catalogFiles.size(); curCat++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   781
          catfile = (String) catalogFiles.elementAt(curCat);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   782
          newQueue.addElement(catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   783
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   784
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   785
        catalogFiles = newQueue;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   786
        localCatalogFiles.clear();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   787
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   788
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   789
      if (!localDelegate.isEmpty()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   790
        Enumeration e = localDelegate.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   791
        while (e.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   792
          catalogEntries.addElement(e.nextElement());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   793
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   794
        localDelegate.clear();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   795
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   796
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   797
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   798
    // We've parsed them all, reinit the vector...
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   799
    catalogFiles.clear();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   800
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   801
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   802
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   803
   * Parse a single catalog file, augmenting internal data structures.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   804
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   805
   * @param fileName The filename of the catalog file to process
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   806
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   807
   * @throws MalformedURLException The fileName cannot be turned into
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   808
   * a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   809
   * @throws IOException Error reading catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   810
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   811
  protected synchronized void parseCatalogFile(String fileName)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   812
    throws MalformedURLException, IOException, CatalogException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   813
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   814
    CatalogEntry entry;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   815
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   816
    // The base-base is the cwd. If the catalog file is specified
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   817
    // with a relative path, this assures that it gets resolved
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   818
    // properly...
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   819
    try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   820
      // tack on a basename because URLs point to files not dirs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   821
      catalogCwd = FileURL.makeURL("basename");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   822
    } catch (MalformedURLException e) {
33351
6e177c9004fd 8078427: More supportive home environment
joehw
parents: 33349
diff changeset
   823
      catalogManager.debug.message(1, "Malformed URL on cwd", "user.dir");
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   824
      catalogCwd = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   825
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   826
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   827
    // The initial base URI is the location of the catalog file
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   828
    try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   829
      base = new URL(catalogCwd, fixSlashes(fileName));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   830
    } catch (MalformedURLException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   831
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   832
        base = new URL("file:" + fixSlashes(fileName));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   833
      } catch (MalformedURLException e2) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   834
        catalogManager.debug.message(1, "Malformed URL on catalog filename",
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   835
                      fixSlashes(fileName));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   836
        base = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   837
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   838
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   839
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   840
    catalogManager.debug.message(2, "Loading catalog", fileName);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   841
    catalogManager.debug.message(4, "Default BASE", base.toString());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   842
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   843
    fileName = base.toString();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   844
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   845
    DataInputStream inStream = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   846
    boolean parsed = false;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   847
    boolean notFound = false;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   848
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   849
    for (int count = 0; !parsed && count < readerArr.size(); count++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   850
      CatalogReader reader = (CatalogReader) readerArr.get(count);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   851
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   852
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   853
        notFound = false;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   854
        inStream = new DataInputStream(base.openStream());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   855
      } catch (FileNotFoundException fnfe) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   856
        // No catalog; give up!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   857
        notFound = true;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   858
        break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   859
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   860
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   861
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   862
        reader.readCatalog(this, inStream);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   863
        parsed = true;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   864
      } catch (CatalogException ce) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   865
        if (ce.getExceptionType() == CatalogException.PARSE_FAILED) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   866
          // give up!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   867
          break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   868
        } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   869
          // try again!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   870
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   871
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   872
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   873
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   874
        inStream.close();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   875
      } catch (IOException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   876
        //nop
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   877
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   878
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   879
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   880
    if (!parsed) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   881
      if (notFound) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   882
        catalogManager.debug.message(3, "Catalog does not exist", fileName);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   883
      } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   884
        catalogManager.debug.message(1, "Failed to parse catalog", fileName);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   885
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   886
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   887
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   888
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   889
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   890
   * Cleanup and process a Catalog entry.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   891
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   892
   * <p>This method processes each Catalog entry, changing mapped
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   893
   * relative system identifiers into absolute ones (based on the current
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   894
   * base URI), and maintaining other information about the current
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   895
   * catalog.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   896
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   897
   * @param entry The CatalogEntry to process.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   898
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   899
  public void addEntry(CatalogEntry entry) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   900
    int type = entry.getEntryType();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   901
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   902
    if (type == BASE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   903
      String value = entry.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   904
      URL newbase = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   905
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   906
      if (base == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   907
        catalogManager.debug.message(5, "BASE CUR", "null");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   908
      } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   909
        catalogManager.debug.message(5, "BASE CUR", base.toString());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   910
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   911
      catalogManager.debug.message(4, "BASE STR", value);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   912
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   913
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   914
        value = fixSlashes(value);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   915
        newbase = new URL(base, value);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   916
      } catch (MalformedURLException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   917
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   918
          newbase = new URL("file:" + value);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   919
        } catch (MalformedURLException e2) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   920
          catalogManager.debug.message(1, "Malformed URL on base", value);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   921
          newbase = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   922
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   923
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   924
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   925
      if (newbase != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   926
        base = newbase;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   927
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   928
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   929
      catalogManager.debug.message(5, "BASE NEW", base.toString());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   930
    } else if (type == CATALOG) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   931
      String fsi = makeAbsolute(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   932
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   933
      catalogManager.debug.message(4, "CATALOG", fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   934
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   935
      localCatalogFiles.addElement(fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   936
    } else if (type == PUBLIC) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   937
      String publicid = PublicId.normalize(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   938
      String systemid = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   939
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   940
      entry.setEntryArg(0, publicid);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   941
      entry.setEntryArg(1, systemid);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   942
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   943
      catalogManager.debug.message(4, "PUBLIC", publicid, systemid);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   944
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   945
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   946
    } else if (type == SYSTEM) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   947
      String systemid = normalizeURI(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   948
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   949
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   950
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   951
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   952
      catalogManager.debug.message(4, "SYSTEM", systemid, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   953
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   954
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   955
    } else if (type == URI) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   956
      String uri = normalizeURI(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   957
      String altURI = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   958
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   959
      entry.setEntryArg(1, altURI);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   960
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   961
      catalogManager.debug.message(4, "URI", uri, altURI);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   962
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   963
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   964
    } else if (type == DOCUMENT) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   965
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(0)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   966
      entry.setEntryArg(0, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   967
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   968
      catalogManager.debug.message(4, "DOCUMENT", fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   969
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   970
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   971
    } else if (type == OVERRIDE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   972
      catalogManager.debug.message(4, "OVERRIDE", entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   973
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   974
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   975
    } else if (type == SGMLDECL) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   976
      // meaningless in XML
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   977
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(0)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   978
      entry.setEntryArg(0, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   979
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   980
      catalogManager.debug.message(4, "SGMLDECL", fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   981
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   982
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   983
    } else if (type == DELEGATE_PUBLIC) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   984
      String ppi = PublicId.normalize(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   985
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   986
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   987
      entry.setEntryArg(0, ppi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   988
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   989
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   990
      catalogManager.debug.message(4, "DELEGATE_PUBLIC", ppi, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   991
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   992
      addDelegate(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   993
    } else if (type == DELEGATE_SYSTEM) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   994
      String psi = normalizeURI(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   995
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   996
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   997
      entry.setEntryArg(0, psi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   998
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   999
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1000
      catalogManager.debug.message(4, "DELEGATE_SYSTEM", psi, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1001
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1002
      addDelegate(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1003
    } else if (type == DELEGATE_URI) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1004
      String pui = normalizeURI(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1005
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1006
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1007
      entry.setEntryArg(0, pui);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1008
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1009
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1010
      catalogManager.debug.message(4, "DELEGATE_URI", pui, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1011
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1012
      addDelegate(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1013
    } else if (type == REWRITE_SYSTEM) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1014
      String psi = normalizeURI(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1015
      String rpx = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1016
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1017
      entry.setEntryArg(0, psi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1018
      entry.setEntryArg(1, rpx);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1019
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1020
      catalogManager.debug.message(4, "REWRITE_SYSTEM", psi, rpx);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1021
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1022
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1023
    } else if (type == REWRITE_URI) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1024
      String pui = normalizeURI(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1025
      String upx = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1026
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1027
      entry.setEntryArg(0, pui);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1028
      entry.setEntryArg(1, upx);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1029
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1030
      catalogManager.debug.message(4, "REWRITE_URI", pui, upx);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1031
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1032
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1033
    } else if (type == SYSTEM_SUFFIX) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1034
      String pui = normalizeURI(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1035
      String upx = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1036
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1037
      entry.setEntryArg(0, pui);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1038
      entry.setEntryArg(1, upx);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1039
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1040
      catalogManager.debug.message(4, "SYSTEM_SUFFIX", pui, upx);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1041
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1042
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1043
    } else if (type == URI_SUFFIX) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1044
      String pui = normalizeURI(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1045
      String upx = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1046
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1047
      entry.setEntryArg(0, pui);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1048
      entry.setEntryArg(1, upx);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1049
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1050
      catalogManager.debug.message(4, "URI_SUFFIX", pui, upx);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1051
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1052
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1053
    } else if (type == DOCTYPE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1054
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1055
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1056
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1057
      catalogManager.debug.message(4, "DOCTYPE", entry.getEntryArg(0), fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1058
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1059
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1060
    } else if (type == DTDDECL) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1061
      // meaningless in XML
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1062
      String fpi = PublicId.normalize(entry.getEntryArg(0));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1063
      entry.setEntryArg(0, fpi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1064
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1065
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1066
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1067
      catalogManager.debug.message(4, "DTDDECL", fpi, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1068
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1069
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1070
    } else if (type == ENTITY) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1071
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1072
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1073
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1074
      catalogManager.debug.message(4, "ENTITY", entry.getEntryArg(0), fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1075
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1076
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1077
    } else if (type == LINKTYPE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1078
      // meaningless in XML
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1079
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1080
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1081
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1082
      catalogManager.debug.message(4, "LINKTYPE", entry.getEntryArg(0), fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1083
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1084
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1085
    } else if (type == NOTATION) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1086
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1087
      entry.setEntryArg(1, fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1088
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1089
      catalogManager.debug.message(4, "NOTATION", entry.getEntryArg(0), fsi);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1090
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1091
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1092
    } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1093
      catalogEntries.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1094
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1095
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1096
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1097
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1098
   * Handle unknown CatalogEntry types.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1099
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1100
   * <p>This method exists to allow subclasses to deal with unknown
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1101
   * entry types.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1102
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1103
  public void unknownEntry(Vector strings) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1104
    if (strings != null && strings.size() > 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1105
      String keyword = (String) strings.elementAt(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1106
      catalogManager.debug.message(2, "Unrecognized token parsing catalog", keyword);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1107
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1108
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1109
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1110
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1111
   * Parse all subordinate catalogs.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1112
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1113
   * <p>This method recursively parses all of the subordinate catalogs.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1114
   * If this method does not throw an exception, you can be confident that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1115
   * no subsequent call to any resolve*() method will either, with two
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1116
   * possible exceptions:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1117
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1118
   * <ol>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1119
   * <li><p>Delegated catalogs are re-parsed each time they are needed
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1120
   * (because a variable list of them may be needed in each case,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1121
   * depending on the length of the matching partial public identifier).</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1122
   * <p>But they are parsed by this method, so as long as they don't
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1123
   * change or disappear while the program is running, they shouldn't
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1124
   * generate errors later if they don't generate errors now.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1125
   * <li><p>If you add new catalogs with <code>parseCatalog</code>, they
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1126
   * won't be loaded until they are needed or until you call
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1127
   * <code>parseAllCatalogs</code> again.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1128
   * </ol>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1129
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1130
   * <p>On the other hand, if you don't call this method, you may
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1131
   * successfully parse documents without having to load all possible
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1132
   * catalogs.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1133
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1134
   * @throws MalformedURLException The filename (URL) for a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1135
   * subordinate or delegated catalog is not a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1136
   * @throws IOException Error reading some subordinate or delegated
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1137
   * catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1138
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1139
  public void parseAllCatalogs()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1140
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1141
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1142
    // Parse all the subordinate catalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1143
    for (int catPos = 0; catPos < catalogs.size(); catPos++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1144
      Catalog c = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1145
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1146
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1147
        c = (Catalog) catalogs.elementAt(catPos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1148
      } catch (ClassCastException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1149
        String catfile = (String) catalogs.elementAt(catPos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1150
        c = newCatalog();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1151
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1152
        c.parseCatalog(catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1153
        catalogs.setElementAt(c, catPos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1154
        c.parseAllCatalogs();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1155
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1156
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1157
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1158
    // Parse all the DELEGATE catalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1159
    Enumeration en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1160
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1161
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1162
      if (e.getEntryType() == DELEGATE_PUBLIC
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1163
          || e.getEntryType() == DELEGATE_SYSTEM
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1164
          || e.getEntryType() == DELEGATE_URI) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1165
        Catalog dcat = newCatalog();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1166
        dcat.parseCatalog(e.getEntryArg(1));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1167
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1168
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1169
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1170
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1171
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1172
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1173
   * Return the applicable DOCTYPE system identifier.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1174
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1175
   * @param entityName The name of the entity (element) for which
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1176
   * a doctype is required.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1177
   * @param publicId The nominal public identifier for the doctype
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1178
   * (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1179
   * @param systemId The nominal system identifier for the doctype
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1180
   * (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1181
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1182
   * @return The system identifier to use for the doctype.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1183
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1184
   * @throws MalformedURLException The formal system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1185
   * subordinate catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1186
   * @throws IOException Error reading subordinate catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1187
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1188
  public String resolveDoctype(String entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1189
                               String publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1190
                               String systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1191
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1192
    String resolved = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1193
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1194
    catalogManager.debug.message(3, "resolveDoctype("
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1195
                  +entityName+","+publicId+","+systemId+")");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1196
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1197
    systemId = normalizeURI(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1198
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1199
    if (publicId != null && publicId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1200
      publicId = PublicId.decodeURN(publicId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1201
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1202
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1203
    if (systemId != null && systemId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1204
      systemId = PublicId.decodeURN(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1205
      if (publicId != null && !publicId.equals(systemId)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1206
        catalogManager.debug.message(1, "urn:publicid: system identifier differs from public identifier; using public identifier");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1207
        systemId = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1208
      } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1209
        publicId = systemId;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1210
        systemId = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1211
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1212
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1213
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1214
    if (systemId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1215
      // If there's a SYSTEM entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1216
      resolved = resolveLocalSystem(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1217
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1218
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1219
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1220
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1221
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1222
    if (publicId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1223
      // If there's a PUBLIC entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1224
      resolved = resolveLocalPublic(DOCTYPE,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1225
                                    entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1226
                                    publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1227
                                    systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1228
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1229
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1230
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1231
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1232
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1233
    // If there's a DOCTYPE entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1234
    boolean over = default_override;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1235
    Enumeration en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1236
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1237
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1238
      if (e.getEntryType() == OVERRIDE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1239
        over = e.getEntryArg(0).equalsIgnoreCase("YES");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1240
        continue;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1241
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1242
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1243
      if (e.getEntryType() == DOCTYPE
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1244
          && e.getEntryArg(0).equals(entityName)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1245
        if (over || systemId == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1246
          return e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1247
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1248
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1249
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1250
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1251
    // Otherwise, look in the subordinate catalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1252
    return resolveSubordinateCatalogs(DOCTYPE,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1253
                                      entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1254
                                      publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1255
                                      systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1256
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1257
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1258
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1259
   * Return the applicable DOCUMENT entry.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1260
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1261
   * @return The system identifier to use for the doctype.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1262
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1263
   * @throws MalformedURLException The formal system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1264
   * subordinate catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1265
   * @throws IOException Error reading subordinate catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1266
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1267
  public String resolveDocument()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1268
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1269
    // If there's a DOCUMENT entry, return it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1270
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1271
    catalogManager.debug.message(3, "resolveDocument");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1272
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1273
    Enumeration en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1274
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1275
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1276
      if (e.getEntryType() == DOCUMENT) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1277
        return e.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1278
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1279
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1280
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1281
    return resolveSubordinateCatalogs(DOCUMENT,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1282
                                      null, null, null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1283
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1284
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1285
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1286
   * Return the applicable ENTITY system identifier.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1287
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1288
   * @param entityName The name of the entity for which
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1289
   * a system identifier is required.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1290
   * @param publicId The nominal public identifier for the entity
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1291
   * (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1292
   * @param systemId The nominal system identifier for the entity
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1293
   * (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1294
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1295
   * @return The system identifier to use for the entity.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1296
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1297
   * @throws MalformedURLException The formal system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1298
   * subordinate catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1299
   * @throws IOException Error reading subordinate catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1300
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1301
  public String resolveEntity(String entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1302
                              String publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1303
                              String systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1304
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1305
    String resolved = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1306
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1307
    catalogManager.debug.message(3, "resolveEntity("
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1308
                  +entityName+","+publicId+","+systemId+")");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1309
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1310
    systemId = normalizeURI(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1311
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1312
    if (publicId != null && publicId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1313
      publicId = PublicId.decodeURN(publicId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1314
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1315
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1316
    if (systemId != null && systemId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1317
      systemId = PublicId.decodeURN(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1318
      if (publicId != null && !publicId.equals(systemId)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1319
        catalogManager.debug.message(1, "urn:publicid: system identifier differs from public identifier; using public identifier");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1320
        systemId = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1321
      } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1322
        publicId = systemId;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1323
        systemId = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1324
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1325
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1326
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1327
    if (systemId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1328
      // If there's a SYSTEM entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1329
      resolved = resolveLocalSystem(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1330
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1331
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1332
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1333
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1334
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1335
    if (publicId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1336
      // If there's a PUBLIC entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1337
      resolved = resolveLocalPublic(ENTITY,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1338
                                    entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1339
                                    publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1340
                                    systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1341
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1342
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1343
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1344
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1345
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1346
    // If there's a ENTITY entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1347
    boolean over = default_override;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1348
    Enumeration en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1349
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1350
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1351
      if (e.getEntryType() == OVERRIDE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1352
        over = e.getEntryArg(0).equalsIgnoreCase("YES");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1353
        continue;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1354
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1355
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1356
      if (e.getEntryType() == ENTITY
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1357
          && e.getEntryArg(0).equals(entityName)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1358
        if (over || systemId == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1359
          return e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1360
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1361
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1362
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1363
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1364
    // Otherwise, look in the subordinate catalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1365
    return resolveSubordinateCatalogs(ENTITY,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1366
                                      entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1367
                                      publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1368
                                      systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1369
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1370
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1371
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1372
   * Return the applicable NOTATION system identifier.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1373
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1374
   * @param notationName The name of the notation for which
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1375
   * a doctype is required.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1376
   * @param publicId The nominal public identifier for the notation
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1377
   * (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1378
   * @param systemId The nominal system identifier for the notation
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1379
   * (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1380
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1381
   * @return The system identifier to use for the notation.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1382
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1383
   * @throws MalformedURLException The formal system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1384
   * subordinate catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1385
   * @throws IOException Error reading subordinate catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1386
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1387
  public String resolveNotation(String notationName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1388
                                String publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1389
                                String systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1390
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1391
    String resolved = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1392
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1393
    catalogManager.debug.message(3, "resolveNotation("
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1394
                  +notationName+","+publicId+","+systemId+")");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1395
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1396
    systemId = normalizeURI(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1397
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1398
    if (publicId != null && publicId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1399
      publicId = PublicId.decodeURN(publicId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1400
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1401
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1402
    if (systemId != null && systemId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1403
      systemId = PublicId.decodeURN(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1404
      if (publicId != null && !publicId.equals(systemId)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1405
        catalogManager.debug.message(1, "urn:publicid: system identifier differs from public identifier; using public identifier");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1406
        systemId = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1407
      } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1408
        publicId = systemId;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1409
        systemId = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1410
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1411
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1412
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1413
    if (systemId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1414
      // If there's a SYSTEM entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1415
      resolved = resolveLocalSystem(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1416
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1417
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1418
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1419
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1420
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1421
    if (publicId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1422
      // If there's a PUBLIC entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1423
      resolved = resolveLocalPublic(NOTATION,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1424
                                    notationName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1425
                                    publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1426
                                    systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1427
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1428
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1429
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1430
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1431
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1432
    // If there's a NOTATION entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1433
    boolean over = default_override;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1434
    Enumeration en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1435
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1436
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1437
      if (e.getEntryType() == OVERRIDE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1438
        over = e.getEntryArg(0).equalsIgnoreCase("YES");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1439
        continue;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1440
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1441
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1442
      if (e.getEntryType() == NOTATION
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1443
          && e.getEntryArg(0).equals(notationName)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1444
        if (over || systemId == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1445
          return e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1446
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1447
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1448
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1449
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1450
    // Otherwise, look in the subordinate catalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1451
    return resolveSubordinateCatalogs(NOTATION,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1452
                                      notationName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1453
                                      publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1454
                                      systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1455
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1456
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1457
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1458
   * Return the applicable PUBLIC or SYSTEM identifier.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1459
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1460
   * <p>This method searches the Catalog and returns the system
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1461
   * identifier specified for the given system or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1462
   * public identifiers. If
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1463
   * no appropriate PUBLIC or SYSTEM entry is found in the Catalog,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1464
   * null is returned.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1465
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1466
   * @param publicId The public identifier to locate in the catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1467
   * Public identifiers are normalized before comparison.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1468
   * @param systemId The nominal system identifier for the entity
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1469
   * in question (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1470
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1471
   * @throws MalformedURLException The formal system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1472
   * subordinate catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1473
   * @throws IOException Error reading subordinate catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1474
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1475
   * @return The system identifier to use.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1476
   * Note that the nominal system identifier is not returned if a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1477
   * match is not found in the catalog, instead null is returned
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1478
   * to indicate that no match was found.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1479
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1480
  public String resolvePublic(String publicId, String systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1481
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1482
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1483
    catalogManager.debug.message(3, "resolvePublic("+publicId+","+systemId+")");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1484
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1485
    systemId = normalizeURI(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1486
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1487
    if (publicId != null && publicId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1488
      publicId = PublicId.decodeURN(publicId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1489
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1490
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1491
    if (systemId != null && systemId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1492
      systemId = PublicId.decodeURN(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1493
      if (publicId != null && !publicId.equals(systemId)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1494
        catalogManager.debug.message(1, "urn:publicid: system identifier differs from public identifier; using public identifier");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1495
        systemId = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1496
      } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1497
        publicId = systemId;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1498
        systemId = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1499
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1500
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1501
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1502
    // If there's a SYSTEM entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1503
    if (systemId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1504
      String resolved = resolveLocalSystem(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1505
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1506
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1507
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1508
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1509
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1510
    // If there's a PUBLIC entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1511
    String resolved = resolveLocalPublic(PUBLIC,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1512
                                         null,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1513
                                         publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1514
                                         systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1515
    if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1516
      return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1517
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1518
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1519
    // Otherwise, look in the subordinate catalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1520
    return resolveSubordinateCatalogs(PUBLIC,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1521
                                      null,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1522
                                      publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1523
                                      systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1524
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1525
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1526
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1527
   * Return the applicable PUBLIC or SYSTEM identifier.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1528
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1529
   * <p>This method searches the Catalog and returns the system
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1530
   * identifier specified for the given system or public identifiers.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1531
   * If no appropriate PUBLIC or SYSTEM entry is found in the Catalog,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1532
   * delegated Catalogs are interrogated.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1533
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1534
   * <p>There are four possible cases:</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1535
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1536
   * <ul>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1537
   * <li>If the system identifier provided matches a SYSTEM entry
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1538
   * in the current catalog, the SYSTEM entry is returned.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1539
   * <li>If the system identifier is not null, the PUBLIC entries
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1540
   * that were encountered when OVERRIDE YES was in effect are
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1541
   * interrogated and the first matching entry is returned.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1542
   * <li>If the system identifier is null, then all of the PUBLIC
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1543
   * entries are interrogated and the first matching entry
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1544
   * is returned. This may not be the same as the preceding case, if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1545
   * some PUBLIC entries are encountered when OVERRIDE NO is in effect. In
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1546
   * XML, the only place where a public identifier may occur without
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1547
   * a system identifier is in a notation declaration.</li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1548
   * <li>Finally, if the public identifier matches one of the partial
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1549
   * public identifiers specified in a DELEGATE* entry in
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1550
   * the Catalog, the delegated catalog is interrogated. The first
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1551
   * time that the delegated catalog is required, it will be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1552
   * retrieved and parsed. It is subsequently cached.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1553
   * </li>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1554
   * </ul>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1555
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1556
   * @param entityType The CatalogEntry type for which this query is
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1557
   * being conducted. This is necessary in order to do the approprate
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1558
   * query on a delegated catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1559
   * @param entityName The name of the entity being searched for, if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1560
   * appropriate.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1561
   * @param publicId The public identifier of the entity in question.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1562
   * @param systemId The nominal system identifier for the entity
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1563
   * in question (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1564
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1565
   * @throws MalformedURLException The formal system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1566
   * delegated catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1567
   * @throws IOException Error reading delegated catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1568
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1569
   * @return The system identifier to use.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1570
   * Note that the nominal system identifier is not returned if a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1571
   * match is not found in the catalog, instead null is returned
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1572
   * to indicate that no match was found.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1573
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1574
  protected synchronized String resolveLocalPublic(int entityType,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1575
                                                   String entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1576
                                                   String publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1577
                                                   String systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1578
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1579
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1580
    // Always normalize the public identifier before attempting a match
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1581
    publicId = PublicId.normalize(publicId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1582
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1583
    // If there's a SYSTEM entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1584
    if (systemId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1585
      String resolved = resolveLocalSystem(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1586
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1587
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1588
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1589
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1590
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1591
    // If there's a PUBLIC entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1592
    boolean over = default_override;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1593
    Enumeration en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1594
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1595
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1596
      if (e.getEntryType() == OVERRIDE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1597
        over = e.getEntryArg(0).equalsIgnoreCase("YES");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1598
        continue;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1599
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1600
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1601
      if (e.getEntryType() == PUBLIC
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1602
          && e.getEntryArg(0).equals(publicId)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1603
        if (over || systemId == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1604
          return e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1605
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1606
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1607
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1608
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1609
    // If there's a DELEGATE_PUBLIC entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1610
    over = default_override;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1611
    en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1612
    Vector delCats = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1613
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1614
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1615
      if (e.getEntryType() == OVERRIDE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1616
        over = e.getEntryArg(0).equalsIgnoreCase("YES");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1617
        continue;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1618
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1619
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1620
      if (e.getEntryType() == DELEGATE_PUBLIC
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1621
          && (over || systemId == null)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1622
        String p = (String) e.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1623
        if (p.length() <= publicId.length()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1624
            && p.equals(publicId.substring(0, p.length()))) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1625
          // delegate this match to the other catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1626
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1627
          delCats.addElement(e.getEntryArg(1));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1628
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1629
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1630
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1631
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1632
    if (delCats.size() > 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1633
      Enumeration enCats = delCats.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1634
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1635
      if (catalogManager.debug.getDebug() > 1) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1636
        catalogManager.debug.message(2, "Switching to delegated catalog(s):");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1637
        while (enCats.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1638
          String delegatedCatalog = (String) enCats.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1639
          catalogManager.debug.message(2, "\t" + delegatedCatalog);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1640
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1641
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1642
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1643
      Catalog dcat = newCatalog();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1644
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1645
      enCats = delCats.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1646
      while (enCats.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1647
        String delegatedCatalog = (String) enCats.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1648
        dcat.parseCatalog(delegatedCatalog);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1649
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1650
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1651
      return dcat.resolvePublic(publicId, null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1652
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1653
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1654
    // Nada!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1655
    return null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1656
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1657
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1658
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1659
   * Return the applicable SYSTEM system identifier.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1660
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1661
   * <p>If a SYSTEM entry exists in the Catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1662
   * for the system ID specified, return the mapped value.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1663
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1664
   * <p>On Windows-based operating systems, the comparison between
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1665
   * the system identifier provided and the SYSTEM entries in the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1666
   * Catalog is case-insensitive.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1667
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1668
   * @param systemId The system ID to locate in the catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1669
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1670
   * @return The resolved system identifier.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1671
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1672
   * @throws MalformedURLException The formal system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1673
   * subordinate catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1674
   * @throws IOException Error reading subordinate catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1675
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1676
  public String resolveSystem(String systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1677
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1678
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1679
    catalogManager.debug.message(3, "resolveSystem("+systemId+")");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1680
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1681
    systemId = normalizeURI(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1682
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1683
    if (systemId != null && systemId.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1684
      systemId = PublicId.decodeURN(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1685
      return resolvePublic(systemId, null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1686
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1687
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1688
    // If there's a SYSTEM entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1689
    if (systemId != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1690
      String resolved = resolveLocalSystem(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1691
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1692
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1693
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1694
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1695
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1696
    // Otherwise, look in the subordinate catalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1697
    return resolveSubordinateCatalogs(SYSTEM,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1698
                                      null,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1699
                                      null,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1700
                                      systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1701
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1702
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1703
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1704
   * Return the applicable SYSTEM system identifier in this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1705
   * catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1706
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1707
   * <p>If a SYSTEM entry exists in the catalog file
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1708
   * for the system ID specified, return the mapped value.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1709
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1710
   * @param systemId The system ID to locate in the catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1711
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1712
   * @return The mapped system identifier or null
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1713
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1714
  protected String resolveLocalSystem(String systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1715
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1716
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
  1717
    String osname = SecuritySupport.getSystemProperty("os.name");
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1718
    boolean windows = (osname.indexOf("Windows") >= 0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1719
    Enumeration en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1720
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1721
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1722
      if (e.getEntryType() == SYSTEM
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1723
          && (e.getEntryArg(0).equals(systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1724
              || (windows
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1725
                  && e.getEntryArg(0).equalsIgnoreCase(systemId)))) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1726
        return e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1727
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1728
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1729
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1730
    // If there's a REWRITE_SYSTEM entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1731
    en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1732
    String startString = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1733
    String prefix = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1734
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1735
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1736
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1737
      if (e.getEntryType() == REWRITE_SYSTEM) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1738
        String p = (String) e.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1739
        if (p.length() <= systemId.length()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1740
            && p.equals(systemId.substring(0, p.length()))) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1741
          // Is this the longest prefix?
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1742
          if (startString == null
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1743
              || p.length() > startString.length()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1744
            startString = p;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1745
            prefix = e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1746
          }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1747
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1748
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1749
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1750
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1751
    if (prefix != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1752
      // return the systemId with the new prefix
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1753
      return prefix + systemId.substring(startString.length());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1754
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1755
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1756
    // If there's a SYSTEM_SUFFIX entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1757
    en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1758
    String suffixString = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1759
    String suffixURI = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1760
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1761
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1762
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1763
      if (e.getEntryType() == SYSTEM_SUFFIX) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1764
        String p = (String) e.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1765
        if (p.length() <= systemId.length()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1766
            && systemId.endsWith(p)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1767
          // Is this the longest prefix?
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1768
          if (suffixString == null
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1769
              || p.length() > suffixString.length()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1770
            suffixString = p;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1771
            suffixURI = e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1772
          }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1773
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1774
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1775
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1776
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1777
    if (suffixURI != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1778
      // return the systemId for the suffix
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1779
      return suffixURI;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1780
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1781
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1782
    // If there's a DELEGATE_SYSTEM entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1783
    en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1784
    Vector delCats = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1785
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1786
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1787
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1788
      if (e.getEntryType() == DELEGATE_SYSTEM) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1789
        String p = (String) e.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1790
        if (p.length() <= systemId.length()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1791
            && p.equals(systemId.substring(0, p.length()))) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1792
          // delegate this match to the other catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1793
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1794
          delCats.addElement(e.getEntryArg(1));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1795
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1796
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1797
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1798
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1799
    if (delCats.size() > 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1800
      Enumeration enCats = delCats.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1801
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1802
      if (catalogManager.debug.getDebug() > 1) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1803
        catalogManager.debug.message(2, "Switching to delegated catalog(s):");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1804
        while (enCats.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1805
          String delegatedCatalog = (String) enCats.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1806
          catalogManager.debug.message(2, "\t" + delegatedCatalog);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1807
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1808
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1809
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1810
      Catalog dcat = newCatalog();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1811
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1812
      enCats = delCats.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1813
      while (enCats.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1814
        String delegatedCatalog = (String) enCats.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1815
        dcat.parseCatalog(delegatedCatalog);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1816
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1817
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1818
      return dcat.resolveSystem(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1819
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1820
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1821
    return null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1822
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1823
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1824
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1825
   * Return the applicable URI.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1826
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1827
   * <p>If a URI entry exists in the Catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1828
   * for the URI specified, return the mapped value.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1829
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1830
   * <p>URI comparison is case sensitive.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1831
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1832
   * @param uri The URI to locate in the catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1833
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1834
   * @return The resolved URI.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1835
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1836
   * @throws MalformedURLException The system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1837
   * subordinate catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1838
   * @throws IOException Error reading subordinate catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1839
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1840
  public String resolveURI(String uri)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1841
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1842
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1843
    catalogManager.debug.message(3, "resolveURI("+uri+")");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1844
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1845
    uri = normalizeURI(uri);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1846
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1847
    if (uri != null && uri.startsWith("urn:publicid:")) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1848
      uri = PublicId.decodeURN(uri);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1849
      return resolvePublic(uri, null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1850
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1851
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1852
    // If there's a URI entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1853
    if (uri != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1854
      String resolved = resolveLocalURI(uri);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1855
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1856
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1857
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1858
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1859
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1860
    // Otherwise, look in the subordinate catalogs
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1861
    return resolveSubordinateCatalogs(URI,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1862
                                      null,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1863
                                      null,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1864
                                      uri);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1865
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1866
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1867
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1868
   * Return the applicable URI in this catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1869
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1870
   * <p>If a URI entry exists in the catalog file
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1871
   * for the URI specified, return the mapped value.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1872
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1873
   * @param uri The URI to locate in the catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1874
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1875
   * @return The mapped URI or null
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1876
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1877
  protected String resolveLocalURI(String uri)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1878
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1879
    Enumeration en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1880
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1881
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1882
      if (e.getEntryType() == URI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1883
          && (e.getEntryArg(0).equals(uri))) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1884
        return e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1885
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1886
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1887
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1888
    // If there's a REWRITE_URI entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1889
    en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1890
    String startString = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1891
    String prefix = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1892
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1893
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1894
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1895
      if (e.getEntryType() == REWRITE_URI) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1896
        String p = (String) e.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1897
        if (p.length() <= uri.length()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1898
            && p.equals(uri.substring(0, p.length()))) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1899
          // Is this the longest prefix?
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1900
          if (startString == null
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1901
              || p.length() > startString.length()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1902
            startString = p;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1903
            prefix = e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1904
          }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1905
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1906
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1907
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1908
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1909
    if (prefix != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1910
      // return the uri with the new prefix
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1911
      return prefix + uri.substring(startString.length());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1912
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1913
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1914
    // If there's a URI_SUFFIX entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1915
    en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1916
    String suffixString = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1917
    String suffixURI = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1918
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1919
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1920
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1921
      if (e.getEntryType() == URI_SUFFIX) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1922
        String p = (String) e.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1923
        if (p.length() <= uri.length()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1924
            && uri.endsWith(p)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1925
          // Is this the longest prefix?
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1926
          if (suffixString == null
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1927
              || p.length() > suffixString.length()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1928
            suffixString = p;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1929
            suffixURI = e.getEntryArg(1);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1930
          }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1931
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1932
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1933
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1934
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1935
    if (suffixURI != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1936
      // return the uri for the suffix
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1937
      return suffixURI;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1938
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1939
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1940
    // If there's a DELEGATE_URI entry in this catalog, use it
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1941
    en = catalogEntries.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1942
    Vector delCats = new Vector();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1943
    while (en.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1944
      CatalogEntry e = (CatalogEntry) en.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1945
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1946
      if (e.getEntryType() == DELEGATE_URI) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1947
        String p = (String) e.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1948
        if (p.length() <= uri.length()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1949
            && p.equals(uri.substring(0, p.length()))) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1950
          // delegate this match to the other catalog
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1951
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1952
          delCats.addElement(e.getEntryArg(1));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1953
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1954
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1955
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1956
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1957
    if (delCats.size() > 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1958
      Enumeration enCats = delCats.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1959
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1960
      if (catalogManager.debug.getDebug() > 1) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1961
        catalogManager.debug.message(2, "Switching to delegated catalog(s):");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1962
        while (enCats.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1963
          String delegatedCatalog = (String) enCats.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1964
          catalogManager.debug.message(2, "\t" + delegatedCatalog);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1965
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1966
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1967
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1968
      Catalog dcat = newCatalog();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1969
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1970
      enCats = delCats.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1971
      while (enCats.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1972
        String delegatedCatalog = (String) enCats.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1973
        dcat.parseCatalog(delegatedCatalog);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1974
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1975
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1976
      return dcat.resolveURI(uri);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1977
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1978
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1979
    return null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1980
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1981
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1982
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1983
   * Search the subordinate catalogs, in order, looking for a match.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1984
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1985
   * <p>This method searches the Catalog and returns the system
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1986
   * identifier specified for the given entity type with the given
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1987
   * name, public, and system identifiers. In some contexts, these
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1988
   * may be null.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1989
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1990
   * @param entityType The CatalogEntry type for which this query is
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1991
   * being conducted. This is necessary in order to do the approprate
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1992
   * query on a subordinate catalog.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1993
   * @param entityName The name of the entity being searched for, if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1994
   * appropriate.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1995
   * @param publicId The public identifier of the entity in question
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1996
   * (as provided in the source document).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1997
   * @param systemId The nominal system identifier for the entity
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1998
   * in question (as provided in the source document). This parameter is
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  1999
   * overloaded for the URI entry type.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2000
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2001
   * @throws MalformedURLException The formal system identifier of a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2002
   * delegated catalog cannot be turned into a valid URL.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2003
   * @throws IOException Error reading delegated catalog file.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2004
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2005
   * @return The system identifier to use.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2006
   * Note that the nominal system identifier is not returned if a
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2007
   * match is not found in the catalog, instead null is returned
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2008
   * to indicate that no match was found.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2009
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2010
  protected synchronized String resolveSubordinateCatalogs(int entityType,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2011
                                                           String entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2012
                                                           String publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2013
                                                           String systemId)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2014
    throws MalformedURLException, IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2015
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2016
    for (int catPos = 0; catPos < catalogs.size(); catPos++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2017
      Catalog c = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2018
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2019
      try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2020
        c = (Catalog) catalogs.elementAt(catPos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2021
      } catch (ClassCastException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2022
        String catfile = (String) catalogs.elementAt(catPos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2023
        c = newCatalog();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2024
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2025
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2026
          c.parseCatalog(catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2027
        } catch (MalformedURLException mue) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2028
          catalogManager.debug.message(1, "Malformed Catalog URL", catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2029
        } catch (FileNotFoundException fnfe) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2030
          catalogManager.debug.message(1, "Failed to load catalog, file not found",
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2031
                        catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2032
        } catch (IOException ioe) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2033
          catalogManager.debug.message(1, "Failed to load catalog, I/O error", catfile);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2034
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2035
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2036
        catalogs.setElementAt(c, catPos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2037
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2038
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2039
      String resolved = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2040
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2041
      // Ok, now what are we supposed to call here?
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2042
      if (entityType == DOCTYPE) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2043
        resolved = c.resolveDoctype(entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2044
                                    publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2045
                                    systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2046
      } else if (entityType == DOCUMENT) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2047
        resolved = c.resolveDocument();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2048
      } else if (entityType == ENTITY) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2049
        resolved = c.resolveEntity(entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2050
                                   publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2051
                                   systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2052
      } else if (entityType == NOTATION) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2053
        resolved = c.resolveNotation(entityName,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2054
                                     publicId,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2055
                                     systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2056
      } else if (entityType == PUBLIC) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2057
        resolved = c.resolvePublic(publicId, systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2058
      } else if (entityType == SYSTEM) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2059
        resolved = c.resolveSystem(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2060
      } else if (entityType == URI) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2061
        resolved = c.resolveURI(systemId);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2062
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2063
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2064
      if (resolved != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2065
        return resolved;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2066
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2067
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2068
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2069
    return null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2070
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2071
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2072
  // -----------------------------------------------------------------
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2073
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2074
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2075
   * Replace backslashes with forward slashes. (URLs always use
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2076
   * forward slashes.)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2077
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2078
   * @param sysid The input system identifier.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2079
   * @return The same system identifier with backslashes turned into
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2080
   * forward slashes.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2081
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2082
  protected String fixSlashes (String sysid) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2083
    return sysid.replace('\\', '/');
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2084
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2085
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2086
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2087
   * Construct an absolute URI from a relative one, using the current
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2088
   * base URI.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2089
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2090
   * @param sysid The (possibly relative) system identifier
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2091
   * @return The system identifier made absolute with respect to the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2092
   * current {@link #base}.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2093
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2094
  protected String makeAbsolute(String sysid) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2095
    URL local = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2096
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2097
    sysid = fixSlashes(sysid);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2098
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2099
    try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2100
      local = new URL(base, sysid);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2101
    } catch (MalformedURLException e) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2102
      catalogManager.debug.message(1, "Malformed URL on system identifier", sysid);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2103
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2104
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2105
    if (local != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2106
      return local.toString();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2107
    } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2108
      return sysid;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2109
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2110
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2111
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2112
26516
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2113
    /**
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2114
     * Perform character normalization on a URI reference.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2115
     *
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2116
     * @param uriref The URI reference
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2117
     * @return The normalized URI reference.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2118
     */
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2119
    protected String normalizeURI(String uriref) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2120
        if (uriref == null) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2121
            return null;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2122
        }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2123
        final int length = uriref.length();
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2124
        for (int i = 0; i < length; ++i) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2125
            char c = uriref.charAt(i);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2126
            if ((c <= 0x20)    // ctrl
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2127
                    || (c > 0x7F)  // high ascii
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2128
                    || (c == 0x22) // "
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2129
                    || (c == 0x3C) // <
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2130
                    || (c == 0x3E) // >
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2131
                    || (c == 0x5C) // \
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2132
                    || (c == 0x5E) // ^
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2133
                    || (c == 0x60) // `
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2134
                    || (c == 0x7B) // {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2135
                    || (c == 0x7C) // |
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2136
                    || (c == 0x7D) // }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2137
                    || (c == 0x7F)) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2138
                return normalizeURI(uriref, i);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2139
            }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2140
        }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2141
        return uriref;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2142
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2143
26516
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2144
    /**
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2145
     * Perform character normalization on a URI reference.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2146
     *
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2147
     * @param uriref The URI reference
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2148
     * @param index The index of the first character which requires escaping.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2149
     * @return The normalized URI reference.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2150
     */
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2151
    private String normalizeURI(String uriref, int index) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2152
        final StringBuilder buffer = new StringBuilder();
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2153
        for (int i = 0; i < index; ++i) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2154
            buffer.append(uriref.charAt(i));
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2155
        }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2156
        final byte[] bytes;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2157
        try {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2158
            bytes = uriref.substring(index).getBytes("UTF-8");
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2159
        }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2160
        catch (UnsupportedEncodingException uee) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2161
            // this can't happen
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2162
            catalogManager.debug.message(1, "UTF-8 is an unsupported encoding!?");
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2163
            return uriref;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2164
        }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2165
        for (int count = 0; count < bytes.length; ++count) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2166
            int ch = bytes[count] & 0xFF;
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2167
            if ((ch <= 0x20)    // ctrl
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2168
                    || (ch > 0x7F)  // high ascii
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2169
                    || (ch == 0x22) // "
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2170
                    || (ch == 0x3C) // <
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2171
                    || (ch == 0x3E) // >
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2172
                    || (ch == 0x5C) // \
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2173
                    || (ch == 0x5E) // ^
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2174
                    || (ch == 0x60) // `
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2175
                    || (ch == 0x7B) // {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2176
                    || (ch == 0x7C) // |
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2177
                    || (ch == 0x7D) // }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2178
                    || (ch == 0x7F)) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2179
                writeEncodedByte(ch, buffer);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2180
            }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2181
            else {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2182
                buffer.append((char) bytes[count]);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2183
            }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2184
        }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2185
        return buffer.toString();
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2186
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2187
26516
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2188
    /**
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2189
     * Perform %-encoding on a single byte.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2190
     *
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2191
     * @param b The 8-bit integer that represents the byte. (Bytes are signed
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2192
     *          but encoding needs to look at the bytes unsigned.)
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2193
     * @return The %-encoded string for the byte in question.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2194
     */
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2195
    protected String encodedByte(int b) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2196
        StringBuilder buffer = new StringBuilder(3);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2197
        writeEncodedByte(b, buffer);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2198
        return buffer.toString();
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2199
    }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2200
26516
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2201
    /**
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2202
     * Perform %-encoding on a single byte.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2203
     *
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2204
     * @param b The 8-bit integer that represents the byte. (Bytes are signed
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2205
     *          but encoding needs to look at the bytes unsigned.)
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2206
     * @param buffer The target for the %-encoded string for the byte in question.
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2207
     */
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2208
    private void writeEncodedByte(int b, StringBuilder buffer) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2209
        String hex = Integer.toHexString(b).toUpperCase(Locale.ENGLISH);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2210
        if (hex.length() < 2) {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2211
            buffer.append("%0");
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2212
            buffer.append(hex);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2213
        }
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2214
        else {
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2215
            buffer.append('%');
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2216
            buffer.append(hex);
8e6a45c22cea 8056202: Xerces Update: Catalog Resolver
joehw
parents: 25868
diff changeset
  2217
        }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2218
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2219
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2220
  // -----------------------------------------------------------------
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2221
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2222
  /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2223
   * Add to the current list of delegated catalogs.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2224
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2225
   * <p>This method always constructs the {@link #localDelegate}
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2226
   * vector so that it is ordered by length of partial
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2227
   * public identifier.</p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2228
   *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2229
   * @param entry The DELEGATE catalog entry
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2230
   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2231
  protected void addDelegate(CatalogEntry entry) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2232
    int pos = 0;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2233
    String partial = entry.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2234
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2235
    Enumeration local = localDelegate.elements();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2236
    while (local.hasMoreElements()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2237
      CatalogEntry dpe = (CatalogEntry) local.nextElement();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2238
      String dp = dpe.getEntryArg(0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2239
      if (dp.equals(partial)) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2240
        // we already have this prefix
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2241
        return;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2242
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2243
      if (dp.length() > partial.length()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2244
        pos++;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2245
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2246
      if (dp.length() < partial.length()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2247
        break;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2248
      }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2249
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2250
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2251
    // now insert partial into the vector at [pos]
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2252
    if (localDelegate.size() == 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2253
      localDelegate.addElement(entry);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2254
    } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2255
      localDelegate.insertElementAt(entry, pos);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2256
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2257
  }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
  2258
}