# HG changeset patch # User joehw # Date 1484168764 28800 # Node ID e73af7b6ce478b0893490648878f970ce15ee0bf # Parent ab2c8b03c3284fcbdd157551a66f807e3a182d9b 8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar Reviewed-by: rriggs, dfuchs, lancea, alanb diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/AltCatalog.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/AltCatalog.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/AltCatalog.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,7 +58,7 @@ } /** - * Returns the catalog attribute as an URI String. + * Returns the catalog attribute as a URI String. * @return The value of the catalog attribute */ String getCatalogId() { @@ -66,7 +66,7 @@ } /** - * Returns the catalog attribute as an URI. + * Returns the catalog attribute as a URI. * @return The value of the catalog attribute */ URI getCatalogURI() { diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/BaseEntry.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/BaseEntry.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/BaseEntry.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Objects; +import static javax.xml.catalog.CatalogMessages.ERR_INVALID_ARGUMENT; /** * Represents a general Catalog entry. @@ -210,13 +211,12 @@ * @param arg The name of the argument * @param uri The URI to be verified * @return The URI created from the specified uri - * @throws IllegalArgumentException if the specified uri is null, - * or an URL can not be created based on the specified base and uri + * @throws NullPointerException if the specified uri is null + * @throws IllegalArgumentException if a URL can not be created based on + * the specified base and uri */ URL verifyURI(String arg, URL base, String uri) { - if (uri == null) { - CatalogMessages.reportIAE(new Object[]{uri, arg}, null); - } + CatalogMessages.reportNPEOnNull(arg, uri); URL url = null; uri = Normalizer.normalizeURI(uri); @@ -228,32 +228,9 @@ url = new URL(uri); } } catch (MalformedURLException e) { - CatalogMessages.reportIAE(new Object[]{uri, arg}, e); + CatalogMessages.reportIAE(ERR_INVALID_ARGUMENT, + new Object[]{uri, arg}, e); } return url; } - - /** - * Construct an absolute URI from a relative one, using the current base - * URI. - * - * @param sysid The (possibly relative) system identifier - * @return The system identifier made absolute with respect to the current - * {@link #base}. - */ - protected String makeAbsolute(String sysid) { - URL local = null; - - sysid = Util.fixSlashes(sysid); - /** - * try { local = new URL(base, sysid); } catch (MalformedURLException e) - * { catalogManager.debug.message(1, "Malformed URL on system - * identifier", sysid); } - */ - if (local != null) { - return local.toString(); - } else { - return sysid; - } - } } diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/Catalog.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/Catalog.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/Catalog.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,7 +44,7 @@ * *

@@ -84,7 +84,7 @@ * * @param systemId the system identifier of the entity to be matched * - * @return an URI string if a mapping is found, or null otherwise + * @return a URI string if a mapping is found, or null otherwise */ public String matchSystem(String systemId); @@ -108,7 +108,7 @@ * * @param publicId the public identifier of the entity to be matched * @see CatalogFeatures.Feature - * @return an URI string if a mapping is found, or null otherwise + * @return a URI string if a mapping is found, or null otherwise */ public String matchPublic(String publicId); @@ -134,7 +134,7 @@ * * @param uri the URI reference of the entity to be matched * - * @return an URI string if a mapping is found, or null otherwise + * @return a URI string if a mapping is found, or null otherwise */ public String matchURI(String uri); diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,14 +56,14 @@ * * * FILES - * A semicolon-delimited list of catalog files. Relative file paths are - * considered relative to ${user.dir}. + * A semicolon-delimited list of URIs to locate the catalog files. + * The URIs must be absolute and have a URL protocol handler for the URI scheme. * * javax.xml.catalog.files * javax.xml.catalog.files * javax.xml.catalog.files * String - * File paths + * URIs * * Reads the first catalog as the current catalog; Loads others if no match * is found in the current catalog including delegate catalogs if any. @@ -170,7 +170,7 @@ * Properties set through the Catalog API override those that may have been set * by system properties and/or in {@code jaxp.properties}. In case of multiple * interfaces, the latest in a procedure shall take preference. For - * {@link Feature#FILES}, this means that the path(s) specified through the methods + * {@link Feature#FILES}, this means that the URI(s) specified through the methods * of the {@link CatalogManager} will override any that may have been entered * through the {@link Builder}. * @@ -188,7 +188,7 @@ * in the following sample code: *

{@code
                 CatalogFeatures f = CatalogFeatures.builder()
-                        .with(Feature.FILES, "catalog.xml")
+                        .with(Feature.FILES, "file:///etc/xml/catalog")
                         .with(Feature.PREFER, "public")
                         .with(Feature.DEFER, "true")
                         .with(Feature.RESOLVE, "ignore")
@@ -202,14 +202,14 @@
  * Schema Validation ({@link javax.xml.validation}), and XML Transformation
  * ({@link javax.xml.transform}). The features described above can be set through JAXP
  * factories or processors that define a setProperty or setAttribute interface.
- * For example, the following code snippet sets a path to a catalog file on a SAX
+ * For example, the following code snippet sets a URI to a catalog file on a SAX
  * parser through the {@code javax.xml.catalog.files} property:
  * 

*

{@code
  *      SAXParserFactory spf = SAXParserFactory.newInstance();
  *      spf.setFeature(XMLConstants.USE_CATALOG, true); [1]
  *      SAXParser parser = spf.newSAXParser();
- *      parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), "catalog.xml");
+ *      parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), "file:///etc/xml/catalog");
  * }
*

