author | thartmann |
Fri, 24 Aug 2018 08:17:23 +0200 | |
changeset 51514 | 1e332d63bd96 |
parent 47216 | 71c04702a3d5 |
child 52902 | e3398b2e1ab0 |
permissions | -rw-r--r-- |
33542 | 1 |
/* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
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 |
||
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
27 |
import java.io.File; |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
28 |
import java.io.IOException; |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
29 |
import java.net.MalformedURLException; |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
30 |
import java.net.URI; |
38497 | 31 |
import java.util.Iterator; |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
32 |
import java.util.jar.JarEntry; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
33 |
import java.util.jar.JarFile; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
34 |
import static javax.xml.catalog.CatalogFeatures.DEFER_FALSE; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
35 |
import static javax.xml.catalog.CatalogFeatures.DEFER_TRUE; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
36 |
import javax.xml.catalog.CatalogFeatures.Feature; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
37 |
import static javax.xml.catalog.CatalogFeatures.PREFER_PUBLIC; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
38 |
import static javax.xml.catalog.CatalogFeatures.PREFER_SYSTEM; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
39 |
import static javax.xml.catalog.CatalogFeatures.RESOLVE_CONTINUE; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
40 |
import static javax.xml.catalog.CatalogFeatures.RESOLVE_IGNORE; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
41 |
import static javax.xml.catalog.CatalogFeatures.RESOLVE_STRICT; |
33542 | 42 |
import jdk.xml.internal.SecuritySupport; |
43 |
||
44 |
/** |
|
45 |
* |
|
46 |
* @since 9 |
|
47 |
*/ |
|
48 |
class Util { |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
49 |
|
38497 | 50 |
final static String URN = "urn:publicid:"; |
51 |
final static String PUBLICID_PREFIX = "-//"; |
|
52 |
final static String PUBLICID_PREFIX_ALT = "+//"; |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
53 |
final static String SCHEME_FILE = "file"; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
54 |
final static String SCHEME_JAR = "jar"; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
55 |
final static String SCHEME_JARFILE = "jar:file:"; |
38497 | 56 |
|
57 |
/** |
|
58 |
* Finds an entry in the catalog that matches with the publicId or systemId. |
|
59 |
* |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
60 |
* The resolution follows the following rules determined by the prefer |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
61 |
* setting: |
38497 | 62 |
* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
63 |
* prefer "system": attempts to resolve with a system entry; attempts to |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
64 |
* resolve with a public entry when only publicId is specified. |
38497 | 65 |
* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
66 |
* prefer "public": attempts to resolve with a system entry; attempts to |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
67 |
* resolve with a public entry if no matching system entry is found. |
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
38497
diff
changeset
|
68 |
* |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
38497
diff
changeset
|
69 |
* If no match is found, continue searching uri entries |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
38497
diff
changeset
|
70 |
* |
38497 | 71 |
* @param catalog the catalog |
72 |
* @param publicId the publicId |
|
73 |
* @param systemId the systemId |
|
74 |
* @return the resolved systemId if a match is found, null otherwise |
|
75 |
*/ |
|
76 |
static String resolve(CatalogImpl catalog, String publicId, String systemId) { |
|
77 |
String resolvedSystemId = null; |
|
78 |
||
79 |
//search the current catalog |
|
80 |
catalog.reset(); |
|
81 |
if (systemId != null) { |
|
82 |
/* |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
83 |
If a system identifier is specified, it is used no matter how |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
84 |
prefer is set. |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
85 |
*/ |
38497 | 86 |
resolvedSystemId = catalog.matchSystem(systemId); |
87 |
} |
|
88 |
||
89 |
if (resolvedSystemId == null && publicId != null) { |
|
90 |
resolvedSystemId = catalog.matchPublic(publicId); |
|
91 |
} |
|
92 |
||
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
38497
diff
changeset
|
93 |
if (resolvedSystemId == null && systemId != null) { |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
38497
diff
changeset
|
94 |
resolvedSystemId = catalog.matchURI(systemId); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
38497
diff
changeset
|
95 |
} |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
38497
diff
changeset
|
96 |
|
38497 | 97 |
//mark the catalog as having been searched before trying alternatives |
98 |
catalog.markAsSearched(); |
|
99 |
||
100 |
//search alternative catalogs |
|
101 |
if (resolvedSystemId == null) { |
|
102 |
Iterator<Catalog> iter = catalog.catalogs().iterator(); |
|
103 |
while (iter.hasNext()) { |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
104 |
resolvedSystemId = resolve((CatalogImpl) iter.next(), publicId, systemId); |
38497 | 105 |
if (resolvedSystemId != null) { |
106 |
break; |
|
107 |
} |
|
108 |
||
109 |
} |
|
110 |
} |
|
111 |
||
112 |
return resolvedSystemId; |
|
113 |
} |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
114 |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
115 |
static void validateUrisSyntax(URI... uris) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
116 |
for (URI uri : uris) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
117 |
validateUriSyntax(uri); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
118 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
119 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
120 |
|
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
121 |
static void validateUrisSyntax(String... uris) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
122 |
for (String uri : uris) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
123 |
validateUriSyntax(URI.create(uri)); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
124 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
125 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
126 |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
127 |
/** |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
128 |
* Validate that the URI must be absolute and a valid URL. |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
129 |
* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
130 |
* Note that this method does not verify the existence of the resource. The |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
131 |
* Catalog standard requires that such resources be ignored. |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
132 |
* |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
133 |
* @param uri |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
134 |
* @throws IllegalArgumentException if the uri is not absolute and a valid |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
135 |
* URL |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
136 |
*/ |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
137 |
static void validateUriSyntax(URI uri) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
138 |
CatalogMessages.reportNPEOnNull("URI input", uri); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
139 |
|
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
140 |
if (!uri.isAbsolute()) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
141 |
CatalogMessages.reportIAE(CatalogMessages.ERR_URI_NOTABSOLUTE, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
142 |
new Object[]{uri}, null); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
143 |
} |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
144 |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
145 |
try { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
146 |
// check if the scheme was valid |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
147 |
uri.toURL(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
148 |
} catch (MalformedURLException ex) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
149 |
CatalogMessages.reportIAE(CatalogMessages.ERR_URI_NOTVALIDURL, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
150 |
new Object[]{uri}, null); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
151 |
} |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
152 |
} |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
153 |
|
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
154 |
/** |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
155 |
* Checks whether the URI is a file URI, including JAR file. |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
156 |
* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
157 |
* @param uri the specified URI. |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
158 |
* @return true if it is a file or JAR file URI, false otherwise |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
159 |
*/ |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
160 |
static boolean isFileUri(URI uri) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
161 |
if (SCHEME_FILE.equals(uri.getScheme()) |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
162 |
|| SCHEME_JAR.equals(uri.getScheme())) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
163 |
return true; |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
164 |
} |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
165 |
return false; |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
166 |
} |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
167 |
|
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
168 |
/** |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
169 |
* Verifies whether the file resource exists. |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
170 |
* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
171 |
* @param uri the URI to locate the resource |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
172 |
* @param openJarFile a flag to indicate whether a JAR file should be |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
173 |
* opened. This operation may be expensive. |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
174 |
* @return true if the resource exists, false otherwise. |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
175 |
*/ |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
176 |
static boolean isFileUriExist(URI uri, boolean openJarFile) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
177 |
if (uri != null && uri.isAbsolute()) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
178 |
if (null != uri.getScheme()) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
179 |
switch (uri.getScheme()) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
180 |
case SCHEME_FILE: |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
181 |
String path = uri.getPath(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
182 |
File f1 = new File(path); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
183 |
if (f1.isFile()) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
184 |
return true; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
185 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
186 |
break; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
187 |
case SCHEME_JAR: |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
188 |
String tempUri = uri.toString(); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
189 |
int pos = tempUri.indexOf("!"); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
190 |
if (pos < 0) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
191 |
return false; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
192 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
193 |
if (openJarFile) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
194 |
String jarFile = tempUri.substring(SCHEME_JARFILE.length(), pos); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
195 |
String entryName = tempUri.substring(pos + 2); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
196 |
try { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
197 |
JarFile jf = new JarFile(jarFile); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
198 |
JarEntry je = jf.getJarEntry(entryName); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
199 |
if (je != null) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
200 |
return true; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
201 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
202 |
} catch (IOException ex) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
203 |
return false; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
204 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
205 |
} else { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
206 |
return true; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
207 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
208 |
break; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
209 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
210 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
211 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
212 |
return false; |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
213 |
} |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
214 |
|
33542 | 215 |
/** |
216 |
* Find catalog file paths by reading the system property, and then |
|
217 |
* jaxp.properties if the system property is not specified. |
|
218 |
* |
|
219 |
* @param sysPropertyName the name of system property |
|
220 |
* @return the catalog file paths, or null if not found. |
|
221 |
*/ |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
222 |
static String[] getCatalogFiles(String sysPropertyName) { |
33542 | 223 |
String value = SecuritySupport.getJAXPSystemProperty(sysPropertyName); |
224 |
if (value != null && !value.equals("")) { |
|
225 |
return value.split(";"); |
|
226 |
} |
|
227 |
return null; |
|
228 |
} |
|
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
229 |
|
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
230 |
/** |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
231 |
* Checks whether the specified string is null or empty, returns the |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
232 |
* original string with leading and trailing spaces removed if not. |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
233 |
* |
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
234 |
* @param test the string to be tested |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
235 |
* @return the original string with leading and trailing spaces removed, or |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
236 |
* null if it is null or empty |
37382
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
237 |
* |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
238 |
*/ |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
239 |
static String getNotNullOrEmpty(String test) { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
240 |
if (test == null) { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
241 |
return test; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
242 |
} else { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
243 |
String temp = test.trim(); |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
244 |
if (temp.length() == 0) { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
245 |
return null; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
246 |
} else { |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
247 |
return temp; |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
248 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
249 |
} |
c7d898d8da12
8151162: Public entries not searched when prefer='system'
joehw
parents:
36700
diff
changeset
|
250 |
} |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
251 |
|
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
252 |
/** |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
253 |
* Validates the input for features. |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
254 |
* |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
255 |
* @param f the feature |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
256 |
* @param value the value |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
257 |
* @throws IllegalArgumentException if the value is invalid for the feature |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
258 |
*/ |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
259 |
static void validateFeatureInput(Feature f, String value) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
260 |
CatalogMessages.reportNPEOnNull(f.name(), value); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
261 |
if (value.length() == 0) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
262 |
CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
263 |
new Object[]{value, f.name()}, null); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
264 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
265 |
|
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
266 |
if (f == Feature.PREFER) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
267 |
if (!value.equals(PREFER_SYSTEM) && !value.equals(PREFER_PUBLIC)) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
268 |
CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
269 |
new Object[]{value, Feature.PREFER.name()}, null); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
270 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
271 |
} else if (f == Feature.DEFER) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
272 |
if (!value.equals(DEFER_TRUE) && !value.equals(DEFER_FALSE)) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
273 |
CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
274 |
new Object[]{value, Feature.DEFER.name()}, null); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
275 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
276 |
} else if (f == Feature.RESOLVE) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
277 |
if (!value.equals(RESOLVE_STRICT) && !value.equals(RESOLVE_CONTINUE) |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
278 |
&& !value.equals(RESOLVE_IGNORE)) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
279 |
CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
280 |
new Object[]{value, Feature.RESOLVE.name()}, null); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
281 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
282 |
} else if (f == Feature.FILES) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
283 |
Util.validateUrisSyntax(value.split(";")); |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
284 |
} |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
40582
diff
changeset
|
285 |
} |
33542 | 286 |
} |