Merge
authorlana
Thu, 14 Jan 2016 12:03:08 -0800
changeset 34986 254cbe482e81
parent 34982 387e8b0026ae (current diff)
parent 34985 512ebcf54647 (diff)
child 34987 9308313bba71
Merge
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java	Thu Jan 14 12:03:08 2016 -0800
@@ -32,7 +32,6 @@
 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 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 @@
      */
     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) {
+            throw new NullPointerException(
+                    formatMessage(CatalogMessages.ERR_NULL_ARGUMENT, new Object[]{"CatalogFeatures"}));
         }
-        if (f == null) {
-            this.features = CatalogFeatures.defaults();
-        } else {
-            this.features = f;
+
+        if (file.length > 0) {
+            CatalogMessages.reportNPEOnNull("The path to the catalog file", file[0]);
         }
-        setPrefer(features.get(Feature.PREFER));
-        setDeferred(features.get(Feature.DEFER));
-        setResolve(features.get(Feature.RESOLVE));
+
+        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 @@
         }
     }
 
+    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.
      */
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java	Thu Jan 14 12:03:08 2016 -0800
@@ -38,33 +38,38 @@
     }
 
     /**
-     * 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 @@
     }
 
     /**
-     * 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 @@
     }
 
     /**
-     * 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);
     }
 }
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogUriResolver.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogUriResolver.java	Thu Jan 14 12:03:08 2016 -0800
@@ -43,9 +43,9 @@
      * 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}.
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/RewriteSystem.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/RewriteSystem.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -72,6 +72,7 @@
     public String getSystemIdStartString () {
         return systemIdStartString;
     }
+
     /**
      * Get the rewritePrefix attribute.
      * @return The rewritePrefix attribute value.
@@ -80,7 +81,6 @@
         return rewritePrefix;
     }
 
-
     /**
      * Try to match the specified systemId with the entry. Return the match if it
      * is successful and the length of the systemIdStartString is longer than the
@@ -91,14 +91,20 @@
      * @return The replacement URI if the match is successful, null if not.
      */
     public String match(String systemId, int currentMatch) {
-        if (systemIdStartString.length() <= systemId.length() &&
+        if (systemIdStartString.length() < systemId.length() &&
                 systemIdStartString.equals(systemId.substring(0, systemIdStartString.length()))) {
             if (currentMatch < systemIdStartString.length()) {
                 String prefix = rewritePrefix.toExternalForm();
-                if (!prefix.endsWith(SLASH) && !systemId.startsWith(SLASH)) {
-                    return prefix + SLASH + systemId.substring(systemIdStartString.length());
+                String sysId;
+                if (systemIdStartString.endsWith(SLASH)) {
+                    sysId = systemId.substring(systemIdStartString.length());
                 } else {
-                    return prefix + systemId.substring(systemIdStartString.length());
+                    sysId = systemId.substring(systemIdStartString.length() + 1);
+                }
+                if (prefix.endsWith(SLASH)) {
+                    return prefix + sysId;
+                } else {
+                    return prefix + SLASH + sysId;
                 }
             }
         }
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/RewriteUri.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/catalog/RewriteUri.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -72,6 +72,7 @@
     public String getURIStartString () {
         return uriStartString;
     }
+
     /**
      * Get the rewritePrefix attribute.
      * @return The rewritePrefix attribute value.
@@ -91,14 +92,20 @@
      */
     @Override
     public String match(String systemId, int currentMatch) {
-        if (uriStartString.length() <= systemId.length() &&
+        if (uriStartString.length() < systemId.length() &&
                 uriStartString.equals(systemId.substring(0, uriStartString.length()))) {
             if (currentMatch < uriStartString.length()) {
                 String prefix = rewritePrefix.toExternalForm();
-                if (!prefix.endsWith(SLASH) && !systemId.startsWith(SLASH)) {
-                    return prefix + SLASH + systemId.substring(uriStartString.length());
+                String sysId;
+                if (uriStartString.endsWith(SLASH)) {
+                    sysId = systemId.substring(uriStartString.length());
                 } else {
-                    return prefix + systemId.substring(uriStartString.length());
+                    sysId = systemId.substring(uriStartString.length() + 1);
+                }
+                if (prefix.endsWith(SLASH)) {
+                    return prefix + sysId;
+                } else {
+                    return prefix + SLASH + sysId;
                 }
             }
         }
--- a/jaxp/src/java.xml/share/classes/javax/xml/transform/Source.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/transform/Source.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -52,4 +52,17 @@
      * if setSystemId was not called.
      */
     public String getSystemId();
+
+    /**
+     * Indicates whether the {@code Source} object is empty. Empty means
+     * that there is no input available from this Source.
+     *
+     * @implSpec The default implementation of this method throws
+     * {@link UnsupportedOperationException}.
+     *
+     * @return true if the {@code Source} object is empty, false otherwise
+     */
+    default boolean isEmpty() {
+        throw new UnsupportedOperationException("The isEmpty method is not supported.");
+    }
 }
--- a/jaxp/src/java.xml/share/classes/javax/xml/transform/dom/DOMSource.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/transform/dom/DOMSource.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -122,6 +122,7 @@
      *
      * @param systemID Base URL for this DOM tree.
      */
+    @Override
     public void setSystemId(String systemID) {
         this.systemID = systemID;
     }
@@ -132,7 +133,25 @@
      *
      * @return Base URL for this DOM tree.
      */
+    @Override
     public String getSystemId() {
         return this.systemID;
     }
+
+    /**
+     * Indicates whether the {@code DOMSource} object is empty. Empty is
+     * defined as follows:
+     * <ul>
+     * <li>if the system identifier and node are {@code null};
+     * </li>
+     * <li>if the system identifier is null, and the {@code node} has no child nodes.
+     * </li>
+     * </ul>
+     *
+     * @return true if the {@code DOMSource} object is empty, false otherwise
+     */
+    @Override
+    public boolean isEmpty() {
+        return systemID == null && (node == null || !node.hasChildNodes());
+    }
 }
--- a/jaxp/src/java.xml/share/classes/javax/xml/transform/sax/SAXSource.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/transform/sax/SAXSource.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -147,6 +147,7 @@
      *
      * @param systemId The system identifier as a URI string.
      */
+    @Override
     public void setSystemId(String systemId) {
 
         if (null == inputSource) {
@@ -162,6 +163,7 @@
      *
      * @return Base URL for the <code>Source</code>, or <code>null</code>.
      */
+    @Override
     public String getSystemId() {
 
         if (inputSource == null) {
@@ -207,4 +209,22 @@
             return null;
         }
     }
+
+    /**
+     * Indicates whether the {@code SAXSource} object is empty. Empty is
+     * defined as follows:
+     * <ul>
+     * <li>if the system identifier and {@code InputSource} are {@code null};
+     * </li>
+     * <li>if the system identifier is {@code null}, and the {@code InputSource}
+     * is empty.
+     * </li>
+     * </ul>
+     *
+     * @return true if the {@code SAXSource} object is empty, false otherwise
+     */
+    @Override
+    public boolean isEmpty() {
+        return getSystemId() == null && (inputSource == null || inputSource.isEmpty());
+    }
 }
--- a/jaxp/src/java.xml/share/classes/javax/xml/transform/stax/StAXSource.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/transform/stax/StAXSource.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -209,6 +209,7 @@
      * @throws UnsupportedOperationException Is <strong>always</strong>
      *   thrown by this method.
      */
+    @Override
     public void setSystemId(final String systemId) {
 
         throw new UnsupportedOperationException(
@@ -229,8 +230,21 @@
      *
      * @return System identifier used by this <code>StAXSource</code>.
      */
+    @Override
     public String getSystemId() {
 
         return systemId;
     }
+
+    /**
+     * Indicates whether the {@code StAXSource} object is empty. Since a
+     * {@code StAXSource} object can never be empty, this method always returns
+     * false.
+     *
+     * @return unconditionally false
+     */
+    @Override
+    public boolean isEmpty() {
+        return false;
+    }
 }
--- a/jaxp/src/java.xml/share/classes/javax/xml/transform/stream/StreamSource.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/javax/xml/transform/stream/StreamSource.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -26,8 +26,10 @@
 package javax.xml.transform.stream;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
+import javax.xml.transform.Result;
 
 import javax.xml.transform.Source;
 
@@ -233,6 +235,7 @@
      *
      * @param systemId The system identifier as a URL string.
      */
+    @Override
     public void setSystemId(String systemId) {
         this.systemId = systemId;
     }
@@ -243,6 +246,7 @@
      * @return The system identifier that was set with setSystemId, or null
      * if setSystemId was not called.
      */
+    @Override
     public String getSystemId() {
         return systemId;
     }
@@ -259,6 +263,59 @@
         this.systemId = f.toURI().toASCIIString();
     }
 
+    /**
+     * Indicates whether the {@code StreamSource} object is empty. Empty is
+     * defined as follows:
+     * <ul>
+     * <li>All of the input sources, including the public identifier, system
+     * identifier, byte stream, and character stream, are {@code null}.
+     * </li>
+     * <li>The public identifier and system identifier are {@code null}, and
+     * byte and character stream are either {@code null} or contain no byte or
+     * character.
+     * <p>
+     * Note that this method will reset the byte stream if it is provided, or
+     * the character stream if the byte stream is not provided.
+     * </li>
+     * </ul>
+     * <p>
+     * In case of error while checking the byte or character stream, the method
+     * will return false to allow the XML processor to handle the error.
+     *
+     * @return true if the {@code StreamSource} object is empty, false otherwise
+     */
+    @Override
+    public boolean isEmpty() {
+        return (publicId == null && systemId == null && isStreamEmpty());
+    }
+
+    private boolean isStreamEmpty() {
+        boolean empty = true;
+        try {
+            if (inputStream != null) {
+                inputStream.reset();
+                int bytesRead = inputStream.available();
+                if (bytesRead > 0) {
+                    return false;
+                }
+            }
+
+            if (reader != null) {
+                reader.reset();
+                int c = reader.read();
+                reader.reset();
+                if (c != -1) {
+                    return false;
+                }
+            }
+        } catch (IOException ex) {
+            //in case of error, return false
+            return false;
+        }
+
+        return empty;
+    }
+
     //////////////////////////////////////////////////////////////////////
     // Internal state.
     //////////////////////////////////////////////////////////////////////
--- a/jaxp/src/java.xml/share/classes/org/xml/sax/InputSource.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/src/java.xml/share/classes/org/xml/sax/InputSource.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -30,6 +30,7 @@
 
 package org.xml.sax;
 
+import java.io.IOException;
 import java.io.Reader;
 import java.io.InputStream;
 
@@ -343,8 +344,57 @@
         return characterStream;
     }
 
+    /**
+     * Indicates whether the {@code InputSource} object is empty. Empty is
+     * defined as follows:
+     * <ul>
+     * <li>All of the input sources, including the public identifier, system
+     * identifier, byte stream, and character stream, are {@code null}.
+     * </li>
+     * <li>The public identifier and system identifier are  {@code null}, and
+     * byte and character stream are either  {@code null} or contain no byte
+     * or character.
+     * <p>
+     * Note that this method will reset the byte stream if it is provided, or
+     * the character stream if the byte stream is not provided.
+     * </li>
+     * </ul>
+     * <p>
+     * In case of error while checking the byte or character stream, the method
+     * will return false to allow the XML processor to handle the error.
+     *
+     * @return true if the {@code InputSource} object is empty, false otherwise
+     */
+    public boolean isEmpty() {
+        return (publicId == null && systemId == null && isStreamEmpty());
+    }
 
+    private boolean isStreamEmpty() {
+        boolean empty = true;
+        try {
+            if (byteStream != null) {
+                byteStream.reset();
+                int bytesRead = byteStream.available();
+                if (bytesRead > 0) {
+                    return false;
+                }
+            }
 
+            if (characterStream != null) {
+                characterStream.reset();
+                int c = characterStream.read();
+                characterStream.reset();
+                if (c != -1) {
+                    return false;
+                }
+            }
+        } catch (IOException ex) {
+            //in case of error, return false
+            return false;
+        }
+
+        return empty;
+    }
     ////////////////////////////////////////////////////////////////////
     // Internal state.
     ////////////////////////////////////////////////////////////////////
--- a/jaxp/test/javax/xml/jaxp/functional/catalog/DeferFeatureTest.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/test/javax/xml/jaxp/functional/catalog/DeferFeatureTest.java	Thu Jan 14 12:03:08 2016 -0800
@@ -56,23 +56,14 @@
 
     @DataProvider(name = "catalog-countOfLoadedCatalogFile")
     private Object[][] data() {
-        return new Object[][] {
-                // This catalog specifies null catalog explicitly,
-                // and the count of loaded catalogs should be 0.
-                { createCatalog(null), 0 },
-
-                // This catalog specifies null catalog implicitly,
-                // and the count of loaded catalogs should be 0.
-                { createCatalog(CatalogFeatures.defaults()), 0 },
-
-                // This catalog loads null catalog with true DEFER,
-                // and the count of loaded catalogs should be 0.
-                { createCatalog(createDeferFeature(DEFER_TRUE)), 0 },
-
-                // This catalog loads null catalog with false DEFER.
-                // It should load all of none-current catalogs and the
-                // count of loaded catalogs should be 3.
-                { createCatalog(createDeferFeature(DEFER_FALSE)), 3 } };
+        return new Object[][]{
+            // By default, alternative catalogs are not loaded.
+            {createCatalog(CatalogFeatures.defaults()), 0},
+            // Alternative catalogs are not loaded when DEFER is set to true.
+            {createCatalog(createDeferFeature(DEFER_TRUE)), 0},
+            // The 3 alternative catalogs are not pre-loaded
+            //when DEFER is set to false.
+            {createCatalog(createDeferFeature(DEFER_FALSE)), 3}};
     }
 
     private CatalogFeatures createDeferFeature(String defer) {
--- a/jaxp/test/javax/xml/jaxp/libs/catalog/CatalogTestUtils.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/test/javax/xml/jaxp/libs/catalog/CatalogTestUtils.java	Thu Jan 14 12:03:08 2016 -0800
@@ -83,7 +83,7 @@
      * Creates CatalogResolver with a set of catalogs.
      */
     static CatalogResolver catalogResolver(String... catalogName) {
-        return catalogResolver(null, catalogName);
+        return catalogResolver(CatalogFeatures.defaults(), catalogName);
     }
 
     /*
@@ -91,15 +91,16 @@
      */
     static CatalogResolver catalogResolver(CatalogFeatures features,
             String... catalogName) {
-        return CatalogManager.catalogResolver(features,
-                getCatalogPaths(catalogName));
+        return (catalogName == null) ?
+                CatalogManager.catalogResolver(features) :
+                CatalogManager.catalogResolver(features, getCatalogPaths(catalogName));
     }
 
     /*
      * Creates catalogUriResolver with a set of catalogs.
      */
     static CatalogUriResolver catalogUriResolver(String... catalogName) {
-        return catalogUriResolver(null, catalogName);
+        return catalogUriResolver(CatalogFeatures.defaults(), catalogName);
     }
 
     /*
@@ -107,8 +108,9 @@
      */
     static CatalogUriResolver catalogUriResolver(
             CatalogFeatures features, String... catalogName) {
-        return CatalogManager.catalogUriResolver(features,
-                getCatalogPaths(catalogName));
+        return (catalogName == null) ?
+                CatalogManager.catalogUriResolver(features) :
+                CatalogManager.catalogUriResolver(features, getCatalogPaths(catalogName));
     }
 
     // Gets the paths of the specified catalogs.
--- a/jaxp/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java	Thu Jan 14 12:03:08 2016 -0800
@@ -89,7 +89,7 @@
     /**
      * BOM table for storing BOM header.
      */
-    private final static Map<String, byte[]> bom = new HashMap();
+    private final static Map<String, byte[]> bom = new HashMap<>();
 
     /**
      * Initialize all BOM headers.
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java	Thu Jan 14 08:08:18 2016 -0800
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java	Thu Jan 14 12:03:08 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -27,14 +27,13 @@
 import javax.xml.catalog.CatalogFeatures.Feature;
 import javax.xml.catalog.CatalogManager;
 import javax.xml.catalog.CatalogResolver;
+import javax.xml.catalog.CatalogUriResolver;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
-import static jaxp.library.JAXPTestUtilities.getPathByClassName;
 import org.testng.Assert;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
-import org.w3c.dom.Element;
 import org.xml.sax.Attributes;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.SAXException;
@@ -42,12 +41,66 @@
 import org.xml.sax.ext.DefaultHandler2;
 
 /*
- * @bug 8081248
+ * @bug 8081248, 8144966, 8146606
  * @summary Tests basic Catalog functions.
  */
 
 public class CatalogTest {
     /*
+       @bug 8146606
+       Verifies that the resulting systemId does not contain duplicate slashes
+    */
+    public void testRewriteSystem() {
+        String catalog = getClass().getResource("rewriteCatalog.xml").getFile();
+
+        try {
+            CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
+            String actualSystemId = resolver.resolveEntity(null, "http://remote.com/dtd/book.dtd").getSystemId();
+            Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
+        } catch (Exception e) {
+            Assert.fail(e.getMessage());
+        }
+
+    }
+
+    /*
+       @bug 8146606
+       Verifies that the resulting systemId does not contain duplicate slashes
+    */
+    public void testRewriteUri() {
+        String catalog = getClass().getResource("rewriteCatalog.xml").getFile();
+
+        try {
+
+            CatalogUriResolver resolver = CatalogManager.catalogUriResolver(CatalogFeatures.defaults(), catalog);
+            String actualSystemId = resolver.resolve("http://remote.com/import/import.xsl", null).getSystemId();
+            Assert.assertTrue(!actualSystemId.contains("//"), "result contains duplicate slashes");
+        } catch (Exception e) {
+            Assert.fail(e.getMessage());
+        }
+    }
+
+    /*
+       @bug 8144966
+       Verifies that passing null as CatalogFeatures will result in a NPE.
+    */
+    @Test(expectedExceptions = NullPointerException.class)
+    public void testFeatureNull() {
+        CatalogResolver resolver = CatalogManager.catalogResolver(null, "");
+
+    }
+
+    /*
+       @bug 8144966
+       Verifies that passing null as the path will result in a NPE.
+    */
+    @Test(expectedExceptions = NullPointerException.class)
+    public void testPathNull() {
+        String path = null;
+        CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), path);
+    }
+
+    /*
        Tests basic catalog feature by using a CatalogResolver instance to
     resolve a DTD reference to a locally specified DTD file. If the resolution
     is successful, the Handler shall return the value of the entity reference
@@ -61,7 +114,7 @@
         }
         String url = getClass().getResource(xml).getFile();
         try {
-            CatalogResolver cr = CatalogManager.catalogResolver(null, catalog);
+            CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
             XMLReader reader = saxParser.getXMLReader();
             reader.setEntityResolver(cr);
             MyHandler handler = new MyHandler(saxParser);
@@ -84,7 +137,7 @@
 
         String test = "testInvalidCatalog";
         try {
-            CatalogResolver resolver = CatalogManager.catalogResolver(null, catalog);
+            CatalogResolver resolver = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
             String actualSystemId = resolver.resolveEntity(null, "http://remote/xml/dtd/sys/alice/docAlice.dtd").getSystemId();
         } catch (Exception e) {
             String msg = e.getMessage();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/rewriteCatalog.xml	Thu Jan 14 12:03:08 2016 -0800
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<catalog
+  xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
+
+    <rewriteSystem systemIdStartString="http://remote.com/dtd"
+                   rewritePrefix="file:///share/docbook/docbook/pass"/> 
+
+    <rewriteURI uriStartString="http://remote.com/import" rewritePrefix="file:///local/import" />
+    
+</catalog>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/Sources.java	Thu Jan 14 12:03:08 2016 -0800
@@ -0,0 +1,202 @@
+/*
+ * 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 common;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stax.StAXSource;
+import javax.xml.transform.stream.StreamSource;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/*
+ * @bug 8144967
+ * @summary Tests related to the javax.xml.transform.Source
+ * and org.xml.sax.InputSource
+ */
+public class Sources {
+
+    /**
+     * @bug 8144967
+     * Tests whether a Source object is empty
+     * @param source the Source object
+     */
+    @Test(dataProvider = "emptySources")
+    public void testIsEmpty(Source source) {
+        Assert.assertTrue(source.isEmpty(), "The source is not empty");
+    }
+
+    /**
+     * @bug 8144967
+     * Tests that the source is not empty
+     * @param source the Source object
+     */
+    @Test(dataProvider = "nonEmptySources")
+    public void testIsNotEmpty(Source source) {
+        Assert.assertTrue(!source.isEmpty(), "The source is empty");
+    }
+
+    /**
+     * @bug 8144967
+     * Tests whether an InputSource object is empty
+     * @param source the InputSource object
+     */
+    @Test(dataProvider = "emptyInputSource")
+    public void testISIsEmpty(InputSource source) {
+        Assert.assertTrue(source.isEmpty(), "The source is not empty");
+    }
+
+    /*
+     * DataProvider: sources that are empty
+     */
+    @DataProvider(name = "emptySources")
+    Object[][] getSources() throws URISyntaxException {
+
+        return new Object[][]{
+            {new DOMSource()},
+            {new DOMSource(getDocument())},
+            {new SAXSource()},
+            {new SAXSource(new InputSource(new StringReader("")))},
+            {new SAXSource(getXMLReader(), new InputSource(new StringReader("")))},
+            {new StreamSource()},
+            {new StreamSource(new ByteArrayInputStream("".getBytes()))},
+            {new StreamSource(new StringReader(""))},
+            {new StreamSource(new StringReader(""), null)},
+            {new StreamSource((String) null)}
+        };
+    }
+
+    /*
+     * DataProvider: sources that are not empty
+     */
+    @DataProvider(name = "nonEmptySources")
+    Object[][] getSourcesEx() throws URISyntaxException {
+        StAXSource ss = null;
+        try {
+            ss = new StAXSource(getXMLEventReader());
+        } catch (XMLStreamException ex) {}
+
+        return new Object[][]{
+            //This will set a non-null systemId on the resulting StreamSource
+            {new StreamSource(new File(""))},
+            //Can't tell because XMLStreamReader is a pull parser, cursor advancement
+            //would have been required in order to examine the reader.
+            {new StAXSource(getXMLStreamReader())},
+            {ss}
+        };
+    }
+
+    /*
+     * DataProvider: sources that are empty
+     */
+    @DataProvider(name = "emptyInputSource")
+    Object[][] getInputSources() throws URISyntaxException {
+        byte[] utf8Bytes = null;
+        try {
+            utf8Bytes = "".getBytes("UTF8");
+        } catch (UnsupportedEncodingException ex) {
+            throw new RuntimeException(ex.getMessage());
+        }
+        return new Object[][]{
+            {new InputSource()},
+            {new InputSource(new ByteArrayInputStream(utf8Bytes))},
+            {new InputSource(new StringReader(""))},
+            {new InputSource((String) null)}
+        };
+    }
+
+    /**
+     * Returns an instance of Document.
+     *
+     * @return an instance of Document.
+     */
+    private Document getDocument() {
+        Document doc = null;
+        try {
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            doc = dbf.newDocumentBuilder().newDocument();
+        } catch (ParserConfigurationException ex) {}
+        return doc;
+    }
+
+    /**
+     * Returns an instance of XMLReader.
+     *
+     * @return an instance of XMLReader.
+     */
+    private XMLReader getXMLReader() {
+        XMLReader reader = null;
+        try {
+            reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+        } catch (ParserConfigurationException | SAXException ex) {}
+        return reader;
+    }
+
+    /**
+     * Returns an instance of XMLStreamReader.
+     *
+     * @return an instance of XMLStreamReader.
+     */
+    private XMLStreamReader getXMLStreamReader() {
+        XMLStreamReader r = null;
+        try {
+            XMLInputFactory xif = XMLInputFactory.newInstance();
+            r = xif.createXMLStreamReader(new ByteArrayInputStream("".getBytes()));
+        } catch (XMLStreamException ex) {}
+
+        return r;
+    }
+
+    /**
+     * Returns an instance of XMLEventReader.
+     *
+     * @return an instance of XMLEventReader.
+     */
+    private XMLEventReader getXMLEventReader() {
+        XMLEventReader r = null;
+        try {
+            r = XMLInputFactory.newInstance().createXMLEventReader(
+                            new ByteArrayInputStream("".getBytes()));
+        } catch (XMLStreamException ex) {}
+
+        return r;
+    }
+}