mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8144966: Catalog API: Null handling and reference to Reader
Reviewed-by: mchung, rriggs
This commit is contained in:
parent
a4d59b2815
commit
fdb8990307
7 changed files with 123 additions and 83 deletions
|
@ -32,7 +32,6 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
@ -43,6 +42,7 @@ import java.util.stream.StreamSupport;
|
|||
import static javax.xml.catalog.BaseEntry.CatalogEntryType;
|
||||
import static javax.xml.catalog.CatalogFeatures.DEFER_TRUE;
|
||||
import javax.xml.catalog.CatalogFeatures.Feature;
|
||||
import static javax.xml.catalog.CatalogMessages.formatMessage;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
@ -109,25 +109,20 @@ class CatalogImpl extends GroupEntry implements Catalog {
|
|||
*/
|
||||
public CatalogImpl(CatalogImpl parent, CatalogFeatures f, String... file) throws CatalogException {
|
||||
super(CatalogEntryType.CATALOG);
|
||||
this.parent = parent;
|
||||
if (parent == null) {
|
||||
level = 0;
|
||||
} else {
|
||||
level = parent.level + 1;
|
||||
}
|
||||
if (f == null) {
|
||||
this.features = CatalogFeatures.defaults();
|
||||
} else {
|
||||
this.features = f;
|
||||
throw new NullPointerException(
|
||||
formatMessage(CatalogMessages.ERR_NULL_ARGUMENT, new Object[]{"CatalogFeatures"}));
|
||||
}
|
||||
setPrefer(features.get(Feature.PREFER));
|
||||
setDeferred(features.get(Feature.DEFER));
|
||||
setResolve(features.get(Feature.RESOLVE));
|
||||
|
||||
if (file.length > 0) {
|
||||
CatalogMessages.reportNPEOnNull("The path to the catalog file", file[0]);
|
||||
}
|
||||
|
||||
init(parent, f);
|
||||
|
||||
//Path of catalog files
|
||||
String[] catalogFile = file;
|
||||
if (level == 0
|
||||
&& (file == null || (file.length == 0 || file[0] == null))) {
|
||||
if (level == 0 && file.length == 0) {
|
||||
String files = features.get(Feature.FILES);
|
||||
if (files != null) {
|
||||
catalogFile = files.split(";[ ]*");
|
||||
|
@ -166,6 +161,23 @@ class CatalogImpl extends GroupEntry implements Catalog {
|
|||
}
|
||||
}
|
||||
|
||||
private void init(CatalogImpl parent, CatalogFeatures f) {
|
||||
this.parent = parent;
|
||||
if (parent == null) {
|
||||
level = 0;
|
||||
} else {
|
||||
level = parent.level + 1;
|
||||
}
|
||||
if (f == null) {
|
||||
this.features = CatalogFeatures.defaults();
|
||||
} else {
|
||||
this.features = f;
|
||||
}
|
||||
setPrefer(features.get(Feature.PREFER));
|
||||
setDeferred(features.get(Feature.DEFER));
|
||||
setResolve(features.get(Feature.RESOLVE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the Catalog instance to its initial state.
|
||||
*/
|
||||
|
|
|
@ -38,33 +38,38 @@ public final class CatalogManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a Catalog object using the specified feature settings and path to
|
||||
* a catalog file. If the features is null, the default features will be used.
|
||||
* If the path is empty, System property {@code javax.xml.catalog.files} will
|
||||
* be read to locate the initial list of catalog files.
|
||||
* Creates a {@code Catalog} object using the specified feature settings and
|
||||
* path to one or more catalog files.
|
||||
* <p>
|
||||
* If more than one catalog files are specified through the path argument or
|
||||
* If {@code paths} is empty, system property {@code javax.xml.catalog.files}
|
||||
* will be read to locate the initial list of catalog files.
|
||||
* <p>
|
||||
* If more than one catalog files are specified through the paths argument or
|
||||
* {@code javax.xml.catalog.files} property, the first entry is considered
|
||||
* the main catalog, while others are treated as alternative catalogs after
|
||||
* those referenced by the {@code nextCatalog} elements in the main catalog.
|
||||
* <p>
|
||||
* As specified in
|
||||
* <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail">
|
||||
* XML Catalogs, OASIS Standard V1.1</a>, invalid path entries will be ignored.
|
||||
* No error will be reported. In case all entries are invalid, the resolver
|
||||
* will return as no mapping is found.
|
||||
*
|
||||
* @param features the catalog features
|
||||
* @param path path(s) to one or more catalogs.
|
||||
* @param paths path(s) to one or more catalogs.
|
||||
*
|
||||
* @return a catalog instance
|
||||
* @throws CatalogException If no catalog can be found whether through the
|
||||
* specified path or the System property {@code javax.xml.catalog.files}, or
|
||||
* an error occurs while parsing the catalog
|
||||
* @return an instance of a {@code Catalog}
|
||||
* @throws CatalogException If an error occurs while parsing the catalog
|
||||
*/
|
||||
public static Catalog catalog(CatalogFeatures features, String... path) {
|
||||
return new CatalogImpl(features, path);
|
||||
public static Catalog catalog(CatalogFeatures features, String... paths) {
|
||||
return new CatalogImpl(features, paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of a CatalogResolver using the specified catalog.
|
||||
* Creates an instance of a {@code CatalogResolver} using the specified catalog.
|
||||
*
|
||||
* @param catalog the catalog instance
|
||||
* @return an instance of a CatalogResolver
|
||||
* @return an instance of a {@code CatalogResolver}
|
||||
*/
|
||||
public static CatalogResolver catalogResolver(Catalog catalog) {
|
||||
if (catalog == null) CatalogMessages.reportNPEOnNull("catalog", null);
|
||||
|
@ -72,10 +77,10 @@ public final class CatalogManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of a CatalogUriResolver using the specified catalog.
|
||||
* Creates an instance of a {@code CatalogUriResolver} using the specified catalog.
|
||||
*
|
||||
* @param catalog the catalog instance
|
||||
* @return an instance of a CatalogResolver
|
||||
* @return an instance of a {@code CatalogResolver}
|
||||
*/
|
||||
public static CatalogUriResolver catalogUriResolver(Catalog catalog) {
|
||||
if (catalog == null) CatalogMessages.reportNPEOnNull("catalog", null);
|
||||
|
@ -83,50 +88,60 @@ public final class CatalogManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of a CatalogResolver using the specified feature settings
|
||||
* and path to a catalog file. If the features is null, the default features will
|
||||
* be used. If the path is empty, System property {@code javax.xml.catalog.files}
|
||||
* Creates an instance of a {@code CatalogResolver} using the specified feature
|
||||
* settings and path to one or more catalog files.
|
||||
* <p>
|
||||
* If {@code paths} is empty, system property {@code javax.xml.catalog.files}
|
||||
* will be read to locate the initial list of catalog files.
|
||||
* <p>
|
||||
* If more than one catalog files are specified through the path argument or
|
||||
* If more than one catalog files are specified through the paths argument or
|
||||
* {@code javax.xml.catalog.files} property, the first entry is considered
|
||||
* the main catalog, while others are treated as alternative catalogs after
|
||||
* those referenced by the {@code nextCatalog} elements in the main catalog.
|
||||
* <p>
|
||||
* As specified in
|
||||
* <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail">
|
||||
* XML Catalogs, OASIS Standard V1.1</a>, invalid path entries will be ignored.
|
||||
* No error will be reported. In case all entries are invalid, the resolver
|
||||
* will return as no mapping is found.
|
||||
*
|
||||
* @param features the catalog features
|
||||
* @param path the path(s) to one or more catalogs
|
||||
* @param paths the path(s) to one or more catalogs
|
||||
*
|
||||
* @return an instance of a CatalogResolver
|
||||
* @throws CatalogException If no catalog can be found whether through the
|
||||
* specified path or the System property {@code javax.xml.catalog.files}, or
|
||||
* an error occurs while parsing the catalog
|
||||
* @return an instance of a {@code CatalogResolver}
|
||||
* @throws CatalogException If an error occurs while parsing the catalog
|
||||
*/
|
||||
public static CatalogResolver catalogResolver(CatalogFeatures features, String... path) {
|
||||
Catalog catalog = catalog(features, path);
|
||||
public static CatalogResolver catalogResolver(CatalogFeatures features, String... paths) {
|
||||
Catalog catalog = catalog(features, paths);
|
||||
return new CatalogResolverImpl(catalog);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of a CatalogUriResolver using the specified feature settings
|
||||
* and path to a catalog file. If the features is null, the default features will
|
||||
* be used. If the path is empty, System property {@code javax.xml.catalog.files}
|
||||
* Creates an instance of a {@code CatalogUriResolver} using the specified
|
||||
* feature settings and path to one or more catalog files.
|
||||
* <p>
|
||||
* If {@code paths} is empty, system property {@code javax.xml.catalog.files}
|
||||
* will be read to locate the initial list of catalog files.
|
||||
* <p>
|
||||
* If more than one catalog files are specified through the path argument or
|
||||
* If more than one catalog files are specified through the paths argument or
|
||||
* {@code javax.xml.catalog.files} property, the first entry is considered
|
||||
* the main catalog, while others are treated as alternative catalogs after
|
||||
* those referenced by the {@code nextCatalog} elements in the main catalog.
|
||||
* <p>
|
||||
* As specified in
|
||||
* <a href="https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html#s.res.fail">
|
||||
* XML Catalogs, OASIS Standard V1.1</a>, invalid path entries will be ignored.
|
||||
* No error will be reported. In case all entries are invalid, the resolver
|
||||
* will return as no mapping is found.
|
||||
*
|
||||
* @param features the catalog features
|
||||
* @param path the path(s) to one or more catalogs
|
||||
* @param paths the path(s) to one or more catalogs
|
||||
*
|
||||
* @return an instance of a CatalogResolver
|
||||
* @throws CatalogException If no catalog can be found whether through the
|
||||
* specified path or the System property {@code javax.xml.catalog.files}, or
|
||||
* an error occurs while parsing the catalog
|
||||
* @return an instance of a {@code CatalogUriResolver}
|
||||
* @throws CatalogException If an error occurs while parsing the catalog
|
||||
*/
|
||||
public static CatalogUriResolver catalogUriResolver(CatalogFeatures features, String... path) {
|
||||
Catalog catalog = catalog(features, path);
|
||||
public static CatalogUriResolver catalogUriResolver(CatalogFeatures features, String... paths) {
|
||||
Catalog catalog = catalog(features, paths);
|
||||
return new CatalogUriResolverImpl(catalog);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,9 +43,9 @@ public interface CatalogUriResolver extends URIResolver {
|
|||
* absolute if the absolute URI is required
|
||||
*
|
||||
* @return a {@link javax.xml.transform.Source} object if a mapping is found.
|
||||
* If no mapping is found, returns a {@link javax.xml.transform.Source} object
|
||||
* containing an empty {@link java.io.Reader} if the
|
||||
* {@code javax.xml.catalog.resolve} property is set to {@code ignore};
|
||||
* If no mapping is found, returns an empty {@link javax.xml.transform.Source}
|
||||
* object if the {@code javax.xml.catalog.resolve} property is set to
|
||||
* {@code ignore};
|
||||
* returns a {@link javax.xml.transform.Source} object with the original URI
|
||||
* (href, or href resolved with base if base is not null) if the
|
||||
* {@code javax.xml.catalog.resolve} property is set to {@code continue}.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue