src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java
author thartmann
Fri, 24 Aug 2018 08:17:23 +0200
changeset 51514 1e332d63bd96
parent 47216 71c04702a3d5
child 53146 62a4355dc9c8
permissions -rw-r--r--
8209833: C2 compilation fails with "assert(ex_map->jvms()->same_calls_as(_exceptions->jvms())) failed: all collected exceptions must come from the same place" Summary: Deoptimize if exception is thrown in _clone intrinsic. Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     1
/*
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     4
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    10
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    15
 * accompanied this code).
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    16
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    20
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    23
 * questions.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    24
 */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    25
package javax.xml.catalog;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    26
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    27
import java.net.URI;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    28
import java.util.ArrayList;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    29
import java.util.HashMap;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    30
import java.util.List;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    31
import java.util.Map;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    32
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    33
/**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    34
 * Represents a group entry.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    35
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    36
 * @since 9
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    37
 */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    38
class GroupEntry extends BaseEntry {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    39
    static final int ATTRIBUTE_PREFER = 0;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    40
    static final int ATTRIBUTE_DEFFER = 1;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    41
    static final int ATTRIBUTE_RESOLUTION = 2;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    42
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    43
    //Unmodifiable features when the Catalog is created
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    44
    CatalogFeatures features;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    45
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    46
    //Value of the prefer attribute
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    47
    boolean isPreferPublic = true;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    48
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
    49
    //The parent of the catalog instance
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
    50
    CatalogImpl parent = null;
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
    51
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    52
    //The catalog instance this group belongs to
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    53
    CatalogImpl catalog;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    54
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    55
    //A list of all entries in a catalog or group
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    56
    List<BaseEntry> entries = new ArrayList<>();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    57
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    58
    //loaded delegated catalog by system id
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
    59
    Map<String, CatalogImpl> delegateCatalogs = new HashMap<>();
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    60
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    61
    //A list of all loaded Catalogs, including this, and next catalogs
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
    62
    Map<String, CatalogImpl> loadedCatalogs = new HashMap<>();
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    63
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    64
    /*
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    65
     A list of Catalog Ids that have already been searched in a matching
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    66
     operation. Check this list before constructing new Catalog to avoid circular
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    67
     reference.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    68
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    69
    List<String> catalogsSearched = new ArrayList<>();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    70
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    71
    //A flag to indicate whether the current match is a system or uri
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    72
    boolean isInstantMatch = false;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    73
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    74
    //A match of a rewrite type
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    75
    String rewriteMatch = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    76
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    77
    //The length of the longest match of a rewrite type
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    78
    int longestRewriteMatch = 0;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    79
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    80
    //A match of a suffix type
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    81
    String suffixMatch = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    82
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    83
    //The length of the longest match of a suffix type
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    84
    int longestSuffixMatch = 0;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    85
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
    86
    //Indicate whether a system entry has been searched
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
    87
    boolean systemEntrySearched = false;
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
    88
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    89
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    90
     * PreferType represents possible values of the prefer property
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    91
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    92
    public static enum PreferType {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    93
        PUBLIC("public"),
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    94
        SYSTEM("system");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    95
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    96
        final String literal;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    97
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    98
        PreferType(String literal) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    99
            this.literal = literal;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   100
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   101
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   102
        public boolean prefer(String prefer) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   103
            return literal.equals(prefer);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   104
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   105
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   106
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   107
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   108
     * PreferType represents possible values of the resolve property
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   109
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   110
    public static enum ResolveType {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   111
        STRICT(CatalogFeatures.RESOLVE_STRICT),
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   112
        CONTINUE(CatalogFeatures.RESOLVE_CONTINUE),
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   113
        IGNORE(CatalogFeatures.RESOLVE_IGNORE);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   114
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   115
        final String literal;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   116
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   117
        ResolveType(String literal) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   118
            this.literal = literal;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   119
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   120
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   121
        static public ResolveType getType(String resolveType) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   122
            for (ResolveType type : ResolveType.values()) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   123
                if (type.isType(resolveType)) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   124
                    return type;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   125
                }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   126
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   127
            return null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   128
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   129
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   130
        public boolean isType(String type) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   131
            return literal.equals(type);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   132
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   133
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   134
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   135
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   136
     * Constructs a GroupEntry
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   137
     *
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   138
     * @param type the type of the entry
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   139
     * @param parent the parent Catalog
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   140
     */
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   141
    public GroupEntry(CatalogEntryType type, CatalogImpl parent) {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   142
        super(type);
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   143
        this.parent = parent;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   144
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   145
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   146
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   147
     * Constructs a group entry.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   148
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   149
     * @param base The baseURI attribute
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   150
     * @param attributes The attributes
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   151
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   152
    public GroupEntry(String base, String... attributes) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   153
        this(null, base, attributes);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   154
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   155
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   156
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   157
     * Resets the group entry to its initial state.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   158
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   159
    public void reset() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   160
        isInstantMatch = false;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   161
        rewriteMatch = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   162
        longestRewriteMatch = 0;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   163
        suffixMatch = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   164
        longestSuffixMatch = 0;
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
   165
        systemEntrySearched = false;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   166
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   167
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   168
     * Constructs a group entry.
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   169
     * @param catalog the catalog this GroupEntry belongs to
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   170
     * @param base the baseURI attribute
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   171
     * @param attributes the attributes
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   172
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   173
    public GroupEntry(CatalogImpl catalog, String base, String... attributes) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   174
        super(CatalogEntryType.GROUP, base);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   175
        setPrefer(attributes[ATTRIBUTE_PREFER]);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   176
        this.catalog = catalog;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   177
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   178
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   179
    /**
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   180
     * Sets the catalog for this GroupEntry.
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   181
     *
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   182
     * @param catalog the catalog this GroupEntry belongs to
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   183
     */
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   184
    void setCatalog(CatalogImpl catalog) {
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   185
        this.catalog = catalog;
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   186
    }
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   187
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   188
    /**
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   189
     * Adds an entry.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   190
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   191
     * @param entry The entry to be added.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   192
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   193
    public void addEntry(BaseEntry entry) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   194
        entries.add(entry);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   195
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   196
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   197
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   198
     * Sets the prefer property. If the value is null or empty, or any String
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   199
     * other than the defined, it will be assumed as the default value.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   200
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   201
     * @param value The value of the prefer attribute
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   202
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   203
    public final void setPrefer(String value) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   204
        isPreferPublic = PreferType.PUBLIC.prefer(value);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   205
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   206
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   207
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   208
     * Queries the prefer attribute
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   209
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   210
     * @return true if the prefer attribute is set to system, false if not.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   211
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   212
    public boolean isPreferPublic() {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   213
        return isPreferPublic;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   214
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   215
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   216
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   217
     * Attempt to find a matching entry in the catalog by systemId.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   218
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   219
     * <p>
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   220
     * The method searches through the system-type entries, including system,
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   221
     * rewriteSystem, systemSuffix, delegateSystem, and group entries in the
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   222
     * current catalog in order to find a match.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   223
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   224
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   225
     * @param systemId The system identifier of the external entity being
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   226
     * referenced.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   227
     *
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   228
     * @return a URI string if a mapping is found, or null otherwise.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   229
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   230
    public String matchSystem(String systemId) {
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
   231
        systemEntrySearched = true;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   232
        String match = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   233
        for (BaseEntry entry : entries) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   234
            switch (entry.type) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   235
                case SYSTEM:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   236
                    match = ((SystemEntry) entry).match(systemId);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   237
                    //if there's a matching system entry, use it
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   238
                    if (match != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   239
                        isInstantMatch = true;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   240
                        return match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   241
                    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   242
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   243
                case REWRITESYSTEM:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   244
                    match = ((RewriteSystem) entry).match(systemId, longestRewriteMatch);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   245
                    if (match != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   246
                        rewriteMatch = match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   247
                        longestRewriteMatch = ((RewriteSystem) entry).getSystemIdStartString().length();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   248
                    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   249
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   250
                case SYSTEMSUFFIX:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   251
                    match = ((SystemSuffix) entry).match(systemId, longestSuffixMatch);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   252
                    if (match != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   253
                        suffixMatch = match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   254
                        longestSuffixMatch = ((SystemSuffix) entry).getSystemIdSuffix().length();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   255
                    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   256
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   257
                case GROUP:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   258
                    GroupEntry grpEntry = (GroupEntry) entry;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   259
                    match = grpEntry.matchSystem(systemId);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   260
                    if (grpEntry.isInstantMatch) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   261
                        //use it if there is a match of the system type
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   262
                        return match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   263
                    } else if (grpEntry.longestRewriteMatch > longestRewriteMatch) {
37384
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   264
                        longestRewriteMatch = grpEntry.longestRewriteMatch;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   265
                        rewriteMatch = match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   266
                    } else if (grpEntry.longestSuffixMatch > longestSuffixMatch) {
37384
04a4a89d81b9 8152527: Relative rewriteSystem with xml:base at group level failed
joehw
parents: 37382
diff changeset
   267
                        longestSuffixMatch = grpEntry.longestSuffixMatch;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   268
                        suffixMatch = match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   269
                    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   270
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   271
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   272
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   273
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   274
        if (longestRewriteMatch > 0) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   275
            return rewriteMatch;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   276
        } else if (longestSuffixMatch > 0) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   277
            return suffixMatch;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   278
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   279
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   280
        //if no single match is found, try delegates
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   281
        return matchDelegate(CatalogEntryType.DELEGATESYSTEM, systemId);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   282
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   283
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   284
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   285
     * Attempt to find a matching entry in the catalog by publicId.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   286
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   287
     * <p>
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   288
     * The method searches through the public-type entries, including public,
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   289
     * delegatePublic, and group entries in the current catalog in order to find
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   290
     * a match.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   291
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   292
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   293
     * @param publicId The public identifier of the external entity being
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   294
     * referenced.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   295
     *
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   296
     * @return a URI string if a mapping is found, or null otherwise.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   297
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   298
    public String matchPublic(String publicId) {
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
   299
        /*
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
   300
           When both public and system identifiers are specified, and prefer is
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
   301
        not public (that is, system), only system entry will be used.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
   302
        */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 33542
diff changeset
   303
        if (!isPreferPublic && systemEntrySearched) {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   304
            return null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   305
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   306
        //match public entries
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   307
        String match = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   308
        for (BaseEntry entry : entries) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   309
            switch (entry.type) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   310
                case PUBLIC:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   311
                    match = ((PublicEntry) entry).match(publicId);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   312
                    break;
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37384
diff changeset
   313
                case URI:
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37384
diff changeset
   314
                    match = ((UriEntry) entry).match(publicId);
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37384
diff changeset
   315
                    break;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   316
                case GROUP:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   317
                    match = ((GroupEntry) entry).matchPublic(publicId);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   318
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   319
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   320
            if (match != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   321
                return match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   322
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   323
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   324
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   325
        //if no single match is found, try delegates
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   326
        return matchDelegate(CatalogEntryType.DELEGATEPUBLIC, publicId);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   327
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   328
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   329
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   330
     * Attempt to find a matching entry in the catalog by the uri element.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   331
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   332
     * <p>
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   333
     * The method searches through the uri-type entries, including uri,
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   334
     * rewriteURI, uriSuffix, delegateURI and group entries in the current
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   335
     * catalog in order to find a match.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   336
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   337
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   338
     * @param uri The URI reference of a resource.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   339
     *
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   340
     * @return a URI string if a mapping is found, or null otherwise.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   341
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   342
    public String matchURI(String uri) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   343
        String match = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   344
        for (BaseEntry entry : entries) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   345
            switch (entry.type) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   346
                case URI:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   347
                    match = ((UriEntry) entry).match(uri);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   348
                    if (match != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   349
                        isInstantMatch = true;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   350
                        return match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   351
                    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   352
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   353
                case REWRITEURI:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   354
                    match = ((RewriteUri) entry).match(uri, longestRewriteMatch);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   355
                    if (match != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   356
                        rewriteMatch = match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   357
                        longestRewriteMatch = ((RewriteUri) entry).getURIStartString().length();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   358
                    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   359
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   360
                case URISUFFIX:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   361
                    match = ((UriSuffix) entry).match(uri, longestSuffixMatch);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   362
                    if (match != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   363
                        suffixMatch = match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   364
                        longestSuffixMatch = ((UriSuffix) entry).getURISuffix().length();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   365
                    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   366
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   367
                case GROUP:
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   368
                    GroupEntry grpEntry = (GroupEntry) entry;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   369
                    match = grpEntry.matchURI(uri);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   370
                    if (grpEntry.isInstantMatch) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   371
                        //use it if there is a match of the uri type
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   372
                        return match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   373
                    } else if (grpEntry.longestRewriteMatch > longestRewriteMatch) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   374
                        rewriteMatch = match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   375
                    } else if (grpEntry.longestSuffixMatch > longestSuffixMatch) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   376
                        suffixMatch = match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   377
                    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   378
                    break;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   379
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   380
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   381
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   382
        if (longestRewriteMatch > 0) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   383
            return rewriteMatch;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   384
        } else if (longestSuffixMatch > 0) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   385
            return suffixMatch;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   386
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   387
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   388
        //if no single match is found, try delegates
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   389
        return matchDelegate(CatalogEntryType.DELEGATEURI, uri);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   390
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   391
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   392
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   393
     * Matches delegatePublic or delegateSystem against the specified id
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   394
     *
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   395
     * @param type the type of the Catalog entry
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   396
     * @param id the system or public id to be matched
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   397
     * @return the URI string if a mapping is found, or null otherwise.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   398
     */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   399
    private String matchDelegate(CatalogEntryType type, String id) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   400
        String match = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   401
        int longestMatch = 0;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   402
        URI catalogId = null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   403
        URI temp;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   404
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   405
        //Check delegate types in the current catalog
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   406
        for (BaseEntry entry : entries) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   407
            if (entry.type == type) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   408
                if (type == CatalogEntryType.DELEGATESYSTEM) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   409
                    temp = ((DelegateSystem)entry).matchURI(id, longestMatch);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   410
                } else if (type == CatalogEntryType.DELEGATEPUBLIC) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   411
                    temp = ((DelegatePublic)entry).matchURI(id, longestMatch);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   412
                } else {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   413
                    temp = ((DelegateUri)entry).matchURI(id, longestMatch);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   414
                }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   415
                if (temp != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   416
                    longestMatch = entry.getMatchId().length();
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   417
                    catalogId = temp;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   418
                }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   419
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   420
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   421
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   422
        //Check delegate Catalogs
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   423
        if (catalogId != null) {
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   424
            Catalog delegateCatalog = loadDelegateCatalog(catalog, catalogId);
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   425
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   426
            if (delegateCatalog != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   427
                if (type == CatalogEntryType.DELEGATESYSTEM) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   428
                    match = delegateCatalog.matchSystem(id);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   429
                } else if (type == CatalogEntryType.DELEGATEPUBLIC) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   430
                    match = delegateCatalog.matchPublic(id);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   431
                } else {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   432
                    match = delegateCatalog.matchURI(id);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   433
                }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   434
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   435
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   436
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   437
        return match;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   438
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   439
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   440
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   441
     * Loads all delegate catalogs.
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   442
     *
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   443
     * @param parent the parent catalog of the delegate catalogs
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   444
     */
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   445
    void loadDelegateCatalogs(CatalogImpl parent) {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   446
        entries.stream()
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   447
                .filter((entry) -> (entry.type == CatalogEntryType.DELEGATESYSTEM ||
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   448
                        entry.type == CatalogEntryType.DELEGATEPUBLIC ||
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   449
                        entry.type == CatalogEntryType.DELEGATEURI))
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   450
                .map((entry) -> (AltCatalog)entry)
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   451
                .forEach((altCatalog) -> {
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   452
                        loadDelegateCatalog(parent, altCatalog.getCatalogURI());
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   453
        });
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   454
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   455
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   456
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   457
     * Loads a delegate catalog by the catalogId specified.
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   458
     *
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   459
     * @param parent the parent catalog of the delegate catalog
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   460
     * @param catalogURI the URI to the catalog
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   461
     */
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   462
    Catalog loadDelegateCatalog(CatalogImpl parent, URI catalogURI) {
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   463
        CatalogImpl delegateCatalog = null;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   464
        if (catalogURI != null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   465
            String catalogId = catalogURI.toASCIIString();
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   466
            if (verifyCatalogFile(parent, catalogURI)) {
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   467
                delegateCatalog = getLoadedCatalog(catalogId);
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   468
                if (delegateCatalog == null) {
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   469
                    delegateCatalog = new CatalogImpl(parent, features, catalogURI);
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   470
                    delegateCatalog.load();
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   471
                    delegateCatalogs.put(catalogId, delegateCatalog);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   472
                }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   473
            }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   474
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   475
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   476
        return delegateCatalog;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   477
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   478
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   479
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   480
     * Returns a previously loaded Catalog object if found.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   481
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   482
     * @param catalogId The systemId of a catalog
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   483
     * @return a Catalog object previously loaded, or null if none in the saved
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   484
     * list
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   485
     */
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   486
    CatalogImpl getLoadedCatalog(String catalogId) {
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   487
        CatalogImpl c = null;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   488
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   489
        //check delegate Catalogs
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   490
        c = delegateCatalogs.get(catalogId);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   491
        if (c == null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   492
            //check other loaded Catalogs
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   493
            c = loadedCatalogs.get(catalogId);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   494
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   495
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   496
        return c;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   497
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   498
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   499
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   500
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   501
     * Verifies that the catalog file represented by the catalogId exists. If it
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   502
     * doesn't, returns false to ignore it as specified in the Catalog
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   503
     * specification, section 8. Resource Failures.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   504
     * <p>
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   505
     * Verifies that the catalog represented by the catalogId has not been
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   506
     * searched or is not circularly referenced.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   507
     *
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   508
     * @param parent the parent of the catalog to be loaded
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   509
     * @param catalogURI the URI to the catalog
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   510
     * @throws CatalogException if circular reference is found.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   511
     * @return true if the catalogId passed verification, false otherwise
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   512
     */
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   513
    final boolean verifyCatalogFile(CatalogImpl parent, URI catalogURI) {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   514
        if (catalogURI == null) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   515
            return false;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   516
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   517
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   518
        //Ignore it if it doesn't exist
43121
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   519
        if (Util.isFileUri(catalogURI) &&
e73af7b6ce47 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents: 40753
diff changeset
   520
                !Util.isFileUriExist(catalogURI, false)) {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   521
            return false;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   522
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   523
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   524
        String catalogId = catalogURI.toASCIIString();
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   525
        if (catalogsSearched.contains(catalogId) || isCircular(parent, catalogId)) {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   526
            CatalogMessages.reportRunTimeError(CatalogMessages.ERR_CIRCULAR_REFERENCE,
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   527
                    new Object[]{CatalogMessages.sanitize(catalogId)});
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   528
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   529
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   530
        return true;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   531
    }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   532
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   533
    /**
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   534
     * Checks whether the catalog is circularly referenced
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   535
     *
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   536
     * @param parent the parent of the catalog to be loaded
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   537
     * @param systemId the system identifier of the catalog to be loaded
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   538
     * @return true if is circular, false otherwise
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   539
     */
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   540
    boolean isCircular(CatalogImpl parent, String systemId) {
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   541
        // first, check the parent of the catalog to be loaded
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   542
        if (parent == null) {
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   543
            return false;
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   544
        }
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   545
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   546
        if (parent.systemId.equals(systemId)) {
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   547
            return true;
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   548
        }
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   549
44380
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   550
       // next, check parent's parent
0197177795e9 8176405: Catalog circular reference check did not work in certain scenarios
joehw
parents: 43121
diff changeset
   551
        return parent.isCircular(parent.parent, systemId);
40753
7fdd41fa7d26 8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents: 38497
diff changeset
   552
    }
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   553
}