author | jjg |
Tue, 16 May 2017 17:36:12 -0700 | |
changeset 45261 | 8a151bf73222 |
parent 43121 | e73af7b6ce47 |
child 45855 | 46c3f654e80f |
permissions | -rw-r--r-- |
33542 | 1 |
/* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
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.net.MalformedURLException; |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
28 |
import java.net.URISyntaxException; |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
29 |
import java.util.HashMap; |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
30 |
import java.util.Map; |
33542 | 31 |
import jdk.xml.internal.SecuritySupport; |
32 |
||
33 |
/** |
|
34 |
* The CatalogFeatures holds a collection of features and properties. |
|
35 |
* <p> |
|
36 |
* |
|
37 |
* |
|
45261 | 38 |
* <table class="plain"> |
39 |
* <caption>Catalog Features</caption> |
|
33542 | 40 |
* <thead> |
41 |
* <tr> |
|
42 |
* <th rowspan="2">Feature</th> |
|
43 |
* <th rowspan="2">Description</th> |
|
44 |
* <th rowspan="2">Property Name</th> |
|
45 |
* <th rowspan="2">System Property [1]</th> |
|
46 |
* <th rowspan="2">jaxp.properties [1]</th> |
|
45261 | 47 |
* <th colspan="2" style="text-align:center">Value [2]</th> |
33542 | 48 |
* <th rowspan="2">Action</th> |
49 |
* </tr> |
|
50 |
* <tr> |
|
51 |
* <th>Type</th> |
|
52 |
* <th>Value</th> |
|
53 |
* </tr> |
|
54 |
* </thead> |
|
55 |
* <tbody> |
|
56 |
* |
|
57 |
* <tr> |
|
45261 | 58 |
* <td><a id="FILES">FILES</a></td> |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
59 |
* <td>A semicolon-delimited list of URIs to locate the catalog files. |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
60 |
* The URIs must be absolute and have a URL protocol handler for the URI scheme. |
33542 | 61 |
* </td> |
62 |
* <td>javax.xml.catalog.files</td> |
|
63 |
* <td>javax.xml.catalog.files</td> |
|
64 |
* <td>javax.xml.catalog.files</td> |
|
65 |
* <td>String</td> |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
66 |
* <td>URIs</td> |
33542 | 67 |
* <td> |
68 |
* Reads the first catalog as the current catalog; Loads others if no match |
|
69 |
* is found in the current catalog including delegate catalogs if any. |
|
70 |
* </td> |
|
71 |
* </tr> |
|
72 |
* |
|
73 |
* <tr> |
|
45261 | 74 |
* <td rowspan="2"><a id="PREFER">PREFER</a></td> |
33542 | 75 |
* <td rowspan="2">Indicates the preference between the public and system |
76 |
* identifiers. The default value is public [3].</td> |
|
77 |
* <td rowspan="2">javax.xml.catalog.prefer</td> |
|
78 |
* <td rowspan="2">N/A</td> |
|
79 |
* <td rowspan="2">N/A</td> |
|
80 |
* <td rowspan="2">String</td> |
|
81 |
* <td>{@code system}</td> |
|
82 |
* <td>Searches system entries for a match; Searches public entries when |
|
83 |
* external identifier specifies only a public identifier</td> |
|
84 |
* </tr> |
|
85 |
* <tr> |
|
86 |
* <td>{@code public}</td> |
|
87 |
* <td>Searches system entries for a match; Searches public entries when |
|
88 |
* there is no matching system entry.</td> |
|
89 |
* </tr> |
|
90 |
* |
|
91 |
* <tr> |
|
45261 | 92 |
* <td rowspan="2"><a id="DEFER">DEFER</a></td> |
33542 | 93 |
* <td rowspan="2">Indicates that the alternative catalogs including those |
94 |
* specified in delegate entries or nextCatalog are not read until they are |
|
95 |
* needed. The default value is true.</td> |
|
96 |
* <td rowspan="2">javax.xml.catalog.defer [4]</td> |
|
97 |
* <td rowspan="2">javax.xml.catalog.defer</td> |
|
98 |
* <td rowspan="2">javax.xml.catalog.defer</td> |
|
99 |
* <td rowspan="2">String</td> |
|
100 |
* <td>{@code true}</td> |
|
101 |
* <td>Loads alternative catalogs as needed. |
|
102 |
* </td> |
|
103 |
* </tr> |
|
104 |
* <tr> |
|
105 |
* <td>{@code false}</td> |
|
106 |
* <td>Loads all catalogs[5]. </td> |
|
107 |
* </tr> |
|
108 |
* |
|
109 |
* <tr> |
|
45261 | 110 |
* <td rowspan="3"><a id="RESOLVE">RESOLVE</a></td> |
33542 | 111 |
* <td rowspan="3">Determines the action if there is no matching entry found after |
112 |
* all of the specified catalogs are exhausted. The default is strict.</td> |
|
113 |
* <td rowspan="3">javax.xml.catalog.resolve [4]</td> |
|
114 |
* <td rowspan="3">javax.xml.catalog.resolve</td> |
|
115 |
* <td rowspan="3">javax.xml.catalog.resolve</td> |
|
116 |
* <td rowspan="3">String</td> |
|
117 |
* <td>{@code strict}</td> |
|
118 |
* <td>Throws CatalogException if there is no match. |
|
119 |
* </td> |
|
120 |
* </tr> |
|
121 |
* <tr> |
|
122 |
* <td>{@code continue}</td> |
|
123 |
* <td>Allows the XML parser to continue as if there is no match. |
|
124 |
* </td> |
|
125 |
* </tr> |
|
126 |
* <tr> |
|
127 |
* <td>{@code ignore}</td> |
|
128 |
* <td>Tells the XML parser to skip the external references if there no match. |
|
129 |
* </td> |
|
130 |
* </tr> |
|
131 |
* |
|
132 |
* </tbody> |
|
133 |
* </table> |
|
134 |
* <p> |
|
135 |
* <b>[1]</b> There is no System property for the features that marked as "N/A". |
|
136 |
* |
|
137 |
* <p> |
|
138 |
* <b>[2]</b> The value shall be exactly as listed in this table, case-sensitive. |
|
139 |
* Any unspecified value will result in {@link IllegalArgumentException}. |
|
140 |
* <p> |
|
141 |
* <b>[3]</b> The Catalog specification defined complex rules on |
|
142 |
* <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#attrib.prefer"> |
|
143 |
* the prefer attribute</a>. Although the prefer can be public or system, the |
|
144 |
* specification actually made system the preferred option, that is, no matter |
|
145 |
* the option, a system entry is always used if found. Public entries are only |
|
146 |
* considered if the prefer is public and system entries are not found. It is |
|
147 |
* therefore recommended that the prefer attribute be set as public |
|
148 |
* (which is the default). |
|
149 |
* <p> |
|
150 |
* <b>[4]</b> Although non-standard attributes in the OASIS Catalog specification, |
|
151 |
* {@code defer} and {@code resolve} are recognized by the Java Catalog API the |
|
152 |
* same as the {@code prefer} as being an attribute in the catalog entry of the |
|
153 |
* main catalog. Note that only the attributes specified for the catalog entry |
|
154 |
* of the main Catalog file will be used. |
|
155 |
* <p> |
|
156 |
* <b>[5]</b> If the intention is to share an entire catalog store, it may be desirable to |
|
157 |
* set the property {@code javax.xml.catalog.defer} to false to allow the entire |
|
158 |
* catalog to be pre-loaded. |
|
159 |
* <p> |
|
160 |
* <h3>Scope and Order</h3> |
|
161 |
* Features and properties can be set through the catalog file, the Catalog API, |
|
162 |
* system properties, and {@code jaxp.properties}, with a preference in the same order. |
|
163 |
* <p> |
|
164 |
* Properties that are specified as attributes in the catalog file for the |
|
165 |
* catalog and group entries shall take preference over any of the other settings. |
|
166 |
* For example, if a {@code prefer} attribute is set in the catalog file as in |
|
167 |
* {@code <catalog prefer="public">}, any other input for the "prefer" property |
|
168 |
* is not necessary or will be ignored. |
|
169 |
* <p> |
|
170 |
* Properties set through the Catalog API override those that may have been set |
|
171 |
* by system properties and/or in {@code jaxp.properties}. In case of multiple |
|
172 |
* interfaces, the latest in a procedure shall take preference. For |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
173 |
* {@link Feature#FILES}, this means that the URI(s) specified through the methods |
33542 | 174 |
* of the {@link CatalogManager} will override any that may have been entered |
175 |
* through the {@link Builder}. |
|
176 |
* |
|
177 |
* <p> |
|
178 |
* System properties when set shall override those in {@code jaxp.properties}. |
|
179 |
* <p> |
|
180 |
* The {@code jaxp.properties} file is typically in the conf directory of the Java |
|
181 |
* installation. The file is read only once by the JAXP implementation and |
|
182 |
* its values are then cached for future use. If the file does not exist |
|
183 |
* when the first attempt is made to read from it, no further attempts are |
|
184 |
* made to check for its existence. It is not possible to change the value |
|
185 |
* of any properties in {@code jaxp.properties} after it has been read. |
|
186 |
* <p> |
|
187 |
* A CatalogFeatures instance can be created through its builder as illustrated |
|
188 |
* in the following sample code: |
|
189 |
* <pre>{@code |
|
190 |
CatalogFeatures f = CatalogFeatures.builder() |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
191 |
.with(Feature.FILES, "file:///etc/xml/catalog") |
33542 | 192 |
.with(Feature.PREFER, "public") |
193 |
.with(Feature.DEFER, "true") |
|
194 |
.with(Feature.RESOLVE, "ignore") |
|
195 |
.build(); |
|
196 |
* }</pre> |
|
197 |
* |
|
39907 | 198 |
* <p> |
199 |
* <h3>JAXP XML Processor Support</h3> |
|
200 |
* The Catalog Features are supported throughout the JAXP processors, including |
|
201 |
* SAX and DOM ({@link javax.xml.parsers}), and StAX parsers ({@link javax.xml.stream}), |
|
202 |
* Schema Validation ({@link javax.xml.validation}), and XML Transformation |
|
203 |
* ({@link javax.xml.transform}). The features described above can be set through JAXP |
|
204 |
* factories or processors that define a setProperty or setAttribute interface. |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
205 |
* For example, the following code snippet sets a URI to a catalog file on a SAX |
39907 | 206 |
* parser through the {@code javax.xml.catalog.files} property: |
207 |
* <p> |
|
208 |
* <pre>{@code |
|
209 |
* SAXParserFactory spf = SAXParserFactory.newInstance(); |
|
210 |
* spf.setFeature(XMLConstants.USE_CATALOG, true); [1] |
|
211 |
* SAXParser parser = spf.newSAXParser(); |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
212 |
* parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), "file:///etc/xml/catalog"); |
39907 | 213 |
* }</pre> |
214 |
* <p> |
|
215 |
* [1] Note that this statement is not required since the default value of |
|
216 |
* {@link javax.xml.XMLConstants#USE_CATALOG USE_CATALOG} is true. |
|
217 |
* |
|
218 |
* <p> |
|
219 |
* The JAXP Processors' support for Catalog depends on both the |
|
220 |
* {@link javax.xml.XMLConstants#USE_CATALOG USE_CATALOG} feature and the |
|
221 |
* existence of valid Catalog file(s). A JAXP processor will use the Catalog |
|
222 |
* only when the feature is true and valid Catalog file(s) are specified through |
|
223 |
* the {@code javax.xml.catalog.files} property. It will make no attempt to use |
|
224 |
* the Catalog if either {@link javax.xml.XMLConstants#USE_CATALOG USE_CATALOG} |
|
225 |
* is set to false, or there is no Catalog file specified. |
|
226 |
* |
|
227 |
* <p> |
|
228 |
* The JAXP processors will observe the default settings of the |
|
229 |
* {@link javax.xml.catalog.CatalogFeatures}. The processors, for example, will |
|
230 |
* report an Exception by default when no matching entry is found since the |
|
231 |
* default value of the {@code javax.xml.catalog.resolve} property is strict. |
|
232 |
* |
|
233 |
* <p> |
|
234 |
* The JAXP processors give preference to user-specified custom resolvers. If such |
|
235 |
* a resolver is registered, it will be used over the CatalogResolver. If it returns |
|
236 |
* null however, the processors will continue resolving with the CatalogResolver. |
|
237 |
* If it returns an empty source, no attempt will be made by the CatalogResolver. |
|
238 |
* |
|
239 |
* <p> |
|
240 |
* The Catalog support is available for any process in the JAXP library that |
|
241 |
* supports a resolver. The following table lists all such processes. |
|
242 |
* |
|
243 |
* <p> |
|
45261 | 244 |
* <h3><a id="ProcessesWithCatalogSupport">Processes with Catalog Support</a></h3> |
39907 | 245 |
* |
45261 | 246 |
* <table class="striped"> |
247 |
* <caption>Processes with Catalog Support</caption> |
|
39907 | 248 |
* <thead> |
249 |
* <tr> |
|
250 |
* <th>Process</th> |
|
251 |
* <th>Catalog Entry Type</th> |
|
252 |
* <th>Example</th> |
|
253 |
* </tr> |
|
254 |
* </thead> |
|
255 |
* <tbody> |
|
256 |
* <tr> |
|
257 |
* <td>DTDs and external entities</td> |
|
258 |
* <td>public, system</td> |
|
259 |
* <td> |
|
260 |
* <pre>{@literal |
|
261 |
The following DTD reference: |
|
262 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
263 |
||
264 |
Can be resolved using the following Catalog entry: |
|
265 |
<public publicId="-//W3C//DTD XHTML 1.0 Strict//EN" uri="catalog/xhtml1-strict.dtd"/> |
|
266 |
or |
|
267 |
<systemSuffix systemIdSuffix="html1-strict.dtd" uri="catalog/xhtml1-strict.dtd"/> |
|
268 |
* }</pre> |
|
269 |
* </td> |
|
270 |
* </tr> |
|
271 |
* <tr> |
|
272 |
* <td>XInclude</td> |
|
273 |
* <td>uri</td> |
|
274 |
* <td> |
|
275 |
* <pre>{@literal |
|
276 |
The following XInclude element: |
|
277 |
<xi:include href="http://openjdk.java.net/xml/disclaimer.xml"/> |
|
278 |
||
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
279 |
can be resolved using a URI entry: |
39907 | 280 |
<uri name="http://openjdk.java.net/xml/disclaimer.xml" uri="file:///pathto/local/disclaimer.xml"/> |
281 |
or |
|
282 |
<uriSuffix uriSuffix="disclaimer.xml" uri="file:///pathto/local/disclaimer.xml"/> |
|
283 |
* }</pre> |
|
284 |
* </td> |
|
285 |
* </tr> |
|
286 |
* <tr> |
|
287 |
* <td>XSD import</td> |
|
288 |
* <td>uri</td> |
|
289 |
* <td> |
|
290 |
* <pre>{@literal |
|
291 |
The following import element: |
|
292 |
<xsd:import namespace="http://openjdk.java.net/xsd/XSDImport_person" |
|
293 |
schemaLocation="http://openjdk.java.net/xsd/XSDImport_person.xsd"/> |
|
294 |
||
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
295 |
can be resolved using a URI entry: |
39907 | 296 |
<uri name="http://openjdk.java.net/xsd/XSDImport_person.xsd" uri="file:///pathto/local/XSDImport_person.xsd"/> |
297 |
or |
|
298 |
<uriSuffix uriSuffix="XSDImport_person.xsd" uri="file:///pathto/local/XSDImport_person.xsd"/> |
|
299 |
or |
|
300 |
<uriSuffix uriSuffix="http://openjdk.java.net/xsd/XSDImport_person" uri="file:///pathto/local/XSDImport_person.xsd"/> |
|
301 |
* }</pre> |
|
302 |
* </td> |
|
303 |
* </tr> |
|
304 |
* <tr> |
|
305 |
* <td>XSD include</td> |
|
306 |
* <td>uri</td> |
|
307 |
* <td> |
|
308 |
* <pre>{@literal |
|
309 |
The following include element: |
|
310 |
<xsd:include schemaLocation="http://openjdk.java.net/xsd/XSDInclude_person.xsd"/> |
|
311 |
||
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
312 |
can be resolved using a URI entry: |
39907 | 313 |
<uri name="http://openjdk.java.net/xsd/XSDInclude_person.xsd" uri="file:///pathto/local/XSDInclude_person.xsd"/> |
314 |
or |
|
315 |
<uriSuffix uriSuffix="XSDInclude_person.xsd" uri="file:///pathto/local/XSDInclude_person.xsd"/> |
|
316 |
* }</pre> |
|
317 |
* </td> |
|
318 |
* </tr> |
|
319 |
* <tr> |
|
320 |
* <td>XSL import and include</td> |
|
321 |
* <td>uri</td> |
|
322 |
* <td> |
|
323 |
* <pre>{@literal |
|
324 |
The following include element: |
|
325 |
<xsl:include href="http://openjdk.java.net/xsl/include.xsl"/> |
|
326 |
||
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
327 |
can be resolved using a URI entry: |
39907 | 328 |
<uri name="http://openjdk.java.net/xsl/include.xsl" uri="file:///pathto/local/include.xsl"/> |
329 |
or |
|
330 |
<uriSuffix uriSuffix="include.xsl" uri="file:///pathto/local/include.xsl"/> |
|
331 |
* }</pre> |
|
332 |
* </td> |
|
333 |
* </tr> |
|
334 |
* <tr> |
|
335 |
* <td>XSL document function</td> |
|
336 |
* <td>uri</td> |
|
337 |
* <td> |
|
338 |
* <pre>{@literal |
|
339 |
The document in the following element: |
|
340 |
<xsl:variable name="dummy" select="document('http://openjdk.java.net/xsl/list.xml')"/> |
|
341 |
||
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
342 |
can be resolved using a URI entry: |
39907 | 343 |
<uri name="http://openjdk.java.net/xsl/list.xml" uri="file:///pathto/local/list.xml"/> |
344 |
or |
|
345 |
<uriSuffix uriSuffix="list.xml" uri="file:///pathto/local/list.xml"/> |
|
346 |
* }</pre> |
|
347 |
* </td> |
|
348 |
* </tr> |
|
349 |
* </tbody> |
|
350 |
* </table> |
|
351 |
* |
|
33542 | 352 |
* @since 9 |
353 |
*/ |
|
354 |
public class CatalogFeatures { |
|
355 |
||
356 |
/** |
|
39907 | 357 |
* The constant name of the javax.xml.catalog.files property as described |
358 |
* in the property table above. |
|
33542 | 359 |
*/ |
360 |
static final String CATALOG_FILES = "javax.xml.catalog.files"; |
|
361 |
||
362 |
/** |
|
39907 | 363 |
* The javax.xml.catalog.prefer property as described |
364 |
* in the property table above. |
|
33542 | 365 |
*/ |
366 |
static final String CATALOG_PREFER = "javax.xml.catalog.prefer"; |
|
367 |
||
368 |
/** |
|
39907 | 369 |
* The javax.xml.catalog.defer property as described |
370 |
* in the property table above. |
|
33542 | 371 |
*/ |
372 |
static final String CATALOG_DEFER = "javax.xml.catalog.defer"; |
|
373 |
||
374 |
/** |
|
39907 | 375 |
* The javax.xml.catalog.resolve property as described |
376 |
* in the property table above. |
|
33542 | 377 |
*/ |
378 |
static final String CATALOG_RESOLVE = "javax.xml.catalog.resolve"; |
|
379 |
||
380 |
//values for the prefer property |
|
381 |
static final String PREFER_SYSTEM = "system"; |
|
382 |
static final String PREFER_PUBLIC = "public"; |
|
383 |
||
384 |
//values for the defer property |
|
385 |
static final String DEFER_TRUE = "true"; |
|
386 |
static final String DEFER_FALSE = "false"; |
|
387 |
||
388 |
//values for the Resolve property |
|
389 |
static final String RESOLVE_STRICT = "strict"; |
|
390 |
static final String RESOLVE_CONTINUE = "continue"; |
|
391 |
static final String RESOLVE_IGNORE = "ignore"; |
|
392 |
||
393 |
/** |
|
394 |
* A Feature type as defined in the |
|
395 |
* <a href="CatalogFeatures.html#CatalogFeatures">Catalog Features table</a>. |
|
396 |
*/ |
|
397 |
public static enum Feature { |
|
398 |
/** |
|
399 |
* The {@code javax.xml.catalog.files} property as described in |
|
400 |
* item <a href="CatalogFeatures.html#FILES">FILES</a> of the |
|
401 |
* Catalog Features table. |
|
402 |
*/ |
|
403 |
FILES(CATALOG_FILES, null, true), |
|
404 |
/** |
|
405 |
* The {@code javax.xml.catalog.prefer} property as described in |
|
406 |
* item <a href="CatalogFeatures.html#PREFER">PREFER</a> of the |
|
407 |
* Catalog Features table. |
|
408 |
*/ |
|
409 |
PREFER(CATALOG_PREFER, PREFER_PUBLIC, false), |
|
410 |
/** |
|
411 |
* The {@code javax.xml.catalog.defer} property as described in |
|
412 |
* item <a href="CatalogFeatures.html#DEFER">DEFER</a> of the |
|
413 |
* Catalog Features table. |
|
414 |
*/ |
|
415 |
DEFER(CATALOG_DEFER, DEFER_TRUE, true), |
|
416 |
/** |
|
417 |
* The {@code javax.xml.catalog.resolve} property as described in |
|
418 |
* item <a href="CatalogFeatures.html#RESOLVE">RESOLVE</a> of the |
|
419 |
* Catalog Features table. |
|
420 |
*/ |
|
421 |
RESOLVE(CATALOG_RESOLVE, RESOLVE_STRICT, true); |
|
422 |
||
423 |
private final String name; |
|
424 |
private final String defaultValue; |
|
425 |
private String value; |
|
426 |
private final boolean hasSystem; |
|
427 |
||
428 |
/** |
|
429 |
* Constructs a CatalogFeature instance. |
|
430 |
* @param name the name of the feature |
|
431 |
* @param value the value of the feature |
|
432 |
* @param hasSystem a flag to indicate whether the feature is supported |
|
433 |
* with a System property |
|
434 |
*/ |
|
435 |
Feature(String name, String value, boolean hasSystem) { |
|
436 |
this.name = name; |
|
437 |
this.defaultValue = value; |
|
438 |
this.hasSystem = hasSystem; |
|
439 |
} |
|
440 |
||
441 |
/** |
|
442 |
* Checks whether the specified property is equal to the current property. |
|
443 |
* @param propertyName the name of a property |
|
444 |
* @return true if the specified property is the current property, false |
|
445 |
* otherwise |
|
446 |
*/ |
|
447 |
boolean equalsPropertyName(String propertyName) { |
|
448 |
return name.equals(propertyName); |
|
449 |
} |
|
450 |
||
451 |
/** |
|
452 |
* Returns the name of the corresponding System Property. |
|
453 |
* |
|
454 |
* @return the name of the System Property |
|
455 |
*/ |
|
456 |
public String getPropertyName() { |
|
457 |
return name; |
|
458 |
} |
|
459 |
||
460 |
/** |
|
461 |
* Returns the default value of the property. |
|
462 |
* @return the default value of the property |
|
463 |
*/ |
|
39907 | 464 |
public String defaultValue() { |
33542 | 465 |
return defaultValue; |
466 |
} |
|
467 |
||
468 |
/** |
|
469 |
* Returns the value of the property. |
|
470 |
* @return the value of the property |
|
471 |
*/ |
|
472 |
String getValue() { |
|
473 |
return value; |
|
474 |
} |
|
475 |
||
476 |
/** |
|
477 |
* Checks whether System property is supported for the feature. |
|
478 |
* @return true it is supported, false otherwise |
|
479 |
*/ |
|
480 |
boolean hasSystemProperty() { |
|
481 |
return hasSystem; |
|
482 |
} |
|
483 |
} |
|
484 |
||
485 |
/** |
|
486 |
* States of the settings of a property, in the order: default value, |
|
487 |
* jaxp.properties file, jaxp system properties, and jaxp api properties |
|
488 |
*/ |
|
489 |
static enum State { |
|
490 |
/** represents the default state of a feature. */ |
|
491 |
DEFAULT("default"), |
|
492 |
/** indicates the value of the feature is read from jaxp.properties. */ |
|
493 |
JAXPDOTPROPERTIES("jaxp.properties"), |
|
494 |
/** indicates the value of the feature is read from its System property. */ |
|
495 |
SYSTEMPROPERTY("system property"), |
|
496 |
/** indicates the value of the feature is specified through the API. */ |
|
497 |
APIPROPERTY("property"), |
|
498 |
/** indicates the value of the feature is specified as a catalog attribute. */ |
|
499 |
CATALOGATTRIBUTE("catalog attribute"); |
|
500 |
||
501 |
final String literal; |
|
502 |
||
503 |
State(String literal) { |
|
504 |
this.literal = literal; |
|
505 |
} |
|
506 |
||
507 |
String literal() { |
|
508 |
return literal; |
|
509 |
} |
|
510 |
} |
|
511 |
||
512 |
/** |
|
513 |
* Values of the properties |
|
514 |
*/ |
|
515 |
private String[] values; |
|
516 |
||
517 |
/** |
|
518 |
* States of the settings for each property |
|
519 |
*/ |
|
520 |
private State[] states; |
|
521 |
||
522 |
/** |
|
523 |
* Private class constructor |
|
524 |
*/ |
|
525 |
private CatalogFeatures() { |
|
526 |
} |
|
527 |
||
528 |
/** |
|
529 |
* Returns a CatalogFeatures instance with default settings. |
|
530 |
* @return a default CatalogFeatures instance |
|
531 |
*/ |
|
532 |
public static CatalogFeatures defaults() { |
|
533 |
return CatalogFeatures.builder().build(); |
|
534 |
} |
|
535 |
||
536 |
/** |
|
537 |
* Constructs a new CatalogFeatures instance with the builder. |
|
538 |
* |
|
539 |
* @param builder the builder to build the CatalogFeatures |
|
540 |
*/ |
|
541 |
CatalogFeatures(Builder builder) { |
|
542 |
init(); |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
543 |
setProperties(builder); |
33542 | 544 |
} |
545 |
||
546 |
/** |
|
547 |
* Returns the value of the specified feature. |
|
548 |
* |
|
549 |
* @param cf the type of the Catalog feature |
|
550 |
* @return the value of the feature |
|
551 |
*/ |
|
552 |
public String get(Feature cf) { |
|
553 |
return values[cf.ordinal()]; |
|
554 |
} |
|
555 |
||
556 |
/** |
|
557 |
* Initializes the supported properties |
|
558 |
*/ |
|
559 |
private void init() { |
|
560 |
values = new String[Feature.values().length]; |
|
561 |
states = new State[Feature.values().length]; |
|
562 |
for (Feature cf : Feature.values()) { |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
563 |
setProperty(cf, State.DEFAULT, cf.defaultValue()); |
33542 | 564 |
} |
565 |
//read system properties or jaxp.properties |
|
566 |
readSystemProperties(); |
|
567 |
} |
|
568 |
||
569 |
/** |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
570 |
* Sets properties by the Builder. |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
571 |
* @param builder the CatalogFeatures builder |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
572 |
*/ |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
573 |
private void setProperties(Builder builder) { |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
574 |
builder.values.entrySet().stream().forEach((entry) -> { |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
575 |
setProperty(entry.getKey(), State.APIPROPERTY, entry.getValue()); |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
576 |
}); |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
577 |
} |
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
578 |
/** |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
579 |
* Sets the value of a property, updates only if it shall override. |
33542 | 580 |
* |
581 |
* @param index the index of the property |
|
582 |
* @param state the state of the property |
|
583 |
* @param value the value of the property |
|
584 |
* @throws IllegalArgumentException if the value is invalid |
|
585 |
*/ |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
586 |
private void setProperty(Feature feature, State state, String value) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
587 |
int index = feature.ordinal(); |
33542 | 588 |
if (value != null && value.length() != 0) { |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
589 |
if (state != State.APIPROPERTY) { |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
590 |
Util.validateFeatureInput(feature, value); |
33542 | 591 |
} |
592 |
if (states[index] == null || state.compareTo(states[index]) >= 0) { |
|
593 |
values[index] = value; |
|
594 |
states[index] = state; |
|
595 |
} |
|
596 |
} |
|
597 |
} |
|
598 |
||
599 |
/** |
|
600 |
* Reads from system properties, or those in jaxp.properties |
|
601 |
*/ |
|
602 |
private void readSystemProperties() { |
|
603 |
for (Feature cf : Feature.values()) { |
|
604 |
getSystemProperty(cf, cf.getPropertyName()); |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
/** |
|
609 |
* Reads from system properties, or those in jaxp.properties |
|
610 |
* |
|
611 |
* @param cf the type of the property |
|
612 |
* @param sysPropertyName the name of system property |
|
613 |
*/ |
|
614 |
private boolean getSystemProperty(Feature cf, String sysPropertyName) { |
|
615 |
if (cf.hasSystemProperty()) { |
|
616 |
String value = SecuritySupport.getSystemProperty(sysPropertyName); |
|
617 |
if (value != null && !value.equals("")) { |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
618 |
setProperty(cf, State.SYSTEMPROPERTY, value); |
33542 | 619 |
return true; |
620 |
} |
|
621 |
||
622 |
value = SecuritySupport.readJAXPProperty(sysPropertyName); |
|
623 |
if (value != null && !value.equals("")) { |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
624 |
setProperty(cf, State.JAXPDOTPROPERTIES, value); |
33542 | 625 |
return true; |
626 |
} |
|
627 |
} |
|
628 |
return false; |
|
629 |
} |
|
630 |
||
631 |
/** |
|
632 |
* Returns an instance of the builder for creating the CatalogFeatures object. |
|
633 |
* |
|
634 |
* @return an instance of the builder |
|
635 |
*/ |
|
636 |
public static Builder builder() { |
|
637 |
return new CatalogFeatures.Builder(); |
|
638 |
} |
|
639 |
||
640 |
/** |
|
641 |
* The Builder class for building the CatalogFeatures object. |
|
642 |
*/ |
|
643 |
public static class Builder { |
|
644 |
/** |
|
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
645 |
* Values of the features supported by CatalogFeatures. |
33542 | 646 |
*/ |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
647 |
Map<Feature, String> values = new HashMap<>(); |
33542 | 648 |
|
649 |
/** |
|
650 |
* Instantiation of Builder is not allowed. |
|
651 |
*/ |
|
652 |
private Builder() {} |
|
653 |
||
654 |
/** |
|
655 |
* Sets the value to a specified Feature. |
|
656 |
* @param feature the Feature to be set |
|
657 |
* @param value the value to be set for the Feature |
|
658 |
* @return this Builder instance |
|
659 |
* @throws IllegalArgumentException if the value is not valid for the |
|
660 |
* Feature or has the wrong syntax for the {@code javax.xml.catalog.files} |
|
661 |
* property |
|
662 |
*/ |
|
663 |
public Builder with(Feature feature, String value) { |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
39907
diff
changeset
|
664 |
Util.validateFeatureInput(feature, value); |
36700
3afcaff239f5
8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents:
33542
diff
changeset
|
665 |
values.put(feature, value); |
33542 | 666 |
return this; |
667 |
} |
|
668 |
||
669 |
/** |
|
670 |
* Returns a CatalogFeatures object built by this builder. |
|
671 |
* |
|
672 |
* @return an instance of CatalogFeatures |
|
673 |
*/ |
|
674 |
public CatalogFeatures build() { |
|
675 |
return new CatalogFeatures(this); |
|
676 |
} |
|
677 |
} |
|
678 |
} |