* [1] Note that this statement is not required since the default value of @@ -275,7 +275,7 @@ The following XInclude element: - can be resolved using an uri entry: + can be resolved using a URI entry: or @@ -291,7 +291,7 @@ - can be resolved using an uri entry: + can be resolved using a URI entry: or @@ -308,7 +308,7 @@ The following include element: - can be resolved using an uri entry: + can be resolved using a URI entry: or @@ -323,7 +323,7 @@ The following include element: - can be resolved using an uri entry: + can be resolved using a URI entry: or @@ -338,7 +338,7 @@ The document in the following element: - can be resolved using an uri entry: + can be resolved using a URI entry: or @@ -559,7 +559,7 @@ values = new String[Feature.values().length]; states = new State[Feature.values().length]; for (Feature cf : Feature.values()) { - setProperty(cf.ordinal(), State.DEFAULT, cf.defaultValue()); + setProperty(cf, State.DEFAULT, cf.defaultValue()); } //read system properties or jaxp.properties readSystemProperties(); @@ -571,52 +571,27 @@ */ private void setProperties(Builder builder) { builder.values.entrySet().stream().forEach((entry) -> { - setProperty(entry.getKey().ordinal(), State.APIPROPERTY, entry.getValue()); + setProperty(entry.getKey(), State.APIPROPERTY, entry.getValue()); }); } /** - * Sets the value of a property by its index, updates only if it shall override. + * Sets the value of a property, updates only if it shall override. * * @param index the index of the property * @param state the state of the property * @param value the value of the property * @throws IllegalArgumentException if the value is invalid */ - private void setProperty(int index, State state, String value) { + private void setProperty(Feature feature, State state, String value) { + int index = feature.ordinal(); if (value != null && value.length() != 0) { - if (index == Feature.PREFER.ordinal()) { - if (!value.equals(PREFER_SYSTEM) && !value.equals(PREFER_PUBLIC)) { - CatalogMessages.reportIAE(new Object[]{value, Feature.PREFER.name()}, null); - } - } else if (index == Feature.DEFER.ordinal()) { - if (!value.equals(DEFER_TRUE) && !value.equals(DEFER_FALSE)) { - CatalogMessages.reportIAE(new Object[]{value, Feature.DEFER.name()}, null); - } - } else if (index == Feature.RESOLVE.ordinal()) { - if (!value.equals(RESOLVE_STRICT) && !value.equals(RESOLVE_CONTINUE) - && !value.equals(RESOLVE_IGNORE)) { - CatalogMessages.reportIAE(new Object[]{value, Feature.RESOLVE.name()}, null); - } - } else if (index == Feature.FILES.ordinal()) { - try { - String[] catalogFile = value.split(";[ ]*"); - for (String temp : catalogFile) { - if (Util.verifyAndGetURI(temp, null) == null) { - CatalogMessages.reportIAE(new Object[]{value, Feature.FILES.name()}, null); - } - } - }catch (MalformedURLException | URISyntaxException | IllegalArgumentException ex) { - CatalogMessages.reportIAE(new Object[]{value, Feature.FILES.name()}, ex); - } + if (state != State.APIPROPERTY) { + Util.validateFeatureInput(feature, value); } if (states[index] == null || state.compareTo(states[index]) >= 0) { values[index] = value; states[index] = state; } - } else { - if (state == State.SYSTEMPROPERTY || state == State.JAXPDOTPROPERTIES) { - CatalogMessages.reportIAE(new Object[]{value, Feature.values()[index].name()}, null); - } } } @@ -639,13 +614,13 @@ if (cf.hasSystemProperty()) { String value = SecuritySupport.getSystemProperty(sysPropertyName); if (value != null && !value.equals("")) { - setProperty(cf.ordinal(), State.SYSTEMPROPERTY, value); + setProperty(cf, State.SYSTEMPROPERTY, value); return true; } value = SecuritySupport.readJAXPProperty(sysPropertyName); if (value != null && !value.equals("")) { - setProperty(cf.ordinal(), State.JAXPDOTPROPERTIES, value); + setProperty(cf, State.JAXPDOTPROPERTIES, value); return true; } } @@ -685,9 +660,7 @@ * property */ public Builder with(Feature feature, String value) { - if (value == null || value.length() == 0) { - CatalogMessages.reportIAE(new Object[]{value, feature.name()}, null); - } + Util.validateFeatureInput(feature, value); values.put(feature, value); return this; } diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -75,7 +75,7 @@ /* A list of catalog entry files from the input, excluding the current catalog. - Paths in the List are normalized. + URIs in the List are verified during input validation or property retrieval. */ List inputFiles; @@ -86,43 +86,44 @@ SAXParser parser; /** - * Construct a Catalog with specified path. + * Construct a Catalog with specified URI. * - * @param file The path to a catalog file. + * @param uris the uri(s) to one or more catalogs * @throws CatalogException If an error happens while parsing the specified * catalog file. */ - public CatalogImpl(CatalogFeatures f, String... file) throws CatalogException { - this(null, f, file); + public CatalogImpl(CatalogFeatures f, URI... uris) throws CatalogException { + this(null, f, uris); } /** - * Construct a Catalog with specified path. + * Construct a Catalog with specified URI. * * @param parent The parent catalog - * @param file The path to a catalog file. + * @param uris the uri(s) to one or more catalogs * @throws CatalogException If an error happens while parsing the specified * catalog file. */ - public CatalogImpl(CatalogImpl parent, CatalogFeatures f, String... file) throws CatalogException { + public CatalogImpl(CatalogImpl parent, CatalogFeatures f, URI... uris) throws CatalogException { super(CatalogEntryType.CATALOG, parent); if (f == null) { throw new NullPointerException( formatMessage(CatalogMessages.ERR_NULL_ARGUMENT, new Object[]{"CatalogFeatures"})); } - if (file.length > 0) { - CatalogMessages.reportNPEOnNull("The path to the catalog file", file[0]); - } - init(f); //Path of catalog files - String[] catalogFile = file; - if (level == 0 && file.length == 0) { + String[] catalogFile = null; + if (level == 0 && uris.length == 0) { String files = features.get(Feature.FILES); if (files != null) { - catalogFile = files.split(";[ ]*"); + catalogFile = files.split(";"); + } + } else { + catalogFile = new String[uris.length]; + for (int i=0; i { - getCatalog(getSystemId(file)); + inputFiles.stream().forEach((uri) -> { + getCatalog(URI.create(uri)); }); } } @@ -454,12 +432,11 @@ } CatalogImpl c = null; - String path = uri.toASCIIString(); if (verifyCatalogFile(uri)) { - c = getLoadedCatalog(path); + c = getLoadedCatalog(uri.toASCIIString()); if (c == null) { - c = new CatalogImpl(this, features, path); + c = new CatalogImpl(this, features, uri); c.load(); } } diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,6 +24,7 @@ */ package javax.xml.catalog; +import java.net.URI; /** * The Catalog Manager manages the creation of XML Catalogs and Catalog Resolvers. @@ -39,30 +40,36 @@ /** * Creates a {@code Catalog} object using the specified feature settings and - * path to one or more catalog files. + * uri(s) to one or more catalog files. *

- * If {@code paths} is empty, system property {@code javax.xml.catalog.files} - * will be read to locate the initial list of catalog files. + * If {@code uris} is empty, system property {@code javax.xml.catalog.files}, + * as defined in {@link CatalogFeatures}, will be read to locate the initial + * list of catalog files. *

- * If more than one catalog files are specified through the paths argument or + * If multiple catalog files are specified through the {@code uris} 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. *

