author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 43121 | jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java@e73af7b6ce47 |
permissions | -rw-r--r-- |
33542 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package javax.xml.catalog; |
|
26 |
||
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
27 |
import java.net.URI; |
33542 | 28 |
|
29 |
/** |
|
30 |
* The Catalog Manager manages the creation of XML Catalogs and Catalog Resolvers. |
|
31 |
* |
|
32 |
* @since 9 |
|
33 |
*/ |
|
34 |
public final class CatalogManager { |
|
35 |
/** |
|
36 |
* Creating CatalogManager instance is not allowed. |
|
37 |
*/ |
|
38 |
private CatalogManager() { |
|
39 |
} |
|
40 |
||
41 |
/** |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
42 |
* Creates a {@code Catalog} object using the specified feature settings and |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
43 |
* uri(s) to one or more catalog files. |
33542 | 44 |
* <p> |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
45 |
* If {@code uris} is empty, system property {@code javax.xml.catalog.files}, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
46 |
* as defined in {@link CatalogFeatures}, will be read to locate the initial |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
47 |
* list of catalog files. |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
48 |
* <p> |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
49 |
* If multiple catalog files are specified through the {@code uris} argument or |
33542 | 50 |
* {@code javax.xml.catalog.files} property, the first entry is considered |
51 |
* the main catalog, while others are treated as alternative catalogs after |
|
52 |
* those referenced by the {@code nextCatalog} elements in the main catalog. |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
53 |
* <p> |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
54 |
* As specified in |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
55 |
* <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail"> |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
56 |
* XML Catalogs, OASIS Standard V1.1</a>, if a catalog entry is invalid, it |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
57 |
* is ignored. In case all entries are invalid, the resulting Catalog object |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
58 |
* will contain no Catalog elements. Any matching operation using the Catalog |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
59 |
* will return null. |
33542 | 60 |
* |
61 |
* @param features the catalog features |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
62 |
* @param uris uri(s) to one or more catalogs. |
33542 | 63 |
* |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
64 |
* @return an instance of a {@code Catalog} |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
65 |
* @throws IllegalArgumentException if either the URIs are not absolute |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
66 |
* or do not have a URL protocol handler for the URI scheme |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
67 |
* @throws CatalogException If an error occurs while parsing the catalog |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
68 |
* @throws SecurityException if access to the resource is denied by the security manager |
33542 | 69 |
*/ |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
70 |
public static Catalog catalog(CatalogFeatures features, URI... uris) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
71 |
Util.validateUrisSyntax(uris); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
72 |
CatalogImpl catalog = new CatalogImpl(features, uris); |
40753
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
73 |
catalog.load(); |
7fdd41fa7d26
8162431: CatalogUriResolver with circular/self referencing catalog file is not throwing CatalogException as expected
joehw
parents:
40582
diff
changeset
|
74 |
return catalog; |
33542 | 75 |
} |
76 |
||
77 |
/** |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
78 |
* Creates an instance of a {@code CatalogResolver} using the specified catalog. |
33542 | 79 |
* |
80 |
* @param catalog the catalog instance |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
81 |
* @return an instance of a {@code CatalogResolver} |
33542 | 82 |
*/ |
83 |
public static CatalogResolver catalogResolver(Catalog catalog) { |
|
84 |
if (catalog == null) CatalogMessages.reportNPEOnNull("catalog", null); |
|
85 |
return new CatalogResolverImpl(catalog); |
|
86 |
} |
|
87 |
||
88 |
/** |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
89 |
* Creates an instance of a {@code CatalogResolver} using the specified feature |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
90 |
* settings and uri(s) to one or more catalog files. |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
91 |
* <p> |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
92 |
* If {@code uris} is empty, system property {@code javax.xml.catalog.files}, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
93 |
* as defined in {@link CatalogFeatures}, will be read to locate the initial |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
94 |
* list of catalog files. |
33542 | 95 |
* <p> |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
96 |
* If multiple catalog files are specified through the {@code uris} argument or |
33542 | 97 |
* {@code javax.xml.catalog.files} property, the first entry is considered |
98 |
* the main catalog, while others are treated as alternative catalogs after |
|
99 |
* those referenced by the {@code nextCatalog} elements in the main catalog. |
|
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
100 |
* <p> |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
101 |
* As specified in |
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
102 |
* <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail"> |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
103 |
* XML Catalogs, OASIS Standard V1.1</a>, if a catalog entry is invalid, it |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
104 |
* is ignored. In case all entries are invalid, the resulting CatalogResolver |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
105 |
* object will contain no valid catalog. Any resolution operation using the |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
106 |
* resolver therefore will return as no mapping is found. See {@link CatalogResolver} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
107 |
* for the behavior when no mapping is found. |
33542 | 108 |
* |
109 |
* @param features the catalog features |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
110 |
* @param uris the uri(s) to one or more catalogs |
33542 | 111 |
* |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
112 |
* @return an instance of a {@code CatalogResolver} |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
113 |
* @throws IllegalArgumentException if either the URIs are not absolute |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
114 |
* or do not have a URL protocol handler for the URI scheme |
34984
48a409c654e9
8144966: Catalog API: Null handling and reference to Reader
joehw
parents:
33542
diff
changeset
|
115 |
* @throws CatalogException If an error occurs while parsing the catalog |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
116 |
* @throws SecurityException if access to the resource is denied by the security manager |
33542 | 117 |
*/ |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
118 |
public static CatalogResolver catalogResolver(CatalogFeatures features, URI... uris) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40753
diff
changeset
|
119 |
Catalog catalog = catalog(features, uris); |
33542 | 120 |
return new CatalogResolverImpl(catalog); |
121 |
} |
|
122 |
} |