* As specified in * - * XML Catalogs, OASIS Standard V1.1, 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. + * XML Catalogs, OASIS Standard V1.1, if a catalog entry is invalid, it + * is ignored. In case all entries are invalid, the resulting Catalog object + * will contain no Catalog elements. Any matching operation using the Catalog + * will return null. * * @param features the catalog features - * @param paths path(s) to one or more catalogs. + * @param uris uri(s) to one or more catalogs. * * @return an instance of a {@code Catalog} + * @throws IllegalArgumentException if either the URIs are not absolute + * or do not have a URL protocol handler for the URI scheme * @throws CatalogException If an error occurs while parsing the catalog + * @throws SecurityException if access to the resource is denied by the security manager */ - public static Catalog catalog(CatalogFeatures features, String... paths) { - CatalogImpl catalog = new CatalogImpl(features, paths); + public static Catalog catalog(CatalogFeatures features, URI... uris) { + Util.validateUrisSyntax(uris); + CatalogImpl catalog = new CatalogImpl(features, uris); catalog.load(); return catalog; } @@ -80,30 +87,36 @@ /** * Creates an instance of a {@code CatalogResolver} using the specified feature - * settings and path to one or more catalog files. + * settings and uri(s) to one or more catalog files. *

- * If {@code paths} is empty, system property {@code javax.xml.catalog.files} - * will be read to locate the initial list of catalog files. + * If {@code uris} is empty, system property {@code javax.xml.catalog.files}, + * as defined in {@link CatalogFeatures}, will be read to locate the initial + * list of catalog files. *

- * If more than one catalog files are specified through the paths argument or + * If multiple catalog files are specified through the {@code uris} 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. *

* As specified in * - * XML Catalogs, OASIS Standard V1.1, 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. + * XML Catalogs, OASIS Standard V1.1, if a catalog entry is invalid, it + * is ignored. In case all entries are invalid, the resulting CatalogResolver + * object will contain no valid catalog. Any resolution operation using the + * resolver therefore will return as no mapping is found. See {@link CatalogResolver} + * for the behavior when no mapping is found. * * @param features the catalog features - * @param paths the path(s) to one or more catalogs + * @param uris the uri(s) to one or more catalogs * * @return an instance of a {@code CatalogResolver} + * @throws IllegalArgumentException if either the URIs are not absolute + * or do not have a URL protocol handler for the URI scheme * @throws CatalogException If an error occurs while parsing the catalog + * @throws SecurityException if access to the resource is denied by the security manager */ - public static CatalogResolver catalogResolver(CatalogFeatures features, String... paths) { - Catalog catalog = catalog(features, paths); + public static CatalogResolver catalogResolver(CatalogFeatures features, URI... uris) { + Catalog catalog = catalog(features, uris); return new CatalogResolverImpl(catalog); } } diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogMessages.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogMessages.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogMessages.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,10 +24,11 @@ */ package javax.xml.catalog; -import jdk.xml.internal.SecuritySupport; +import java.net.URI; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import jdk.xml.internal.SecuritySupport; /** * Catalog Error messages @@ -38,6 +39,8 @@ public static final String ERR_INVALID_CATALOG = "InvalidCatalog"; public static final String ERR_INVALID_ENTRY_TYPE = "InvalidEntryType"; + public static final String ERR_URI_NOTABSOLUTE = "UriNotAbsolute"; + public static final String ERR_URI_NOTVALIDURL = "UriNotValidUrl"; public static final String ERR_INVALID_ARGUMENT = "InvalidArgument"; public static final String ERR_NULL_ARGUMENT = "NullArgument"; public static final String ERR_CIRCULAR_REFERENCE = "CircularReference"; @@ -120,7 +123,7 @@ * @param name the name of the argument * @param value the value of the argument */ - static void reportNPEOnNull(String name, String value) { + static void reportNPEOnNull(String name, Object value) { if (value == null) { throw new NullPointerException( formatMessage(ERR_NULL_ARGUMENT, new Object[]{name})); @@ -132,9 +135,9 @@ * @param arguments the arguments for formating the error message * @param cause the cause if any */ - static void reportIAE(Object[] arguments, Throwable cause) { + static void reportIAE(String key, Object[] arguments, Throwable cause) { throw new IllegalArgumentException( - formatMessage(ERR_INVALID_ARGUMENT, arguments), cause); + formatMessage(key, arguments), cause); } /** @@ -174,7 +177,7 @@ /** * Returns sanitized URI. - * @param uri an URI to be sanitized + * @param uri a URI to be sanitized */ static String sanitize(String uri) { if (uri == null) { diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogMessages.properties --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogMessages.properties Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogMessages.properties Wed Jan 11 13:06:04 2017 -0800 @@ -31,6 +31,8 @@ CircularReference = Circular reference is not allowed: ''{0}''. #errors +UriNotAbsolute = The specified URI ''{0}'' is not absolute. +UriNotValidUrl = The specified URI ''{0}'' is not a valid URL. InvalidArgument = The specified argument ''{0}'' (case sensitive) for ''{1}'' is not valid. NullArgument = The argument ''{0}'' can not be null. InvalidPath = The path ''{0}'' is invalid. diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogReader.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogReader.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogReader.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,10 +25,6 @@ package javax.xml.catalog; import java.io.StringReader; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Path; -import java.nio.file.Paths; import javax.xml.catalog.BaseEntry.CatalogEntryType; import javax.xml.parsers.SAXParser; import javax.xml.transform.Source; @@ -94,25 +90,6 @@ this.parser = parser; } - /** - * Returns when the specified path is valid. - * @param path a path - * @return true if the path is valid, false otherwise - */ - boolean isValidPath(String path) { - boolean valid = true; - try { - Path p = Paths.get(new URI(path)); - if (!p.toFile().exists()) { - valid = false; - } - } catch (URISyntaxException ex) { - valid = false; - } - - return valid; - } - @Override public void startElement(String namespaceURI, String localName, diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogResolver.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogResolver.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogResolver.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -47,7 +47,7 @@ * {@link javax.xml.stream.XMLResolver} and {@link org.w3c.dom.ls.LSResourceResolver} * however, make no such distinction. * In consistent with the existing Java API, this CatalogResolver recognizes a - * system identifier as an URI and will search both {@code system} and {@code uri} + * system identifier as a URI and will search both {@code system} and {@code uri} * entries in a catalog in order to find a matching entry. *

* The search is started in the current catalog. If a match is found, @@ -137,9 +137,9 @@ * with the specified {@code href} attribute. The {@code href} attribute will * be used literally, with no attempt to be made absolute to the {@code base}. *

- * If the value is an URN, the {@code href} attribute is recognized as a + * If the value is a URN, the {@code href} attribute is recognized as a * {@code publicId}, and used to search {@code public} entries. - * If the value is an URI, it is taken as a {@code systemId}, and used to + * If the value is a URI, it is taken as a {@code systemId}, and used to * search both {@code system} and {@code uri} entries. * * @@ -219,7 +219,7 @@ * @param publicId the public identifier of the external entity being * referenced, or {@code null} if no public identifier was * supplied or if the resource is not an entity. - * @param systemId the system identifier, an URI reference of the + * @param systemId the system identifier, a URI reference of the * external resource being referenced * @param baseUri the absolute base URI, not used by the CatalogResolver * diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -73,7 +73,7 @@ systemId = Normalizer.normalizeURI(Util.getNotNullOrEmpty(systemId)); publicId = Normalizer.normalizePublicId(Normalizer.decodeURN(Util.getNotNullOrEmpty(publicId))); - //check whether systemId is an urn + //check whether systemId is a urn if (systemId != null && systemId.startsWith(Util.URN)) { systemId = Normalizer.decodeURN(systemId); if (publicId != null && !publicId.equals(systemId)) { @@ -123,7 +123,7 @@ return null; } - //check whether uri is an urn + //check whether uri is a urn if (uri != null && uri.startsWith(Util.URN)) { String publicId = Normalizer.decodeURN(uri); if (publicId != null) { @@ -131,7 +131,7 @@ } } - //if no match with a public id, continue search for an URI + //if no match with a public id, continue search for a URI if (result == null) { //remove fragment if any. int hashPos = uri.indexOf("#"); diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,8 +25,6 @@ package javax.xml.catalog; import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -217,7 +215,7 @@ * @param systemId The system identifier of the external entity being * referenced. * - * @return An URI string if a mapping is found, or null otherwise. + * @return a URI string if a mapping is found, or null otherwise. */ public String matchSystem(String systemId) { systemEntrySearched = true; @@ -285,7 +283,7 @@ * @param publicId The public identifier of the external entity being * referenced. * - * @return An URI string if a mapping is found, or null otherwise. + * @return a URI string if a mapping is found, or null otherwise. */ public String matchPublic(String publicId) { /* @@ -329,7 +327,7 @@ * * @param uri The URI reference of a resource. * - * @return An URI string if a mapping is found, or null otherwise. + * @return a URI string if a mapping is found, or null otherwise. */ public String matchURI(String uri) { String match = null; @@ -455,7 +453,7 @@ delegateCatalog = getLoadedCatalog(catalogId); if (delegateCatalog == null) { if (verifyCatalogFile(catalogURI)) { - delegateCatalog = new CatalogImpl(catalog, features, catalogId); + delegateCatalog = new CatalogImpl(catalog, features, catalogURI); delegateCatalog.load(); delegateCatalogs.put(catalogId, delegateCatalog); } @@ -504,7 +502,8 @@ } //Ignore it if it doesn't exist - if (!Files.exists(Paths.get(catalogURI))) { + if (Util.isFileUri(catalogURI) && + !Util.isFileUriExist(catalogURI, false)) { return false; } diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/UriEntry.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/UriEntry.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/UriEntry.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,7 @@ import java.net.URL; /** - * Represents an uriEntry entry. + * Represents a uri entry. * * @since 9 */ @@ -36,7 +36,7 @@ URL uri; /** - * Construct a group entry. + * Construct a uri entry. * @param name The name attribute. * @param uri The uri attribute. */ diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/src/java.xml/share/classes/javax/xml/catalog/Util.java --- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/Util.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/Util.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,13 +25,20 @@ package javax.xml.catalog; import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Iterator; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import static javax.xml.catalog.CatalogFeatures.DEFER_FALSE; +import static javax.xml.catalog.CatalogFeatures.DEFER_TRUE; +import javax.xml.catalog.CatalogFeatures.Feature; +import static javax.xml.catalog.CatalogFeatures.PREFER_PUBLIC; +import static javax.xml.catalog.CatalogFeatures.PREFER_SYSTEM; +import static javax.xml.catalog.CatalogFeatures.RESOLVE_CONTINUE; +import static javax.xml.catalog.CatalogFeatures.RESOLVE_IGNORE; +import static javax.xml.catalog.CatalogFeatures.RESOLVE_STRICT; import jdk.xml.internal.SecuritySupport; /** @@ -39,22 +46,25 @@ * @since 9 */ class Util { + final static String URN = "urn:publicid:"; final static String PUBLICID_PREFIX = "-//"; final static String PUBLICID_PREFIX_ALT = "+//"; + final static String SCHEME_FILE = "file"; + final static String SCHEME_JAR = "jar"; + final static String SCHEME_JARFILE = "jar:file:"; /** * Finds an entry in the catalog that matches with the publicId or systemId. * - * The resolution follows the following rules determined by the prefer setting: + * The resolution follows the following rules determined by the prefer + * setting: * - * prefer "system": attempts to resolve with a system entry; - * attempts to resolve with a public entry when only - * publicId is specified. + * prefer "system": attempts to resolve with a system entry; attempts to + * resolve with a public entry when only publicId is specified. * - * prefer "public": attempts to resolve with a system entry; - * attempts to resolve with a public entry if no matching - * system entry is found. + * prefer "public": attempts to resolve with a system entry; attempts to + * resolve with a public entry if no matching system entry is found. * * If no match is found, continue searching uri entries * @@ -70,9 +80,9 @@ catalog.reset(); if (systemId != null) { /* - If a system identifier is specified, it is used no matter how - prefer is set. - */ + If a system identifier is specified, it is used no matter how + prefer is set. + */ resolvedSystemId = catalog.matchSystem(systemId); } @@ -91,7 +101,7 @@ if (resolvedSystemId == null) { Iterator iter = catalog.catalogs().iterator(); while (iter.hasNext()) { - resolvedSystemId = resolve((CatalogImpl)iter.next(), publicId, systemId); + resolvedSystemId = resolve((CatalogImpl) iter.next(), publicId, systemId); if (resolvedSystemId != null) { break; } @@ -102,73 +112,112 @@ return resolvedSystemId; } + static void validateUrisSyntax(URI... uris) { + for (URI uri : uris) { + validateUriSyntax(uri); + } + } + + static void validateUrisSyntax(String... uris) { + for (String uri : uris) { + validateUriSyntax(URI.create(uri)); + } + } + /** - * Resolves the specified file path to an absolute systemId. If it is - * relative, it shall be resolved using the base or user.dir property if - * base is not specified. + * Validate that the URI must be absolute and a valid URL. * - * @param file The specified file path - * @param baseURI the base URI - * @return The URI - * @throws CatalogException if the specified file path can not be converted - * to a system id + * Note that this method does not verify the existence of the resource. The + * Catalog standard requires that such resources be ignored. + * + * @param uri + * @throws IllegalArgumentException if the uri is not absolute and a valid + * URL */ - static URI verifyAndGetURI(String file, URL baseURI) - throws MalformedURLException, URISyntaxException, IllegalArgumentException { - URL filepath; - URI temp; - if (file != null && file.length() > 0) { - File f = new File(file); + static void validateUriSyntax(URI uri) { + CatalogMessages.reportNPEOnNull("URI input", uri); + + if (!uri.isAbsolute()) { + CatalogMessages.reportIAE(CatalogMessages.ERR_URI_NOTABSOLUTE, + new Object[]{uri}, null); + } - if (baseURI != null && !f.isAbsolute()) { - filepath = new URL(baseURI, fixSlashes(file)); - temp = filepath.toURI(); - } else { - temp = resolveURI(file); - } - //Paths.get may throw IllegalArgumentException - Path path = Paths.get(temp); - if (path.toFile().isFile()) { - return temp; + try { + // check if the scheme was valid + uri.toURL(); + } catch (MalformedURLException ex) { + CatalogMessages.reportIAE(CatalogMessages.ERR_URI_NOTVALIDURL, + new Object[]{uri}, null); + } + + // verify the resource exists where possible + if (isFileUri(uri)) { + if (!isFileUriExist(uri, false)) { + CatalogMessages.reportIAE(CatalogMessages.ERR_URI_NOTVALIDURL, + new Object[]{uri}, null); } } - return null; } /** - * Resolves the specified uri. If the uri is relative, makes it absolute by - * the user.dir directory. + * Checks whether the URI is a file URI, including JAR file. * - * @param uri The specified URI. - * @return The resolved URI + * @param uri the specified URI. + * @return true if it is a file or JAR file URI, false otherwise */ - static URI resolveURI(String uri) throws MalformedURLException { - if (uri == null) { - uri = ""; + static boolean isFileUri(URI uri) { + if (SCHEME_FILE.equals(uri.getScheme()) + || SCHEME_JAR.equals(uri.getScheme())) { + return true; } - - URI temp = null; - try { - URL url = new URL(uri); - temp = url.toURI(); - } catch (MalformedURLException | URISyntaxException mue) { - File file = new File(uri); - temp = file.toURI(); - } - - return temp; + return false; } /** - * Replace backslashes with forward slashes. (URLs always use forward - * slashes.) + * Verifies whether the file resource exists. * - * @param sysid The input system identifier. - * @return The same system identifier with backslashes turned into forward - * slashes. + * @param uri the URI to locate the resource + * @param openJarFile a flag to indicate whether a JAR file should be + * opened. This operation may be expensive. + * @return true if the resource exists, false otherwise. */ - static String fixSlashes(String sysid) { - return sysid.replace('\\', '/'); + static boolean isFileUriExist(URI uri, boolean openJarFile) { + if (uri != null && uri.isAbsolute()) { + if (null != uri.getScheme()) { + switch (uri.getScheme()) { + case SCHEME_FILE: + String path = uri.getPath(); + File f1 = new File(path); + if (f1.isFile()) { + return true; + } + break; + case SCHEME_JAR: + String tempUri = uri.toString(); + int pos = tempUri.indexOf("!"); + if (pos < 0) { + return false; + } + if (openJarFile) { + String jarFile = tempUri.substring(SCHEME_JARFILE.length(), pos); + String entryName = tempUri.substring(pos + 2); + try { + JarFile jf = new JarFile(jarFile); + JarEntry je = jf.getJarEntry(entryName); + if (je != null) { + return true; + } + } catch (IOException ex) { + return false; + } + } else { + return true; + } + break; + } + } + } + return false; } /** @@ -187,11 +236,12 @@ } /** - * Checks whether the specified string is null or empty, returns the original - * string with leading and trailing spaces removed if not. + * Checks whether the specified string is null or empty, returns the + * original string with leading and trailing spaces removed if not. + * * @param test the string to be tested - * @return the original string with leading and trailing spaces removed, - * or null if it is null or empty + * @return the original string with leading and trailing spaces removed, or + * null if it is null or empty * */ static String getNotNullOrEmpty(String test) { @@ -206,4 +256,39 @@ } } } + + /** + * Validates the input for features. + * + * @param f the feature + * @param value the value + * @throws IllegalArgumentException if the value is invalid for the feature + */ + static void validateFeatureInput(Feature f, String value) { + CatalogMessages.reportNPEOnNull(f.name(), value); + if (value.length() == 0) { + CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, + new Object[]{value, f.name()}, null); + } + + if (f == Feature.PREFER) { + if (!value.equals(PREFER_SYSTEM) && !value.equals(PREFER_PUBLIC)) { + CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, + new Object[]{value, Feature.PREFER.name()}, null); + } + } else if (f == Feature.DEFER) { + if (!value.equals(DEFER_TRUE) && !value.equals(DEFER_FALSE)) { + CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, + new Object[]{value, Feature.DEFER.name()}, null); + } + } else if (f == Feature.RESOLVE) { + if (!value.equals(RESOLVE_STRICT) && !value.equals(RESOLVE_CONTINUE) + && !value.equals(RESOLVE_IGNORE)) { + CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, + new Object[]{value, Feature.RESOLVE.name()}, null); + } + } else if (f == Feature.FILES) { + Util.validateUrisSyntax(value.split(";")); + } + } } diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/functional/catalog/SpecifyCatalogTest.java --- a/jaxp/test/javax/xml/jaxp/functional/catalog/SpecifyCatalogTest.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/test/javax/xml/jaxp/functional/catalog/SpecifyCatalogTest.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -81,7 +81,7 @@ @Test public void specifyCatalogViaSysProps() { setSystemProperty(FEATURE_FILES, - getCatalogPath("specifyCatalog-sysProps.xml")); + getCatalogPath("specifyCatalog-sysProps.xml").toASCIIString()); checkResolutionOnEntityResolver(catalogResolver((String[]) null), "http://local/base/dtd/docSysPropsSys.dtd"); @@ -107,6 +107,6 @@ } private static CatalogFeatures createFeature(String catalogName) { - return builder().with(FILES, getCatalogPath(catalogName)).build(); + return builder().with(FILES, getCatalogPath(catalogName).toASCIIString()).build(); } } diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/functional/catalog/catalogFiles/dummy.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/test/javax/xml/jaxp/functional/catalog/catalogFiles/dummy.xml Wed Jan 11 13:06:04 2017 -0800 @@ -0,0 +1,1 @@ + diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/libs/catalog/CatalogTestUtils.java --- a/jaxp/test/javax/xml/jaxp/libs/catalog/CatalogTestUtils.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/test/javax/xml/jaxp/libs/catalog/CatalogTestUtils.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,17 +25,16 @@ import java.io.File; import java.io.IOException; +import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; - import javax.xml.catalog.CatalogFeatures; import javax.xml.catalog.CatalogManager; import javax.xml.catalog.CatalogResolver; - import jaxp.library.JAXPTestUtilities; /* @@ -115,20 +114,20 @@ } // Gets the paths of the specified catalogs. - private static String[] getCatalogPaths(String... catalogNames) { + private static URI[] getCatalogPaths(String... catalogNames) { return catalogNames == null ? null : Stream.of(catalogNames).map( catalogName -> getCatalogPath(catalogName)).collect( - Collectors.toList()).toArray(new String[0]); + Collectors.toList()).toArray(new URI[0]); } // Gets the paths of the specified catalogs. - static String getCatalogPath(String catalogName) { + static URI getCatalogPath(String catalogName) { return catalogName == null ? null - : JAXPTestUtilities.getPathByClassName(CatalogTestUtils.class, "catalogFiles") - + catalogName; + : Paths.get(JAXPTestUtilities.getPathByClassName(CatalogTestUtils.class, "catalogFiles") + + catalogName).toUri(); } /* ********** jaxp.properties ********** */ diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/libs/jaxp/library/JarUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/test/javax/xml/jaxp/libs/jaxp/library/JarUtils.java Wed Jan 11 13:06:04 2017 -0800 @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jaxp.library; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * This class consists exclusively of static utility methods that are useful + * for creating and manipulating JAR files. + */ + +public final class JarUtils { + private JarUtils() { } + + /** + * Creates a JAR file. + * + * Equivalent to {@code jar cfm -C

file...} + * + * The input files are resolved against the given directory. Any input + * files that are directories are processed recursively. + */ + public static void createJarFile(Path jarfile, Manifest man, Path dir, Path... file) + throws IOException + { + // create the target directory + Path parent = jarfile.getParent(); + if (parent != null) + Files.createDirectories(parent); + + List entries = new ArrayList<>(); + for (Path entry : file) { + Files.find(dir.resolve(entry), Integer.MAX_VALUE, + (p, attrs) -> attrs.isRegularFile()) + .map(e -> dir.relativize(e)) + .forEach(entries::add); + } + + try (OutputStream out = Files.newOutputStream(jarfile); + JarOutputStream jos = new JarOutputStream(out)) + { + if (man != null) { + JarEntry je = new JarEntry(JarFile.MANIFEST_NAME); + jos.putNextEntry(je); + man.write(jos); + jos.closeEntry(); + } + + for (Path entry : entries) { + String name = toJarEntryName(entry); + jos.putNextEntry(new JarEntry(name)); + Files.copy(dir.resolve(entry), jos); + jos.closeEntry(); + } + } + } + + /** + * Creates a JAR file. + * + * Equivalent to {@code jar cf -C file...} + * + * The input files are resolved against the given directory. Any input + * files that are directories are processed recursively. + */ + public static void createJarFile(Path jarfile, Path dir, Path... file) + throws IOException + { + createJarFile(jarfile, null, dir, file); + } + + /** + * Creates a JAR file. + * + * Equivalent to {@code jar cf -C file...} + * + * The input files are resolved against the given directory. Any input + * files that are directories are processed recursively. + */ + public static void createJarFile(Path jarfile, Path dir, String... input) + throws IOException + { + Path[] paths = Stream.of(input).map(Paths::get).toArray(Path[]::new); + createJarFile(jarfile, dir, paths); + } + + /** + * Creates a JAR file from the contents of a directory. + * + * Equivalent to {@code jar cf -C .} + */ + public static void createJarFile(Path jarfile, Path dir) throws IOException { + createJarFile(jarfile, dir, Paths.get(".")); + } + + /** + * Map a file path to the equivalent name in a JAR file + */ + private static String toJarEntryName(Path file) { + Path normalized = file.normalize(); + return normalized.subpath(0, normalized.getNameCount()) // drop root + .toString() + .replace(File.separatorChar, '/'); + } +} diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/libs/jaxp/library/SimpleHttpServer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/test/javax/xml/jaxp/libs/jaxp/library/SimpleHttpServer.java Wed Jan 11 13:06:04 2017 -0800 @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jaxp.library; + +import com.sun.net.httpserver.Headers; +import com.sun.net.httpserver.HttpContext; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.URI; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * A simple HTTP Server + */ +public class SimpleHttpServer { + HttpServer _httpserver; + ExecutorService _executor; + + String _address; + + String _context, _docroot; + int _port; + + public SimpleHttpServer(String context, String docroot) { + //let the system pick up an ephemeral port in a bind operation + this(0, context, docroot); + } + + public SimpleHttpServer(int port, String context, String docroot) { + _port = port; + _context = context; + _docroot = docroot; + } + + public void start() { + MyHttpHandler handler = new MyHttpHandler(_docroot); + InetSocketAddress addr = new InetSocketAddress(_port); + try { + _httpserver = HttpServer.create(addr, 0); + } catch (IOException ex) { + throw new RuntimeException("cannot create httpserver", ex); + } + + //TestHandler is mapped to /test + HttpContext ctx = _httpserver.createContext(_context, handler); + + _executor = Executors.newCachedThreadPool(); + _httpserver.setExecutor(_executor); + _httpserver.start(); + + _address = "http://localhost:" + _httpserver.getAddress().getPort(); + } + + public void stop() { + _httpserver.stop(2); + _executor.shutdown(); + } + + public String getAddress() { + return _address; + } + + static class MyHttpHandler implements HttpHandler { + + String _docroot; + + public MyHttpHandler(String docroot) { + _docroot = docroot; + } + + public void handle(HttpExchange t) + throws IOException { + InputStream is = t.getRequestBody(); + Headers map = t.getRequestHeaders(); + Headers rmap = t.getResponseHeaders(); + OutputStream os = t.getResponseBody(); + URI uri = t.getRequestURI(); + String path = uri.getPath(); + + + while (is.read() != -1) ; + is.close(); + + File f = new File(_docroot, path); + if (!f.exists()) { + notfound(t, path); + return; + } + + String method = t.getRequestMethod(); + if (method.equals("HEAD")) { + rmap.set("Content-Length", Long.toString(f.length())); + t.sendResponseHeaders(200, -1); + t.close(); + } else if (!method.equals("GET")) { + t.sendResponseHeaders(405, -1); + t.close(); + return; + } + + if (path.endsWith(".html") || path.endsWith(".htm")) { + rmap.set("Content-Type", "text/html"); + } else { + rmap.set("Content-Type", "text/plain"); + } + + t.sendResponseHeaders (200, f.length()); + + FileInputStream fis = new FileInputStream(f); + int count = 0; + try { + byte[] buf = new byte[16 * 1024]; + int len; + while ((len = fis.read(buf)) != -1) { + os.write(buf, 0, len); + count += len; + } + } catch (IOException e) { + e.printStackTrace(); + } + fis.close(); + os.close(); + } + + void moved(HttpExchange t) throws IOException { + Headers req = t.getRequestHeaders(); + Headers map = t.getResponseHeaders(); + URI uri = t.getRequestURI(); + String host = req.getFirst("Host"); + String location = "http://" + host + uri.getPath() + "/"; + map.set("Content-Type", "text/html"); + map.set("Location", location); + t.sendResponseHeaders(301, -1); + t.close(); + } + + void notfound(HttpExchange t, String p) throws IOException { + t.getResponseHeaders().set("Content-Type", "text/html"); + t.sendResponseHeaders(404, 0); + OutputStream os = t.getResponseBody(); + String s = "

File not found

"; + s = s + p + "

"; + os.write(s.getBytes()); + os.close(); + t.close(); + } + } + +} diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogAccessTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogAccessTest.java Wed Jan 11 13:06:04 2017 -0800 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package catalog; + +import java.net.URI; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogManager; +import javax.xml.catalog.CatalogResolver; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; +import static jaxp.library.JAXPTestUtilities.tryRunWithAllPerm; + +/* + * @test + * @bug 8171243 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @run testng/othervm -DrunSecMngr=true catalog.CatalogAccessTest + * @summary the Catalog API grants no privilege to external resources. This test + * verifies that SecurityException will be thrown if access to resources is denied + * by the security manager. + */ +@Listeners({jaxp.library.BasePolicy.class}) +public class CatalogAccessTest { + static final CatalogFeatures FEATURES = CatalogFeatures.builder(). + with(CatalogFeatures.Feature.PREFER, "system").build(); + + /* + * Verifies that the SecurityException is thrown if access to the resource is + * denied by the security manager. + */ + @Test(dataProvider = "accessTest", expectedExceptions = SecurityException.class) + public void testSecurity(String cfile, String sysId, String pubId) throws Exception { + CatalogResolver cr = CatalogManager.catalogResolver(FEATURES, URI.create(cfile)); + InputSource is = cr.resolveEntity(pubId, sysId); + Assert.fail("Failed to throw SecurityException"); + } + + /* + DataProvider: used for SecurityException testing + Data columns: + catalog uri, systemId, publicId + */ + @DataProvider(name = "accessTest") + Object[][] getDataForAccessTest() throws Exception { + String systemId = "http://www.sys00test.com/rewrite.dtd"; + String publicId = "PUB-404"; + String urlFile = tryRunWithAllPerm(() -> + getClass().getResource("rewriteSystem_id.xml").toExternalForm()); + return new Object[][]{ + {urlFile, systemId, publicId} + }; + } +} diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogFileInputTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogFileInputTest.java Wed Jan 11 13:06:04 2017 -0800 @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package catalog; + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import static java.nio.file.StandardOpenOption.APPEND; +import static java.nio.file.StandardOpenOption.CREATE; +import javax.xml.catalog.Catalog; +import javax.xml.catalog.CatalogException; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogManager; +import javax.xml.catalog.CatalogResolver; +import static jaxp.library.JAXPTestUtilities.getSystemProperty; +import jaxp.library.JarUtils; +import jaxp.library.SimpleHttpServer; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; + +/* + * @test + * @bug 8151154 8171243 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @run testng/othervm catalog.CatalogFileInputTest + * @summary Verifies that the Catalog API accepts valid URIs only; + Verifies that the CatalogFeatures' builder throws + * IllegalArgumentException on invalid file inputs. + * This test was splitted from CatalogTest.java due to + * JDK-8168968, it has to only run without SecurityManager + * because an ACE will be thrown for invalid path. + */ +@Listeners({jaxp.library.FilePolicy.class, jaxp.library.NetAccessPolicy.class}) +public class CatalogFileInputTest extends CatalogSupportBase { + + static final CatalogFeatures FEATURES = CatalogFeatures.builder(). + with(CatalogFeatures.Feature.PREFER, "system").build(); + static String USER_DIR = getSystemProperty("user.dir"); + static String CLS_DIR = getSystemProperty("test.classes"); + static String SRC_DIR = System.getProperty("test.src"); + static String JAR_CONTENT = "META-INF"; + final static String SCHEME_JARFILE = "jar:"; + static final String REMOTE_FILE_LOCATION = "/jar/META-INF"; + static final String DOCROOT = SRC_DIR; + static final String TESTCONTEXT = REMOTE_FILE_LOCATION; //mapped to local file path + SimpleHttpServer _httpserver; + String _remoteFilePath; + + /* + * Initializing fields + */ + @BeforeClass + public void setUpClass() throws Exception { + super.setUp(); + + // set up HttpServer + _httpserver = new SimpleHttpServer(TESTCONTEXT, DOCROOT); + _httpserver.start(); + _remoteFilePath = _httpserver.getAddress() + REMOTE_FILE_LOCATION; + + } + + @AfterClass + protected void tearDown() throws Exception { + if (_httpserver != null) { + _httpserver.stop(); + } + } + + /* + * Verifies that the Catalog can be created with file system paths including JAR + * and http URL, and used to resolve a systemId as expected. + */ + @Test(dataProvider = "acceptedURI") + public void testMatch(String uri, String sysId, String pubId, + String expectedId, String msg) throws Exception { + CatalogResolver cr = CatalogManager.catalogResolver(FEATURES, URI.create(uri)); + InputSource is = cr.resolveEntity(pubId, sysId); + Assert.assertNotNull(is, msg); + Assert.assertEquals(expectedId, is.getSystemId(), msg); + } + + @Test(dataProvider = "invalidCatalog") + public void testEmptyCatalog(String uri, String publicId, String msg) { + Catalog c = CatalogManager.catalog(FEATURES, uri != null? URI.create(uri) : null); + Assert.assertNull(c.matchSystem(publicId), msg); + } + + @Test(dataProvider = "invalidCatalog", expectedExceptions = CatalogException.class) + public void testCatalogResolverWEmptyCatalog(String uri, String publicId, String msg) { + CatalogResolver cr = CatalogManager.catalogResolver( + CatalogFeatures.builder().with(CatalogFeatures.Feature.RESOLVE, "strict").build(), + uri != null? URI.create(uri) : null); + InputSource is = cr.resolveEntity(publicId, ""); + } + + @Test(dataProvider = "invalidCatalog") + public void testCatalogResolverWEmptyCatalog1(String uri, String publicId, String msg) { + CatalogResolver cr = CatalogManager.catalogResolver( + CatalogFeatures.builder().with(CatalogFeatures.Feature.RESOLVE, "continue").build(), + uri != null? URI.create(uri) : null); + Assert.assertNull(cr.resolveEntity(publicId, ""), msg); + } + + @Test(dataProvider = "invalidInput", expectedExceptions = IllegalArgumentException.class) + public void testFileInput(String file) { + CatalogFeatures features = CatalogFeatures.builder() + .with(CatalogFeatures.Feature.FILES, file) + .build(); + } + + @Test(dataProvider = "invalidInput", expectedExceptions = IllegalArgumentException.class) + public void testInvalidUri(String file) { + CatalogResolver cr = CatalogManager.catalogResolver(FEATURES, file != null? URI.create(file) : null); + } + + @Test(dataProvider = "invalidInput", expectedExceptions = IllegalArgumentException.class) + public void testInvalidUri1(String file) { + Catalog c = CatalogManager.catalog(FEATURES, file != null? URI.create(file) : null); + System.err.println("Catalog =" + c); + } + + + @Test(expectedExceptions = NullPointerException.class) + public void testNullFileInput() { + CatalogFeatures features = CatalogFeatures.builder() + .with(CatalogFeatures.Feature.FILES, null) + .build(); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullUri() { + URI uri = null; + CatalogResolver cr = CatalogManager.catalogResolver(FEATURES, uri); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullUri1() { + URI uri = null; + Catalog c = CatalogManager.catalog(FEATURES, uri); + } + + String systemId = "http://www.sys00test.com/rewrite.dtd"; + String publicId = "PUB-404"; + String expected = "http://www.groupxmlbase.com/dtds/rewrite.dtd"; + String errMsg = "Relative rewriteSystem with xml:base at group level failed"; + + /* + DataProvider: used to verify CatalogResolver's resolveEntity function. + Data columns: + catalog, systemId, publicId, expectedUri, msg + */ + @DataProvider(name = "acceptedURI") + Object[][] getData() throws Exception { + String filename = "rewriteSystem_id.xml"; + String urlFile = getClass().getResource(filename).toExternalForm(); + String urlHttp = _remoteFilePath + "/jax-ws-catalog.xml"; + String remoteXSD = _remoteFilePath + "/catalog/ws-addr.xsd"; + File file = new File(CLS_DIR + "/JDK8171243.jar!/META-INF/jax-ws-catalog.xml"); + String jarPath = SCHEME_JARFILE + file.toURI().toString(); + String xsd = jarPath.substring(0, jarPath.lastIndexOf("/")) + "/catalog/ws-addr.xsd"; + + // create JAR file + try { + JarUtils.createJarFile(Paths.get(CLS_DIR + "/JDK8171243.jar"), + Paths.get(SRC_DIR + "/jar"), JAR_CONTENT); + } catch (IOException ex) { + Assert.fail("Failed to create JAR: " + ex.getMessage()); + } + + return new Object[][]{ + // URL + {urlFile, systemId, publicId, expected, errMsg}, + {urlHttp, "http://www.w3.org/2006/03/addressing/ws-addr.xsd", "", remoteXSD, "http test failed."}, + // JAR file + {jarPath, "http://www.w3.org/2006/03/addressing/ws-addr.xsd", "", xsd, "jar file test failed."}, + }; + } + + /* + * DataProvider: invalid catalog result in empty catalog + * Note: the difference from invalidInput is that invalidInput is syntactically + * rejected with an IAE. + */ + @DataProvider(name = "invalidCatalog") + public Object[][] getInvalidCatalog() throws Exception { + String catalogUri = getClass().getResource("catalog_invalid.xml").toExternalForm(); + return new Object[][]{ + {catalogUri, "-//W3C//DTD XHTML 1.0 Strict//EN", + "The catalog is invalid, attempting to match the public entry shall return null."} + }; + } + + /* + * DataProvider: a list of invalid inputs, expects IAE + * Note: exclude null since NPE would have been expected + */ + @DataProvider(name = "invalidInput") + public Object[][] getFiles() throws Exception { + String filename = "rewriteSystem_id.xml"; + copyFile(Paths.get(SRC_DIR + "/" + filename), Paths.get(filename)); + String absolutePath = getClass().getResource(filename).getFile(); + + return new Object[][]{ + {""}, + {"file:a/b\\c"}, + {"file:/../../.."}, + {"c:/te:t"}, + {"c:/te?t"}, + {"c/te*t"}, + {"in|valid.txt"}, + {"shema:invalid.txt"}, + // relative file path + {filename}, + // absolute file path + {absolutePath} + }; + } + + /* + DataProvider: a list of invalid inputs + */ + @DataProvider(name = "nullTest") + public Object[][] getNull() throws Exception { + + return new Object[][]{ + {null}, + }; + } + + void copyFile(Path src, Path target) throws Exception { + + try (InputStream in = Files.newInputStream(src); + BufferedReader reader + = new BufferedReader(new InputStreamReader(in)); + OutputStream out = new BufferedOutputStream( + Files.newOutputStream(target, CREATE, APPEND)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out))) { + String line = null; + while ((line = reader.readLine()) != null) { + bw.write(line); + } + } catch (IOException x) { + throw new Exception(x.getMessage()); + } + } +} diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogInvalidPathTest.java --- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogInvalidPathTest.java Wed Jul 05 22:40:29 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package catalog; - -import javax.xml.catalog.CatalogFeatures; - -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -/* - * @test - * @bug 8151154 - * @run testng/othervm catalog.CatalogInvalidPathTest - * @summary Verifies that the CatalogFeatures' builder throws - * IllegalArgumentException on invalid file inputs. - * This test was splitted from CatalogTest.java due to - * JDK-8168968, it has to only run without SecurityManager - * because an ACE will be thrown for invalid path. - */ -public class CatalogInvalidPathTest { - /* - DataProvider: for testing the verification of file paths by - the CatalogFeatures builder - */ - @DataProvider(name = "invalidPaths") - public Object[][] getFiles() { - return new Object[][]{ - {null}, - {""}, - {"file:a/b\\c"}, - {"file:/../../.."}, - {"c:/te:t"}, - {"c:/te?t"}, - {"c/te*t"}, - {"in|valid.txt"}, - {"shema:invalid.txt"}, - }; - } - - @Test(dataProvider = "invalidPaths", expectedExceptions = IllegalArgumentException.class) - public void testFileInput(String file) { - CatalogFeatures features = CatalogFeatures.builder() - .with(CatalogFeatures.Feature.FILES, file) - .build(); - } -} diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java --- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java Wed Jul 05 22:40:29 2017 +0200 +++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java Wed Jan 11 13:06:04 2017 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,6 +35,13 @@ import java.io.StringReader; import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import java.nio.file.Paths; +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.security.Policy; +import java.security.ProtectionDomain; import javax.xml.XMLConstants; import javax.xml.catalog.CatalogFeatures; import javax.xml.catalog.CatalogResolver; @@ -133,8 +140,8 @@ dtd_system = filepath + "system.dtd"; dtd_systemResolved = ""; - xml_catalog = filepath + "CatalogSupport.xml"; - xml_bogus_catalog = filepath + "CatalogSupport_bogus.xml"; + xml_catalog = Paths.get(filepath + "CatalogSupport.xml").toUri().toASCIIString(); + xml_bogus_catalog = Paths.get(filepath + "CatalogSupport_bogus.xml").toUri().toASCIIString(); xml_xInclude = "\n" + " 0) { result = c.matchPublic(publicId); @@ -430,8 +434,9 @@ * system entry is found. */ @Test(dataProvider = "resolveWithPrefer") - public void resolveWithPrefer(String prefer, String cfile, String publicId, String systemId, String expected) { - String catalogFile = getClass().getResource(cfile).getFile(); + public void resolveWithPrefer(String prefer, String cfile, String publicId, + String systemId, String expected) throws Exception { + URI catalogFile = getClass().getResource(cfile).toURI(); CatalogFeatures f = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, prefer).with(CatalogFeatures.Feature.RESOLVE, "ignore").build(); CatalogResolver catalogResolver = CatalogManager.catalogResolver(f, catalogFile); String result = catalogResolver.resolveEntity(publicId, systemId).getSystemId(); @@ -445,8 +450,8 @@ * be loaded is determined by the defer attribute. */ @Test(dataProvider = "invalidAltCatalogs", expectedExceptions = CatalogException.class) - public void testDeferAltCatalogs(String file) { - String catalogFile = getClass().getResource(file).getFile(); + public void testDeferAltCatalogs(String file) throws Exception { + URI catalogFile = getClass().getResource(file).toURI(); CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.DEFER, "true").build(); /* Since the defer attribute is set to false in the specified catalog file, @@ -462,8 +467,8 @@ * PREFER from Features API taking precedence over catalog file */ @Test - public void testJDK8146237() { - String catalogFile = getClass().getResource("JDK8146237_catalog.xml").getFile(); + public void testJDK8146237() throws Exception { + URI catalogFile = getClass().getResource("JDK8146237_catalog.xml").toURI(); try { CatalogFeatures features = CatalogFeatures.builder().with(CatalogFeatures.Feature.PREFER, "system").build(); @@ -482,8 +487,8 @@ Verifies that the resulting systemId does not contain duplicate slashes */ @Test - public void testRewriteSystem() { - String catalog = getClass().getResource("rewriteCatalog.xml").getFile(); + public void testRewriteSystem() throws Exception { + URI catalog = getClass().getResource("rewriteCatalog.xml").toURI(); try { CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog); @@ -500,8 +505,8 @@ Verifies that the resulting systemId does not contain duplicate slashes */ @Test - public void testRewriteUri() { - String catalog = getClass().getResource("rewriteCatalog.xml").getFile(); + public void testRewriteUri() throws Exception { + URI catalog = getClass().getResource("rewriteCatalog.xml").toURI(); try { @@ -519,18 +524,18 @@ */ @Test(expectedExceptions = NullPointerException.class) public void testFeatureNull() { - CatalogResolver resolver = CatalogManager.catalogResolver(null, ""); + CatalogResolver resolver = CatalogManager.catalogResolver(null, null); } /* @bug 8144966 - Verifies that passing null as the path will result in a NPE. + Verifies that passing null as the URI will result in a NPE. */ @Test(expectedExceptions = NullPointerException.class) public void testPathNull() { - String path = null; - CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), path); + URI uri = null; + CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), uri); } /* @@ -540,10 +545,11 @@ that matches the expected value. */ @Test(dataProvider = "catalog") - public void testCatalogResolver(String test, String expected, String catalogFile, String xml, SAXParser saxParser) { - String catalog = null; + public void testCatalogResolver(String test, String expected, String catalogFile, + String xml, SAXParser saxParser) throws Exception { + URI catalog = null; if (catalogFile != null) { - catalog = getClass().getResource(catalogFile).getFile(); + catalog = getClass().getResource(catalogFile).toURI(); } String url = getClass().getResource(xml).getFile(); try { @@ -565,8 +571,8 @@ catalog is provided, the resolver will throw an exception by default. */ @Test - public void testInvalidCatalog() { - String catalog = getClass().getResource("catalog_invalid.xml").getFile(); + public void testInvalidCatalog() throws Exception { + URI catalog = getClass().getResource("catalog_invalid.xml").toURI(); String test = "testInvalidCatalog"; try { @@ -590,7 +596,7 @@ */ @Test public void testIgnoreInvalidCatalog() { - String catalog = getClass().getResource("catalog_invalid.xml").getFile(); + String catalog = getClass().getResource("catalog_invalid.xml").toExternalForm(); CatalogFeatures f = CatalogFeatures.builder() .with(Feature.FILES, catalog) .with(Feature.PREFER, "public") @@ -600,7 +606,7 @@ String test = "testInvalidCatalog"; try { - CatalogResolver resolver = CatalogManager.catalogResolver(f, ""); + CatalogResolver resolver = CatalogManager.catalogResolver(f); String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId(); System.out.println("testIgnoreInvalidCatalog: expected [null]"); System.out.println("testIgnoreInvalidCatalog: expected [null]"); diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/unittest/catalog/jar/META-INF/MANIFEST.MF --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/jar/META-INF/MANIFEST.MF Wed Jan 11 13:06:04 2017 -0800 @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Created-By: 9-ea (Oracle Corporation) + diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/unittest/catalog/jar/META-INF/catalog/ws-addr.xsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/jar/META-INF/catalog/ws-addr.xsd Wed Jan 11 13:06:04 2017 -0800 @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r ab2c8b03c328 -r e73af7b6ce47 jaxp/test/javax/xml/jaxp/unittest/catalog/jar/META-INF/jax-ws-catalog.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/jar/META-INF/jax-ws-catalog.xml Wed Jan 11 13:06:04 2017 -0800 @@ -0,0 +1,4 @@ + + + + \ No newline at end of file