changeset 149:9f9aa1efd581 jdk6-b46

8186080: Transform XML interfaces 8188880: A JAXB JCK test failure found after 8186080 Reviewed-by: joehw, lancea, dfuchs
author aefimov
date Thu, 19 Oct 2017 17:03:20 +0100
parents 5381e4f5902f
children 9d183c18dcd6
files drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltDynamic.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltSets.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/Extensions.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/Translet.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/output/TransletOutputHandlerFactory.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/SAX2DOM.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TrAXFilter.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/Util.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/opti/SchemaParsingConfig.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/traversers/SchemaContentHandler.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/DOMValidatorHelper.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/StAXValidatorHelper.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorHandlerImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/DTDConfiguration.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/NonValidatingConfiguration.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/util/XMLCatalogResolver.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/dtm/DTMManager.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/dtm/ref/DTMManagerDefault.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/Catalog.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/CatalogManager.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/Resolver.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/CatalogResolver.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingParser.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLFilter.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLReader.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/TreeWalker.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/utils/AttList.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/utils/DOM2Helper.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/AttList.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/DOM2Helper.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/DOMHelper.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/DOMOrder.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/TreeWalker.java drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/CachedXPathAPI.java drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/XPathAPI.java drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/XPathContext.java drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/JAXPExtensionsProvider.java drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathExpressionImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java drop_included/jaxp_src/src/javax/xml/transform/FactoryFinder.java drop_included/jaxp_src/src/javax/xml/transform/TransformerFactory.java drop_included/jaxp_src/src/javax/xml/validation/SchemaFactoryFinder.java drop_included/jaxp_src/src/javax/xml/xpath/XPathFactoryFinder.java drop_included/jaxp_src/src/jdk/xml/internal/JdkXmlFeatures.java drop_included/jaxp_src/src/jdk/xml/internal/JdkXmlUtils.java drop_included/jaxp_src/src/jdk/xml/internal/SecuritySupport.java src/jdk/xml/internal/JdkXmlFeatures.java src/jdk/xml/internal/JdkXmlUtils.java src/jdk/xml/internal/SecuritySupport.java
diffstat 68 files changed, 2739 insertions(+), 2903 deletions(-) [+]
line wrap: on
line diff
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltDynamic.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltDynamic.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -37,6 +36,7 @@
 import com.sun.org.apache.xpath.internal.objects.XNodeSet;
 import com.sun.org.apache.xpath.internal.objects.XNumber;
 import com.sun.org.apache.xpath.internal.objects.XObject;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -411,10 +411,7 @@
         {
           if (lDoc == null)
           {
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            dbf.setNamespaceAware(true);
-            DocumentBuilder db = dbf.newDocumentBuilder();
-            lDoc = db.newDocument();
+            lDoc = JdkXmlUtils.getDOMDocument();
           }
 
           Element element = null;
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltSets.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltSets.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -22,7 +22,7 @@
  */
 package com.sun.org.apache.xalan.internal.lib;
 
-import com.sun.org.apache.xml.internal.utils.DOMHelper;
+import com.sun.org.apache.xml.internal.utils.DOM2Helper;
 import com.sun.org.apache.xpath.internal.NodeSet;
 import java.util.HashMap;
 import java.util.Map;
@@ -72,8 +72,8 @@
     for (int i = 0; i < nl1.getLength(); i++)
     {
       Node testNode = nl1.item(i);
-      if (DOMHelper.isNodeAfter(testNode, endNode)
-          && !DOMHelper.isNodeTheSame(testNode, endNode))
+      if (DOM2Helper.isNodeAfter(testNode, endNode)
+          && !DOM2Helper.isNodeTheSame(testNode, endNode))
         leadNodes.addElement(testNode);
     }
     return leadNodes;
@@ -107,8 +107,8 @@
     for (int i = 0; i < nl1.getLength(); i++)
     {
       Node testNode = nl1.item(i);
-      if (DOMHelper.isNodeAfter(startNode, testNode)
-          && !DOMHelper.isNodeTheSame(startNode, testNode))
+      if (DOM2Helper.isNodeAfter(startNode, testNode)
+          && !DOM2Helper.isNodeTheSame(startNode, testNode))
         trailNodes.addElement(testNode);
     }
     return trailNodes;
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -23,12 +22,8 @@
 package com.sun.org.apache.xalan.internal.lib;
 
 import java.util.StringTokenizer;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.ParserConfigurationException;
-
 import com.sun.org.apache.xpath.internal.NodeSet;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -52,7 +47,6 @@
  */
 public class ExsltStrings extends ExsltBase
 {
-   static final String JDK_DEFAULT_DOM = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
 
   /**
    * The str:align function aligns a string within another string.
@@ -227,7 +221,7 @@
         token = str.substring(fromIndex);
       }
 
-      Document doc = getDocument();
+      Document doc = JdkXmlUtils.getDOMDocument();
       synchronized (doc)
       {
         Element element = doc.createElement("token");
@@ -291,7 +285,7 @@
     {
       StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
 
-      Document doc = getDocument();
+      Document doc = JdkXmlUtils.getDOMDocument();
       synchronized (doc)
       {
         while (lTokenizer.hasMoreTokens())
@@ -307,7 +301,7 @@
     else
     {
 
-      Document doc = getDocument();
+      Document doc = JdkXmlUtils.getDOMDocument();
       synchronized (doc)
       {
         for (int i = 0; i < toTokenize.length(); i++)
@@ -329,23 +323,4 @@
   {
     return tokenize(toTokenize, " \t\n\r");
   }
-
-    /**
-   * @return an instance of DOM Document
-     */
-   private static Document getDocument()
-   {
-        try
-        {
-            if (System.getSecurityManager() == null) {
-                return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-            } else {
-                return DocumentBuilderFactory.newInstance(JDK_DEFAULT_DOM, null).newDocumentBuilder().newDocument();
-            }
-        }
-        catch(ParserConfigurationException pce)
-        {
-            throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(pce);
-        }
-    }
 }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/Extensions.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/lib/Extensions.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -31,8 +31,8 @@
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.StringTokenizer;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
+import jdk.xml.internal.JdkXmlUtils;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Node;
@@ -51,7 +51,6 @@
  */
 public class Extensions
 {
-    static final String JDK_DEFAULT_DOM = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
   /**
    * Constructor Extensions
    *
@@ -110,7 +109,7 @@
 
       // This no longer will work right since the DTM.
       // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
-      Document myDoc = getDocument();
+      Document myDoc = JdkXmlUtils.getDOMDocument();
 
       Text textNode = myDoc.createTextNode(textNodeValue);
       DocumentFragment docFrag = myDoc.createDocumentFragment();
@@ -236,7 +235,7 @@
   public static NodeList tokenize(String toTokenize, String delims)
   {
 
-    Document doc = getDocument();
+    Document doc = JdkXmlUtils.getDOMDocument();
 
     StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
     NodeSet resultSet = new NodeSet();
@@ -270,119 +269,4 @@
     return tokenize(toTokenize, " \t\n\r");
   }
 
-  /**
-   * Return a Node of basic debugging information from the
-   * EnvironmentCheck utility about the Java environment.
-   *
-   * <p>Simply calls the {@link com.sun.org.apache.xalan.internal.xslt.EnvironmentCheck}
-   * utility to grab info about the Java environment and CLASSPATH,
-   * etc., and then returns the resulting Node.  Stylesheets can
-   * then maniuplate this data or simply xsl:copy-of the Node.  Note
-   * that we first attempt to load the more advanced
-   * org.apache.env.Which utility by reflection; only if that fails
-   * to we still use the internal version.  Which is available from
-   * <a href="http://xml.apache.org/commons/">http://xml.apache.org/commons/</a>.</p>
-   *
-   * <p>We throw a WrappedRuntimeException in the unlikely case
-   * that reading information from the environment throws us an
-   * exception. (Is this really the best thing to do?)</p>
-   *
-   * @param myContext an <code>ExpressionContext</code> passed in by the
-   *                  extension mechanism.  This must be an XPathContext.
-   * @return a Node as described above.
-   */
-  public static Node checkEnvironment(ExpressionContext myContext)
-  {
-
-    Document factoryDocument = getDocument();
-
-    Node resultNode = null;
-    try
-    {
-      // First use reflection to try to load Which, which is a
-      //  better version of EnvironmentCheck
-      resultNode = checkEnvironmentUsingWhich(myContext, factoryDocument);
-
-      if (null != resultNode)
-        return resultNode;
-
-      // If reflection failed, fallback to our internal EnvironmentCheck
-      EnvironmentCheck envChecker = new EnvironmentCheck();
-      Map<String, Object> h = envChecker.getEnvironmentHash();
-      resultNode = factoryDocument.createElement("checkEnvironmentExtension");
-      envChecker.appendEnvironmentReport(resultNode, factoryDocument, h);
-      envChecker = null;
-    }
-    catch(Exception e)
-    {
-      throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
-    }
-
-    return resultNode;
-  }
-
-  /**
-   * Private worker method to attempt to use org.apache.env.Which.
-   *
-   * @param myContext an <code>ExpressionContext</code> passed in by the
-   *                  extension mechanism.  This must be an XPathContext.
-   * @param factoryDocument providing createElement services, etc.
-   * @return a Node with environment info; null if any error
-   */
-  private static Node checkEnvironmentUsingWhich(ExpressionContext myContext,
-        Document factoryDocument)
-  {
-    final String WHICH_CLASSNAME = "org.apache.env.Which";
-    final String WHICH_METHODNAME = "which";
-    final Class WHICH_METHOD_ARGS[] = { java.util.Hashtable.class,
-                                        java.lang.String.class,
-                                        java.lang.String.class };
-    try
-    {
-      // Use reflection to try to find xml-commons utility 'Which'
-      Class clazz = ObjectFactory.findProviderClass(
-        WHICH_CLASSNAME, ObjectFactory.findClassLoader(), true);
-      if (null == clazz)
-        return null;
-
-      // Fully qualify names since this is the only method they're used in
-      java.lang.reflect.Method method = clazz.getMethod(WHICH_METHODNAME, WHICH_METHOD_ARGS);
-      Hashtable report = new Hashtable();
-
-      // Call the method with our Hashtable, common options, and ignore return value
-      Object[] methodArgs = { report, "XmlCommons;Xalan;Xerces;Crimson;Ant", "" };
-      Object returnValue = method.invoke(null, methodArgs);
-
-      // Create a parent to hold the report and append hash to it
-      Node resultNode = factoryDocument.createElement("checkEnvironmentExtension");
-      com.sun.org.apache.xml.internal.utils.Hashtree2Node.appendHashToNode(report, "whichReport",
-            resultNode, factoryDocument);
-
-      return resultNode;
-    }
-    catch (Throwable t)
-    {
-      // Simply return null; no need to report error
-      return null;
-    }
-  }
-
-    /**
-   * @return an instance of DOM Document
-     */
-   private static Document getDocument()
-   {
-        try
-        {
-            if (System.getSecurityManager() == null) {
-                return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-            } else {
-                return DocumentBuilderFactory.newInstance(JDK_DEFAULT_DOM, null).newDocumentBuilder().newDocument();
-            }
-        }
-        catch(ParserConfigurationException pce)
-        {
-            throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(pce);
-        }
-    }
 }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/Translet.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/Translet.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -51,4 +50,6 @@
     public String[] getUrisArray();
     public int[]    getTypesArray();
     public String[] getNamespaceArray();
+    public boolean overrideDefaultParser();
+    public void setOverrideDefaultParser(boolean flag);
 }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -26,6 +25,7 @@
 import java.io.File;
 import java.net.URL;
 import java.util.Vector;
+import jdk.xml.internal.JdkXmlFeatures;
 
 import com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOpt;
 import com.sun.org.apache.xalan.internal.xsltc.cmdline.getopt.GetOptsException;
@@ -78,7 +78,7 @@
 	    final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv");
 	    if (args.length < 1) printUsage();
 
-	    final XSLTC xsltc = new XSLTC();
+		final XSLTC xsltc = new XSLTC(new JdkXmlFeatures(false));
 	    xsltc.init();
 
 	    int c;
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java	Thu Oct 19 17:03:20 2017 +0100
@@ -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.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -54,6 +54,7 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Vector;
+import jdk.xml.internal.JdkXmlFeatures;
 
 /**
  * @author Jacek Ambroziak
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java	Thu Oct 19 17:03:20 2017 +0100
@@ -34,12 +34,10 @@
 import java.util.Stack;
 import java.util.StringTokenizer;
 import java.util.Vector;
+import jdk.xml.internal.JdkXmlUtils;
 
 import com.sun.java_cup.internal.runtime.Symbol;
 import javax.xml.XMLConstants;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
 
 import com.sun.org.apache.xalan.internal.XalanConstants;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
@@ -53,7 +51,6 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
 import org.xml.sax.XMLReader;
 
 /**
@@ -96,8 +93,11 @@
 
     private int _currentImportPrecedence;
 
-    public Parser(XSLTC xsltc) {
+    private boolean _overrideDefaultParser;
+
+    public Parser(XSLTC xsltc, boolean useOverrideDefaultParser) {
         _xsltc = xsltc;
+        _overrideDefaultParser = useOverrideDefaultParser;
     }
 
     public void init() {
@@ -450,54 +450,25 @@
      * @return The root of the abstract syntax tree
      */
     public SyntaxTreeNode parse(InputSource input) {
-        try {
-            // Create a SAX parser and get the XMLReader object it uses
-            final SAXParserFactory factory = SAXParserFactory.newInstance();
+        final XMLReader reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
+                _xsltc.isSecureProcessing());
 
-            if (_xsltc.isSecureProcessing()) {
-                try {
-                    factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
-                }
-                catch (SAXException e) {}
-            }
-
-            try {
-                factory.setFeature(Constants.NAMESPACE_FEATURE,true);
-            }
-            catch (Exception e) {
-                factory.setNamespaceAware(true);
+        String lastProperty = "";
+        try {
+            XMLSecurityManager securityManager =
+                    (XMLSecurityManager) _xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
+            for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
+                lastProperty = limit.apiProperty();
+                reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
             }
-            final SAXParser parser = factory.newSAXParser();
-            final XMLReader reader = parser.getXMLReader();
-            String lastProperty = "";
-            try {
-                XMLSecurityManager securityManager =
-                        (XMLSecurityManager)_xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
-                for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
-                    lastProperty = limit.apiProperty();
-                    reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
-                }
-                if (securityManager.printEntityCountInfo()) {
-                    lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
-                    parser.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
-                }
-            } catch (SAXException se) {
-                XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);
+            if (securityManager.printEntityCountInfo()) {
+                lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
+                reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
             }
-
-            return(parse(reader, input));
-        }
-        catch (ParserConfigurationException e) {
-            ErrorMsg err = new ErrorMsg(ErrorMsg.SAX_PARSER_CONFIG_ERR);
-            reportError(ERROR, err);
+        } catch (SAXException se) {
+            XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);
         }
-        catch (SAXParseException e){
-            reportError(ERROR, new ErrorMsg(e.getMessage(),e.getLineNumber()));
-        }
-        catch (SAXException e) {
-            reportError(ERROR, new ErrorMsg(e.getMessage()));
-        }
-        return null;
+        return (parse(reader, input));
     }
 
     public SyntaxTreeNode getDocumentRoot() {
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -48,6 +48,7 @@
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
 import com.sun.org.apache.xml.internal.dtm.DTM;
 
+import jdk.xml.internal.JdkXmlFeatures;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
@@ -108,6 +109,8 @@
 
     private XMLSecurityManager _xmlSecurityManager;
 
+    private final JdkXmlFeatures _xmlFeatures;
+
     // Compiler options (passed from command line or XSLTC client)
     private boolean _debug = false;      // -x
     private String  _jarFileName = null; // -j <jar-file-name>
@@ -135,11 +138,17 @@
      */
     private boolean _isSecureProcessing = false;
 
+    private boolean _overrideDefaultParser;
+
+
     /**
      * XSLTC compiler constructor
      */
-    public XSLTC() {
-        _parser = new Parser(this);
+    public XSLTC(JdkXmlFeatures featureManager) {
+        _overrideDefaultParser = featureManager.getFeature(
+                JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
+        _parser = new Parser(this, _overrideDefaultParser);
+        _xmlFeatures = featureManager;
     }
 
     /**
@@ -157,6 +166,15 @@
     }
 
     /**
+     * Return the value of the specified feature
+     * @param name name of the feature
+     * @return true if the feature is enabled, false otherwise
+     */
+    public boolean getFeature(JdkXmlFeatures.XmlFeature name) {
+        return _xmlFeatures.getFeature(name);
+    }
+
+    /**
      * Return allowed protocols for accessing external stylesheet.
      */
     public Object getProperty(String name) {
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java	Thu Oct 19 17:03:20 2017 +0100
@@ -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.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -47,6 +47,7 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Templates;
+import jdk.xml.internal.JdkXmlUtils;
 import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
 
@@ -105,6 +106,8 @@
     // This is the name of the index used for ID attributes
     private final static String ID_INDEX_NAME = "##id";
 
+    private boolean _overrideDefaultParser;
+
     
     /************************************************************************
      * Debugging
@@ -549,7 +552,7 @@
     {
 	try {
 	    final TransletOutputHandlerFactory factory 
-		= TransletOutputHandlerFactory.newInstance();
+		= TransletOutputHandlerFactory.newInstance(_overrideDefaultParser);
 
             String dirStr = new File(filename).getParent();
             if ((null != dirStr) && (dirStr.length() > 0)) {
@@ -740,7 +743,21 @@
     
     public void setTemplates(Templates templates) {
     	_templates = templates;
-    }    
+    }
+
+    /**
+     * Return the state of the services mechanism feature.
+     */
+    public boolean overrideDefaultParser() {
+        return _overrideDefaultParser;
+    }
+
+    /**
+     * Set the state of the services mechanism feature.
+     */
+    public void setOverrideDefaultParser(boolean flag) {
+        _overrideDefaultParser = flag;
+    }
     
     /************************************************************************
      * DOMImplementation caching for basis library
@@ -751,8 +768,8 @@
         throws ParserConfigurationException 
     {
         if (_domImplementation == null) {
-            _domImplementation = DocumentBuilderFactory.newInstance()
-                .newDocumentBuilder().getDOMImplementation();
+            DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(_overrideDefaultParser);
+            _domImplementation = dbf.newDocumentBuilder().getDOMImplementation();
         }
         return _domImplementation.createDocument(uri, qname, null);
     }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/output/TransletOutputHandlerFactory.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/runtime/output/TransletOutputHandlerFactory.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -72,8 +71,18 @@
     private ContentHandler _handler                 = null;
     private LexicalHandler _lexHandler              = null;
 
+    private boolean _overrideDefaultParser;
+
     static public TransletOutputHandlerFactory newInstance() {
-        return new TransletOutputHandlerFactory();
+        return new TransletOutputHandlerFactory(true);
+    }
+
+    static public TransletOutputHandlerFactory newInstance(boolean overrideDefaultParser) {
+        return new TransletOutputHandlerFactory(overrideDefaultParser);
+    }
+
+    public TransletOutputHandlerFactory(boolean overrideDefaultParser) {
+        _overrideDefaultParser = overrideDefaultParser;
     }
 
     public void setOutputType(int outputType) {
@@ -188,7 +197,9 @@
                 return result;
 
             case DOM :
-                _handler = (_node != null) ? new SAX2DOM(_node, _nextSibling) : new SAX2DOM();
+                _handler = (_node != null) ?
+                        new SAX2DOM(_node, _nextSibling, _overrideDefaultParser) :
+                        new SAX2DOM(_overrideDefaultParser);
                 _lexHandler = (LexicalHandler) _handler;
                 // falls through
             case STAX :
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/SAX2DOM.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/SAX2DOM.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -32,12 +31,12 @@
 import javax.xml.parsers.ParserConfigurationException;
 
 import com.sun.org.apache.xalan.internal.xsltc.runtime.Constants;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.w3c.dom.Comment;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-import org.w3c.dom.Text;
 import org.w3c.dom.ProcessingInstruction;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
@@ -69,27 +68,16 @@
      * synchronization because the Javadoc is not explicit about 
      * thread safety.
      */
-    static final DocumentBuilderFactory _factory =
-            DocumentBuilderFactory.newInstance();
-    static final DocumentBuilder _internalBuilder;
-    static {
-        DocumentBuilder tmpBuilder = null;
-        try {
-            if (_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl) {
-                tmpBuilder = _factory.newDocumentBuilder();
-            }
-        } catch(Exception e) {
-            // It's OK. Will create DocumentBuilder every time
-        }
-        _internalBuilder = tmpBuilder;
-    }
-    
-    public SAX2DOM() throws ParserConfigurationException {
-        _document = createDocument();
+    static DocumentBuilderFactory _factory;
+    static boolean _internal;
+
+    public SAX2DOM(boolean overrideDefaultParser) throws ParserConfigurationException {
+        _document = createDocument(overrideDefaultParser);
 	_root = _document;
     }
 
-    public SAX2DOM(Node root, Node nextSibling) throws ParserConfigurationException {
+    public SAX2DOM(Node root, Node nextSibling, boolean overrideDefaultParser)
+            throws ParserConfigurationException {
 	_root = root;
 	if (root instanceof Document) {
 	  _document = (Document)root;
@@ -98,15 +86,15 @@
 	  _document = root.getOwnerDocument();
 	}
 	else {
-          _document = createDocument();
-	  _root = _document;
+        _document = createDocument(overrideDefaultParser);
+        _root = _document;
 	}
 	
 	_nextSibling = nextSibling;
     }
-    
-    public SAX2DOM(Node root) throws ParserConfigurationException {
-        this(root, null);
+
+    public SAX2DOM(Node root, boolean overrideDefaultParser) throws ParserConfigurationException {
+        this(root, null, overrideDefaultParser);
     }
 
     public Node getDOM() {
@@ -318,11 +306,19 @@
     public void startDTD(String name, String publicId, String systemId)
         throws SAXException {}
     
-    private static Document createDocument() throws ParserConfigurationException {
+    private static Document createDocument(boolean overrideDefaultParser)
+            throws ParserConfigurationException {
+        if (_factory == null) {
+            _factory = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
+            _internal = true;
+            if (!(_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl)) {
+                _internal = false;
+            }
+        }
         Document doc;
-        if (_internalBuilder != null) {
+        if (_internal) {
             //default implementation is thread safe
-            doc = _internalBuilder.newDocument();
+            doc = _factory.newDocumentBuilder().newDocument();
         } else {
             synchronized(SAX2DOM.class) {
                 doc = _factory.newDocumentBuilder().newDocument();
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -95,7 +94,7 @@
         _tfactory = tfactory;
 
         // Instantiate XSLTC and get reference to parser object
-        XSLTC xsltc = new XSLTC();
+        XSLTC xsltc = new XSLTC(tfactory.getJdkXmlFeatures());
         if (tfactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING))
             xsltc.setSecureProcessing(true);
         xsltc.setProperty(XalanConstants.SECURITY_MANAGER,
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -124,6 +124,11 @@
      */
     private transient TransformerFactoryImpl _tfactory = null;
 
+    /**
+     * A flag to determine whether the system-default parser may be overridden
+     */
+    private transient boolean _overrideDefaultParser;
+
     static final class TransletClassLoader extends ClassLoader {
         TransletClassLoader(ClassLoader parent) {
             super(parent);
@@ -169,6 +174,7 @@
         _outputProperties = outputProperties;
         _indentNumber = indentNumber;
         _tfactory = tfactory;
+        _overrideDefaultParser = tfactory.overrideDefaultParser();
     }
 
     /**
@@ -298,6 +304,13 @@
     }
 
     /**
+     * Return the state of the services mechanism feature.
+     */
+    public boolean overrideDefaultParser() {
+        return _overrideDefaultParser;
+    }
+
+    /**
      * Returns the translet bytecodes stored in this template
      *
      * Note: This method is private for security reasons. See
@@ -414,6 +427,7 @@
             AbstractTranslet translet = (AbstractTranslet) _class[_transletIndex].newInstance();
             translet.postInitialization();
             translet.setTemplates(this);
+            translet.setOverrideDefaultParser(_overrideDefaultParser);
             if (_auxClasses != null) {
                 translet.setAuxiliaryClasses(_auxClasses);
             }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TrAXFilter.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TrAXFilter.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -26,11 +25,6 @@
 
 import java.io.IOException;
 
-import javax.xml.XMLConstants;
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.ErrorListener;
 import javax.xml.transform.Templates;
 import javax.xml.transform.Transformer;
@@ -38,13 +32,13 @@
 import javax.xml.transform.sax.SAXResult;
 
 import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLFilterImpl;
-import org.xml.sax.helpers.XMLReaderFactory;
 
 /**
  * skeleton extension of XMLFilterImpl for now.
@@ -55,6 +49,7 @@
     private Templates              _templates;
     private TransformerImpl        _transformer;
     private TransformerHandlerImpl _transformerHandler;
+    private boolean _overrideDefaultParser;
 
     public TrAXFilter(Templates templates)  throws
         TransformerConfigurationException
@@ -62,6 +57,7 @@
         _templates = templates;
         _transformer = (TransformerImpl) templates.newTransformer();
         _transformerHandler = new TransformerHandlerImpl(_transformer);
+        _overrideDefaultParser = _transformer.overrideDefaultParser();
     }
 
     public Transformer getTransformer() {
@@ -69,36 +65,14 @@
     }
 
     private void createParent() throws SAXException {
-        XMLReader parent = null;
-        try {
-            SAXParserFactory pfactory = SAXParserFactory.newInstance();
-            pfactory.setNamespaceAware(true);
-
-            if (_transformer.isSecureProcessing()) {
-                try {
-                    pfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
-                }
-                catch (SAXException e) {}
-            }
-
-            SAXParser saxparser = pfactory.newSAXParser();
-            parent = saxparser.getXMLReader();
-        }
-        catch (ParserConfigurationException e) {
-            throw new SAXException(e);
-        }
-        catch (FactoryConfigurationError e) {
-            throw new SAXException(e.toString());
-        }
-
-        if (parent == null) {
-            parent = XMLReaderFactory.createXMLReader();
-        }
+        XMLReader parent = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
+                _transformer.isSecureProcessing());
 
         // make this XMLReader the parent of this filter
         setParent(parent);
     }
 
+    @Override
     public void parse (InputSource input) throws SAXException, IOException
     {
         XMLReader managedReader = null;
@@ -106,7 +80,7 @@
         try {
             if (getParent() == null) {
                 try {
-                    managedReader = XMLReaderManager.getInstance()
+                    managedReader = XMLReaderManager.getInstance(_overrideDefaultParser)
                                                     .getXMLReader();
                     setParent(managedReader);
                 } catch (SAXException  e) {
@@ -118,7 +92,7 @@
             getParent().parse(input);
         } finally {
             if (managedReader != null) {
-                XMLReaderManager.getInstance().releaseXMLReader(managedReader);
+                XMLReaderManager.getInstance(_overrideDefaultParser).releaseXMLReader(managedReader);
             }
         }
     }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -74,6 +74,8 @@
 import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
 import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
 
+import jdk.xml.internal.JdkXmlFeatures;
+import jdk.xml.internal.JdkXmlUtils;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLFilter;
 import org.xml.sax.XMLReader;
@@ -207,6 +209,16 @@
      * <p>State of secure mode.</p>
      */
     private boolean _isSecureMode = false;
+
+    /**
+     * Indicates whether 3rd party parser may be used to override the system-default
+     * Note the default value (false) is the safe option.
+     * Note same as the old property useServicesMechanism
+     */
+    private boolean _overrideDefaultParser;
+
+    private final JdkXmlFeatures _xmlFeatures;
+
     /**
      * javax.xml.transform.sax.TransformerFactory implementation.
      */
@@ -216,6 +228,10 @@
             _isNotSecureProcessing = false;
         }
 
+        _xmlFeatures = new JdkXmlFeatures(!_isNotSecureProcessing);
+        _overrideDefaultParser = _xmlFeatures.getFeature(
+                JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
+
         //Parser's security manager
         _xmlSecurityManager = new XMLSecurityManager(true);
     }
@@ -423,24 +439,37 @@
     public void setFeature(String name, boolean value)
         throws TransformerConfigurationException {
 
-	// feature name cannot be null
-	if (name == null) {
+        // feature name cannot be null
+        if (name == null) {
             ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SET_FEATURE_NULL_NAME);
-    	    throw new NullPointerException(err.toString());
-	}		
-	// secure processing?
-	else if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
+            throw new NullPointerException(err.toString());
+        }
+        // secure processing?
+        else if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
             if ((_isSecureMode) && (!value)) {
                 ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SECUREPROCESSING_FEATURE);
                 throw new TransformerConfigurationException(err.toString());
             }
-	    _isNotSecureProcessing = !value;
+            _isNotSecureProcessing = !value;
             _xmlSecurityManager.setSecureProcessing(value);
-	    // all done processing feature
-	    return;
-	}
-	else {	
-	    // unknown feature
+
+            if (value && _xmlFeatures != null) {
+                _xmlFeatures.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION,
+                        JdkXmlFeatures.State.FSP, false);
+            }
+        }
+        else {
+            if (_xmlFeatures != null &&
+                    _xmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) {
+                if (name.equals(JdkXmlUtils.OVERRIDE_PARSER) ||
+                        name.equals(JdkXmlFeatures.ORACLE_FEATURE_SERVICE_MECHANISM)) {
+                    _overrideDefaultParser = _xmlFeatures.getFeature(
+                            JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
+                }
+                return;
+            }
+
+            // unknown feature
             ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name);
             throw new TransformerConfigurationException(err.toString());
         }
@@ -456,40 +485,61 @@
      * @return 'true' if feature is supported, 'false' if not
      */
     @Override
-    public boolean getFeature(String name) { 
-	// All supported features should be listed here
-	String[] features = {
-	    DOMSource.FEATURE,
-	    DOMResult.FEATURE,
-	    SAXSource.FEATURE,
-	    SAXResult.FEATURE,
-	    StAXSource.FEATURE,
-	    StAXResult.FEATURE,
-	    StreamSource.FEATURE,
-	    StreamResult.FEATURE,
-	    SAXTransformerFactory.FEATURE,
-	    SAXTransformerFactory.FEATURE_XMLFILTER
-	};
+    public boolean getFeature(String name) {
+        // All supported features should be listed here
+        String[] features = {
+            DOMSource.FEATURE,
+            DOMResult.FEATURE,
+            SAXSource.FEATURE,
+            SAXResult.FEATURE,
+            StAXSource.FEATURE,
+            StAXResult.FEATURE,
+            StreamSource.FEATURE,
+            StreamResult.FEATURE,
+            SAXTransformerFactory.FEATURE,
+            SAXTransformerFactory.FEATURE_XMLFILTER
+        };
+
+        // feature name cannot be null
+        if (name == null) {
+            ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME);
+            throw new NullPointerException(err.toString());
+        }
+
+        // Inefficient, but array is small
+        for (int i =0; i < features.length; i++) {
+            if (name.equals(features[i])) {
+                return true;
 
-	// feature name cannot be null
-	if (name == null) {
-    	    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME);
-    	    throw new NullPointerException(err.toString());
-	}
+            }
+        }
+        // secure processing?
+        if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
+            return !_isNotSecureProcessing;
+        }
+
+        /** Check to see if the property is managed by the JdkXmlFeatures **/
+        int index = _xmlFeatures.getIndex(name);
+        if (index > -1) {
+            return _xmlFeatures.getFeature(index);
+        }
 
-	// Inefficient, but array is small
-	for (int i =0; i < features.length; i++) {
-	    if (name.equals(features[i])) {
-		return true;
-	    }
-	}
-	// secure processing?
-	if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
-		return !_isNotSecureProcessing;
-	}
+        // Feature not supported
+        return false;
+    }
 
-	// Feature not supported
-	return false;
+    /**
+     * Return the state of the services mechanism feature.
+     */
+    public boolean overrideDefaultParser() {
+             return _overrideDefaultParser;
+    }
+
+    /**
+     * @return the feature manager
+    */
+    public JdkXmlFeatures getJdkXmlFeatures() {
+        return _xmlFeatures;
     }
 
     /**
@@ -541,10 +591,9 @@
 	throws TransformerConfigurationException {
 
         String baseId;
-        XMLReader reader;
+        XMLReader reader = null;
         InputSource isource;
 
-
         /**
          * Fix for bugzilla bug 24187
          */
@@ -563,24 +612,15 @@
                 dom2sax.setContentHandler( _stylesheetPIHandler);
                 dom2sax.parse();
             } else {
+                if (source instanceof SAXSource) {
+                    reader = ((SAXSource)source).getXMLReader();
+                }
                 isource = SAXSource.sourceToInputSource(source);
                 baseId = isource.getSystemId();
 
-                SAXParserFactory factory = SAXParserFactory.newInstance();
-                factory.setNamespaceAware(true);
-                
-                if (!_isNotSecureProcessing) {
-                    try {
-                        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
-                    }
-                    catch (org.xml.sax.SAXException e) {}
-                }
-                
-                SAXParser jaxpParser = factory.newSAXParser();
-
-                reader = jaxpParser.getXMLReader();
                 if (reader == null) {
-                    reader = XMLReaderFactory.createXMLReader();
+                    reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
+                            !_isNotSecureProcessing);
                 }
 
                 _stylesheetPIHandler.setBaseId(baseId);
@@ -595,22 +635,12 @@
 
         } catch (StopParseException e ) {
           // startElement encountered so do not parse further
-
-        } catch (javax.xml.parsers.ParserConfigurationException e) {
-
-             throw new TransformerConfigurationException(
-             "getAssociatedStylesheets failed", e);
-
         } catch (org.xml.sax.SAXException se) {
-
-             throw new TransformerConfigurationException(
-             "getAssociatedStylesheets failed", se);
-
-
+            throw new TransformerConfigurationException(
+                "getAssociatedStylesheets failed", se);
         } catch (IOException ioe ) {
-           throw new TransformerConfigurationException(
-           "getAssociatedStylesheets failed", ioe);
-
+            throw new TransformerConfigurationException(
+                "getAssociatedStylesheets failed", ioe);
         }
 
          return _stylesheetPIHandler.getAssociatedStylesheet();
@@ -779,7 +809,7 @@
 	}
 	
 	// Create and initialize a stylesheet compiler
-	final XSLTC xsltc = new XSLTC();
+	final XSLTC xsltc = new XSLTC(_xmlFeatures);
 	if (_debug) xsltc.setDebug(true);
 	if (_enableInlining) xsltc.setTemplateInlining(true);
 	if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -85,7 +85,7 @@
 
 import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
 import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
-
+import jdk.xml.internal.JdkXmlUtils;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -103,9 +103,7 @@
 
     private final static String LEXICAL_HANDLER_PROPERTY =
 	"http://xml.org/sax/properties/lexical-handler";
-    private static final String NAMESPACE_FEATURE =
-	"http://xml.org/sax/features/namespaces";
-    
+
     /**
      * Namespace prefixes feature for {@link XMLReader}.
      */
@@ -182,7 +180,7 @@
     /**
      * A reference to an object that creates and caches XMLReader objects.
      */
-    private XMLReaderManager _readerManager = XMLReaderManager.getInstance();
+    private XMLReaderManager _readerManager;
     
     /**
      * A flag indicating whether we use incremental building of the DTM.
@@ -201,6 +199,11 @@
     private boolean _isSecureProcessing = false;
 
     /**
+     * Indicates whether 3rd party parser may be used to override the system-default
+     */
+    private boolean _overrideDefaultParser;
+
+    /**
      * A map to store parameters for the identity transform. These
      * are not needed during the transformation, but we must keep track of 
      * them to be fully complaint with the JAXP API.
@@ -246,14 +249,16 @@
     }
 
     protected TransformerImpl(Translet translet, Properties outputProperties,
-	int indentNumber, TransformerFactoryImpl tfactory) 
+        int indentNumber, TransformerFactoryImpl tfactory)
     {
-	_translet = (AbstractTranslet) translet;
-	_properties = createOutputProperties(outputProperties);
-	_propertiesClone = (Properties) _properties.clone();
-	_indentNumber = indentNumber;
-	_tfactory = tfactory;
+        _translet = (AbstractTranslet) translet;
+        _properties = createOutputProperties(outputProperties);
+        _propertiesClone = (Properties) _properties.clone();
+        _indentNumber = indentNumber;
+        _tfactory = tfactory;
+        _overrideDefaultParser = _tfactory.overrideDefaultParser();
         _securityManager = (XMLSecurityManager)_tfactory.getAttribute(XalanConstants.SECURITY_MANAGER);
+        _readerManager = XMLReaderManager.getInstance(_overrideDefaultParser);
         _readerManager.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _isSecureProcessing);
         _readerManager.setProperty(XalanConstants.SECURITY_MANAGER, _securityManager);
 	//_isIncremental = tfactory._incremental;
@@ -275,6 +280,20 @@
     }
 
     /**
+     * Return the state of the services mechanism feature.
+     */
+    public boolean overrideDefaultParser() {
+        return _overrideDefaultParser;
+    }
+
+    /**
+     * Set the state of the services mechanism feature.
+     */
+    public void setOverrideDefaultParser(boolean flag) {
+        _overrideDefaultParser = flag;
+    }
+
+    /**
      * Returns the translet wrapped inside this Transformer or
      * null if this is the identity transform.
      */
@@ -345,34 +364,34 @@
      * the type and contents of the TrAX Result object passed to the 
      * transform() method. 
      */
-    public SerializationHandler getOutputHandler(Result result) 
-	throws TransformerException 
+    public SerializationHandler getOutputHandler(Result result)
+            throws TransformerException
     {
-	// Get output method using get() to ignore defaults 
-	_method = (String) _properties.get(OutputKeys.METHOD);
+        // Get output method using get() to ignore defaults
+        _method = (String) _properties.get(OutputKeys.METHOD);
 
-	// Get encoding using getProperty() to use defaults
-	_encoding = (String) _properties.getProperty(OutputKeys.ENCODING);
+        // Get encoding using getProperty() to use defaults
+        _encoding = (String) _properties.getProperty(OutputKeys.ENCODING);
 
-	_tohFactory = TransletOutputHandlerFactory.newInstance();
-	_tohFactory.setEncoding(_encoding);
-	if (_method != null) {
-	    _tohFactory.setOutputMethod(_method);
-	}
+        _tohFactory = TransletOutputHandlerFactory.newInstance(_overrideDefaultParser);
+        _tohFactory.setEncoding(_encoding);
+        if (_method != null) {
+            _tohFactory.setOutputMethod(_method);
+        }
 
-	// Set indentation number in the factory
-	if (_indentNumber >= 0) {
-	    _tohFactory.setIndentNumber(_indentNumber);
-	}
+        // Set indentation number in the factory
+        if (_indentNumber >= 0) {
+            _tohFactory.setIndentNumber(_indentNumber);
+        }
 
-	// Return the content handler for this Result object
-	try {
-	    // Result object could be SAXResult, DOMResult, or StreamResult 
-	    if (result instanceof SAXResult) {
+        // Return the content handler for this Result object
+        try {
+            // Result object could be SAXResult, DOMResult, or StreamResult
+            if (result instanceof SAXResult) {
                 final SAXResult target = (SAXResult)result;
                 final ContentHandler handler = target.getHandler();
 
-		_tohFactory.setHandler(handler);
+                _tohFactory.setHandler(handler);
 
                 /**
                  * Fix for bug 24414
@@ -382,11 +401,11 @@
                 LexicalHandler lexicalHandler = target.getLexicalHandler();
 
                 if (lexicalHandler != null ) {
-		    _tohFactory.setLexicalHandler(lexicalHandler);
-		}
+                    _tohFactory.setLexicalHandler(lexicalHandler);
+                }
 
-		_tohFactory.setOutputType(TransletOutputHandlerFactory.SAX);
-		return _tohFactory.getSerializationHandler();
+                _tohFactory.setOutputType(TransletOutputHandlerFactory.SAX);
+                return _tohFactory.getSerializationHandler();
             }
             else if (result instanceof StAXResult) {
                 if (((StAXResult) result).getXMLEventWriter() != null) 
@@ -396,47 +415,47 @@
                 _tohFactory.setOutputType(TransletOutputHandlerFactory.STAX);
                 return _tohFactory.getSerializationHandler();
             }
-	    else if (result instanceof DOMResult) {
-		_tohFactory.setNode(((DOMResult) result).getNode());
-		_tohFactory.setNextSibling(((DOMResult) result).getNextSibling());
-		_tohFactory.setOutputType(TransletOutputHandlerFactory.DOM);
-		return _tohFactory.getSerializationHandler();
+            else if (result instanceof DOMResult) {
+                _tohFactory.setNode(((DOMResult) result).getNode());
+                _tohFactory.setNextSibling(((DOMResult) result).getNextSibling());
+                _tohFactory.setOutputType(TransletOutputHandlerFactory.DOM);
+                return _tohFactory.getSerializationHandler();
             }
-	    else if (result instanceof StreamResult) {
-		// Get StreamResult
-		final StreamResult target = (StreamResult) result;	
+            else if (result instanceof StreamResult) {
+                // Get StreamResult
+                final StreamResult target = (StreamResult) result;
 
-		// StreamResult may have been created with a java.io.File,
-		// java.io.Writer, java.io.OutputStream or just a String
-		// systemId. 
+                // StreamResult may have been created with a java.io.File,
+                // java.io.Writer, java.io.OutputStream or just a String
+                // systemId.
 
-		_tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM);
+                _tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM);
 
-		// try to get a Writer from Result object
-		final Writer writer = target.getWriter();
-		if (writer != null) {
-		    _tohFactory.setWriter(writer);
-		    return _tohFactory.getSerializationHandler();
-		}
+                // try to get a Writer from Result object
+                final Writer writer = target.getWriter();
+                if (writer != null) {
+                    _tohFactory.setWriter(writer);
+                    return _tohFactory.getSerializationHandler();
+                }
 
-		// or try to get an OutputStream from Result object
-		final OutputStream ostream = target.getOutputStream();
-		if (ostream != null) {
-		    _tohFactory.setOutputStream(ostream);
-		    return _tohFactory.getSerializationHandler();
-		}
+                // or try to get an OutputStream from Result object
+                final OutputStream ostream = target.getOutputStream();
+                if (ostream != null) {
+                    _tohFactory.setOutputStream(ostream);
+                    return _tohFactory.getSerializationHandler();
+                }
 
-		// or try to get just a systemId string from Result object
-		String systemId = result.getSystemId();
-		if (systemId == null) {
-		    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_RESULT_ERR);
+                // or try to get just a systemId string from Result object
+                String systemId = result.getSystemId();
+                if (systemId == null) {
+                    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_RESULT_ERR);
                     throw new TransformerException(err.toString());
-		}
+                }
 
-		// System Id may be in one of several forms, (1) a uri
-		// that starts with 'file:', (2) uri that starts with 'http:'
-		// or (3) just a filename on the local system.
-		URL url;
+                // System Id may be in one of several forms, (1) a uri
+                // that starts with 'file:', (2) uri that starts with 'http:'
+                // or (3) just a filename on the local system.
+                URL url;
                 if (systemId.startsWith("file:")) {
                     // if StreamResult(File) or setSystemID(File) was used,
                     // the systemId will be URI encoded as a result of File.toURI(),
@@ -471,23 +490,23 @@
                         
                     url = new URL(systemId);
                     _ostream = new FileOutputStream(url.getFile());
-		    _tohFactory.setOutputStream(_ostream);
-		    return _tohFactory.getSerializationHandler();
+                    _tohFactory.setOutputStream(_ostream);
+                    return _tohFactory.getSerializationHandler();
                 }
                 else if (systemId.startsWith("http:")) {
                     url = new URL(systemId);
                     final URLConnection connection = url.openConnection();
-		    _tohFactory.setOutputStream(_ostream = connection.getOutputStream());
-		    return _tohFactory.getSerializationHandler();
+                    _tohFactory.setOutputStream(_ostream = connection.getOutputStream());
+                    return _tohFactory.getSerializationHandler();
                 }
                 else {
                     // system id is just a filename
-		    _tohFactory.setOutputStream(
-		        _ostream = new FileOutputStream(new File(systemId)));
-		    return _tohFactory.getSerializationHandler();
+                    _tohFactory.setOutputStream(
+                            _ostream = new FileOutputStream(new File(systemId)));
+                    return _tohFactory.getSerializationHandler();
                 }
-	    }
-	}
+            }
+        }
         // If we cannot write to the location specified by the SystemId
         catch (UnknownServiceException e) {
             throw new TransformerException(e);
@@ -499,7 +518,7 @@
         catch (IOException e) {
             throw new TransformerException(e);
         }
-	return null;
+        return null;
     }
 
     /**
@@ -530,6 +549,7 @@
                  if (_dtmManager == null) {
                      _dtmManager =
                          _tfactory.createNewDTMManagerInstance();
+                     _dtmManager.setOverrideDefaultParser(_overrideDefaultParser);
                  }
                  dom = (DOM)_dtmManager.getDTM(source, false, wsfilter, true,
                                               false, false, 0, hasIdCall);
@@ -614,7 +634,6 @@
                     ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_SOURCE_ERR);
                     throw new TransformerException(err.toString());
                 }
-
                 // Start pushing SAX events
                 reader.parse(input);
             } finally {
@@ -701,8 +720,7 @@
                 ((SAXSource)source).getXMLReader()==null )||
                 (source instanceof DOMSource && 
                 ((DOMSource)source).getNode()==null)){
-                        DocumentBuilderFactory builderF = 
-                                DocumentBuilderFactory.newInstance();
+                        DocumentBuilderFactory builderF = JdkXmlUtils.getDOMFactory(_overrideDefaultParser);
                         DocumentBuilder builder = 
                                 builderF.newDocumentBuilder();
                         String systemID = source.getSystemId();
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/Util.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xalan/internal/xsltc/trax/Util.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -40,7 +39,8 @@
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stax.StAXSource;
 import javax.xml.transform.stream.StreamSource;
-
+import jdk.xml.internal.JdkXmlFeatures;
+import jdk.xml.internal.JdkXmlUtils;
 import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
@@ -52,12 +52,12 @@
 import org.xml.sax.SAXNotRecognizedException;
 import org.xml.sax.SAXNotSupportedException;
 import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
 
 /**
  * @author Santiago Pericas-Geertsen
  */
 public final class Util {
+    private static final String property = "org.xml.sax.driver";
 
     public static String baseName(String name) {
         return com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util.baseName(name);
@@ -93,55 +93,20 @@
                 try {
                     XMLReader reader = sax.getXMLReader();
 
-                     /*
-                      * Fix for bug 24695
-                      * According to JAXP 1.2 specification if a SAXSource
-                      * is created using a SAX InputSource the Transformer or
-                      * TransformerFactory creates a reader via the
-                      * XMLReaderFactory if setXMLReader is not used
-                      */
-
                     if (reader == null) {
-                       try {
-                           reader= XMLReaderFactory.createXMLReader();
-                           try {
-                                reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,
-                                            xsltc.isSecureProcessing());
-                           } catch (SAXNotRecognizedException e) {
-                                XMLSecurityManager.printWarning(reader.getClass().getName(),
-                                        XMLConstants.FEATURE_SECURE_PROCESSING, e);
-                           }
-                       } catch (Exception e ) {
-                           try {
-
-                               //Incase there is an exception thrown
-                               // resort to JAXP
-                               SAXParserFactory parserFactory =
-                                      SAXParserFactory.newInstance();
-                               parserFactory.setNamespaceAware(true);
-
-                               if (xsltc.isSecureProcessing()) {
-                                  try {
-                                      parserFactory.setFeature(
-                                          XMLConstants.FEATURE_SECURE_PROCESSING, true);
-                                  }
-                                  catch (org.xml.sax.SAXException se) {}
-                               }
-
-                               reader = parserFactory.newSAXParser()
-                                     .getXMLReader();
-
-
-                           } catch (ParserConfigurationException pce ) {
-                               throw new TransformerConfigurationException
-                                 ("ParserConfigurationException" ,pce);
-                           }
+                        if (reader == null) {
+                            boolean overrideDefaultParser = xsltc.getFeature(
+                                    JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
+                            reader = JdkXmlUtils.getXMLReader(overrideDefaultParser,
+                                    xsltc.isSecureProcessing());
+                        } else {
+                            // compatibility for legacy applications
+                            reader.setFeature
+                                    (JdkXmlUtils.NAMESPACES_FEATURE,true);
+                            reader.setFeature
+                                    (JdkXmlUtils.NAMESPACE_PREFIXES_FEATURE,false);
                        }
                     }
-                    reader.setFeature
-                        ("http://xml.org/sax/features/namespaces",true);
-                    reader.setFeature
-                        ("http://xml.org/sax/features/namespace-prefixes",false);
 
                     String lastProperty = "";
                     try {
@@ -168,9 +133,6 @@
                 }catch (SAXNotSupportedException snse ) {
                   throw new TransformerConfigurationException
                        ("SAXNotSupportedException ",snse);
-                }catch (SAXException se ) {
-                  throw new TransformerConfigurationException
-                       ("SAXException ",se);
                 }
 
             }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -25,7 +24,7 @@
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Vector;
-
+import jdk.xml.internal.JdkXmlUtils;
 import org.w3c.dom.DOMConfiguration;
 import org.w3c.dom.DOMErrorHandler;
 import org.w3c.dom.DOMStringList;
@@ -239,6 +238,7 @@
             DYNAMIC_VALIDATION,
             NORMALIZE_DATA,
             SEND_PSVI,
+            JdkXmlUtils.OVERRIDE_PARSER
         };
         addRecognizedFeatures(recognizedFeatures);
 
@@ -250,6 +250,7 @@
         setFeature(NORMALIZE_DATA, false);
         setFeature(XERCES_NAMESPACES, true);
         setFeature(SEND_PSVI, true);
+        setFeature(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
 
         // add default recognized properties
         final String[] recognizedProperties = {
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java	Thu Oct 19 17:03:20 2017 +0100
@@ -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.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -67,6 +67,7 @@
 import java.util.StringTokenizer;
 import java.util.Vector;
 import javax.xml.XMLConstants;
+import jdk.xml.internal.JdkXmlUtils;
 import org.w3c.dom.DOMConfiguration;
 import org.w3c.dom.DOMError;
 import org.w3c.dom.DOMErrorHandler;
@@ -136,8 +137,10 @@
         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
     
     protected static final String PARSER_SETTINGS = 
-        Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;   
-    
+        Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
+
+    protected static final String OVERRIDE_PARSER = JdkXmlUtils.OVERRIDE_PARSER;
+
     // recognized features:
     private static final String[] RECOGNIZED_FEATURES = {
         SCHEMA_FULL_CHECKING,
@@ -148,7 +151,8 @@
         DISALLOW_DOCTYPE,
         GENERATE_SYNTHETIC_ANNOTATIONS,
         VALIDATE_ANNOTATIONS,
-        HONOUR_ALL_SCHEMALOCATIONS
+        HONOUR_ALL_SCHEMALOCATIONS,
+        OVERRIDE_PARSER
     };
     
     // property identifiers
@@ -267,18 +271,14 @@
      * @param sHandler
      * @param builder
      */
-    XMLSchemaLoader(XMLErrorReporter errorReporter,
-            XSGrammarBucket grammarBucket,
+    XMLSchemaLoader(XMLErrorReporter errorReporter, XSGrammarBucket grammarBucket,
             SubstitutionGroupHandler sHandler, CMBuilder builder) {
         this(null, errorReporter, null, grammarBucket, sHandler, builder);
     }
     
-    XMLSchemaLoader(SymbolTable symbolTable,
-            XMLErrorReporter errorReporter,
-            XMLEntityManager entityResolver,
-            XSGrammarBucket grammarBucket,
-            SubstitutionGroupHandler sHandler,
-            CMBuilder builder) {
+    XMLSchemaLoader(SymbolTable symbolTable, XMLErrorReporter errorReporter,
+            XMLEntityManager entityResolver, XSGrammarBucket grammarBucket,
+            SubstitutionGroupHandler sHandler, CMBuilder builder) {
         
         // store properties and features in configuration
         fLoaderConfig.addRecognizedFeatures(RECOGNIZED_FEATURES);
@@ -1150,7 +1150,8 @@
                 name.equals(ALLOW_JAVA_ENCODINGS) ||
                 name.equals(STANDARD_URI_CONFORMANT_FEATURE) ||
                 name.equals(GENERATE_SYNTHETIC_ANNOTATIONS) ||
-                name.equals(HONOUR_ALL_SCHEMALOCATIONS)) {
+                name.equals(HONOUR_ALL_SCHEMALOCATIONS) ||
+                name.equals(OVERRIDE_PARSER)) {
                 return true;
                 
             }
@@ -1226,6 +1227,7 @@
             v.add(VALIDATE_ANNOTATIONS);
             v.add(GENERATE_SYNTHETIC_ANNOTATIONS);
             v.add(HONOUR_ALL_SCHEMALOCATIONS);
+            v.add(OVERRIDE_PARSER);
             fRecognizedParameters = new DOMStringListImpl(v);      	
         }
         return fRecognizedParameters;
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java	Thu Oct 19 17:03:20 2017 +0100
@@ -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.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -80,6 +80,7 @@
 import java.util.Map;
 import java.util.Stack;
 import java.util.Vector;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * The XML Schema validator. The validator implements a document
@@ -217,6 +218,8 @@
     protected static final String JAXP_SCHEMA_LANGUAGE =
         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
 
+    protected static final String OVERRIDE_PARSER = JdkXmlUtils.OVERRIDE_PARSER;
+
     // recognized features and properties
 
     /** Recognized features. */
@@ -232,7 +235,9 @@
             GENERATE_SYNTHETIC_ANNOTATIONS,
             VALIDATE_ANNOTATIONS,
             HONOUR_ALL_SCHEMALOCATIONS,
-            USE_GRAMMAR_POOL_ONLY};
+            USE_GRAMMAR_POOL_ONLY,
+            OVERRIDE_PARSER
+        };
 
     /** Feature defaults. */
     private static final Boolean[] FEATURE_DEFAULTS = { null,
@@ -251,7 +256,9 @@
         null,
         null,
         null,
-        null};
+        null,
+        JdkXmlUtils.OVERRIDE_PARSER_DEFAULT
+    };
 
     /** Recognized properties. */
     private static final String[] RECOGNIZED_PROPERTIES =
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/opti/SchemaParsingConfig.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/opti/SchemaParsingConfig.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -48,6 +47,7 @@
 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * @xerces.internal
@@ -299,7 +299,8 @@
             PARSER_SETTINGS, WARN_ON_DUPLICATE_ATTDEF,   WARN_ON_UNDECLARED_ELEMDEF,
             ALLOW_JAVA_ENCODINGS,       CONTINUE_AFTER_FATAL_ERROR,
             LOAD_EXTERNAL_DTD,          NOTIFY_BUILTIN_REFS,
-            NOTIFY_CHAR_REFS, GENERATE_SYNTHETIC_ANNOTATIONS
+            NOTIFY_CHAR_REFS, GENERATE_SYNTHETIC_ANNOTATIONS,
+            JdkXmlUtils.OVERRIDE_PARSER
         };
         addRecognizedFeatures(recognizedFeatures);
         fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
@@ -313,6 +314,7 @@
         fFeatures.put(NOTIFY_BUILTIN_REFS, Boolean.FALSE);
         fFeatures.put(NOTIFY_CHAR_REFS, Boolean.FALSE);
         fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE);
+        fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
 
         // add default recognized properties
         final String[] recognizedProperties = {
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/traversers/SchemaContentHandler.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/traversers/SchemaContentHandler.java	Thu Oct 19 17:03:20 2017 +0100
@@ -25,6 +25,7 @@
 import com.sun.org.apache.xerces.internal.util.SAXLocatorWrapper;
 import com.sun.org.apache.xerces.internal.util.SymbolTable;
 import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
+import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
 import com.sun.org.apache.xerces.internal.util.XMLSymbols;
 import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
 import com.sun.org.apache.xerces.internal.xni.QName;
@@ -77,6 +78,7 @@
     private final QName fAttributeQName = new QName();
     private final XMLAttributesImpl fAttributes = new XMLAttributesImpl();
     private final XMLString fTempString = new XMLString();
+    private final XMLStringBuffer fStringBuffer = new XMLStringBuffer();
 
     /**
      * <p>Constructs an SchemaContentHandler.</p>
@@ -102,6 +104,7 @@
      */
     public void startDocument() throws SAXException {
         fNeedPushNSContext = true;
+        fNamespaceContext.reset();
         try {
             fSchemaDOMParser.startDocument(fSAXLocatorWrapper, null, fNamespaceContext, null);
         }
@@ -325,7 +328,11 @@
             if (nsPrefix.length() > 0) {
                 prefix = XMLSymbols.PREFIX_XMLNS;
                 localpart = nsPrefix;
-                rawname = fSymbolTable.addSymbol(prefix + ":" + localpart);
+                fStringBuffer.clear();
+                fStringBuffer.append(prefix);
+                fStringBuffer.append(':');
+                fStringBuffer.append(localpart);
+                rawname = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);
             }
             else {
                 prefix = XMLSymbols.EMPTY_STRING;
@@ -333,7 +340,8 @@
                 rawname = XMLSymbols.PREFIX_XMLNS;
             }
             fAttributeQName.setValues(prefix, localpart, rawname, NamespaceContext.XMLNS_URI);
-            fAttributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol, nsURI);
+            fAttributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol,
+                    (nsURI != null) ? nsURI : XMLSymbols.EMPTY_STRING);
         }
     }
 
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -77,13 +77,13 @@
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import jdk.xml.internal.JdkXmlUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
 
 
 /**
@@ -343,6 +343,8 @@
     
     // the Grammar Pool
     private XMLGrammarPool fGrammarPool;
+
+    private boolean fOverrideDefaultParser;
     
     //************ Traversers **********
     XSDAttributeGroupTraverser fAttributeGroupTraverser;
@@ -488,14 +490,9 @@
                 catch (SAXException se) {}
             }
             else {
-                try {
-                    parser = XMLReaderFactory.createXMLReader();
-                }
-                // If something went wrong with the factory
-                // just use our own SAX parser.
-                catch (SAXException se) {
-                    parser = new SAXParser();
-                }
+                parser = JdkXmlUtils.getXMLReader(fOverrideDefaultParser,
+                        fSecureProcessing != null && fSecureProcessing.isSecureProcessing());
+
                 try {
                     parser.setFeature(NAMESPACE_PREFIXES, true);
                     namespacePrefixes = true;
@@ -1717,14 +1714,9 @@
                 catch (SAXException se) {}
             }
             else {
-                try {
-                    parser = XMLReaderFactory.createXMLReader();
-                }
-                // If something went wrong with the factory
-                // just use our own SAX parser.
-                catch (SAXException se) {
-                    parser = new SAXParser();
-                }
+                parser = JdkXmlUtils.getXMLReader(fOverrideDefaultParser,
+                            fSecureProcessing != null && fSecureProcessing.isSecureProcessing());
+
                 try {
                     parser.setFeature(NAMESPACE_PREFIXES, true);
                     namespacePrefixes = true;
@@ -1801,7 +1793,8 @@
                 XSDKey key = null;
                 String schemaId = null;
                 if (referType != XSDDescription.CONTEXT_PREPARSE){
-                    schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false);
+                    schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(),
+                            schemaSource.getBaseSystemId(), false);
                     key = new XSDKey(schemaId, referType, schemaNamespace);
                     if((schemaElement = (Element)fTraversed.get(key)) != null) {
                         fLastSchemaWasDuplicate = true;
@@ -2049,7 +2042,9 @@
             }
         } catch (XMLConfigurationException e) {
         }
-        
+
+        fOverrideDefaultParser = componentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER);
+        fSchemaParser.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
     } // reset(XMLComponentManager)
     
     
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/DOMValidatorHelper.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/DOMValidatorHelper.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2005 The Apache Software Foundation.
@@ -46,6 +45,7 @@
 import com.sun.org.apache.xerces.internal.xni.XMLString;
 import com.sun.org.apache.xerces.internal.xni.XNIException;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
+import jdk.xml.internal.JdkXmlUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.CDATASection;
 import org.w3c.dom.Comment;
@@ -381,7 +381,8 @@
         }
         if (result.getNode() == null) {
             try {
-                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+                DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory(
+                        fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
                 factory.setNamespaceAware(true);
                 DocumentBuilder builder = factory.newDocumentBuilder();
                 result.setNode(builder.newDocument());
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/StAXValidatorHelper.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/StAXValidatorHelper.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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,6 +25,7 @@
 
 package com.sun.org.apache.xerces.internal.jaxp.validation;
 
+import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
 import com.sun.org.apache.xerces.internal.impl.Constants;
 import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
 
@@ -41,6 +42,7 @@
 import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stax.StAXResult;
 import javax.xml.transform.stax.StAXSource;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.xml.sax.SAXException;
 
@@ -70,8 +72,11 @@
          
             if( identityTransformer1==null ) {
                 try {
-                    SAXTransformerFactory tf = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
-                    XMLSecurityManager securityManager = (XMLSecurityManager)fComponentManager.getProperty(Constants.SECURITY_MANAGER);
+                    SAXTransformerFactory tf = JdkXmlUtils.getSAXTransformFactory(
+                            fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
+
+                    XMLSecurityManager securityManager =
+                            (XMLSecurityManager)fComponentManager.getProperty(Constants.SECURITY_MANAGER);
                     if (securityManager != null) {
                         for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
                             if (securityManager.isSet(limit.ordinal())){
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2005 The Apache Software Foundation.
@@ -41,6 +40,7 @@
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactoryConfigurationError;
+import jdk.xml.internal.JdkXmlUtils;
 import org.xml.sax.SAXException;
 
 /**
@@ -117,7 +117,9 @@
             
             if( result!=null ) {
                 try {
-                    SAXTransformerFactory tf = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
+                    SAXTransformerFactory tf = JdkXmlUtils.getSAXTransformFactory(
+                            fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
+
                     identityTransformerHandler = tf.newTransformerHandler();
                 } catch (TransformerConfigurationException e) {
                     throw new TransformerFactoryConfigurationError(e);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorHandlerImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorHandlerImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2005 The Apache Software Foundation.
@@ -28,13 +27,13 @@
 
 import javax.xml.XMLConstants;
 import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.sax.SAXResult;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.validation.TypeInfoProvider;
 import javax.xml.validation.ValidatorHandler;
+import jdk.xml.internal.JdkXmlUtils;
 
 import com.sun.org.apache.xerces.internal.impl.Constants;
 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
@@ -669,15 +668,14 @@
                 XMLReader reader = saxSource.getXMLReader();
                 if( reader==null ) {
                     // create one now
-                    SAXParserFactory spf = SAXParserFactory.newInstance();
-                    spf.setNamespaceAware(true);
+                    reader = JdkXmlUtils.getXMLReader(fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER),
+                            fComponentManager.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
+
                     try {
-                        spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,
-                                fComponentManager.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
-                        reader = spf.newSAXParser().getXMLReader();
                         // If this is a Xerces SAX parser, set the security manager if there is one
                         if (reader instanceof com.sun.org.apache.xerces.internal.parsers.SAXParser) {
-                           XMLSecurityManager securityManager = (XMLSecurityManager) fComponentManager.getProperty(SECURITY_MANAGER);
+                           XMLSecurityManager securityManager =
+                                   (XMLSecurityManager) fComponentManager.getProperty(SECURITY_MANAGER);
                            if (securityManager != null) {
                                try {
                                    reader.setProperty(SECURITY_MANAGER, securityManager);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2005 The Apache Software Foundation.
@@ -31,6 +30,8 @@
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
+import jdk.xml.internal.JdkXmlFeatures;
+import jdk.xml.internal.JdkXmlUtils;
 
 import com.sun.org.apache.xerces.internal.impl.Constants;
 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader;
@@ -102,6 +103,15 @@
     
     /** The container for the real grammar pool. */ 
     private XMLGrammarPoolWrapper fXMLGrammarPoolWrapper;
+
+    private final JdkXmlFeatures fXmlFeatures;
+
+    /**
+     * Indicates whether 3rd party parser may be used to override the system-default
+     * Note the default value (false) is the safe option.
+     * Note same as the old property useServicesMechanism
+     */
+    private final boolean fOverrideDefaultParser;
     
     public XMLSchemaFactory() {
         fErrorHandlerWrapper = new ErrorHandlerWrapper(DraconianErrorHandler.getInstance());
@@ -115,6 +125,10 @@
         // Enable secure processing feature by default
         fSecurityManager = new XMLSecurityManager(true);
         fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
+        fXmlFeatures = new JdkXmlFeatures(fSecurityManager.isSecureProcessing());
+        fOverrideDefaultParser = fXmlFeatures.getFeature(
+                JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
+        fXMLSchemaLoader.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
     }
     
     /**
@@ -293,8 +307,14 @@
                     SAXMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(),
                     "property-not-supported", new Object [] {name}));
         }
+        /** Check to see if the property is managed by the JdkXmlFeatues **/
+        int index = fXmlFeatures.getIndex(name);
+        if (index > -1) {
+            return fXmlFeatures.getFeature(index);
+        }
+
         try {
-	    return fXMLSchemaLoader.getProperty(name);
+            return fXMLSchemaLoader.getProperty(name);
         }
         catch (XMLConfigurationException e) {
             String identifier = e.getIdentifier();
@@ -328,6 +348,14 @@
             fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
             return;
         }
+
+        if ((fXmlFeatures != null) &&
+                fXmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) {
+            if (name.equals(JdkXmlUtils.OVERRIDE_PARSER)) {
+                fXMLSchemaLoader.setFeature(name, value);
+            }
+            return;
+        }
         try {
             fXMLSchemaLoader.setFeature(name, value);
         }
@@ -387,6 +415,7 @@
 
     private void propagateFeatures(AbstractXMLSchema schema) {
         schema.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, fSecurityManager != null);
+        schema.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
         String[] features = fXMLSchemaLoader.getRecognizedFeatures();
         for (int i = 0; i < features.length; ++i) {
             boolean state = fXMLSchemaLoader.getFeature(features[i]);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/DTDConfiguration.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/DTDConfiguration.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -45,6 +44,7 @@
 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * This is the DTD-only parser configuration.  It extends the basic
@@ -301,6 +301,7 @@
             //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl
             //NOTIFY_CHAR_REFS,		// from XMLDocumentFragmentScannerImpl
             //WARN_ON_DUPLICATE_ENTITYDEF,  // from XMLEntityManager
+            JdkXmlUtils.OVERRIDE_PARSER
         };
         addRecognizedFeatures(recognizedFeatures);
 
@@ -313,6 +314,7 @@
         //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl
         //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl
         //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager
+        fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
 
         // add default recognized properties
         final String[] recognizedProperties = {
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/NonValidatingConfiguration.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/NonValidatingConfiguration.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
@@ -43,6 +42,7 @@
 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * This is the non validating parser configuration. It extends the basic
@@ -284,6 +284,7 @@
             //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl
             //NOTIFY_CHAR_REFS,		// from XMLDocumentFragmentScannerImpl
             //WARN_ON_DUPLICATE_ENTITYDEF   // from XMLEntityManager
+            JdkXmlUtils.OVERRIDE_PARSER
         };
         addRecognizedFeatures(recognizedFeatures);
 
@@ -298,6 +299,7 @@
         //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl
         //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl
         //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager
+        fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
 
         // add default recognized properties
         final String[] recognizedProperties = {
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -25,6 +24,7 @@
 import java.util.HashMap;
 import java.util.Locale;
 import javax.xml.XMLConstants;
+import jdk.xml.internal.JdkXmlUtils;
 
 import com.sun.org.apache.xerces.internal.impl.Constants;
 import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl;
@@ -50,7 +50,6 @@
 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;
 import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
 import com.sun.org.apache.xerces.internal.util.SymbolTable;
-import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
@@ -453,41 +452,43 @@
 
         // add default recognized features
         final String[] recognizedFeatures =
-            {   
-            	CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
-		VALIDATION,                 
-		NAMESPACES,
+            {
+                CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
+                                VALIDATION,
+                                NAMESPACES,
                 NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, SCHEMA_AUGMENT_PSVI,
                 GENERATE_SYNTHETIC_ANNOTATIONS, VALIDATE_ANNOTATIONS,
                 HONOUR_ALL_SCHEMALOCATIONS, USE_GRAMMAR_POOL_ONLY,
-            	// NOTE: These shouldn't really be here but since the XML Schema
-            	//       validator is constructed dynamically, its recognized
-            	//       features might not have been set and it would cause a
-            	//       not-recognized exception to be thrown. -Ac
-            	XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING, 			
-		EXTERNAL_GENERAL_ENTITIES,  
-		EXTERNAL_PARAMETER_ENTITIES,
-		PARSER_SETTINGS,
-                XMLConstants.FEATURE_SECURE_PROCESSING
-			};
+                // NOTE: These shouldn't really be here but since the XML Schema
+                //       validator is constructed dynamically, its recognized
+                //       features might not have been set and it would cause a
+                //       not-recognized exception to be thrown. -Ac
+                XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING,
+                    EXTERNAL_GENERAL_ENTITIES,
+                    EXTERNAL_PARAMETER_ENTITIES,
+                    PARSER_SETTINGS,
+                    XMLConstants.FEATURE_SECURE_PROCESSING,
+                    JdkXmlUtils.OVERRIDE_PARSER
+                        };
 
         addRecognizedFeatures(recognizedFeatures);
-		// set state for default features
-	fFeatures.put(VALIDATION, Boolean.FALSE);
-	fFeatures.put(NAMESPACES, Boolean.TRUE);
-	fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
-	fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
-	fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
-	fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
-	fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE);
-	fFeatures.put(NORMALIZE_DATA, Boolean.TRUE);
-	fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
+                // set state for default features
+                fFeatures.put(VALIDATION, Boolean.FALSE);
+                fFeatures.put(NAMESPACES, Boolean.TRUE);
+                fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
+                fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
+                fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
+                fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
+                fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE);
+                fFeatures.put(NORMALIZE_DATA, Boolean.TRUE);
+                fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
         fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE);
         fFeatures.put(VALIDATE_ANNOTATIONS, Boolean.FALSE);
         fFeatures.put(HONOUR_ALL_SCHEMALOCATIONS, Boolean.FALSE);
         fFeatures.put(USE_GRAMMAR_POOL_ONLY, Boolean.FALSE);
-	fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
+        fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
         fFeatures.put(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
+        fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
 
         // add default recognized properties
         final String[] recognizedProperties =
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/util/XMLCatalogResolver.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xerces/internal/util/XMLCatalogResolver.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
@@ -44,6 +43,7 @@
 import com.sun.org.apache.xml.internal.resolver.CatalogManager;
 import com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader;
 import com.sun.org.apache.xml.internal.resolver.readers.SAXCatalogReader;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * <p>The catalog resolver handles the resolution of external
@@ -574,8 +574,8 @@
      */
     private void attachReaderToCatalog (Catalog catalog) {
 
-        SAXParserFactory spf = new SAXParserFactoryImpl();
-        spf.setNamespaceAware(true);
+        SAXParserFactory spf = JdkXmlUtils.getSAXFactory(
+                catalog.getCatalogManager().overrideDefaultParser());
         spf.setValidating(false);
 
         SAXCatalogReader saxReader = new SAXCatalogReader(spf);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/dtm/DTMManager.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/dtm/DTMManager.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -51,6 +51,8 @@
    */
   protected XMLStringFactory m_xsf = null;
 
+  private boolean _overrideDefaultParser;
+
   /**
    * Default constructor is protected on purpose.
    */
@@ -292,6 +294,20 @@
     m_source_location = sourceLocation;
   }
 
+  /**
+   * Return the state of the services mechanism feature.
+   */
+  public boolean overrideDefaultParser() {
+      return _overrideDefaultParser;
+  }
+
+  /**
+   * Set the state of the services mechanism feature.
+   */
+  public void setOverrideDefaultParser(boolean flag) {
+      _overrideDefaultParser = flag;
+  }
+
 
   // -------------------- private methods --------------------
 
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/dtm/ref/DTMManagerDefault.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/dtm/ref/DTMManagerDefault.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -44,6 +43,7 @@
 import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
 import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
 import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -606,7 +606,7 @@
       // If user did not supply a reader, ask for one from the reader manager
       if (null == reader) {
         if (m_readerManager == null) {
-            m_readerManager = XMLReaderManager.getInstance();
+            m_readerManager = XMLReaderManager.getInstance(super.overrideDefaultParser());
         }
 
         reader = m_readerManager.getXMLReader();
@@ -765,7 +765,7 @@
 
     try
     {
-      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+      DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(super.overrideDefaultParser());
 
       dbf.setNamespaceAware(true);
 
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/Catalog.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/Catalog.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -40,6 +40,7 @@
 import java.util.Map;
 import java.util.Vector;
 import javax.xml.parsers.SAXParserFactory;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * Represents OASIS Open Catalog files.
@@ -394,8 +395,7 @@
    * Setup readers.
    */
   public void setupReaders() {
-    SAXParserFactory spf = SAXParserFactory.newInstance();
-    spf.setNamespaceAware(true);
+    SAXParserFactory spf = JdkXmlUtils.getSAXFactory(catalogManager.overrideDefaultParser());
     spf.setValidating(false);
 
     SAXCatalogReader saxReader = new SAXCatalogReader(spf);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/CatalogManager.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/CatalogManager.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,3 +1,6 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ */
 /*
  * reserved comment block
  * DO NOT REMOVE OR ALTER!
@@ -196,6 +199,13 @@
   /** Current catalog class name. */
   private String catalogClassName = null;
 
+  /**
+   * Indicates whether implementation parts should use
+   *   service loader (or similar).
+   * Note the default value (false) is the safe option..
+   */
+  private boolean overrideDefaultParser;
+
   /** The manager's debug object. Used for printing debugging messages.
    *
    * <p>This field is public so that objects that have access to this
@@ -211,6 +221,8 @@
     // read from the propertyFile for some other reason. That way, there's
     // no attempt to read from the file before the caller has had a chance
     // to avoid it.
+
+    overrideDefaultParser =  (System.getSecurityManager() == null);
   }
 
   /** Constructor that specifies an explicit property file. */
@@ -223,6 +235,8 @@
     // read from the propertyFile for some other reason. That way, there's
     // no attempt to read from the file before the caller has had a chance
     // to avoid it.
+
+    overrideDefaultParser =  (System.getSecurityManager() == null);
   }
 
   /** Set the bootstrap resolver.*/
@@ -771,6 +785,10 @@
     return oasisXMLCatalogPI.booleanValue();
   }
 
+  public boolean overrideDefaultParser() {
+    return overrideDefaultParser;
+  }
+
   /**
    * Set the XML Catalog PI setting
    */
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/Resolver.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/Resolver.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,3 +1,6 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ */
 /*
  * reserved comment block
  * DO NOT REMOVE OR ALTER!
@@ -36,6 +39,7 @@
 import com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader;
 import com.sun.org.apache.xml.internal.resolver.readers.TR9401CatalogReader;
 import javax.xml.parsers.SAXParserFactory;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * An extension to OASIS Open Catalog files, this class supports
@@ -85,8 +89,7 @@
    * Setup readers.
    */
   public void setupReaders() {
-    SAXParserFactory spf = SAXParserFactory.newInstance();
-    spf.setNamespaceAware(true);
+    SAXParserFactory spf = JdkXmlUtils.getSAXFactory(catalogManager.overrideDefaultParser());
     spf.setValidating(false);
 
     SAXCatalogReader saxReader = new SAXCatalogReader(spf);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/CatalogResolver.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/CatalogResolver.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,3 +1,6 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ */
 /*
  * reserved comment block
  * DO NOT REMOVE OR ALTER!
@@ -43,6 +46,7 @@
 import com.sun.org.apache.xml.internal.resolver.Catalog;
 import com.sun.org.apache.xml.internal.resolver.CatalogManager;
 import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * A SAX EntityResolver/JAXP URIResolver that uses catalogs.
@@ -302,10 +306,9 @@
   private void setEntityResolver(SAXSource source) throws TransformerException {
     XMLReader reader = source.getXMLReader();
     if (reader == null) {
-      SAXParserFactory spFactory = SAXParserFactory.newInstance();
-      spFactory.setNamespaceAware(true);
+      SAXParserFactory spf = JdkXmlUtils.getSAXFactory(catalogManager.overrideDefaultParser());
       try {
-        reader = spFactory.newSAXParser().getXMLReader();
+        reader = spf.newSAXParser().getXMLReader();
       }
       catch (ParserConfigurationException ex) {
         throw new TransformerException(ex);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingParser.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingParser.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,3 +1,6 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ */
 /*
  * reserved comment block
  * DO NOT REMOVE OR ALTER!
@@ -45,6 +48,7 @@
 import com.sun.org.apache.xml.internal.resolver.Catalog;
 import com.sun.org.apache.xml.internal.resolver.CatalogManager;
 import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * A SAX Parser that performs catalog-based entity resolution.
@@ -122,8 +126,7 @@
   private void initParser() {
     catalogResolver = new CatalogResolver(catalogManager);
 
-    SAXParserFactory spf = SAXParserFactory.newInstance();
-    spf.setNamespaceAware(namespaceAware);
+    SAXParserFactory spf = JdkXmlUtils.getSAXFactory(catalogManager.overrideDefaultParser());
     spf.setValidating(validating);
 
     try {
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLFilter.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLFilter.java	Thu Oct 19 17:03:20 2017 +0100
@@ -63,7 +63,7 @@
   public static boolean suppressExplanation = false;
 
   /** The manager for the underlying resolver. */
-  private CatalogManager catalogManager = CatalogManager.getStaticManager();
+  CatalogManager catalogManager = CatalogManager.getStaticManager();
 
   /** The underlying catalog resolver. */
   private CatalogResolver catalogResolver = null;
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLReader.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLReader.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,3 +1,6 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ */
 /*
  * reserved comment block
  * DO NOT REMOVE OR ALTER!
@@ -28,6 +31,7 @@
 import javax.xml.parsers.*;
 
 import com.sun.org.apache.xml.internal.resolver.*;
+import jdk.xml.internal.JdkXmlUtils;
 
 /**
  * A SAX XMLReader that performs catalog-based entity resolution.
@@ -60,8 +64,7 @@
    */
   public ResolvingXMLReader() {
     super();
-    SAXParserFactory spf = SAXParserFactory.newInstance();
-    spf.setNamespaceAware(namespaceAware);
+    SAXParserFactory spf = JdkXmlUtils.getSAXFactory(catalogManager.overrideDefaultParser());
     spf.setValidating(validating);
     try {
       SAXParser parser = spf.newSAXParser();
@@ -80,8 +83,7 @@
    */
   public ResolvingXMLReader(CatalogManager manager) {
     super(manager);
-    SAXParserFactory spf = SAXParserFactory.newInstance();
-    spf.setNamespaceAware(namespaceAware);
+    SAXParserFactory spf = JdkXmlUtils.getSAXFactory(catalogManager.overrideDefaultParser());
     spf.setValidating(validating);
     try {
       SAXParser parser = spf.newSAXParser();
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/TreeWalker.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/TreeWalker.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,11 +20,9 @@
 
 package com.sun.org.apache.xml.internal.serializer;
 
-import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
-import java.io.File;
-
-import com.sun.org.apache.xml.internal.serializer.utils.AttList;
-import com.sun.org.apache.xml.internal.serializer.utils.DOM2Helper;
+import com.sun.org.apache.xml.internal.utils.AttList;
+import com.sun.org.apache.xml.internal.utils.DOM2Helper;
+import javax.xml.transform.Result;
 import org.w3c.dom.Comment;
 import org.w3c.dom.Element;
 import org.w3c.dom.EntityReference;
@@ -32,7 +30,6 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.ProcessingInstruction;
 import org.w3c.dom.Text;
-
 import org.xml.sax.ContentHandler;
 import org.xml.sax.Locator;
 import org.xml.sax.ext.LexicalHandler;
@@ -59,12 +56,6 @@
    */
   final private SerializationHandler m_Serializer;
 
-  // ARGHH!!  JAXP Uses Xerces without setting the namespace processing to ON!
-  // DOM2Helper m_dh = new DOM2Helper();
-
-  /** DomHelper for this TreeWalker          */
-  final protected DOM2Helper m_dh;
-
   /** Locator object for this TreeWalker          */
   final private LocatorImpl m_locator = new LocatorImpl();
 
@@ -79,7 +70,7 @@
   }
 
   public TreeWalker(ContentHandler ch) {
-      this(ch,null);
+      this(ch, null);
   }
   /**
    * Constructor.
@@ -101,8 +92,6 @@
       if (systemId != null) {
           m_locator.setSystemId(systemId);
       }
-
-      m_dh = new DOM2Helper();
   }
 
   /**
@@ -211,7 +200,7 @@
     this.m_contentHandler.endDocument();
   }
 
-  /** Flag indicating whether following text to be processed is raw text          */
+  // Flag indicating whether following text to be processed is raw text
   boolean nextIsRaw = false;
 
   /**
@@ -315,7 +304,6 @@
         final int colon = attrName.indexOf(':');
         final String prefix;
 
-        // System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue());
         if (attrName.equals("xmlns") || attrName.startsWith("xmlns:"))
         {
           // Use "" instead of null, as Xerces likes "" for the
@@ -337,13 +325,13 @@
         }
       }
 
-      String ns = m_dh.getNamespaceOfNode(node);
+      String ns = DOM2Helper.getNamespaceOfNode(node);
       if(null == ns)
         ns = "";
       this.m_contentHandler.startElement(ns,
-                                         m_dh.getLocalNameOfNode(node),
+                                         DOM2Helper.getLocalNameOfNode(node),
                                          node.getNodeName(),
-                                         new AttList(atts, m_dh));
+                                         new AttList(atts));
       break;
     case Node.PROCESSING_INSTRUCTION_NODE :
     {
@@ -391,9 +379,9 @@
       {
         nextIsRaw = false;
 
-        m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
+        m_contentHandler.processingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, "");
         dispatachChars(node);
-        m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
+        m_contentHandler.processingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, "");
       }
       else
       {
@@ -438,12 +426,12 @@
       break;
 
     case Node.ELEMENT_NODE :
-      String ns = m_dh.getNamespaceOfNode(node);
+      String ns = DOM2Helper.getNamespaceOfNode(node);
       if(null == ns)
         ns = "";
       this.m_contentHandler.endElement(ns,
-                                         m_dh.getLocalNameOfNode(node),
-                                         node.getNodeName());
+              DOM2Helper.getLocalNameOfNode(node),
+              node.getNodeName());
 
       if (m_Serializer == null) {
       // Don't bother with endPrefixMapping calls if the ContentHandler is a
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/utils/AttList.java	Fri Feb 05 14:40:11 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,265 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * $Id: AttList.java,v 1.1.4.1 2005/09/08 11:03:08 suresh_emailid Exp $
- */
-package com.sun.org.apache.xml.internal.serializer.utils;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-import org.xml.sax.Attributes;
-
-/**
- * Wraps a DOM attribute list in a SAX Attributes.
- *
- * This class is a copy of the one in com.sun.org.apache.xml.internal.utils.
- * It exists to cut the serializers dependancy on that package.
- * A minor changes from that package are:
- * DOMHelper reference changed to DOM2Helper, class is not "public"
- *
- * This class is not a public API, it is only public because it is
- * used in com.sun.org.apache.xml.internal.serializer.
- *
- * @xsl.usage internal
- */
-public final class AttList implements Attributes
-{
-
-  /** List of attribute nodes          */
-  NamedNodeMap m_attrs;
-
-  /** Index of last attribute node          */
-  int m_lastIndex;
-
-  // ARGHH!!  JAXP Uses Xerces without setting the namespace processing to ON!
-  // DOM2Helper m_dh = new DOM2Helper();
-
-  /** Local reference to DOMHelper          */
-  DOM2Helper m_dh;
-
-//  /**
-//   * Constructor AttList
-//   *
-//   *
-//   * @param attrs List of attributes this will contain
-//   */
-//  public AttList(NamedNodeMap attrs)
-//  {
-//
-//    m_attrs = attrs;
-//    m_lastIndex = m_attrs.getLength() - 1;
-//    m_dh = new DOM2Helper();
-//  }
-
-  /**
-   * Constructor AttList
-   *
-   *
-   * @param attrs List of attributes this will contain
-   * @param dh DOMHelper
-   */
-  public AttList(NamedNodeMap attrs, DOM2Helper dh)
-  {
-
-    m_attrs = attrs;
-    m_lastIndex = m_attrs.getLength() - 1;
-    m_dh = dh;
-  }
-
-  /**
-   * Get the number of attribute nodes in the list
-   *
-   *
-   * @return number of attribute nodes
-   */
-  public int getLength()
-  {
-    return m_attrs.getLength();
-  }
-
-  /**
-   * Look up an attribute's Namespace URI by index.
-   *
-   * @param index The attribute index (zero-based).
-   * @return The Namespace URI, or the empty string if none
-   *         is available, or null if the index is out of
-   *         range.
-   */
-  public String getURI(int index)
-  {
-    String ns = m_dh.getNamespaceOfNode(((Attr) m_attrs.item(index)));
-    if(null == ns)
-      ns = "";
-    return ns;
-  }
-
-  /**
-   * Look up an attribute's local name by index.
-   *
-   * @param index The attribute index (zero-based).
-   * @return The local name, or the empty string if Namespace
-   *         processing is not being performed, or null
-   *         if the index is out of range.
-   */
-  public String getLocalName(int index)
-  {
-    return m_dh.getLocalNameOfNode(((Attr) m_attrs.item(index)));
-  }
-
-  /**
-   * Look up an attribute's qualified name by index.
-   *
-   *
-   * @param i The attribute index (zero-based).
-   *
-   * @return The attribute's qualified name
-   */
-  public String getQName(int i)
-  {
-    return ((Attr) m_attrs.item(i)).getName();
-  }
-
-  /**
-   * Get the attribute's node type by index
-   *
-   *
-   * @param i The attribute index (zero-based)
-   *
-   * @return the attribute's node type
-   */
-  public String getType(int i)
-  {
-    return "CDATA";  // for the moment
-  }
-
-  /**
-   * Get the attribute's node value by index
-   *
-   *
-   * @param i The attribute index (zero-based)
-   *
-   * @return the attribute's node value
-   */
-  public String getValue(int i)
-  {
-    return ((Attr) m_attrs.item(i)).getValue();
-  }
-
-  /**
-   * Get the attribute's node type by name
-   *
-   *
-   * @param name Attribute name
-   *
-   * @return the attribute's node type
-   */
-  public String getType(String name)
-  {
-    return "CDATA";  // for the moment
-  }
-
-  /**
-   * Look up an attribute's type by Namespace name.
-   *
-   * @param uri The Namespace URI, or the empty String if the
-   *        name has no Namespace URI.
-   * @param localName The local name of the attribute.
-   * @return The attribute type as a string, or null if the
-   *         attribute is not in the list or if Namespace
-   *         processing is not being performed.
-   */
-  public String getType(String uri, String localName)
-  {
-    return "CDATA";  // for the moment
-  }
-
-  /**
-   * Look up an attribute's value by name.
-   *
-   *
-   * @param name The attribute node's name
-   *
-   * @return The attribute node's value
-   */
-  public String getValue(String name)
-  {
-    Attr attr = ((Attr) m_attrs.getNamedItem(name));
-    return (null != attr)
-          ? attr.getValue() : null;
-  }
-
-  /**
-   * Look up an attribute's value by Namespace name.
-   *
-   * @param uri The Namespace URI, or the empty String if the
-   *        name has no Namespace URI.
-   * @param localName The local name of the attribute.
-   * @return The attribute value as a string, or null if the
-   *         attribute is not in the list.
-   */
-  public String getValue(String uri, String localName)
-  {
-        Node a=m_attrs.getNamedItemNS(uri,localName);
-        return (a==null) ? null : a.getNodeValue();
-  }
-
-  /**
-   * Look up the index of an attribute by Namespace name.
-   *
-   * @param uri The Namespace URI, or the empty string if
-   *        the name has no Namespace URI.
-   * @param localPart The attribute's local name.
-   * @return The index of the attribute, or -1 if it does not
-   *         appear in the list.
-   */
-  public int getIndex(String uri, String localPart)
-  {
-    for(int i=m_attrs.getLength()-1;i>=0;--i)
-    {
-      Node a=m_attrs.item(i);
-      String u=a.getNamespaceURI();
-      if( (u==null ? uri==null : u.equals(uri))
-      &&
-      a.getLocalName().equals(localPart) )
-    return i;
-    }
-    return -1;
-  }
-
-  /**
-   * Look up the index of an attribute by raw XML 1.0 name.
-   *
-   * @param qName The qualified (prefixed) name.
-   * @return The index of the attribute, or -1 if it does not
-   *         appear in the list.
-   */
-  public int getIndex(String qName)
-  {
-    for(int i=m_attrs.getLength()-1;i>=0;--i)
-    {
-      Node a=m_attrs.item(i);
-      if(a.getNodeName().equals(qName) )
-    return i;
-    }
-    return -1;
-  }
-}
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/serializer/utils/DOM2Helper.java	Fri Feb 05 14:40:11 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * $Id: DOM2Helper.java,v 1.1.4.1 2005/09/08 11:03:09 suresh_emailid Exp $
- */
-package com.sun.org.apache.xml.internal.serializer.utils;
-
-import java.io.IOException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-import org.xml.sax.InputSource;
-
-/**
- * This class provides a DOM level 2 "helper", which provides services currently
- * not provided be the DOM standard.
- *
- * This class is a copy of the one in com.sun.org.apache.xml.internal.utils.
- * It exists to cut the serializers dependancy on that package.
- *
- * The differences from the original class are:
- * it doesn't extend DOMHelper, not depricated,
- * dropped method isNodeAfter(Node node1, Node node2)
- * dropped method parse(InputSource)
- * dropped method supportSAX()
- * dropped method setDocument(doc)
- * dropped method checkNode(Node)
- * dropped method getDocument()
- * dropped method getElementByID(String id, Document doc)
- * dropped method getParentOfNode(Node node)
- * dropped field Document m_doc;
- * made class non-public
- *
- * This class is not a public API, it is only public because it is
- * used in com.sun.org.apache.xml.internal.serializer.
- *
- * @xsl.usage internal
- */
-public final class DOM2Helper
-{
-
-  /**
-   * Construct an instance.
-   */
-  public DOM2Helper(){}
-
-  /**
-   * Returns the local name of the given node, as defined by the
-   * XML Namespaces specification. This is prepared to handle documents
-   * built using DOM Level 1 methods by falling back upon explicitly
-   * parsing the node name.
-   *
-   * @param n Node to be examined
-   *
-   * @return String containing the local name, or null if the node
-   * was not assigned a Namespace.
-   */
-  public String getLocalNameOfNode(Node n)
-  {
-
-    String name = n.getLocalName();
-
-    return (null == name) ? getLocalNameOfNodeFallback(n) : name;
-  }
-
-  /**
-   * Returns the local name of the given node. If the node's name begins
-   * with a namespace prefix, this is the part after the colon; otherwise
-   * it's the full node name.
-   *
-   * This method is copied from com.sun.org.apache.xml.internal.utils.DOMHelper
-   *
-   * @param n the node to be examined.
-   *
-   * @return String containing the Local Name
-   */
-  private String getLocalNameOfNodeFallback(Node n)
-  {
-
-    String qname = n.getNodeName();
-    int index = qname.indexOf(':');
-
-    return (index < 0) ? qname : qname.substring(index + 1);
-  }
-
-  /**
-   * Returns the Namespace Name (Namespace URI) for the given node.
-   * In a Level 2 DOM, you can ask the node itself. Note, however, that
-   * doing so conflicts with our decision in getLocalNameOfNode not
-   * to trust the that the DOM was indeed created using the Level 2
-   * methods. If Level 1 methods were used, these two functions will
-   * disagree with each other.
-   * <p>
-   * TODO: Reconcile with getLocalNameOfNode.
-   *
-   * @param n Node to be examined
-   *
-   * @return String containing the Namespace URI bound to this DOM node
-   * at the time the Node was created.
-   */
-  public String getNamespaceOfNode(Node n)
-  {
-    return n.getNamespaceURI();
-  }
-
-  /** Field m_useDOM2getNamespaceURI is a compile-time flag which
-   *  gates some of the parser options used to build a DOM -- but
-   * that code is commented out at this time and nobody else
-   * references it, so I've commented this out as well. */
-  //private boolean m_useDOM2getNamespaceURI = false;
-}
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/AttList.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/AttList.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -41,39 +40,18 @@
   /** Index of last attribute node          */
   int m_lastIndex;
 
-  // ARGHH!!  JAXP Uses Xerces without setting the namespace processing to ON!
+  // JAXP Uses Xerces without setting the namespace processing to ON!
   // DOM2Helper m_dh = new DOM2Helper();
 
-  /** Local reference to DOMHelper          */
-  DOMHelper m_dh;
-
-//  /**
-//   * Constructor AttList
-//   *
-//   *
-//   * @param attrs List of attributes this will contain
-//   */
-//  public AttList(NamedNodeMap attrs)
-//  {
-//
-//    m_attrs = attrs;
-//    m_lastIndex = m_attrs.getLength() - 1;
-//    m_dh = new DOM2Helper();
-//  }
-
   /**
    * Constructor AttList
    *
-   *
    * @param attrs List of attributes this will contain
-   * @param dh DOMHelper
    */
-  public AttList(NamedNodeMap attrs, DOMHelper dh)
+  public AttList(NamedNodeMap attrs)
   {
-
     m_attrs = attrs;
     m_lastIndex = m_attrs.getLength() - 1;
-    m_dh = dh;
   }
 
   /**
@@ -97,7 +75,7 @@
    */
   public String getURI(int index)
   {
-    String ns = m_dh.getNamespaceOfNode(((Attr) m_attrs.item(index)));
+    String ns = DOM2Helper.getNamespaceOfNode(((Attr) m_attrs.item(index)));
     if(null == ns)
       ns = "";
     return ns;
@@ -113,7 +91,7 @@
    */
   public String getLocalName(int index)
   {
-    return m_dh.getLocalNameOfNode(((Attr) m_attrs.item(index)));
+    return DOM2Helper.getLocalNameOfNode(((Attr) m_attrs.item(index)));
   }
 
   /**
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/DOM2Helper.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/DOM2Helper.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -22,295 +21,321 @@
  */
 package com.sun.org.apache.xml.internal.utils;
 
-import java.io.IOException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
-
+import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
 import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
-import org.xml.sax.InputSource;
 
 /**
- * @deprecated Since the introduction of the DTM, this class will be removed.
- * This class provides a DOM level 2 "helper", which provides services currently
- * not provided be the DOM standard.
+ * This class provides a DOM level 2 "helper", which provides several services.
+ *
+ * The original class extended DOMHelper that was deprecated and then removed.
  */
-public class DOM2Helper extends DOMHelper
-{
-
-  /**
-   * Construct an instance.
-   */
-  public DOM2Helper(){}
+public final class DOM2Helper {
 
-  /**
-   * Check node to see if it was created by a DOM implementation
-   * that this helper is intended to support. This is currently
-   * disabled, and assumes all nodes are acceptable rather than checking
-   * that they implement com.sun.org.apache.xerces.internal.dom.NodeImpl.
-   *
-   * @param node The node to be tested.
-   *
-   * @throws TransformerException if the node is not one which this
-   * DOM2Helper can support. If we return without throwing the exception,
-   * the node is compatable.
-   * @xsl.usage internal
-   */
-  public void checkNode(Node node) throws TransformerException
-  {
-
-    // if(!(node instanceof com.sun.org.apache.xerces.internal.dom.NodeImpl))
-    //  throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XERCES_CANNOT_HANDLE_NODES, new Object[]{((Object)node).getClass()})); //"DOM2Helper can not handle nodes of type"
-    //+((Object)node).getClass());
-  }
+    /**
+     * Construct an instance.
+     */
+    private DOM2Helper() {
+    }
 
-  /**
-   * Returns true if the DOM implementation handled by this helper
-   * supports the SAX ContentHandler interface.
-   *
-   * @return true (since Xerces does).
-   */
-  public boolean supportsSAX()
-  {
-    return true;
-  }
-
-  /** Field m_doc: Document Node for the document this helper is currently
-   * accessing or building
-   * @see #setDocument
-   * @see #getDocument
-   *  */
-  private Document m_doc;
-
-  /**
-   * Specify which document this helper is currently operating on.
-   *
-   * @param doc The DOM Document node for this document.
-   * @see #getDocument
-   */
-  public void setDocument(Document doc)
-  {
-    m_doc = doc;
-  }
-
-  /**
-   * Query which document this helper is currently operating on.
-   *
-   * @return The DOM Document node for this document.
-   * @see #setDocument
-   */
-  public Document getDocument()
-  {
-    return m_doc;
-  }
+    /**
+     * Returns the local name of the given node, as defined by the XML
+     * Namespaces specification. This is prepared to handle documents built
+     * using DOM Level 1 methods by falling back upon explicitly parsing the
+     * node name.
+     *
+     * @param n Node to be examined
+     *
+     * @return String containing the local name, or null if the node was not
+     * assigned a Namespace.
+     */
+    public static String getLocalNameOfNode(Node n) {
+        String name = n.getLocalName();
+        return (null == name) ? getLocalNameOfNodeFallback(n) : name;
+    }
 
-  /**
-   * Parse an XML document.
-   *
-   * <p>Right now the Xerces DOMParser class is used.  This needs
-   * fixing, either via jaxp, or via some other, standard method.</p>
-   *
-   * <p>The application can use this method to instruct the SAX parser
-   * to begin parsing an XML document from any valid input
-   * source (a character stream, a byte stream, or a URI).</p>
-   *
-   * <p>Applications may not invoke this method while a parse is in
-   * progress (they should create a new Parser instead for each
-   * additional XML document).  Once a parse is complete, an
-   * application may reuse the same Parser object, possibly with a
-   * different input source.</p>
-   *
-   * @param source The input source for the top-level of the
-   *        XML document.
-   *
-   * @throws TransformerException if any checked exception is thrown.
-   * @xsl.usage internal
-   */
-  public void parse(InputSource source) throws TransformerException
-  {
-
-    try
-    {
-
-      // I guess I should use JAXP factory here... when it's legal.
-      // com.sun.org.apache.xerces.internal.parsers.DOMParser parser
-      //  = new com.sun.org.apache.xerces.internal.parsers.DOMParser();
-      DocumentBuilderFactory builderFactory =
-        DocumentBuilderFactory.newInstance();
-
-      builderFactory.setNamespaceAware(true);
-      builderFactory.setValidating(true);
+    /**
+     * Returns the local name of the given node. If the node's name begins with
+     * a namespace prefix, this is the part after the colon; otherwise it's the
+     * full node name.
+     *
+     * This method is copied from
+     * com.sun.org.apache.xml.internal.utils.DOMHelper
+     *
+     * @param n the node to be examined.
+     *
+     * @return String containing the Local Name
+     */
+    private static String getLocalNameOfNodeFallback(Node n) {
+        String qname = n.getNodeName();
+        int index = qname.indexOf(':');
 
-      DocumentBuilder parser = builderFactory.newDocumentBuilder();
-
-      /*
-      // domParser.setFeature("http://apache.org/xml/features/dom/create-entity-ref-nodes", getShouldExpandEntityRefs()? false : true);
-      if(m_useDOM2getNamespaceURI)
-      {
-      parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
-      parser.setFeature("http://xml.org/sax/features/namespaces", true);
-      }
-      else
-      {
-      parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
-      }
-
-      parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
-      */
+        return (index < 0) ? qname : qname.substring(index + 1);
+    }
 
-      parser.setErrorHandler(
-        new com.sun.org.apache.xml.internal.utils.DefaultErrorHandler());
-
-      // if(null != m_entityResolver)
-      // {
-      // System.out.println("Setting the entity resolver.");
-      //  parser.setEntityResolver(m_entityResolver);
-      // }
-      setDocument(parser.parse(source));
-    }
-    catch (org.xml.sax.SAXException se)
-    {
-      throw new TransformerException(se);
-    }
-    catch (ParserConfigurationException pce)
-    {
-      throw new TransformerException(pce);
-    }
-    catch (IOException ioe)
-    {
-      throw new TransformerException(ioe);
+    /**
+     * Returns the Namespace Name (Namespace URI) for the given node. In a Level
+     * 2 DOM, you can ask the node itself. Note, however, that doing so
+     * conflicts with our decision in getLocalNameOfNode not to trust the that
+     * the DOM was indeed created using the Level 2 methods. If Level 1 methods
+     * were used, these two functions will disagree with each other.
+     * <p>
+     * TODO: Reconcile with getLocalNameOfNode.
+     *
+     * @param n Node to be examined
+     *
+     * @return String containing the Namespace URI bound to this DOM node at the
+     * time the Node was created.
+     */
+    public static String getNamespaceOfNode(Node n) {
+        return n.getNamespaceURI();
     }
 
-    // setDocument(((com.sun.org.apache.xerces.internal.parsers.DOMParser)parser).getDocument());
-  }
+    /**
+     * Figure out whether node2 should be considered as being later in the
+     * document than node1, in Document Order as defined by the XPath model.
+     * This may not agree with the ordering defined by other XML applications.
+     * <p>
+     * There are some cases where ordering isn't defined, and neither are the
+     * results of this function -- though we'll generally return true.
+     *
+     * @param node1 DOM Node to perform position comparison on.
+     * @param node2 DOM Node to perform position comparison on .
+     *
+     * @return false if node2 comes before node1, otherwise return true. You can
+     * think of this as
+     * {@code (node1.documentOrderPosition &lt;= node2.documentOrderPosition)}.
+     */
+    public static boolean isNodeAfter(Node node1, Node node2) {
+        if (node1 == node2 || isNodeTheSame(node1, node2)) {
+            return true;
+        }
+
+        // Default return value, if there is no defined ordering
+        boolean isNodeAfter = true;
+
+        Node parent1 = getParentOfNode(node1);
+        Node parent2 = getParentOfNode(node2);
 
-  /**
-   * Given an XML ID, return the element. This requires assistance from the
-   * DOM and parser, and is meaningful only in the context of a DTD
-   * or schema which declares attributes as being of type ID. This
-   * information may or may not be available in all parsers, may or
-   * may not be available for specific documents, and may or may not
-   * be available when validation is not turned on.
-   *
-   * @param id The ID to search for, as a String.
-   * @param doc The document to search within, as a DOM Document node.
-   * @return DOM Element node with an attribute of type ID whose value
-   * uniquely matches the requested id string, or null if there isn't
-   * such an element or if the DOM can't answer the question for other
-   * reasons.
-   */
-  public Element getElementByID(String id, Document doc)
-  {
-    return doc.getElementById(id);
-  }
+        // Optimize for most common case
+        if (parent1 == parent2 || isNodeTheSame(parent1, parent2)) // then we know they are siblings
+        {
+            if (null != parent1) {
+                isNodeAfter = isNodeAfterSibling(parent1, node1, node2);
+            }
+        } else {
+            // General strategy: Figure out the lengths of the two
+            // ancestor chains, reconcile the lengths, and look for
+            // the lowest common ancestor. If that ancestor is one of
+            // the nodes being compared, it comes before the other.
+            // Otherwise perform a sibling compare.
+            //
+            // NOTE: If no common ancestor is found, ordering is undefined
+            // and we return the default value of isNodeAfter.
+            // Count parents in each ancestor chain
+            int nParents1 = 2, nParents2 = 2;  // include node & parent obtained above
+
+            while (parent1 != null) {
+                nParents1++;
+                parent1 = getParentOfNode(parent1);
+            }
+
+            while (parent2 != null) {
+                nParents2++;
+
+                parent2 = getParentOfNode(parent2);
+            }
 
-  /**
-   * Figure out whether node2 should be considered as being later
-   * in the document than node1, in Document Order as defined
-   * by the XPath model. This may not agree with the ordering defined
-   * by other XML applications.
-   * <p>
-   * There are some cases where ordering isn't defined, and neither are
-   * the results of this function -- though we'll generally return true.
-   * <p>
-   * TODO: Make sure this does the right thing with attribute nodes!!!
-   *
-   * @param node1 DOM Node to perform position comparison on.
-   * @param node2 DOM Node to perform position comparison on .
-   *
-   * @return false if node2 comes before node1, otherwise return true.
-   * You can think of this as
-   * <code>(node1.documentOrderPosition &lt;= node2.documentOrderPosition)</code>.
-   */
-  public static boolean isNodeAfter(Node node1, Node node2)
-  {
+            // Initially assume scan for common ancestor starts with
+            // the input nodes.
+            Node startNode1 = node1, startNode2 = node2;
+
+            // If one ancestor chain is longer, adjust its start point
+            // so we're comparing at the same depths
+            if (nParents1 < nParents2) {
+                // Adjust startNode2 to depth of startNode1
+                int adjust = nParents2 - nParents1;
+
+                for (int i = 0; i < adjust; i++) {
+                    startNode2 = getParentOfNode(startNode2);
+                }
+            } else if (nParents1 > nParents2) {
+                // adjust startNode1 to depth of startNode2
+                int adjust = nParents1 - nParents2;
+
+                for (int i = 0; i < adjust; i++) {
+                    startNode1 = getParentOfNode(startNode1);
+                }
+            }
+
+            Node prevChild1 = null, prevChild2 = null;  // so we can "back up"
 
-    // Assume first that the nodes are DTM nodes, since discovering node
-    // order is massivly faster for the DTM.
-    if(node1 instanceof DOMOrder && node2 instanceof DOMOrder)
-    {
-      int index1 = ((DOMOrder) node1).getUid();
-      int index2 = ((DOMOrder) node2).getUid();
+            // Loop up the ancestor chain looking for common parent
+            while (null != startNode1) {
+                if (startNode1 == startNode2 || isNodeTheSame(startNode1, startNode2)) // common parent?
+                {
+                    if (null == prevChild1) // first time in loop?
+                    {
+
+                        // Edge condition: one is the ancestor of the other.
+                        isNodeAfter = (nParents1 < nParents2) ? true : false;
 
-      return index1 <= index2;
-    }
-    else
-    {
+                        break;  // from while loop
+                    } else {
+                        // Compare ancestors below lowest-common as siblings
+                        isNodeAfter = isNodeAfterSibling(startNode1, prevChild1,
+                                prevChild2);
+
+                        break;  // from while loop
+                    }
+                }  // end if(startNode1 == startNode2)
 
-      // isNodeAfter will return true if node is after countedNode
-      // in document order. The base isNodeAfter is sloooow (relatively).
-      return DOMHelper.isNodeAfter(node1, node2);
-    }
-  }
+                // Move up one level and try again
+                prevChild1 = startNode1;
+                startNode1 = getParentOfNode(startNode1);
+                prevChild2 = startNode2;
+                startNode2 = getParentOfNode(startNode2);
+            }  // end while(parents exist to examine)
+        }  // end big else (not immediate siblings)
+
+        return isNodeAfter;
+    }  // end isNodeAfter(Node node1, Node node2)
 
-  /**
-   * Get the XPath-model parent of a node.  This version takes advantage
-   * of the DOM Level 2 Attr.ownerElement() method; the base version we
-   * would otherwise inherit is prepared to fall back on exhaustively
-   * walking the document to find an Attr's parent.
-   *
-   * @param node Node to be examined
-   *
-   * @return the DOM parent of the input node, if there is one, or the
-   * ownerElement if the input node is an Attr, or null if the node is
-   * a Document, a DocumentFragment, or an orphan.
-   */
-  public static Node getParentOfNode(Node node)
-  {
-          Node parent=node.getParentNode();
-          if(parent==null && (Node.ATTRIBUTE_NODE == node.getNodeType()) )
-           parent=((Attr) node).getOwnerElement();
-          return parent;
-  }
+    /**
+     * Use DTMNodeProxy to determine whether two nodes are the same.
+     *
+     * @param node1 The first DOM node to compare.
+     * @param node2 The second DOM node to compare.
+     * @return true if the two nodes are the same.
+     */
+    public static boolean isNodeTheSame(Node node1, Node node2) {
+        if (node1 instanceof DTMNodeProxy && node2 instanceof DTMNodeProxy) {
+            return ((DTMNodeProxy) node1).equals((DTMNodeProxy) node2);
+        } else {
+            return (node1 == node2);
+        }
+    }
+
+    /**
+     * Get the XPath-model parent of a node. This version takes advantage of the
+     * DOM Level 2 Attr.ownerElement() method; the base version we would
+     * otherwise inherit is prepared to fall back on exhaustively walking the
+     * document to find an Attr's parent.
+     *
+     * @param node Node to be examined
+     *
+     * @return the DOM parent of the input node, if there is one, or the
+     * ownerElement if the input node is an Attr, or null if the node is a
+     * Document, a DocumentFragment, or an orphan.
+     */
+    public static Node getParentOfNode(Node node) {
+        Node parent = node.getParentNode();
+        if (parent == null && (Node.ATTRIBUTE_NODE == node.getNodeType())) {
+            parent = ((Attr) node).getOwnerElement();
+        }
+        return parent;
+    }
+
+    /**
+     * Figure out if child2 is after child1 in document order.
+     * <p>
+     * Warning: Some aspects of "document order" are not well defined. For
+     * example, the order of attributes is considered meaningless in XML, and
+     * the order reported by our model will be consistent for a given invocation
+     * but may not match that of either the source file or the serialized
+     * output.
+     *
+     * @param parent Must be the parent of both child1 and child2.
+     * @param child1 Must be the child of parent and not equal to child2.
+     * @param child2 Must be the child of parent and not equal to child1.
+     * @return true if child 2 is after child1 in document order.
+     */
+    private static boolean isNodeAfterSibling(Node parent, Node child1,
+            Node child2) {
+
+        boolean isNodeAfterSibling = false;
+        short child1type = child1.getNodeType();
+        short child2type = child2.getNodeType();
+
+        if ((Node.ATTRIBUTE_NODE != child1type)
+                && (Node.ATTRIBUTE_NODE == child2type)) {
+
+            // always sort attributes before non-attributes.
+            isNodeAfterSibling = false;
+        } else if ((Node.ATTRIBUTE_NODE == child1type)
+                && (Node.ATTRIBUTE_NODE != child2type)) {
 
-  /**
-   * Returns the local name of the given node, as defined by the
-   * XML Namespaces specification. This is prepared to handle documents
-   * built using DOM Level 1 methods by falling back upon explicitly
-   * parsing the node name.
-   *
-   * @param n Node to be examined
-   *
-   * @return String containing the local name, or null if the node
-   * was not assigned a Namespace.
-   */
-  public String getLocalNameOfNode(Node n)
-  {
+            // always sort attributes before non-attributes.
+            isNodeAfterSibling = true;
+        } else if (Node.ATTRIBUTE_NODE == child1type) {
+            NamedNodeMap children = parent.getAttributes();
+            int nNodes = children.getLength();
+            boolean found1 = false, found2 = false;
+
+            // Count from the start until we find one or the other.
+            for (int i = 0; i < nNodes; i++) {
+                Node child = children.item(i);
 
-    String name = n.getLocalName();
+                if (child1 == child || isNodeTheSame(child1, child)) {
+                    if (found2) {
+                        isNodeAfterSibling = false;
+
+                        break;
+                    }
 
-    return (null == name) ? super.getLocalNameOfNode(n) : name;
-  }
+                    found1 = true;
+                } else if (child2 == child || isNodeTheSame(child2, child)) {
+                    if (found1) {
+                        isNodeAfterSibling = true;
+
+                        break;
+                    }
 
-  /**
-   * Returns the Namespace Name (Namespace URI) for the given node.
-   * In a Level 2 DOM, you can ask the node itself. Note, however, that
-   * doing so conflicts with our decision in getLocalNameOfNode not
-   * to trust the that the DOM was indeed created using the Level 2
-   * methods. If Level 1 methods were used, these two functions will
-   * disagree with each other.
-   * <p>
-   * TODO: Reconcile with getLocalNameOfNode.
-   *
-   * @param n Node to be examined
-   *
-   * @return String containing the Namespace URI bound to this DOM node
-   * at the time the Node was created.
-   */
-  public String getNamespaceOfNode(Node n)
-  {
-    return n.getNamespaceURI();
-  }
+                    found2 = true;
+                }
+            }
+        } else {
+            // TODO: Check performance of alternate solution:
+            // There are two choices here: Count from the start of
+            // the document until we find one or the other, or count
+            // from one until we find or fail to find the other.
+            // Either can wind up scanning all the siblings in the worst
+            // case, which on a wide document can be a lot of work but
+            // is more typically is a short list.
+            // Scanning from the start involves two tests per iteration,
+            // but it isn't clear that scanning from the middle doesn't
+            // yield more iterations on average.
+            // We should run some testcases.
+            Node child = parent.getFirstChild();
+            boolean found1 = false, found2 = false;
+
+            while (null != child) {
 
-  /** Field m_useDOM2getNamespaceURI is a compile-time flag which
-   *  gates some of the parser options used to build a DOM -- but
-   * that code is commented out at this time and nobody else
-   * references it, so I've commented this out as well. */
-  //private boolean m_useDOM2getNamespaceURI = false;
+                // Node child = children.item(i);
+                if (child1 == child || isNodeTheSame(child1, child)) {
+                    if (found2) {
+                        isNodeAfterSibling = false;
+
+                        break;
+                    }
+
+                    found1 = true;
+                } else if (child2 == child || isNodeTheSame(child2, child)) {
+                    if (found1) {
+                        isNodeAfterSibling = true;
+
+                        break;
+                    }
+
+                    found2 = true;
+                }
+
+                child = child.getNextSibling();
+            }
+        }
+
+        return isNodeAfterSibling;
+    }  // end isNodeAfterSibling(Node parent, Node child1, Node child2)
 }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/DOMHelper.java	Fri Feb 05 14:40:11 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1330 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- */
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * $Id: DOMHelper.java,v 1.2.4.1 2005/09/15 08:15:40 suresh_emailid Exp $
- */
-package com.sun.org.apache.xml.internal.utils;
-
-import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
-import com.sun.org.apache.xml.internal.res.XMLErrorResources;
-import com.sun.org.apache.xml.internal.res.XMLMessages;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Entity;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-/**
- * @deprecated Since the introduction of the DTM, this class will be removed.
- * This class provides a front-end to DOM implementations, providing
- * a number of utility functions that either aren't yet standardized
- * by the DOM spec or that are defined in optional DOM modules and
- * hence may not be present in all DOMs.
- */
-public class DOMHelper
-{
-
-  /**
-   * DOM Level 1 did not have a standard mechanism for creating a new
-   * Document object. This function provides a DOM-implementation-independent
-   * abstraction for that for that concept. It's typically used when
-   * outputting a new DOM as the result of an operation.
-   * <p>
-   * TODO: This isn't directly compatable with DOM Level 2.
-   * The Level 2 createDocument call also creates the root
-   * element, and thus requires that you know what that element will be
-   * before creating the Document. We should think about whether we want
-   * to change this code, and the callers, so we can use the DOM's own
-   * method. (It's also possible that DOM Level 3 may relax this
-   * sequence, but you may give up some intelligence in the DOM by
-   * doing so; the intent was that knowing the document type and root
-   * element might let the DOM automatically switch to a specialized
-   * subclass for particular kinds of documents.)
-   *
-   * @param isSecureProcessing state of the secure processing feature.
-   * @return The newly created DOM Document object, with no children, or
-   * null if we can't find a DOM implementation that permits creating
-   * new empty Documents.
-   */
-  public static Document createDocument(boolean isSecureProcessing)
-  {
-
-    try
-    {
-
-      // Use an implementation of the JAVA API for XML Parsing 1.0 to
-      // create a DOM Document node to contain the result.
-      DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
-
-      dfactory.setNamespaceAware(true);
-      dfactory.setValidating(true);
-
-      if (isSecureProcessing)
-      {
-        try
-        {
-          dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
-        }
-        catch (ParserConfigurationException pce) {}
-      }
-
-      DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
-      Document outNode = docBuilder.newDocument();
-
-      return outNode;
-    }
-    catch (ParserConfigurationException pce)
-    {
-      throw new RuntimeException(
-        XMLMessages.createXMLMessage(
-          XMLErrorResources.ER_CREATEDOCUMENT_NOT_SUPPORTED, null));  //"createDocument() not supported in XPathContext!");
-
-      // return null;
-    }
-  }
-
-  /**
-   * DOM Level 1 did not have a standard mechanism for creating a new
-   * Document object. This function provides a DOM-implementation-independent
-   * abstraction for that for that concept. It's typically used when
-   * outputting a new DOM as the result of an operation.
-   *
-   * @return The newly created DOM Document object, with no children, or
-   * null if we can't find a DOM implementation that permits creating
-   * new empty Documents.
-   */
-  public static Document createDocument()
-  {
-    return createDocument(false);
-  }
-
-  /**
-   * Tells, through the combination of the default-space attribute
-   * on xsl:stylesheet, xsl:strip-space, xsl:preserve-space, and the
-   * xml:space attribute, whether or not extra whitespace should be stripped
-   * from the node.  Literal elements from template elements should
-   * <em>not</em> be tested with this function.
-   * @param textNode A text node from the source tree.
-   * @return true if the text node should be stripped of extra whitespace.
-   *
-   * @throws javax.xml.transform.TransformerException
-   * @xsl.usage advanced
-   */
-  public boolean shouldStripSourceNode(Node textNode)
-          throws javax.xml.transform.TransformerException
-  {
-
-    // return (null == m_envSupport) ? false : m_envSupport.shouldStripSourceNode(textNode);
-    return false;
-  }
-
-  /**
-   * Supports the XPath function GenerateID by returning a unique
-   * identifier string for any given DOM Node.
-   * <p>
-   * Warning: The base implementation uses the Node object's hashCode(),
-   * which is NOT guaranteed to be unique. If that method hasn't been
-   * overridden in this DOM ipmlementation, most Java implementions will
-   * derive it from the object's address and should be OK... but if
-   * your DOM uses a different definition of hashCode (eg hashing the
-   * contents of the subtree), or if your DOM may have multiple objects
-   * that represent a single Node in the data structure (eg via proxying),
-   * you may need to find another way to assign a unique identifier.
-   * <p>
-   * Also, be aware that if nodes are destroyed and recreated, there is
-   * an open issue regarding whether an ID may be reused. Currently
-   * we're assuming that the input document is stable for the duration
-   * of the XPath/XSLT operation, so this shouldn't arise in this context.
-   * <p>
-   * (DOM Level 3 is investigating providing a unique node "key", but
-   * that won't help Level 1 and Level 2 implementations.)
-   *
-   * @param node whose identifier you want to obtain
-   *
-   * @return a string which should be different for every Node object.
-   */
-  public String getUniqueID(Node node)
-  {
-    return "N" + Integer.toHexString(node.hashCode()).toUpperCase();
-  }
-
-  /**
-   * Figure out whether node2 should be considered as being later
-   * in the document than node1, in Document Order as defined
-   * by the XPath model. This may not agree with the ordering defined
-   * by other XML applications.
-   * <p>
-   * There are some cases where ordering isn't defined, and neither are
-   * the results of this function -- though we'll generally return true.
-   *
-   * TODO: Make sure this does the right thing with attribute nodes!!!
-   *
-   * @param node1 DOM Node to perform position comparison on.
-   * @param node2 DOM Node to perform position comparison on .
-   *
-   * @return false if node2 comes before node1, otherwise return true.
-   * You can think of this as
-   * <code>(node1.documentOrderPosition &lt;= node2.documentOrderPosition)</code>.
-   */
-  public static boolean isNodeAfter(Node node1, Node node2)
-  {
-    if (node1 == node2 || isNodeTheSame(node1, node2))
-      return true;
-
-        // Default return value, if there is no defined ordering
-    boolean isNodeAfter = true;
-
-    Node parent1 = getParentOfNode(node1);
-    Node parent2 = getParentOfNode(node2);
-
-    // Optimize for most common case
-    if (parent1 == parent2 || isNodeTheSame(parent1, parent2))  // then we know they are siblings
-    {
-      if (null != parent1)
-        isNodeAfter = isNodeAfterSibling(parent1, node1, node2);
-      else
-      {
-                  // If both parents are null, ordering is not defined.
-                  // We're returning a value in lieu of throwing an exception.
-                  // Not a case we expect to arise in XPath, but beware if you
-                  // try to reuse this method.
-
-                  // We can just fall through in this case, which allows us
-                  // to hit the debugging code at the end of the function.
-          //return isNodeAfter;
-      }
-    }
-    else
-    {
-
-      // General strategy: Figure out the lengths of the two
-      // ancestor chains, reconcile the lengths, and look for
-          // the lowest common ancestor. If that ancestor is one of
-          // the nodes being compared, it comes before the other.
-      // Otherwise perform a sibling compare.
-                //
-                // NOTE: If no common ancestor is found, ordering is undefined
-                // and we return the default value of isNodeAfter.
-
-      // Count parents in each ancestor chain
-      int nParents1 = 2, nParents2 = 2;  // include node & parent obtained above
-
-      while (parent1 != null)
-      {
-        nParents1++;
-
-        parent1 = getParentOfNode(parent1);
-      }
-
-      while (parent2 != null)
-      {
-        nParents2++;
-
-        parent2 = getParentOfNode(parent2);
-      }
-
-          // Initially assume scan for common ancestor starts with
-          // the input nodes.
-      Node startNode1 = node1, startNode2 = node2;
-
-      // If one ancestor chain is longer, adjust its start point
-          // so we're comparing at the same depths
-      if (nParents1 < nParents2)
-      {
-        // Adjust startNode2 to depth of startNode1
-        int adjust = nParents2 - nParents1;
-
-        for (int i = 0; i < adjust; i++)
-        {
-          startNode2 = getParentOfNode(startNode2);
-        }
-      }
-      else if (nParents1 > nParents2)
-      {
-        // adjust startNode1 to depth of startNode2
-        int adjust = nParents1 - nParents2;
-
-        for (int i = 0; i < adjust; i++)
-        {
-          startNode1 = getParentOfNode(startNode1);
-        }
-      }
-
-      Node prevChild1 = null, prevChild2 = null;  // so we can "back up"
-
-      // Loop up the ancestor chain looking for common parent
-      while (null != startNode1)
-      {
-        if (startNode1 == startNode2 || isNodeTheSame(startNode1, startNode2))  // common parent?
-        {
-          if (null == prevChild1)  // first time in loop?
-          {
-
-            // Edge condition: one is the ancestor of the other.
-            isNodeAfter = (nParents1 < nParents2) ? true : false;
-
-            break;  // from while loop
-          }
-          else
-          {
-                        // Compare ancestors below lowest-common as siblings
-            isNodeAfter = isNodeAfterSibling(startNode1, prevChild1,
-                                             prevChild2);
-
-            break;  // from while loop
-          }
-        }  // end if(startNode1 == startNode2)
-
-                // Move up one level and try again
-        prevChild1 = startNode1;
-        startNode1 = getParentOfNode(startNode1);
-        prevChild2 = startNode2;
-        startNode2 = getParentOfNode(startNode2);
-      }  // end while(parents exist to examine)
-    }  // end big else (not immediate siblings)
-
-        // WARNING: The following diagnostic won't report the early
-        // "same node" case. Fix if/when needed.
-
-    /* -- please do not remove... very useful for diagnostics --
-    System.out.println("node1 = "+node1.getNodeName()+"("+node1.getNodeType()+")"+
-    ", node2 = "+node2.getNodeName()
-    +"("+node2.getNodeType()+")"+
-    ", isNodeAfter = "+isNodeAfter); */
-    return isNodeAfter;
-  }  // end isNodeAfter(Node node1, Node node2)
-
-  /**
-   * Use DTMNodeProxy to determine whether two nodes are the same.
-   *
-   * @param node1 The first DOM node to compare.
-   * @param node2 The second DOM node to compare.
-   * @return true if the two nodes are the same.
-   */
-  public static boolean isNodeTheSame(Node node1, Node node2)
-  {
-    if (node1 instanceof DTMNodeProxy && node2 instanceof DTMNodeProxy)
-      return ((DTMNodeProxy)node1).equals((DTMNodeProxy)node2);
-    else
-      return (node1 == node2);
-  }
-
-  /**
-   * Figure out if child2 is after child1 in document order.
-   * <p>
-   * Warning: Some aspects of "document order" are not well defined.
-   * For example, the order of attributes is considered
-   * meaningless in XML, and the order reported by our model will
-   * be consistant for a given invocation but may not
-   * match that of either the source file or the serialized output.
-   *
-   * @param parent Must be the parent of both child1 and child2.
-   * @param child1 Must be the child of parent and not equal to child2.
-   * @param child2 Must be the child of parent and not equal to child1.
-   * @return true if child 2 is after child1 in document order.
-   */
-  private static boolean isNodeAfterSibling(Node parent, Node child1,
-                                            Node child2)
-  {
-
-    boolean isNodeAfterSibling = false;
-    short child1type = child1.getNodeType();
-    short child2type = child2.getNodeType();
-
-    if ((Node.ATTRIBUTE_NODE != child1type)
-            && (Node.ATTRIBUTE_NODE == child2type))
-    {
-
-      // always sort attributes before non-attributes.
-      isNodeAfterSibling = false;
-    }
-    else if ((Node.ATTRIBUTE_NODE == child1type)
-             && (Node.ATTRIBUTE_NODE != child2type))
-    {
-
-      // always sort attributes before non-attributes.
-      isNodeAfterSibling = true;
-    }
-    else if (Node.ATTRIBUTE_NODE == child1type)
-    {
-      NamedNodeMap children = parent.getAttributes();
-      int nNodes = children.getLength();
-      boolean found1 = false, found2 = false;
-
-          // Count from the start until we find one or the other.
-      for (int i = 0; i < nNodes; i++)
-      {
-        Node child = children.item(i);
-
-        if (child1 == child || isNodeTheSame(child1, child))
-        {
-          if (found2)
-          {
-            isNodeAfterSibling = false;
-
-            break;
-          }
-
-          found1 = true;
-        }
-        else if (child2 == child || isNodeTheSame(child2, child))
-        {
-          if (found1)
-          {
-            isNodeAfterSibling = true;
-
-            break;
-          }
-
-          found2 = true;
-        }
-      }
-    }
-    else
-    {
-                // TODO: Check performance of alternate solution:
-                // There are two choices here: Count from the start of
-                // the document until we find one or the other, or count
-                // from one until we find or fail to find the other.
-                // Either can wind up scanning all the siblings in the worst
-                // case, which on a wide document can be a lot of work but
-                // is more typically is a short list.
-                // Scanning from the start involves two tests per iteration,
-                // but it isn't clear that scanning from the middle doesn't
-                // yield more iterations on average.
-                // We should run some testcases.
-      Node child = parent.getFirstChild();
-      boolean found1 = false, found2 = false;
-
-      while (null != child)
-      {
-
-        // Node child = children.item(i);
-        if (child1 == child || isNodeTheSame(child1, child))
-        {
-          if (found2)
-          {
-            isNodeAfterSibling = false;
-
-            break;
-          }
-
-          found1 = true;
-        }
-        else if (child2 == child || isNodeTheSame(child2, child))
-        {
-          if (found1)
-          {
-            isNodeAfterSibling = true;
-
-            break;
-          }
-
-          found2 = true;
-        }
-
-        child = child.getNextSibling();
-      }
-    }
-
-    return isNodeAfterSibling;
-  }  // end isNodeAfterSibling(Node parent, Node child1, Node child2)
-
-  //==========================================================
-  // SECTION: Namespace resolution
-  //==========================================================
-
-  /**
-   * Get the depth level of this node in the tree (equals 1 for
-   * a parentless node).
-   *
-   * @param n Node to be examined.
-   * @return the number of ancestors, plus one
-   * @xsl.usage internal
-   */
-  public short getLevel(Node n)
-  {
-
-    short level = 1;
-
-    while (null != (n = getParentOfNode(n)))
-    {
-      level++;
-    }
-
-    return level;
-  }
-
-  /**
-   * Given an XML Namespace prefix and a context in which the prefix
-   * is to be evaluated, return the Namespace Name this prefix was
-   * bound to. Note that DOM Level 3 is expected to provide a version of
-   * this which deals with the DOM's "early binding" behavior.
-   *
-   * Default handling:
-   *
-   * @param prefix String containing namespace prefix to be resolved,
-   * without the ':' which separates it from the localname when used
-   * in a Node Name. The empty sting signifies the default namespace
-   * at this point in the document.
-   * @param namespaceContext Element which provides context for resolution.
-   * (We could extend this to work for other nodes by first seeking their
-   * nearest Element ancestor.)
-   *
-   * @return a String containing the Namespace URI which this prefix
-   * represents in the specified context.
-   */
-  public String getNamespaceForPrefix(String prefix, Element namespaceContext)
-  {
-
-    int type;
-    Node parent = namespaceContext;
-    String namespace = null;
-
-    if (prefix.equals("xml"))
-    {
-      namespace = QName.S_XMLNAMESPACEURI; // Hardcoded, per Namespace spec
-    }
-        else if(prefix.equals("xmlns"))
-    {
-          // Hardcoded in the DOM spec, expected to be adopted by
-          // Namespace spec. NOTE: Namespace declarations _must_ use
-          // the xmlns: prefix; other prefixes declared as belonging
-          // to this namespace will not be recognized and should
-          // probably be rejected by parsers as erroneous declarations.
-      namespace = "http://www.w3.org/2000/xmlns/";
-    }
-    else
-    {
-          // Attribute name for this prefix's declaration
-          String declname=(prefix=="")
-                        ? "xmlns"
-                        : "xmlns:"+prefix;
-
-          // Scan until we run out of Elements or have resolved the namespace
-      while ((null != parent) && (null == namespace)
-             && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
-                 || (type == Node.ENTITY_REFERENCE_NODE)))
-      {
-        if (type == Node.ELEMENT_NODE)
-        {
-
-                        // Look for the appropriate Namespace Declaration attribute,
-                        // either "xmlns:prefix" or (if prefix is "") "xmlns".
-                        // TODO: This does not handle "implicit declarations"
-                        // which may be created when the DOM is edited. DOM Level
-                        // 3 will define how those should be interpreted. But
-                        // this issue won't arise in freshly-parsed DOMs.
-
-                // NOTE: declname is set earlier, outside the loop.
-                        Attr attr=((Element)parent).getAttributeNode(declname);
-                        if(attr!=null)
-                        {
-                namespace = attr.getNodeValue();
-                break;
-                        }
-                }
-
-        parent = getParentOfNode(parent);
-      }
-    }
-
-    return namespace;
-  }
-
-  /**
-   * An experiment for the moment.
-   */
-  Map<Node, NSInfo> m_NSInfos = new HashMap<Node, NSInfo>();
-
-  /** Object to put into the m_NSInfos table that tells that a node has not been
-   *  processed, but has xmlns namespace decls.  */
-  protected static final NSInfo m_NSInfoUnProcWithXMLNS = new NSInfo(false,
-                                                            true);
-
-  /** Object to put into the m_NSInfos table that tells that a node has not been
-   *  processed, but has no xmlns namespace decls.  */
-  protected static final NSInfo m_NSInfoUnProcWithoutXMLNS = new NSInfo(false,
-                                                               false);
-
-  /** Object to put into the m_NSInfos table that tells that a node has not been
-   *  processed, and has no xmlns namespace decls, and has no ancestor decls.  */
-  protected static final NSInfo m_NSInfoUnProcNoAncestorXMLNS =
-    new NSInfo(false, false, NSInfo.ANCESTORNOXMLNS);
-
-  /** Object to put into the m_NSInfos table that tells that a node has been
-   *  processed, and has xmlns namespace decls.  */
-  protected static final NSInfo m_NSInfoNullWithXMLNS = new NSInfo(true,
-                                                          true);
-
-  /** Object to put into the m_NSInfos table that tells that a node has been
-   *  processed, and has no xmlns namespace decls.  */
-  protected static final NSInfo m_NSInfoNullWithoutXMLNS = new NSInfo(true,
-                                                             false);
-
-  /** Object to put into the m_NSInfos table that tells that a node has been
-   *  processed, and has no xmlns namespace decls. and has no ancestor decls.  */
-  protected static final NSInfo m_NSInfoNullNoAncestorXMLNS =
-    new NSInfo(true, false, NSInfo.ANCESTORNOXMLNS);
-
-  /** Vector of node (odd indexes) and NSInfos (even indexes) that tell if
-   *  the given node is a candidate for ancestor namespace processing.  */
-  protected Vector m_candidateNoAncestorXMLNS = new Vector();
-
-  /**
-   * Returns the namespace of the given node. Differs from simply getting
-   * the node's prefix and using getNamespaceForPrefix in that it attempts
-   * to cache some of the data in NSINFO objects, to avoid repeated lookup.
-   * TODO: Should we consider moving that logic into getNamespaceForPrefix?
-   *
-   * @param n Node to be examined.
-   *
-   * @return String containing the Namespace Name (uri) for this node.
-   * Note that this is undefined for any nodes other than Elements and
-   * Attributes.
-   */
-  public String getNamespaceOfNode(Node n)
-  {
-
-    String namespaceOfPrefix;
-    boolean hasProcessedNS;
-    NSInfo nsInfo;
-    short ntype = n.getNodeType();
-
-    if (Node.ATTRIBUTE_NODE != ntype)
-    {
-      nsInfo = m_NSInfos.get(n);
-      hasProcessedNS = (nsInfo == null) ? false : nsInfo.m_hasProcessedNS;
-    }
-    else
-    {
-      hasProcessedNS = false;
-      nsInfo = null;
-    }
-
-    if (hasProcessedNS)
-    {
-      namespaceOfPrefix = nsInfo.m_namespace;
-    }
-    else
-    {
-      namespaceOfPrefix = null;
-
-      String nodeName = n.getNodeName();
-      int indexOfNSSep = nodeName.indexOf(':');
-      String prefix;
-
-      if (Node.ATTRIBUTE_NODE == ntype)
-      {
-        if (indexOfNSSep > 0)
-        {
-          prefix = nodeName.substring(0, indexOfNSSep);
-        }
-        else
-        {
-
-          // Attributes don't use the default namespace, so if
-          // there isn't a prefix, we're done.
-          return namespaceOfPrefix;
-        }
-      }
-      else
-      {
-        prefix = (indexOfNSSep >= 0)
-                 ? nodeName.substring(0, indexOfNSSep) : "";
-      }
-
-      boolean ancestorsHaveXMLNS = false;
-      boolean nHasXMLNS = false;
-
-      if (prefix.equals("xml"))
-      {
-        namespaceOfPrefix = QName.S_XMLNAMESPACEURI;
-      }
-      else
-      {
-        int parentType;
-        Node parent = n;
-
-        while ((null != parent) && (null == namespaceOfPrefix))
-        {
-          if ((null != nsInfo)
-                  && (nsInfo.m_ancestorHasXMLNSAttrs
-                      == NSInfo.ANCESTORNOXMLNS))
-          {
-            break;
-          }
-
-          parentType = parent.getNodeType();
-
-          if ((null == nsInfo) || nsInfo.m_hasXMLNSAttrs)
-          {
-            boolean elementHasXMLNS = false;
-
-            if (parentType == Node.ELEMENT_NODE)
-            {
-              NamedNodeMap nnm = parent.getAttributes();
-
-              for (int i = 0; i < nnm.getLength(); i++)
-              {
-                Node attr = nnm.item(i);
-                String aname = attr.getNodeName();
-
-                if (aname.charAt(0) == 'x')
-                {
-                  boolean isPrefix = aname.startsWith("xmlns:");
-
-                  if (aname.equals("xmlns") || isPrefix)
-                  {
-                    if (n == parent)
-                      nHasXMLNS = true;
-
-                    elementHasXMLNS = true;
-                    ancestorsHaveXMLNS = true;
-
-                    String p = isPrefix ? aname.substring(6) : "";
-
-                    if (p.equals(prefix))
-                    {
-                      namespaceOfPrefix = attr.getNodeValue();
-
-                      break;
-                    }
-                  }
-                }
-              }
-            }
-
-            if ((Node.ATTRIBUTE_NODE != parentType) && (null == nsInfo)
-                    && (n != parent))
-            {
-              nsInfo = elementHasXMLNS
-                       ? m_NSInfoUnProcWithXMLNS : m_NSInfoUnProcWithoutXMLNS;
-
-              m_NSInfos.put(parent, nsInfo);
-            }
-          }
-
-          if (Node.ATTRIBUTE_NODE == parentType)
-          {
-            parent = getParentOfNode(parent);
-          }
-          else
-          {
-            m_candidateNoAncestorXMLNS.addElement(parent);
-            m_candidateNoAncestorXMLNS.addElement(nsInfo);
-
-            parent = parent.getParentNode();
-          }
-
-          if (null != parent)
-          {
-            nsInfo = m_NSInfos.get(parent);
-          }
-        }
-
-        int nCandidates = m_candidateNoAncestorXMLNS.size();
-
-        if (nCandidates > 0)
-        {
-          if ((false == ancestorsHaveXMLNS) && (null == parent))
-          {
-            for (int i = 0; i < nCandidates; i += 2)
-            {
-              Object candidateInfo = m_candidateNoAncestorXMLNS.elementAt(i
-                                       + 1);
-
-              if (candidateInfo == m_NSInfoUnProcWithoutXMLNS)
-              {
-                m_NSInfos.put((Node)m_candidateNoAncestorXMLNS.elementAt(i),
-                              m_NSInfoUnProcNoAncestorXMLNS);
-              }
-              else if (candidateInfo == m_NSInfoNullWithoutXMLNS)
-              {
-                m_NSInfos.put((Node)m_candidateNoAncestorXMLNS.elementAt(i),
-                              m_NSInfoNullNoAncestorXMLNS);
-              }
-            }
-          }
-
-          m_candidateNoAncestorXMLNS.removeAllElements();
-        }
-      }
-
-      if (Node.ATTRIBUTE_NODE != ntype)
-      {
-        if (null == namespaceOfPrefix)
-        {
-          if (ancestorsHaveXMLNS)
-          {
-            if (nHasXMLNS)
-              m_NSInfos.put(n, m_NSInfoNullWithXMLNS);
-            else
-              m_NSInfos.put(n, m_NSInfoNullWithoutXMLNS);
-          }
-          else
-          {
-            m_NSInfos.put(n, m_NSInfoNullNoAncestorXMLNS);
-          }
-        }
-        else
-        {
-          m_NSInfos.put(n, new NSInfo(namespaceOfPrefix, nHasXMLNS));
-        }
-      }
-    }
-
-    return namespaceOfPrefix;
-  }
-
-  /**
-   * Returns the local name of the given node. If the node's name begins
-   * with a namespace prefix, this is the part after the colon; otherwise
-   * it's the full node name.
-   *
-   * @param n the node to be examined.
-   *
-   * @return String containing the Local Name
-   */
-  public String getLocalNameOfNode(Node n)
-  {
-
-    String qname = n.getNodeName();
-    int index = qname.indexOf(':');
-
-    return (index < 0) ? qname : qname.substring(index + 1);
-  }
-
-  /**
-   * Returns the element name with the namespace prefix (if any) replaced
-   * by the Namespace URI it was bound to. This is not a standard
-   * representation of a node name, but it allows convenient
-   * single-string comparison of the "universal" names of two nodes.
-   *
-   * @param elem Element to be examined.
-   *
-   * @return String in the form "namespaceURI:localname" if the node
-   * belongs to a namespace, or simply "localname" if it doesn't.
-   * @see #getExpandedAttributeName
-   */
-  public String getExpandedElementName(Element elem)
-  {
-
-    String namespace = getNamespaceOfNode(elem);
-
-    return (null != namespace)
-           ? namespace + ":" + getLocalNameOfNode(elem)
-           : getLocalNameOfNode(elem);
-  }
-
-  /**
-   * Returns the attribute name with the namespace prefix (if any) replaced
-   * by the Namespace URI it was bound to. This is not a standard
-   * representation of a node name, but it allows convenient
-   * single-string comparison of the "universal" names of two nodes.
-   *
-   * @param attr Attr to be examined
-   *
-   * @return String in the form "namespaceURI:localname" if the node
-   * belongs to a namespace, or simply "localname" if it doesn't.
-   * @see #getExpandedElementName
-   */
-  public String getExpandedAttributeName(Attr attr)
-  {
-
-    String namespace = getNamespaceOfNode(attr);
-
-    return (null != namespace)
-           ? namespace + ":" + getLocalNameOfNode(attr)
-           : getLocalNameOfNode(attr);
-  }
-
-  //==========================================================
-  // SECTION: DOM Helper Functions
-  //==========================================================
-
-  /**
-   * Tell if the node is ignorable whitespace. Note that this can
-   * be determined only in the context of a DTD or other Schema,
-   * and that DOM Level 2 has nostandardized DOM API which can
-   * return that information.
-   * @deprecated
-   *
-   * @param node Node to be examined
-   *
-   * @return CURRENTLY HARDCODED TO FALSE, but should return true if
-   * and only if the node is of type Text, contains only whitespace,
-   * and does not appear as part of the #PCDATA content of an element.
-   * (Note that determining this last may require allowing for
-   * Entity References.)
-   */
-  public boolean isIgnorableWhitespace(Text node)
-  {
-
-    boolean isIgnorable = false;  // return value
-
-    // TODO: I can probably do something to figure out if this
-    // space is ignorable from just the information in
-    // the DOM tree.
-        // -- You need to be able to distinguish whitespace
-        // that is #PCDATA from whitespace that isn't.  That requires
-        // DTD support, which won't be standardized until DOM Level 3.
-    return isIgnorable;
-  }
-
-  /**
-   * Get the first unparented node in the ancestor chain.
-   * @deprecated
-   *
-   * @param node Starting node, to specify which chain to chase
-   *
-   * @return the topmost ancestor.
-   */
-  public Node getRoot(Node node)
-  {
-
-    Node root = null;
-
-    while (node != null)
-    {
-      root = node;
-      node = getParentOfNode(node);
-    }
-
-    return root;
-  }
-
-  /**
-   * Get the root node of the document tree, regardless of
-   * whether or not the node passed in is a document node.
-   * <p>
-   * TODO: This doesn't handle DocumentFragments or "orphaned" subtrees
-   * -- it's currently returning ownerDocument even when the tree is
-   * not actually part of the main Document tree. We should either
-   * rewrite the description to say that it finds the Document node,
-   * or change the code to walk up the ancestor chain.
-
-   *
-   * @param n Node to be examined
-   *
-   * @return the Document node. Note that this is not the correct answer
-   * if n was (or was a child of) a DocumentFragment or an orphaned node,
-   * as can arise if the DOM has been edited rather than being generated
-   * by a parser.
-   */
-  public Node getRootNode(Node n)
-  {
-    int nt = n.getNodeType();
-    return ( (Node.DOCUMENT_NODE == nt) || (Node.DOCUMENT_FRAGMENT_NODE == nt) )
-           ? n : n.getOwnerDocument();
-  }
-
-  /**
-   * Test whether the given node is a namespace decl node. In DOM Level 2
-   * this can be done in a namespace-aware manner, but in Level 1 DOMs
-   * it has to be done by testing the node name.
-   *
-   * @param n Node to be examined.
-   *
-   * @return boolean -- true iff the node is an Attr whose name is
-   * "xmlns" or has the "xmlns:" prefix.
-   */
-  public boolean isNamespaceNode(Node n)
-  {
-
-    if (Node.ATTRIBUTE_NODE == n.getNodeType())
-    {
-      String attrName = n.getNodeName();
-
-      return (attrName.startsWith("xmlns:") || attrName.equals("xmlns"));
-    }
-
-    return false;
-  }
-
-  /**
-   * Obtain the XPath-model parent of a DOM node -- ownerElement for Attrs,
-   * parent for other nodes.
-   * <p>
-   * Background: The DOM believes that you must be your Parent's
-   * Child, and thus Attrs don't have parents. XPath said that Attrs
-   * do have their owning Element as their parent. This function
-   * bridges the difference, either by using the DOM Level 2 ownerElement
-   * function or by using a "silly and expensive function" in Level 1
-   * DOMs.
-   * <p>
-   * (There's some discussion of future DOMs generalizing ownerElement
-   * into ownerNode and making it work on all types of nodes. This
-   * still wouldn't help the users of Level 1 or Level 2 DOMs)
-   * <p>
-   *
-   * @param node Node whose XPath parent we want to obtain
-   *
-   * @return the parent of the node, or the ownerElement if it's an
-   * Attr node, or null if the node is an orphan.
-   *
-   * @throws RuntimeException if the Document has no root element.
-   * This can't arise if the Document was created
-   * via the DOM Level 2 factory methods, but is possible if other
-   * mechanisms were used to obtain it
-   */
-  public static Node getParentOfNode(Node node) throws RuntimeException
-  {
-    Node parent;
-    short nodeType = node.getNodeType();
-
-    if (Node.ATTRIBUTE_NODE == nodeType)
-    {
-      Document doc = node.getOwnerDocument();
-          /*
-      TBD:
-      if(null == doc)
-      {
-        throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CHILD_HAS_NO_OWNER_DOCUMENT, null));//"Attribute child does not have an owner document!");
-      }
-      */
-
-          // Given how expensive the tree walk may be, we should first ask
-          // whether this DOM can answer the question for us. The additional
-          // test does slow down Level 1 DOMs slightly. DOMHelper2, which
-          // is currently specialized for Xerces, assumes it can use the
-          // Level 2 solution. We might want to have an intermediate stage,
-          // which would assume DOM Level 2 but not assume Xerces.
-          //
-          // (Shouldn't have to check whether impl is null in a compliant DOM,
-          // but let's be paranoid for a moment...)
-          DOMImplementation impl=doc.getImplementation();
-          if(impl!=null && impl.hasFeature("Core","2.0"))
-          {
-                  parent=((Attr)node).getOwnerElement();
-                  return parent;
-          }
-
-          // DOM Level 1 solution, as fallback. Hugely expensive.
-
-      Element rootElem = doc.getDocumentElement();
-
-      if (null == rootElem)
-      {
-        throw new RuntimeException(
-          XMLMessages.createXMLMessage(
-            XMLErrorResources.ER_CHILD_HAS_NO_OWNER_DOCUMENT_ELEMENT,
-            null));  //"Attribute child does not have an owner document element!");
-      }
-
-      parent = locateAttrParent(rootElem, node);
-
-        }
-    else
-    {
-      parent = node.getParentNode();
-
-      // if((Node.DOCUMENT_NODE != nodeType) && (null == parent))
-      // {
-      //   throw new RuntimeException("Child does not have parent!");
-      // }
-    }
-
-    return parent;
-  }
-
-  /**
-   * Given an ID, return the element. This can work only if the document
-   * is interpreted in the context of a DTD or Schema, since otherwise
-   * we don't know which attributes are or aren't IDs.
-   * <p>
-   * Note that DOM Level 1 had no ability to retrieve this information.
-   * DOM Level 2 introduced it but does not promise that it will be
-   * supported in all DOMs; those which can't support it will always
-   * return null.
-   * <p>
-   * TODO: getElementByID is currently unimplemented. Support DOM Level 2?
-   *
-   * @param id The unique identifier to be searched for.
-   * @param doc The document to search within.
-   * @return CURRENTLY HARDCODED TO NULL, but it should be:
-   * The node which has this unique identifier, or null if there
-   * is no such node or this DOM can't reliably recognize it.
-   */
-  public Element getElementByID(String id, Document doc)
-  {
-    return null;
-  }
-
-  /**
-   * The getUnparsedEntityURI function returns the URI of the unparsed
-   * entity with the specified name in the same document as the context
-   * node (see [3.3 Unparsed Entities]). It returns the empty string if
-   * there is no such entity.
-   * <p>
-   * XML processors may choose to use the System Identifier (if one
-   * is provided) to resolve the entity, rather than the URI in the
-   * Public Identifier. The details are dependent on the processor, and
-   * we would have to support some form of plug-in resolver to handle
-   * this properly. Currently, we simply return the System Identifier if
-   * present, and hope that it a usable URI or that our caller can
-   * map it to one.
-   * TODO: Resolve Public Identifiers... or consider changing function name.
-   * <p>
-   * If we find a relative URI
-   * reference, XML expects it to be resolved in terms of the base URI
-   * of the document. The DOM doesn't do that for us, and it isn't
-   * entirely clear whether that should be done here; currently that's
-   * pushed up to a higher levelof our application. (Note that DOM Level
-   * 1 didn't store the document's base URI.)
-   * TODO: Consider resolving Relative URIs.
-   * <p>
-   * (The DOM's statement that "An XML processor may choose to
-   * completely expand entities before the structure model is passed
-   * to the DOM" refers only to parsed entities, not unparsed, and hence
-   * doesn't affect this function.)
-   *
-   * @param name A string containing the Entity Name of the unparsed
-   * entity.
-   * @param doc Document node for the document to be searched.
-   *
-   * @return String containing the URI of the Unparsed Entity, or an
-   * empty string if no such entity exists.
-   */
-  public String getUnparsedEntityURI(String name, Document doc)
-  {
-
-    String url = "";
-    DocumentType doctype = doc.getDoctype();
-
-    if (null != doctype)
-    {
-      NamedNodeMap entities = doctype.getEntities();
-      if(null == entities)
-        return url;
-      Entity entity = (Entity) entities.getNamedItem(name);
-      if(null == entity)
-        return url;
-
-      String notationName = entity.getNotationName();
-
-      if (null != notationName)  // then it's unparsed
-      {
-        // The draft says: "The XSLT processor may use the public
-        // identifier to generate a URI for the entity instead of the URI
-        // specified in the system identifier. If the XSLT processor does
-        // not use the public identifier to generate the URI, it must use
-        // the system identifier; if the system identifier is a relative
-        // URI, it must be resolved into an absolute URI using the URI of
-        // the resource containing the entity declaration as the base
-        // URI [RFC2396]."
-        // So I'm falling a bit short here.
-        url = entity.getSystemId();
-
-        if (null == url)
-        {
-          url = entity.getPublicId();
-        }
-        else
-        {
-          // This should be resolved to an absolute URL, but that's hard
-          // to do from here.
-        }
-      }
-    }
-
-    return url;
-  }
-
-  /**
-   * Support for getParentOfNode; walks a DOM tree until it finds
-   * the Element which owns the Attr. This is hugely expensive, and
-   * if at all possible you should use the DOM Level 2 Attr.ownerElement()
-   * method instead.
-   *  <p>
-   * The DOM Level 1 developers expected that folks would keep track
-   * of the last Element they'd seen and could recover the info from
-   * that source. Obviously that doesn't work very well if the only
-   * information you've been presented with is the Attr. The DOM Level 2
-   * getOwnerElement() method fixes that, but only for Level 2 and
-   * later DOMs.
-   *
-   * @param elem Element whose subtree is to be searched for this Attr
-   * @param attr Attr whose owner is to be located.
-   *
-   * @return the first Element whose attribute list includes the provided
-   * attr. In modern DOMs, this will also be the only such Element. (Early
-   * DOMs had some hope that Attrs might be sharable, but this idea has
-   * been abandoned.)
-   */
-  private static Node locateAttrParent(Element elem, Node attr)
-  {
-
-    Node parent = null;
-
-        // This should only be called for Level 1 DOMs, so we don't have to
-        // worry about namespace issues. In later levels, it's possible
-        // for a DOM to have two Attrs with the same NodeName but
-        // different namespaces, and we'd need to get getAttributeNodeNS...
-        // but later levels also have Attr.getOwnerElement.
-        Attr check=elem.getAttributeNode(attr.getNodeName());
-        if(check==attr)
-                parent = elem;
-
-    if (null == parent)
-    {
-      for (Node node = elem.getFirstChild(); null != node;
-              node = node.getNextSibling())
-      {
-        if (Node.ELEMENT_NODE == node.getNodeType())
-        {
-          parent = locateAttrParent((Element) node, attr);
-
-          if (null != parent)
-            break;
-        }
-      }
-    }
-
-    return parent;
-  }
-
-  /**
-   * The factory object used for creating nodes
-   * in the result tree.
-   */
-  protected Document m_DOMFactory = null;
-
-  /**
-   * Store the factory object required to create DOM nodes
-   * in the result tree. In fact, that's just the result tree's
-   * Document node...
-   *
-   * @param domFactory The DOM Document Node within whose context
-   * the result tree will be built.
-   */
-  public void setDOMFactory(Document domFactory)
-  {
-    this.m_DOMFactory = domFactory;
-  }
-
-  /**
-   * Retrieve the factory object required to create DOM nodes
-   * in the result tree.
-   *
-   * @return The result tree's DOM Document Node.
-   */
-  public Document getDOMFactory()
-  {
-
-    if (null == this.m_DOMFactory)
-    {
-      this.m_DOMFactory = createDocument();
-    }
-
-    return this.m_DOMFactory;
-  }
-
-  /**
-   * Get the textual contents of the node. See
-   * getNodeData(Node,FastStringBuffer) for discussion of how
-   * whitespace nodes are handled.
-   *
-   * @param node DOM Node to be examined
-   * @return String containing a concatenation of all the
-   * textual content within that node.
-   * @see #getNodeData(Node,FastStringBuffer)
-   *
-   */
-  public static String getNodeData(Node node)
-  {
-
-    FastStringBuffer buf = StringBufferPool.get();
-    String s;
-
-    try
-    {
-      getNodeData(node, buf);
-
-      s = (buf.length() > 0) ? buf.toString() : "";
-    }
-    finally
-    {
-      StringBufferPool.free(buf);
-    }
-
-    return s;
-  }
-
-  /**
-   * Retrieve the text content of a DOM subtree, appending it into a
-   * user-supplied FastStringBuffer object. Note that attributes are
-   * not considered part of the content of an element.
-   * <p>
-   * There are open questions regarding whitespace stripping.
-   * Currently we make no special effort in that regard, since the standard
-   * DOM doesn't yet provide DTD-based information to distinguish
-   * whitespace-in-element-context from genuine #PCDATA. Note that we
-   * should probably also consider xml:space if/when we address this.
-   * DOM Level 3 may solve the problem for us.
-   *
-   * @param node Node whose subtree is to be walked, gathering the
-   * contents of all Text or CDATASection nodes.
-   * @param buf FastStringBuffer into which the contents of the text
-   * nodes are to be concatenated.
-   */
-  public static void getNodeData(Node node, FastStringBuffer buf)
-  {
-
-    switch (node.getNodeType())
-    {
-    case Node.DOCUMENT_FRAGMENT_NODE :
-    case Node.DOCUMENT_NODE :
-    case Node.ELEMENT_NODE :
-    {
-      for (Node child = node.getFirstChild(); null != child;
-              child = child.getNextSibling())
-      {
-        getNodeData(child, buf);
-      }
-    }
-    break;
-    case Node.TEXT_NODE :
-    case Node.CDATA_SECTION_NODE :
-      buf.append(node.getNodeValue());
-      break;
-    case Node.ATTRIBUTE_NODE :
-      buf.append(node.getNodeValue());
-      break;
-    case Node.PROCESSING_INSTRUCTION_NODE :
-      // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
-      break;
-    default :
-      // ignore
-      break;
-    }
-  }
-}
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/DOMOrder.java	Fri Feb 05 14:40:11 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * $Id: DOMOrder.java,v 1.2.4.1 2005/09/15 08:15:41 suresh_emailid Exp $
- */
-package com.sun.org.apache.xml.internal.utils;
-
-/**
- * @deprecated Since the introduction of the DTM, this class will be removed.
- * Nodes that implement this index can return a document order index.
- * Eventually, this will be replaced by DOM 3 methods.
- * (compareDocumentOrder and/or compareTreePosition.)
- */
-public interface DOMOrder
-{
-
-  /**
-   * Get the UID (document order index).
-   *
-   * @return integer whose relative value corresponds to document order
-   * -- that is, if node1.getUid()<node2.getUid(), node1 comes before
-   * node2, and if they're equal node1 and node2 are the same node. No
-   * promises are made beyond that.
-   */
-  public int getUid();
-}
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/TreeWalker.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/TreeWalker.java	Thu Oct 19 17:03:20 2017 +0100
@@ -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.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -20,9 +20,8 @@
 
 package com.sun.org.apache.xml.internal.utils;
 
-import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
-import java.io.File;
-
+import com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler;
+import javax.xml.transform.Result;
 import org.w3c.dom.Comment;
 import org.w3c.dom.Element;
 import org.w3c.dom.EntityReference;
@@ -48,14 +47,8 @@
   /** Local reference to a ContentHandler          */
   private ContentHandler m_contentHandler = null;
 
-  // ARGHH!!  JAXP Uses Xerces without setting the namespace processing to ON!
-  // DOM2Helper m_dh = new DOM2Helper();
-
-  /** DomHelper for this TreeWalker          */
-  protected DOMHelper m_dh;
-
-        /** Locator object for this TreeWalker          */
-        private LocatorImpl m_locator = new LocatorImpl();
+   /** Locator object for this TreeWalker          */
+   private LocatorImpl m_locator = new LocatorImpl();
 
   /**
    * Get the ContentHandler used for the tree walk.
@@ -77,32 +70,21 @@
     m_contentHandler = ch;
   }
 
-        /**
+  /**
    * Constructor.
    * @param   contentHandler The implementation of the
    * @param   systemId System identifier for the document.
    * contentHandler operation (toXMLString, digest, ...)
    */
-  public TreeWalker(ContentHandler contentHandler, DOMHelper dh, String systemId)
+  public TreeWalker(ContentHandler contentHandler, String systemId)
   {
     this.m_contentHandler = contentHandler;
-    m_contentHandler.setDocumentLocator(m_locator);
+    if (m_contentHandler != null) {
+        m_contentHandler.setDocumentLocator(m_locator);
+    }
     if (systemId != null) {
         m_locator.setSystemId(systemId);
     }
-    m_dh = dh;
-  }
-
-  /**
-   * Constructor.
-   * @param   contentHandler The implemention of the
-   * contentHandler operation (toXMLString, digest, ...)
-   */
-  public TreeWalker(ContentHandler contentHandler, DOMHelper dh)
-  {
-    this.m_contentHandler = contentHandler;
-    m_contentHandler.setDocumentLocator(m_locator);
-    m_dh = dh;
   }
 
   /**
@@ -112,11 +94,7 @@
    */
   public TreeWalker(ContentHandler contentHandler)
   {
-    this.m_contentHandler = contentHandler;
-    if (m_contentHandler != null) {
-        m_contentHandler.setDocumentLocator(m_locator);
-    }
-    m_dh = new DOM2Helper();
+      this(contentHandler, null);
   }
 
   /**
@@ -225,7 +203,7 @@
     this.m_contentHandler.endDocument();
   }
 
-  /** Flag indicating whether following text to be processed is raw text          */
+  // Flag indicating whether following text to be processed is raw text
   boolean nextIsRaw = false;
 
   /**
@@ -234,9 +212,9 @@
   private final void dispatachChars(Node node)
      throws org.xml.sax.SAXException
   {
-    if(m_contentHandler instanceof com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler)
+    if(m_contentHandler instanceof CharacterNodeHandler)
     {
-      ((com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.CharacterNodeHandler)m_contentHandler).characters(node);
+      ((CharacterNodeHandler)m_contentHandler).characters(node);
     }
     else
     {
@@ -299,17 +277,14 @@
     case Node.ELEMENT_NODE :
       NamedNodeMap atts = ((Element) node).getAttributes();
       int nAttrs = atts.getLength();
-      // System.out.println("TreeWalker#startNode: "+node.getNodeName());
 
       for (int i = 0; i < nAttrs; i++)
       {
         Node attr = atts.item(i);
         String attrName = attr.getNodeName();
 
-        // System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue());
         if (attrName.equals("xmlns") || attrName.startsWith("xmlns:"))
         {
-          // System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue());
           int index;
           // Use "" instead of null, as Xerces likes "" for the
           // name of the default namespace.  Fix attributed
@@ -323,15 +298,13 @@
 
       }
 
-      // System.out.println("m_dh.getNamespaceOfNode(node): "+m_dh.getNamespaceOfNode(node));
-      // System.out.println("m_dh.getLocalNameOfNode(node): "+m_dh.getLocalNameOfNode(node));
-      String ns = m_dh.getNamespaceOfNode(node);
+      String ns = DOM2Helper.getNamespaceOfNode(node);
       if(null == ns)
         ns = "";
       this.m_contentHandler.startElement(ns,
-                                         m_dh.getLocalNameOfNode(node),
+                                         DOM2Helper.getLocalNameOfNode(node),
                                          node.getNodeName(),
-                                         new AttList(atts, m_dh));
+                                         new AttList(atts));
       break;
     case Node.PROCESSING_INSTRUCTION_NODE :
     {
@@ -379,9 +352,9 @@
       {
         nextIsRaw = false;
 
-        m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
+        m_contentHandler.processingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, "");
         dispatachChars(node);
-        m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
+        m_contentHandler.processingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, "");
       }
       else
       {
@@ -426,12 +399,12 @@
       break;
 
     case Node.ELEMENT_NODE :
-      String ns = m_dh.getNamespaceOfNode(node);
+      String ns = DOM2Helper.getNamespaceOfNode(node);
       if(null == ns)
         ns = "";
       this.m_contentHandler.endElement(ns,
-                                         m_dh.getLocalNameOfNode(node),
-                                         node.getNodeName());
+              DOM2Helper.getLocalNameOfNode(node),
+              node.getNodeName());
 
       NamedNodeMap atts = ((Element) node).getAttributes();
       int nAttrs = atts.getLength();
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -31,6 +30,7 @@
 import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
@@ -43,29 +43,21 @@
  */
 public class XMLReaderManager {
 
-    private static final String NAMESPACES_FEATURE =
-                             "http://xml.org/sax/features/namespaces";
-    private static final String NAMESPACE_PREFIXES_FEATURE =
-                             "http://xml.org/sax/features/namespace-prefixes";
     private static final XMLReaderManager m_singletonManager =
                                                      new XMLReaderManager();
     private static final String property = "org.xml.sax.driver";
-    /**
-     * Parser factory to be used to construct XMLReader objects
-     */
-    private static SAXParserFactory m_parserFactory;
 
     /**
      * Cache of XMLReader objects
      */
-    private ThreadLocal m_readers;
+    private ThreadLocal<ReaderWrapper> m_readers;
 
+    private boolean m_overrideDefaultParser;
     /**
      * Keeps track of whether an XMLReader object is in use.
      */
     private HashMap m_inUse;
 
-
     private boolean _secureProcessing;
 
     private XMLSecurityManager _xmlSecurityManager;
@@ -78,7 +70,8 @@
     /**
      * Retrieves the singleton reader manager
      */
-    public static XMLReaderManager getInstance() {
+    public static XMLReaderManager getInstance(boolean overrideDefaultParser) {
+        m_singletonManager.setOverrideDefaultParser(overrideDefaultParser);
         return m_singletonManager;
     }
 
@@ -101,62 +94,29 @@
             m_inUse = new HashMap();
         }
 
-        // If the cached reader for this thread is in use, construct a new
-        // one; otherwise, return the cached reader unless it isn't an 
-        // instance of the class set in the 'org.xml.sax.driver' property
-        reader = (XMLReader) m_readers.get();
-        boolean threadHasReader = (reader != null);
+        /**
+         * Constructs a new XMLReader if:
+         * (1) the cached reader for this thread is in use, or
+         * (2) the requirement for overriding has changed,
+         * (3) the cached reader isn't an instance of the class set in the
+         * 'org.xml.sax.driver' property
+         *
+         * otherwise, returns the cached reader
+         */
+        ReaderWrapper rw = m_readers.get();
+        boolean threadHasReader = (rw != null);
+        reader = threadHasReader ? rw.reader : null;
         String factory = SecuritySupport.getInstance().getSystemProperty(property);
         if (threadHasReader && m_inUse.get(reader) != Boolean.TRUE &&
+                (rw.overrideDefaultParser == m_overrideDefaultParser) &&
                 ( factory == null || reader.getClass().getName().equals(factory))) {
             m_inUse.put(reader, Boolean.TRUE);
         } else {
-            try {
-                try {
-                    // According to JAXP 1.2 specification, if a SAXSource
-                    // is created using a SAX InputSource the Transformer or
-                    // TransformerFactory creates a reader via the
-                    // XMLReaderFactory if setXMLReader is not used
-                    reader = XMLReaderFactory.createXMLReader();
-                    try {
-                        reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _secureProcessing);
-                    } catch (SAXNotRecognizedException e) {
-                        XMLSecurityManager.printWarning(reader.getClass().getName(),
-                                XMLConstants.FEATURE_SECURE_PROCESSING, e);
-                    }
-                } catch (Exception e) {
-                   try {
-                        // If unable to create an instance, let's try to use
-                        // the XMLReader from JAXP
-                        if (m_parserFactory == null) {
-                            m_parserFactory = SAXParserFactory.newInstance();
-                            m_parserFactory.setNamespaceAware(true);
-                        }
-
-                        reader = m_parserFactory.newSAXParser().getXMLReader();
-                   } catch (ParserConfigurationException pce) {
-                       throw pce;   // pass along pce
-                   }
-                }
-                try {
-                    reader.setFeature(NAMESPACES_FEATURE, true);
-                    reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
-                } catch (SAXException se) {
-                    // Try to carry on if we've got a parser that
-                    // doesn't know about namespace prefixes.
-                }
-            } catch (ParserConfigurationException ex) {
-                throw new SAXException(ex);
-            } catch (FactoryConfigurationError ex1) {
-                throw new SAXException(ex1.toString());
-            } catch (NoSuchMethodError ex2) {
-            } catch (AbstractMethodError ame) {
-            }
-
+            reader = JdkXmlUtils.getXMLReader(m_overrideDefaultParser, _secureProcessing);
             // Cache the XMLReader if this is the first time we've created
             // a reader for this thread.
             if (!threadHasReader) {
-                m_readers.set(reader);
+                m_readers.set(new ReaderWrapper(reader, m_overrideDefaultParser));
                 m_inUse.put(reader, Boolean.TRUE);
             }
         }
@@ -217,8 +177,32 @@
     public synchronized void releaseXMLReader(XMLReader reader) {
         // If the reader that's being released is the cached reader
         // for this thread, remove it from the m_isUse list.
-        if (m_readers.get() == reader && reader != null) {
+        ReaderWrapper rw = m_readers.get();
+        if (rw.reader == reader && reader != null) {
             m_inUse.remove(reader);
         }
     }
+    /**
+     * Return the state of the services mechanism feature.
+     */
+    public boolean overrideDefaultParser() {
+        return m_overrideDefaultParser;
+    }
+
+    /**
+     * Set the state of the services mechanism feature.
+     */
+    public void setOverrideDefaultParser(boolean flag) {
+        m_overrideDefaultParser = flag;
+    }
+
+    class ReaderWrapper {
+        XMLReader reader;
+        boolean overrideDefaultParser;
+
+        public ReaderWrapper(XMLReader reader, boolean overrideDefaultParser) {
+            this.reader = reader;
+            this.overrideDefaultParser = overrideDefaultParser;
+        }
+    }
 }
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/CachedXPathAPI.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/CachedXPathAPI.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -27,6 +26,7 @@
 import com.sun.org.apache.xml.internal.utils.PrefixResolver;
 import com.sun.org.apache.xml.internal.utils.PrefixResolverDefault;
 import com.sun.org.apache.xpath.internal.objects.XObject;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -74,7 +74,7 @@
    */
   public CachedXPathAPI()
   {
-    xpathSupport = new XPathContext();
+    xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
   }
 
   /**
@@ -329,7 +329,7 @@
     XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
 
     // Execute the XPath, and have it return the result
-    XPathContext xpathSupport = new XPathContext();
+    XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
     int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
 
     return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/XPathAPI.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/XPathAPI.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -27,6 +26,7 @@
 import com.sun.org.apache.xml.internal.utils.PrefixResolver;
 import com.sun.org.apache.xml.internal.utils.PrefixResolverDefault;
 import com.sun.org.apache.xpath.internal.objects.XObject;
+import jdk.xml.internal.JdkXmlUtils;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -222,7 +222,7 @@
     // (Changed from: XPathContext xpathSupport = new XPathContext();
     //    because XPathContext is weak in a number of areas... perhaps
     //    XPathContext should be done away with.)
-    XPathContext xpathSupport = new XPathContext();
+    XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
 
     // Create an object to resolve namespace prefixes.
     // XPath namespaces are resolved from the input context node's document element
@@ -277,7 +277,7 @@
     XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
 
     // Execute the XPath, and have it return the result
-    XPathContext xpathSupport = new XPathContext();
+    XPathContext xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
     int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
 
     return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/XPathContext.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/XPathContext.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -50,6 +49,7 @@
 import javax.xml.transform.SourceLocator;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.URIResolver;
+import jdk.xml.internal.JdkXmlUtils;
 import org.xml.sax.XMLReader;
 
 /**
@@ -92,6 +92,8 @@
    */
   private boolean m_isSecureProcessing = false;
 
+  private boolean m_overrideDefaultParser;
+
   /**
    * Though XPathContext context extends
    * the DTMManager, it really is a proxy for this object, which
@@ -308,6 +310,7 @@
     m_currentNodes.push(DTM.NULL);
     m_currentExpressionNodes.push(DTM.NULL);
     m_saxLocations.push(null);
+    m_overrideDefaultParser = false;
   }
 
   /**
@@ -326,6 +329,7 @@
     m_currentNodes.push(DTM.NULL);
     m_currentExpressionNodes.push(DTM.NULL);
     m_saxLocations.push(null);
+    m_overrideDefaultParser = false;
   }
 
   /**
@@ -1069,6 +1073,21 @@
       return XPathContext.this.getErrorListener();
     }
 
+
+      /**
+       * Return the state of the services mechanism feature.
+       */
+      public boolean overrideDefaultParser() {
+          return m_overrideDefaultParser;
+      }
+
+      /**
+       * Set the state of the services mechanism feature.
+       */
+      public void setOverrideDefaultParser(boolean flag) {
+          m_overrideDefaultParser = flag;
+      }
+
     /**
      * Get the value of a node as a number.
      * @param n Node to be converted to a number.  May be null.
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/JAXPExtensionsProvider.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/JAXPExtensionsProvider.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -22,13 +21,11 @@
 
 package com.sun.org.apache.xpath.internal.jaxp;
 
-import javax.xml.transform.TransformerException;
 import javax.xml.xpath.XPathFunctionResolver;
 import javax.xml.xpath.XPathFunction;
 import javax.xml.xpath.XPathFunctionException;
 
 import com.sun.org.apache.xpath.internal.ExtensionsProvider;
-import com.sun.org.apache.xpath.internal.XPathContext;
 import com.sun.org.apache.xpath.internal.objects.XObject;
 import com.sun.org.apache.xpath.internal.objects.XNodeSet;
 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
@@ -38,6 +35,7 @@
 import java.util.Vector;
 import java.util.ArrayList;
 import javax.xml.namespace.QName;
+import jdk.xml.internal.JdkXmlFeatures;
 
 /**
  *
@@ -54,9 +52,12 @@
     }
 
     public JAXPExtensionsProvider(XPathFunctionResolver resolver,
-        boolean featureSecureProcessing ) {
+        boolean featureSecureProcessing, JdkXmlFeatures featureManager ) {
         this.resolver = resolver;
-        this.extensionInvocationDisabled = featureSecureProcessing;
+        if (featureSecureProcessing &&
+                !featureManager.getFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION)) {
+            this.extensionInvocationDisabled = true;
+        }
     }
 
     /**
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathExpressionImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathExpressionImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,7 +1,6 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
+ /*
+  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
  *
@@ -21,26 +20,21 @@
 
 package com.sun.org.apache.xpath.internal.jaxp;
 
-import com.sun.org.apache.xpath.internal.*;
-import javax.xml.transform.TransformerException;
-
 import com.sun.org.apache.xpath.internal.objects.XObject;
 import com.sun.org.apache.xml.internal.dtm.DTM;
-import com.sun.org.apache.xml.internal.utils.PrefixResolver;
 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
 import com.sun.org.apache.xalan.internal.res.XSLMessages;
 
-import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathFunctionResolver;
 import javax.xml.xpath.XPathVariableResolver;
-import javax.xml.xpath.XPathConstants;
 
+import jdk.xml.internal.JdkXmlFeatures;
+import jdk.xml.internal.JdkXmlUtils;
 import org.w3c.dom.Node;
 import org.w3c.dom.Document;
-import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.traversal.NodeIterator;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.DocumentBuilder;
@@ -64,32 +58,36 @@
     // extensions function need to throw XPathFunctionException
     private boolean featureSecureProcessing = false;
 
+    boolean overrideDefaultParser;
+    private final JdkXmlFeatures featureManager;
+
     /** Protected constructor to prevent direct instantiation; use compile()
      * from the context.
      */
-    protected XPathExpressionImpl() { };
+    protected XPathExpressionImpl() {
+        this(null, null, null, null, false, new JdkXmlFeatures(false));
+    };
 
     protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath,
             JAXPPrefixResolver prefixResolver,
             XPathFunctionResolver functionResolver,
             XPathVariableResolver variableResolver ) {
-        this.xpath = xpath;
-        this.prefixResolver = prefixResolver;
-        this.functionResolver = functionResolver;
-        this.variableResolver = variableResolver;
-        this.featureSecureProcessing = false;
+        this(xpath, prefixResolver, functionResolver, variableResolver,
+                false, new JdkXmlFeatures(false));
     };
 
     protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath,
-            JAXPPrefixResolver prefixResolver,
-            XPathFunctionResolver functionResolver,
-            XPathVariableResolver variableResolver,
-            boolean featureSecureProcessing ) {
+            JAXPPrefixResolver prefixResolver, XPathFunctionResolver functionResolver,
+            XPathVariableResolver variableResolver, boolean featureSecureProcessing,
+            JdkXmlFeatures featureManager) {
         this.xpath = xpath;
         this.prefixResolver = prefixResolver;
         this.functionResolver = functionResolver;
         this.variableResolver = variableResolver;
         this.featureSecureProcessing = featureSecureProcessing;
+        this.featureManager = featureManager;
+        this.overrideDefaultParser = featureManager.getFeature(
+                JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
     };
 
     public void setXPath (com.sun.org.apache.xpath.internal.XPath xpath ) {
@@ -107,7 +105,7 @@
         com.sun.org.apache.xpath.internal.XPathContext xpathSupport = null;
         if ( functionResolver != null ) {
             JAXPExtensionsProvider jep = new JAXPExtensionsProvider(
-                    functionResolver, featureSecureProcessing );
+                    functionResolver, featureSecureProcessing, featureManager );
             xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext( jep );
         } else {
             xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext();
@@ -286,9 +284,7 @@
         }
         try {
             if ( dbf == null ) {
-                dbf = DocumentBuilderFactory.newInstance();
-                dbf.setNamespaceAware( true );
-                dbf.setValidating( false );
+                dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
             }
             db = dbf.newDocumentBuilder();
             Document document = db.parse( source );
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -29,6 +28,7 @@
 import javax.xml.xpath.XPathFactoryConfigurationException;
 import javax.xml.xpath.XPathFunctionResolver;
 import javax.xml.xpath.XPathVariableResolver;
+import jdk.xml.internal.JdkXmlFeatures;
 
 /**
  * The XPathFactory builds XPaths.
@@ -61,6 +61,12 @@
          * <p>State of secure mode.</p>
          */
         private boolean _isSecureMode = false;
+
+        /**
+         * XML Features manager
+         */
+        private final JdkXmlFeatures _featureManager;
+
         /**
          * javax.xml.xpath.XPathFactory implementation.
          */
@@ -69,6 +75,7 @@
                 _isSecureMode = true;
                 _isNotSecureProcessing = false;
             }
+            _featureManager = new JdkXmlFeatures(!_isNotSecureProcessing);
         }
 		
 	/**
@@ -119,7 +126,7 @@
 	public javax.xml.xpath.XPath newXPath() {
 	    return new com.sun.org.apache.xpath.internal.jaxp.XPathImpl(
                     xPathVariableResolver, xPathFunctionResolver,
-                    !_isNotSecureProcessing );
+                    !_isNotSecureProcessing, _featureManager);
 	}
 	    
 	/**
@@ -169,15 +176,25 @@
                 }
 
                 _isNotSecureProcessing = !value;
-						
+
+                if (value && _featureManager != null) {
+                    _featureManager.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION,
+                            JdkXmlFeatures.State.FSP, false);
+                }
+
                 // all done processing feature
                 return;
             }
-		
+
+            if (_featureManager != null &&
+                    _featureManager.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) {
+                return;
+            }
+
             // unknown feature
             String fmsg = XSLMessages.createXPATHMessage(
                     XPATHErrorResources.ER_FEATURE_UNKNOWN,
-                    new Object[] { name, CLASS_NAME, new Boolean(value) } );
+                    new Object[] { name, CLASS_NAME, value } );
             throw new XPathFactoryConfigurationException( fmsg );
 	}
 
@@ -219,7 +236,13 @@
             if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
                 return !_isNotSecureProcessing;
             }
-		
+
+            /** Check to see if the property is managed by the feature manager **/
+            int index = _featureManager.getIndex(name);
+            if (index > -1) {
+                return _featureManager.getFeature(index);
+            }
+
             // unknown feature
             String fmsg = XSLMessages.createXPATHMessage(
                     XPATHErrorResources.ER_GETTING_UNKNOWN_FEATURE,
--- a/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,6 +1,5 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -47,6 +46,9 @@
 
 import java.io.IOException;
 
+import jdk.xml.internal.JdkXmlFeatures;
+import jdk.xml.internal.JdkXmlUtils;
+
 /**
  * The XPathImpl class provides implementation for the methods defined  in
  * javax.xml.xpath.XPath interface. This provide simple access to the results
@@ -68,17 +70,21 @@
     // Secure Processing Feature is set on XPathFactory then the invocation of
     // extensions function need to throw XPathFunctionException
     private boolean featureSecureProcessing = false;
+    private boolean overrideDefaultParser = true;
+    private final JdkXmlFeatures featureManager;
 
     XPathImpl( XPathVariableResolver vr, XPathFunctionResolver fr ) {
-        this.origVariableResolver = this.variableResolver = vr;
-        this.origFunctionResolver = this.functionResolver = fr;
+        this(vr, fr, false, new JdkXmlFeatures(false));
     }
 
     XPathImpl( XPathVariableResolver vr, XPathFunctionResolver fr,
-            boolean featureSecureProcessing ) {
+            boolean featureSecureProcessing, JdkXmlFeatures featureManager ) {
         this.origVariableResolver = this.variableResolver = vr;
         this.origFunctionResolver = this.functionResolver = fr;
         this.featureSecureProcessing = featureSecureProcessing;
+        this.featureManager = featureManager;
+        this.overrideDefaultParser = featureManager.getFeature(
+                JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
     }
 
     /**
@@ -156,7 +162,7 @@
 
     private static Document d = null;
 
-    private static DocumentBuilder getParser() {
+    private DocumentBuilder getParser() {
         try {
             // we'd really like to cache those DocumentBuilders, but we can't because:
             // 1. thread safety. parsers are not thread-safe, so at least
@@ -169,9 +175,7 @@
             //
             // so we really have to create a fresh DocumentBuilder every time we need one
             // - KK
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            dbf.setNamespaceAware( true );
-            dbf.setValidating( false );
+            DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
             return dbf.newDocumentBuilder();
         } catch (ParserConfigurationException e) {
             // this should never happen with a well-behaving JAXP implementation.
@@ -179,7 +183,7 @@
         }
     }
 
-    private static Document getDummyDocument( ) {
+    private Document getDummyDocument( ) {
         // we don't need synchronization here; even if two threads
         // enter this code at the same time, we just waste a little time
         if(d==null) {
@@ -198,7 +202,7 @@
         com.sun.org.apache.xpath.internal.XPathContext xpathSupport = null;
         if ( functionResolver != null ) {
             JAXPExtensionsProvider jep = new JAXPExtensionsProvider(
-                    functionResolver, featureSecureProcessing );
+                    functionResolver, featureSecureProcessing, featureManager );
             xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext( jep );
         } else {
             xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext();
@@ -397,9 +401,9 @@
             com.sun.org.apache.xpath.internal.XPath xpath = new XPath (expression, null,
                     prefixResolver, com.sun.org.apache.xpath.internal.XPath.SELECT );
             // Can have errorListener
-            XPathExpressionImpl ximpl = new XPathExpressionImpl (xpath,
+            XPathExpressionImpl ximpl = new XPathExpressionImpl(xpath,
                     prefixResolver, functionResolver, variableResolver,
-                    featureSecureProcessing );
+                    featureSecureProcessing, featureManager);
             return ximpl;
         } catch ( javax.xml.transform.TransformerException te ) {
             throw new XPathExpressionException ( te ) ;
--- a/drop_included/jaxp_src/src/javax/xml/transform/FactoryFinder.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/javax/xml/transform/FactoryFinder.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -164,7 +164,8 @@
      * @param useBSClsLoader True if cl=null actually meant bootstrap classLoader. This parameter
      * is needed since DocumentBuilderFactory/SAXParserFactory defined null as context classLoader.
      */
-    static Object newInstance(String className, ClassLoader cl, boolean doFallback, boolean useBSClsLoader)
+    static Object newInstance(String className, ClassLoader cl,
+                              boolean doFallback, boolean useBSClsLoader)
         throws ConfigurationError
     {
         // make sure we have access to restricted packages
@@ -178,6 +179,7 @@
         try {
             Class providerClass = getProviderClass(className, cl, doFallback, useBSClsLoader);
             Object instance = providerClass.newInstance();
+
             if (debug) {    // Extra check to avoid computing cl strings
                 dPrint("created new instance of " + providerClass +
                        " using ClassLoader: " + cl);
--- a/drop_included/jaxp_src/src/javax/xml/transform/TransformerFactory.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/javax/xml/transform/TransformerFactory.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
--- a/drop_included/jaxp_src/src/javax/xml/validation/SchemaFactoryFinder.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/javax/xml/validation/SchemaFactoryFinder.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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,6 +25,7 @@
 
 package javax.xml.validation;
 
+import com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
--- a/drop_included/jaxp_src/src/javax/xml/xpath/XPathFactoryFinder.java	Fri Feb 05 14:40:11 2016 +0300
+++ b/drop_included/jaxp_src/src/javax/xml/xpath/XPathFactoryFinder.java	Thu Oct 19 17:03:20 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 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,6 +25,7 @@
 
 package javax.xml.xpath;
 
+import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -431,7 +432,7 @@
      *      if there was an error.
      */
     private XPathFactory loadFromProperty( String keyName, String resourceName, InputStream in )
-        throws IOException {
+        throws IOException, XPathFactoryConfigurationException {
         debugPrintln("Reading "+resourceName );
 
         Properties props = new Properties();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drop_included/jaxp_src/src/jdk/xml/internal/JdkXmlFeatures.java	Thu Oct 19 17:03:20 2017 +0100
@@ -0,0 +1,383 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 jdk.xml.internal;
+
+import javax.xml.XMLConstants;
+import static jdk.xml.internal.JdkXmlUtils.OVERRIDE_PARSER;
+
+/**
+ * This class manages JDK's XML Features. Previously added features and properties
+ * may be gradually moved to this class.
+ */
+public class JdkXmlFeatures {
+    public static final String ORACLE_JAXP_PROPERTY_PREFIX =
+        "http://www.oracle.com/xml/jaxp/properties/";
+
+    public static final String XML_FEATURE_MANAGER =
+            ORACLE_JAXP_PROPERTY_PREFIX + "XmlFeatureManager";
+
+    public static final String ORACLE_FEATURE_SERVICE_MECHANISM =
+            "http://www.oracle.com/feature/use-service-mechanism";
+
+    /**
+     * Feature enableExtensionFunctions
+     */
+    public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
+            ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
+    public static final String SP_ENABLE_EXTENSION_FUNCTION =
+            "javax.xml.enableExtensionFunctions";
+    // This is the correct name by the spec
+    public static final String SP_ENABLE_EXTENSION_FUNCTION_SPEC =
+            "jdk.xml.enableExtensionFunctions";
+
+    public static enum XmlFeature {
+        /**
+         * Feature enableExtensionFunctions
+         * FSP: extension function is enforced by FSP. When FSP is on, extension
+         * function is disabled.
+         */
+        ENABLE_EXTENSION_FUNCTION(ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION_SPEC,
+                ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION,
+                true, false, true, true),
+
+        /**
+         * Feature overrideDefaultParser
+         * FSP: not enforced by FSP.
+         */
+        JDK_OVERRIDE_PARSER(OVERRIDE_PARSER, OVERRIDE_PARSER,
+                ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM,
+                false, false, true, false);
+
+        private final String name;
+        private final String nameSP;
+        private final String nameOld;
+        private final String nameOldSP;
+        private final boolean valueDefault;
+        private final boolean valueEnforced;
+        private final boolean hasSystem;
+        private final boolean enforced;
+
+        /**
+         * Constructs an XmlFeature instance.
+         * @param name the name of the feature
+         * @param nameSP the name of the System Property
+         * @param nameOld the name of the corresponding legacy property
+         * @param nameOldSP the system property of the legacy property
+         * @param value the value of the feature
+         * @param hasSystem a flag to indicate whether the feature is supported
+         * @param enforced a flag indicating whether the feature is
+         * FSP (Feature_Secure_Processing) enforced
+         * with a System property
+         */
+        XmlFeature(String name, String nameSP, String nameOld, String nameOldSP,
+                boolean value, boolean valueEnforced, boolean hasSystem, boolean enforced) {
+            this.name = name;
+            this.nameSP = nameSP;
+            this.nameOld = nameOld;
+            this.nameOldSP = nameOldSP;
+            this.valueDefault = value;
+            this.valueEnforced = valueEnforced;
+            this.hasSystem = hasSystem;
+            this.enforced = enforced;
+        }
+
+        /**
+         * Checks whether the specified property is equal to the current property.
+         * @param propertyName the name of a property
+         * @return true if the specified property is the current property, false
+         * otherwise
+         */
+        boolean equalsPropertyName(String propertyName) {
+            return name.equals(propertyName) ||
+                    (nameOld != null && nameOld.equals(propertyName));
+        }
+
+        /**
+         * Returns the name of the property.
+         *
+         * @return the name of the property
+         */
+        public String apiProperty() {
+            return name;
+        }
+
+        /**
+         * Returns the name of the corresponding System Property.
+         *
+         * @return the name of the System Property
+         */
+        String systemProperty() {
+            return nameSP;
+        }
+
+        /**
+         * Returns the name of the legacy System Property.
+         *
+         * @return the name of the legacy System Property
+         */
+        String systemPropertyOld() {
+            return nameOldSP;
+        }
+
+        /**
+         * Returns the default value of the property.
+         * @return the default value of the property
+         */
+        public boolean defaultValue() {
+            return valueDefault;
+        }
+
+        /**
+         * Returns the FSP-enforced value.
+         * @return the FSP-enforced value
+         */
+        public boolean enforcedValue() {
+            return valueEnforced;
+        }
+
+        /**
+         * Checks whether System property is supported for the feature.
+         * @return true it is supported, false otherwise
+         */
+        boolean hasSystemProperty() {
+            return hasSystem;
+        }
+
+        /**
+         * Checks whether the property is enforced by FSP
+         * @return true it is, false otherwise
+         */
+        boolean enforced() {
+            return enforced;
+        }
+
+    }
+
+    /**
+     * States of the settings of a property, in the order: default value, value
+     * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
+     * properties, and jaxp api properties
+     */
+    public static enum State {
+        //this order reflects the overriding order
+
+        DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
+        JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
+        APIPROPERTY("property");
+
+        final String literal;
+        State(String literal) {
+            this.literal = literal;
+        }
+
+        String literal() {
+            return literal;
+        }
+    }
+
+    /**
+     * Values of the features
+     */
+    private final boolean[] featureValues;
+
+    /**
+     * States of the settings for each property
+     */
+    private final State[] states;
+
+    /**
+     * Flag indicating if secure processing is set
+     */
+    boolean secureProcessing;
+
+    /**
+     * Instantiate JdkXmlFeatures and initialize the fields
+     * @param secureProcessing
+     */
+    public JdkXmlFeatures(boolean secureProcessing) {
+        featureValues = new boolean[XmlFeature.values().length];
+        states = new State[XmlFeature.values().length];
+        this.secureProcessing = secureProcessing;
+        for (XmlFeature f : XmlFeature.values()) {
+            if (secureProcessing && f.enforced()) {
+                featureValues[f.ordinal()] = f.enforcedValue();
+                states[f.ordinal()] = State.FSP;
+            } else {
+                featureValues[f.ordinal()] = f.defaultValue();
+                states[f.ordinal()] = State.DEFAULT;
+            }
+        }
+        //read system properties or jaxp.properties
+        readSystemProperties();
+    }
+
+    /**
+     * Updates the JdkXmlFeatures instance by reading the system properties again.
+     * This will become necessary in case the system properties are set after
+     * the instance has been created.
+     */
+    public void update() {
+        readSystemProperties();
+    }
+
+    /**
+     * Set feature by property name and state
+     * @param propertyName property name
+     * @param state the state of the property
+     * @param value the value of the property
+     * @return true if the property is managed by the JdkXmlFeatures instance;
+     *         false otherwise.
+     */
+    public boolean setFeature(String propertyName, State state, Object value) {
+        int index = getIndex(propertyName);
+        if (index > -1) {
+            setFeature(index, state, value);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Set the value for a specific feature.
+     *
+     * @param feature the feature
+     * @param state the state of the property
+     * @param value the value of the property
+     */
+    public void setFeature(XmlFeature feature, State state, boolean value) {
+        setFeature(feature.ordinal(), state, value);
+    }
+
+    /**
+     * Return the value of the specified property
+     *
+     * @param feature the property
+     * @return the value of the property
+     */
+    public boolean getFeature(XmlFeature feature) {
+        return featureValues[feature.ordinal()];
+    }
+
+    /**
+     * Return the value of a feature by its index (the Feature's ordinal)
+     * @param index the index of a feature
+     * @return value of a feature
+     */
+    public boolean getFeature(int index) {
+        return featureValues[index];
+    }
+
+    /**
+     * Set the value of a property by its index
+     *
+     * @param index the index of the property
+     * @param state the state of the property
+     * @param value the value of the property
+     */
+    public void setFeature(int index, State state, Object value) {
+        boolean temp;
+        if (Boolean.class.isAssignableFrom(value.getClass())) {
+            temp = (Boolean)value;
+        } else {
+            temp = Boolean.parseBoolean((String) value);
+        }
+        setFeature(index, state, temp);
+    }
+
+    /**
+     * Set the value of a property by its index
+     *
+     * @param index the index of the property
+     * @param state the state of the property
+     * @param value the value of the property
+     */
+    public void setFeature(int index, State state, boolean value) {
+        //only update if it shall override
+        if (state.compareTo(states[index]) >= 0) {
+            featureValues[index] = value;
+            states[index] = state;
+        }
+    }
+
+    /**
+     * Get the index by property name
+     *
+     * @param propertyName property name
+     * @return the index of the property if found; return -1 if not
+     */
+    public int getIndex(String propertyName) {
+        for (XmlFeature feature : XmlFeature.values()) {
+            if (feature.equalsPropertyName(propertyName)) {
+                //internally, ordinal is used as index
+                return feature.ordinal();
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Read from system properties, or those in jaxp.properties
+     */
+    private void readSystemProperties() {
+        for (XmlFeature feature : XmlFeature.values()) {
+            if (!getSystemProperty(feature, feature.systemProperty())) {
+                //if system property is not found, try the older form if any
+                String oldName = feature.systemPropertyOld();
+                if (oldName != null) {
+                    getSystemProperty(feature, oldName);
+                }
+            }
+        }
+    }
+
+    /**
+     * Read from system properties, or those in jaxp.properties
+     *
+     * @param feature the feature get
+     * @param sysPropertyName the name of system property
+     * @return true if the system property is found, false otherwise
+     */
+    private boolean getSystemProperty(XmlFeature feature, String sysPropertyName) {
+        try {
+            String value = SecuritySupport.getSystemProperty(sysPropertyName);
+            if (value != null && !value.equals("")) {
+                setFeature(feature, State.SYSTEMPROPERTY, Boolean.parseBoolean(value));
+                return true;
+            }
+
+            value = SecuritySupport.readJAXPProperty(sysPropertyName);
+            if (value != null && !value.equals("")) {
+                setFeature(feature, State.JAXPDOTPROPERTIES, Boolean.parseBoolean(value));
+                return true;
+            }
+        } catch (NumberFormatException e) {
+            //invalid setting
+            throw new NumberFormatException("Invalid setting for system property: " + feature.systemProperty());
+        }
+        return false;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drop_included/jaxp_src/src/jdk/xml/internal/JdkXmlUtils.java	Thu Oct 19 17:03:20 2017 +0100
@@ -0,0 +1,276 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 jdk.xml.internal;
+
+import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
+import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
+import com.sun.org.apache.xerces.internal.impl.Constants;
+import com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
+import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+
+/**
+ * Constants for use across JAXP processors.
+ */
+public class JdkXmlUtils {
+    private static final String DOM_FACTORY_ID = "javax.xml.parsers.DocumentBuilderFactory";
+    private static final String SAX_FACTORY_ID = "javax.xml.parsers.SAXParserFactory";
+    private static final String SAX_DRIVER = "org.xml.sax.driver";
+
+    /**
+     * Xerces features
+     */
+    public static final String NAMESPACES_FEATURE =
+        Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
+    public static final String NAMESPACE_PREFIXES_FEATURE =
+        Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACE_PREFIXES_FEATURE;
+
+    /**
+     * jdk.xml.overrideDefaultParser: enables the use of a 3rd party's parser
+     * implementation to override the system-default parser.
+     */
+    public static final String OVERRIDE_PARSER = "jdk.xml.overrideDefaultParser";
+    public static final boolean OVERRIDE_PARSER_DEFAULT = SecuritySupport.getJAXPSystemProperty(
+                    Boolean.class, OVERRIDE_PARSER, "false");
+
+    /**
+     * Values for a feature
+     */
+    public static final String FEATURE_TRUE = "true";
+    public static final String FEATURE_FALSE = "false";
+
+    /**
+     * The system-default factory
+     */
+    private static final SAXParserFactory defaultSAXFactory = getSAXFactory(false);
+
+    /**
+     * Returns the value.
+     *
+     * @param value the specified value
+     * @param defValue the default value
+     * @return the value, or the default value if the value is null
+     */
+    public static int getValue(Object value, int defValue) {
+        if (value == null) {
+            return defValue;
+        }
+
+        if (value instanceof Number) {
+            return ((Number) value).intValue();
+        } else if (value instanceof String) {
+            return Integer.parseInt(String.valueOf(value));
+        } else {
+            throw new IllegalArgumentException("Unexpected class: "
+                    + value.getClass());
+        }
+    }
+
+    /**
+     * Sets the XMLReader instance with the specified property if the the
+     * property is supported, ignores error if not, issues a warning if so
+     * requested.
+     *
+     * @param reader an XMLReader instance
+     * @param property the name of the property
+     * @param value the value of the property
+     * @param warn a flag indicating whether a warning should be issued
+     */
+    public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
+            Object value, boolean warn) {
+        SAXException err = null;
+        try {
+            reader.setProperty(property, value);
+        } catch (SAXNotRecognizedException e) {
+            err = e;
+        } catch (SAXNotSupportedException e) {
+            err = e;
+        }
+        if (warn && err != null) {
+            XMLSecurityManager.printWarning(reader.getClass().getName(), property, err);
+        }
+    }
+
+    /**
+     * Returns an XMLReader instance. If overrideDefaultParser is requested, use
+     * SAXParserFactory or XMLReaderFactory, otherwise use the system-default
+     * SAXParserFactory to locate an XMLReader.
+     *
+     * @param overrideDefaultParser a flag indicating whether a 3rd party's
+     * parser implementation may be used to override the system-default one
+     * @param secureProcessing a flag indicating whether secure processing is
+     * requested
+     * @return an XMLReader instance
+     */
+    public static XMLReader getXMLReader(boolean overrideDefaultParser,
+            boolean secureProcessing) {
+        SAXParserFactory saxFactory;
+        XMLReader reader = null;
+        String spSAXDriver = SecuritySupport.getSystemProperty(SAX_DRIVER);
+        if (spSAXDriver != null) {
+            reader = getXMLReaderWXMLReaderFactory();
+        } else if (overrideDefaultParser) {
+            reader = getXMLReaderWSAXFactory(overrideDefaultParser);
+        }
+
+        if (reader != null) {
+            if (secureProcessing) {
+                try {
+                    reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, secureProcessing);
+                } catch (SAXException e) {
+                    XMLSecurityManager.printWarning(reader.getClass().getName(),
+                            XMLConstants.FEATURE_SECURE_PROCESSING, e);
+                }
+            }
+            try {
+                reader.setFeature(NAMESPACES_FEATURE, true);
+                reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
+            } catch (SAXException se) {
+                // older version of a parser
+            }
+            return reader;
+        }
+
+        // use the system-default
+        saxFactory = defaultSAXFactory;
+
+        try {
+            reader = saxFactory.newSAXParser().getXMLReader();
+        } catch (ParserConfigurationException ex) {
+            // shall not happen with the system-default reader
+        } catch (SAXException ex) {
+            // shall not happen with the system-default reader
+        }
+        return reader;
+    }
+
+    /**
+     * Creates a system-default DOM Document.
+     *
+     * @return a DOM Document instance
+     */
+    public static Document getDOMDocument() {
+        try {
+            DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(false);
+            return dbf.newDocumentBuilder().newDocument();
+        } catch (ParserConfigurationException pce) {
+            // can never happen with the system-default configuration
+        }
+        return null;
+    }
+
+    /**
+     * Returns a DocumentBuilderFactory instance.
+     *
+     * @param overrideDefaultParser a flag indicating whether the system-default
+     * implementation may be overridden. If the system property of the
+     * DOM factory ID is set, override is always allowed.
+     *
+     * @return a DocumentBuilderFactory instance.
+     */
+    public static DocumentBuilderFactory getDOMFactory(boolean overrideDefaultParser) {
+        boolean override = overrideDefaultParser;
+        String spDOMFactory = SecuritySupport.getJAXPSystemProperty(DOM_FACTORY_ID);
+
+        if (spDOMFactory != null && System.getSecurityManager() == null) {
+            override = true;
+        }
+        DocumentBuilderFactory dbf
+                = !override
+                        ? new DocumentBuilderFactoryImpl()
+                        : DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        // false is the default setting. This step here is for compatibility
+        dbf.setValidating(false);
+        return dbf;
+    }
+
+    /**
+     * Returns a SAXParserFactory instance.
+     *
+     * @param overrideDefaultParser a flag indicating whether the system-default
+     * implementation may be overridden. If the system property of the
+     * DOM factory ID is set, override is always allowed.
+     *
+     * @return a SAXParserFactory instance.
+     */
+    public static SAXParserFactory getSAXFactory(boolean overrideDefaultParser) {
+        boolean override = overrideDefaultParser;
+        String spSAXFactory = SecuritySupport.getJAXPSystemProperty(SAX_FACTORY_ID);
+        if (spSAXFactory != null && System.getSecurityManager() == null) {
+            override = true;
+        }
+
+        SAXParserFactory factory
+                = !override
+                        ? new SAXParserFactoryImpl()
+                        : SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        return factory;
+    }
+
+    public static SAXTransformerFactory getSAXTransformFactory(boolean overrideDefaultParser) {
+        SAXTransformerFactory tf = overrideDefaultParser
+                ? (SAXTransformerFactory) SAXTransformerFactory.newInstance()
+                : (SAXTransformerFactory) new TransformerFactoryImpl();
+        try {
+            tf.setFeature(OVERRIDE_PARSER, overrideDefaultParser);
+        } catch (TransformerConfigurationException ex) {
+            // ignore since it'd never happen with the JDK impl.
+        }
+        return tf;
+    }
+
+    private static XMLReader getXMLReaderWSAXFactory(boolean overrideDefaultParser) {
+        SAXParserFactory saxFactory = getSAXFactory(overrideDefaultParser);
+        try {
+            return saxFactory.newSAXParser().getXMLReader();
+        } catch (ParserConfigurationException ex) {
+            return getXMLReaderWXMLReaderFactory();
+        } catch (SAXException ex) {
+            return getXMLReaderWXMLReaderFactory();
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private static XMLReader getXMLReaderWXMLReaderFactory() {
+        try {
+            return org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
+        } catch (SAXException ex1) {
+        }
+        return null;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drop_included/jaxp_src/src/jdk/xml/internal/SecuritySupport.java	Thu Oct 19 17:03:20 2017 +0100
@@ -0,0 +1,168 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 jdk.xml.internal;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Properties;
+
+/**
+ * This class contains utility methods for reading resources in the JAXP packages
+ */
+class SecuritySupport {
+    /**
+     * Cache for properties in java.home/lib/jaxp.properties
+     */
+    static final Properties cacheProps = new Properties();
+
+    /**
+     * Flag indicating whether java.home/lib/jaxp.properties has been read
+     */
+    static volatile boolean firstTime = true;
+
+    private SecuritySupport() {}
+
+    /**
+     * Reads JAXP system property with privilege
+     *
+     * @param propName the name of the property
+     * @return the value of the property
+     */
+    public static String getSystemProperty(final String propName) {
+        return AccessController.doPrivileged(new PrivilegedAction<String>() {
+            @Override
+            public String run() {
+                return System.getProperty(propName);
+            }
+        });
+    }
+
+    /**
+     * Reads a system property.
+     *
+     * @param <T> the type of the property value
+     * @param type the type of the property value
+     * @param propName the name of the property
+     * @param defValue the default value
+     * @return the value of the property, or the default value of no system
+     * property is found
+     */
+    public static <T> T getJAXPSystemProperty(Class<T> type, String propName, String defValue) {
+        String value = getJAXPSystemProperty(propName);
+        if (value == null) {
+            value = defValue;
+        }
+        if (Integer.class.isAssignableFrom(type)) {
+            return type.cast(Integer.parseInt(value));
+        } else if (Boolean.class.isAssignableFrom(type)) {
+            return type.cast(Boolean.parseBoolean(value));
+        }
+        return type.cast(value);
+    }
+
+    /**
+     * Reads JAXP system property in this order: system property,
+     * $java.home/lib/jaxp.properties if the system property is not specified
+     *
+     * @param propName the name of the property
+     * @return the value of the property
+     */
+    public static String getJAXPSystemProperty(String propName) {
+        String value = getSystemProperty(propName);
+        if (value == null) {
+            value = readJAXPProperty(propName);
+        }
+        return value;
+    }
+
+    /**
+     * Reads the specified property from $java.home/lib/jaxp.properties
+     *
+     * @param propName the name of the property
+     * @return the value of the property
+     */
+    public static String readJAXPProperty(String propName) {
+        String value = null;
+        InputStream is = null;
+        try {
+            if (firstTime) {
+                synchronized (cacheProps) {
+                    if (firstTime) {
+                        String configFile = getSystemProperty("java.home") + File.separator
+                                + "lib" + File.separator + "jaxp.properties";
+                        File f = new File(configFile);
+                        if (getFileExists(f)) {
+                            is = getFileInputStream(f);
+                            cacheProps.load(is);
+                        }
+                        firstTime = false;
+                    }
+                }
+            }
+            value = cacheProps.getProperty(propName);
+
+        } catch (IOException ex) {
+        } finally {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (IOException ex) {}
+            }
+        }
+
+        return value;
+    }
+
+//------------------- private methods ---------------------------
+    static boolean getFileExists(final File f) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+            @Override
+            public Boolean run() {
+                return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+            }
+        });
+    }
+
+    static FileInputStream getFileInputStream(final File file) throws FileNotFoundException {
+        try {
+            return AccessController.doPrivileged(new PrivilegedExceptionAction<FileInputStream>() {
+                @Override
+                public FileInputStream run() throws Exception {
+                    return new FileInputStream(file);
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            throw (FileNotFoundException) e.getException();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/xml/internal/JdkXmlFeatures.java	Thu Oct 19 17:03:20 2017 +0100
@@ -0,0 +1,383 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 jdk.xml.internal;
+
+import javax.xml.XMLConstants;
+import static jdk.xml.internal.JdkXmlUtils.OVERRIDE_PARSER;
+
+/**
+ * This class manages JDK's XML Features. Previously added features and properties
+ * may be gradually moved to this class.
+ */
+public class JdkXmlFeatures {
+    public static final String ORACLE_JAXP_PROPERTY_PREFIX =
+        "http://www.oracle.com/xml/jaxp/properties/";
+
+    public static final String XML_FEATURE_MANAGER =
+            ORACLE_JAXP_PROPERTY_PREFIX + "XmlFeatureManager";
+
+    public static final String ORACLE_FEATURE_SERVICE_MECHANISM =
+            "http://www.oracle.com/feature/use-service-mechanism";
+
+    /**
+     * Feature enableExtensionFunctions
+     */
+    public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
+            ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
+    public static final String SP_ENABLE_EXTENSION_FUNCTION =
+            "javax.xml.enableExtensionFunctions";
+    // This is the correct name by the spec
+    public static final String SP_ENABLE_EXTENSION_FUNCTION_SPEC =
+            "jdk.xml.enableExtensionFunctions";
+
+    public static enum XmlFeature {
+        /**
+         * Feature enableExtensionFunctions
+         * FSP: extension function is enforced by FSP. When FSP is on, extension
+         * function is disabled.
+         */
+        ENABLE_EXTENSION_FUNCTION(ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION_SPEC,
+                ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION,
+                true, false, true, true),
+
+        /**
+         * Feature overrideDefaultParser
+         * FSP: not enforced by FSP.
+         */
+        JDK_OVERRIDE_PARSER(OVERRIDE_PARSER, OVERRIDE_PARSER,
+                ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM,
+                false, false, true, false);
+
+        private final String name;
+        private final String nameSP;
+        private final String nameOld;
+        private final String nameOldSP;
+        private final boolean valueDefault;
+        private final boolean valueEnforced;
+        private final boolean hasSystem;
+        private final boolean enforced;
+
+        /**
+         * Constructs an XmlFeature instance.
+         * @param name the name of the feature
+         * @param nameSP the name of the System Property
+         * @param nameOld the name of the corresponding legacy property
+         * @param nameOldSP the system property of the legacy property
+         * @param value the value of the feature
+         * @param hasSystem a flag to indicate whether the feature is supported
+         * @param enforced a flag indicating whether the feature is
+         * FSP (Feature_Secure_Processing) enforced
+         * with a System property
+         */
+        XmlFeature(String name, String nameSP, String nameOld, String nameOldSP,
+                boolean value, boolean valueEnforced, boolean hasSystem, boolean enforced) {
+            this.name = name;
+            this.nameSP = nameSP;
+            this.nameOld = nameOld;
+            this.nameOldSP = nameOldSP;
+            this.valueDefault = value;
+            this.valueEnforced = valueEnforced;
+            this.hasSystem = hasSystem;
+            this.enforced = enforced;
+        }
+
+        /**
+         * Checks whether the specified property is equal to the current property.
+         * @param propertyName the name of a property
+         * @return true if the specified property is the current property, false
+         * otherwise
+         */
+        boolean equalsPropertyName(String propertyName) {
+            return name.equals(propertyName) ||
+                    (nameOld != null && nameOld.equals(propertyName));
+        }
+
+        /**
+         * Returns the name of the property.
+         *
+         * @return the name of the property
+         */
+        public String apiProperty() {
+            return name;
+        }
+
+        /**
+         * Returns the name of the corresponding System Property.
+         *
+         * @return the name of the System Property
+         */
+        String systemProperty() {
+            return nameSP;
+        }
+
+        /**
+         * Returns the name of the legacy System Property.
+         *
+         * @return the name of the legacy System Property
+         */
+        String systemPropertyOld() {
+            return nameOldSP;
+        }
+
+        /**
+         * Returns the default value of the property.
+         * @return the default value of the property
+         */
+        public boolean defaultValue() {
+            return valueDefault;
+        }
+
+        /**
+         * Returns the FSP-enforced value.
+         * @return the FSP-enforced value
+         */
+        public boolean enforcedValue() {
+            return valueEnforced;
+        }
+
+        /**
+         * Checks whether System property is supported for the feature.
+         * @return true it is supported, false otherwise
+         */
+        boolean hasSystemProperty() {
+            return hasSystem;
+        }
+
+        /**
+         * Checks whether the property is enforced by FSP
+         * @return true it is, false otherwise
+         */
+        boolean enforced() {
+            return enforced;
+        }
+
+    }
+
+    /**
+     * States of the settings of a property, in the order: default value, value
+     * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
+     * properties, and jaxp api properties
+     */
+    public static enum State {
+        //this order reflects the overriding order
+
+        DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
+        JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
+        APIPROPERTY("property");
+
+        final String literal;
+        State(String literal) {
+            this.literal = literal;
+        }
+
+        String literal() {
+            return literal;
+        }
+    }
+
+    /**
+     * Values of the features
+     */
+    private final boolean[] featureValues;
+
+    /**
+     * States of the settings for each property
+     */
+    private final State[] states;
+
+    /**
+     * Flag indicating if secure processing is set
+     */
+    boolean secureProcessing;
+
+    /**
+     * Instantiate JdkXmlFeatures and initialize the fields
+     * @param secureProcessing
+     */
+    public JdkXmlFeatures(boolean secureProcessing) {
+        featureValues = new boolean[XmlFeature.values().length];
+        states = new State[XmlFeature.values().length];
+        this.secureProcessing = secureProcessing;
+        for (XmlFeature f : XmlFeature.values()) {
+            if (secureProcessing && f.enforced()) {
+                featureValues[f.ordinal()] = f.enforcedValue();
+                states[f.ordinal()] = State.FSP;
+            } else {
+                featureValues[f.ordinal()] = f.defaultValue();
+                states[f.ordinal()] = State.DEFAULT;
+            }
+        }
+        //read system properties or jaxp.properties
+        readSystemProperties();
+    }
+
+    /**
+     * Updates the JdkXmlFeatures instance by reading the system properties again.
+     * This will become necessary in case the system properties are set after
+     * the instance has been created.
+     */
+    public void update() {
+        readSystemProperties();
+    }
+
+    /**
+     * Set feature by property name and state
+     * @param propertyName property name
+     * @param state the state of the property
+     * @param value the value of the property
+     * @return true if the property is managed by the JdkXmlFeatures instance;
+     *         false otherwise.
+     */
+    public boolean setFeature(String propertyName, State state, Object value) {
+        int index = getIndex(propertyName);
+        if (index > -1) {
+            setFeature(index, state, value);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Set the value for a specific feature.
+     *
+     * @param feature the feature
+     * @param state the state of the property
+     * @param value the value of the property
+     */
+    public void setFeature(XmlFeature feature, State state, boolean value) {
+        setFeature(feature.ordinal(), state, value);
+    }
+
+    /**
+     * Return the value of the specified property
+     *
+     * @param feature the property
+     * @return the value of the property
+     */
+    public boolean getFeature(XmlFeature feature) {
+        return featureValues[feature.ordinal()];
+    }
+
+    /**
+     * Return the value of a feature by its index (the Feature's ordinal)
+     * @param index the index of a feature
+     * @return value of a feature
+     */
+    public boolean getFeature(int index) {
+        return featureValues[index];
+    }
+
+    /**
+     * Set the value of a property by its index
+     *
+     * @param index the index of the property
+     * @param state the state of the property
+     * @param value the value of the property
+     */
+    public void setFeature(int index, State state, Object value) {
+        boolean temp;
+        if (Boolean.class.isAssignableFrom(value.getClass())) {
+            temp = (Boolean)value;
+        } else {
+            temp = Boolean.parseBoolean((String) value);
+        }
+        setFeature(index, state, temp);
+    }
+
+    /**
+     * Set the value of a property by its index
+     *
+     * @param index the index of the property
+     * @param state the state of the property
+     * @param value the value of the property
+     */
+    public void setFeature(int index, State state, boolean value) {
+        //only update if it shall override
+        if (state.compareTo(states[index]) >= 0) {
+            featureValues[index] = value;
+            states[index] = state;
+        }
+    }
+
+    /**
+     * Get the index by property name
+     *
+     * @param propertyName property name
+     * @return the index of the property if found; return -1 if not
+     */
+    public int getIndex(String propertyName) {
+        for (XmlFeature feature : XmlFeature.values()) {
+            if (feature.equalsPropertyName(propertyName)) {
+                //internally, ordinal is used as index
+                return feature.ordinal();
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Read from system properties, or those in jaxp.properties
+     */
+    private void readSystemProperties() {
+        for (XmlFeature feature : XmlFeature.values()) {
+            if (!getSystemProperty(feature, feature.systemProperty())) {
+                //if system property is not found, try the older form if any
+                String oldName = feature.systemPropertyOld();
+                if (oldName != null) {
+                    getSystemProperty(feature, oldName);
+                }
+            }
+        }
+    }
+
+    /**
+     * Read from system properties, or those in jaxp.properties
+     *
+     * @param feature the feature get
+     * @param sysPropertyName the name of system property
+     * @return true if the system property is found, false otherwise
+     */
+    private boolean getSystemProperty(XmlFeature feature, String sysPropertyName) {
+        try {
+            String value = SecuritySupport.getSystemProperty(sysPropertyName);
+            if (value != null && !value.equals("")) {
+                setFeature(feature, State.SYSTEMPROPERTY, Boolean.parseBoolean(value));
+                return true;
+            }
+
+            value = SecuritySupport.readJAXPProperty(sysPropertyName);
+            if (value != null && !value.equals("")) {
+                setFeature(feature, State.JAXPDOTPROPERTIES, Boolean.parseBoolean(value));
+                return true;
+            }
+        } catch (NumberFormatException e) {
+            //invalid setting
+            throw new NumberFormatException("Invalid setting for system property: " + feature.systemProperty());
+        }
+        return false;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/xml/internal/JdkXmlUtils.java	Thu Oct 19 17:03:20 2017 +0100
@@ -0,0 +1,269 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 jdk.xml.internal;
+
+import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
+import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
+import com.sun.org.apache.xerces.internal.impl.Constants;
+import com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl;
+import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+
+/**
+ * Constants for use across JAXP processors.
+ */
+public class JdkXmlUtils {
+    private static final String DOM_FACTORY_ID = "javax.xml.parsers.DocumentBuilderFactory";
+    private static final String SAX_FACTORY_ID = "javax.xml.parsers.SAXParserFactory";
+    private static final String SAX_DRIVER = "org.xml.sax.driver";
+
+    /**
+     * Xerces features
+     */
+    public static final String NAMESPACES_FEATURE =
+        Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
+    public static final String NAMESPACE_PREFIXES_FEATURE =
+        Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACE_PREFIXES_FEATURE;
+
+    /**
+     * jdk.xml.overrideDefaultParser: enables the use of a 3rd party's parser
+     * implementation to override the system-default parser.
+     */
+    public static final String OVERRIDE_PARSER = "jdk.xml.overrideDefaultParser";
+    public static final boolean OVERRIDE_PARSER_DEFAULT = SecuritySupport.getJAXPSystemProperty(
+                    Boolean.class, OVERRIDE_PARSER, "false");
+
+    /**
+     * Values for a feature
+     */
+    public static final String FEATURE_TRUE = "true";
+    public static final String FEATURE_FALSE = "false";
+
+    /**
+     * The system-default factory
+     */
+    private static final SAXParserFactory defaultSAXFactory = getSAXFactory(false);
+
+    /**
+     * Returns the value.
+     *
+     * @param value the specified value
+     * @param defValue the default value
+     * @return the value, or the default value if the value is null
+     */
+    public static int getValue(Object value, int defValue) {
+        if (value == null) {
+            return defValue;
+        }
+
+        if (value instanceof Number) {
+            return ((Number) value).intValue();
+        } else if (value instanceof String) {
+            return Integer.parseInt(String.valueOf(value));
+        } else {
+            throw new IllegalArgumentException("Unexpected class: "
+                    + value.getClass());
+        }
+    }
+
+    /**
+     * Sets the XMLReader instance with the specified property if the the
+     * property is supported, ignores error if not, issues a warning if so
+     * requested.
+     *
+     * @param reader an XMLReader instance
+     * @param property the name of the property
+     * @param value the value of the property
+     * @param warn a flag indicating whether a warning should be issued
+     */
+    public static void setXMLReaderPropertyIfSupport(XMLReader reader, String property,
+            Object value, boolean warn) {
+        try {
+            reader.setProperty(property, value);
+        } catch (SAXNotRecognizedException | SAXNotSupportedException e) {
+            if (warn) {
+                XMLSecurityManager.printWarning(reader.getClass().getName(),
+                        property, e);
+            }
+        }
+    }
+
+    /**
+     * Returns an XMLReader instance. If overrideDefaultParser is requested, use
+     * SAXParserFactory or XMLReaderFactory, otherwise use the system-default
+     * SAXParserFactory to locate an XMLReader.
+     *
+     * @param overrideDefaultParser a flag indicating whether a 3rd party's
+     * parser implementation may be used to override the system-default one
+     * @param secureProcessing a flag indicating whether secure processing is
+     * requested
+     * @return an XMLReader instance
+     */
+    public static XMLReader getXMLReader(boolean overrideDefaultParser,
+            boolean secureProcessing) {
+        SAXParserFactory saxFactory;
+        XMLReader reader = null;
+        String spSAXDriver = SecuritySupport.getSystemProperty(SAX_DRIVER);
+        if (spSAXDriver != null) {
+            reader = getXMLReaderWXMLReaderFactory();
+        } else if (overrideDefaultParser) {
+            reader = getXMLReaderWSAXFactory(overrideDefaultParser);
+        }
+
+        if (reader != null) {
+            if (secureProcessing) {
+                try {
+                    reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, secureProcessing);
+                } catch (SAXException e) {
+                    XMLSecurityManager.printWarning(reader.getClass().getName(),
+                            XMLConstants.FEATURE_SECURE_PROCESSING, e);
+                }
+            }
+            try {
+                reader.setFeature(NAMESPACES_FEATURE, true);
+                reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
+            } catch (SAXException se) {
+                // older version of a parser
+            }
+            return reader;
+        }
+
+        // use the system-default
+        saxFactory = defaultSAXFactory;
+
+        try {
+            reader = saxFactory.newSAXParser().getXMLReader();
+        } catch (ParserConfigurationException | SAXException ex) {
+            // shall not happen with the system-default reader
+        }
+        return reader;
+    }
+
+    /**
+     * Creates a system-default DOM Document.
+     *
+     * @return a DOM Document instance
+     */
+    public static Document getDOMDocument() {
+        try {
+            DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(false);
+            return dbf.newDocumentBuilder().newDocument();
+        } catch (ParserConfigurationException pce) {
+            // can never happen with the system-default configuration
+        }
+        return null;
+    }
+
+    /**
+     * Returns a DocumentBuilderFactory instance.
+     *
+     * @param overrideDefaultParser a flag indicating whether the system-default
+     * implementation may be overridden. If the system property of the
+     * DOM factory ID is set, override is always allowed.
+     *
+     * @return a DocumentBuilderFactory instance.
+     */
+    public static DocumentBuilderFactory getDOMFactory(boolean overrideDefaultParser) {
+        boolean override = overrideDefaultParser;
+        String spDOMFactory = SecuritySupport.getJAXPSystemProperty(DOM_FACTORY_ID);
+
+        if (spDOMFactory != null && System.getSecurityManager() == null) {
+            override = true;
+        }
+        DocumentBuilderFactory dbf
+                = !override
+                        ? new DocumentBuilderFactoryImpl()
+                        : DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        // false is the default setting. This step here is for compatibility
+        dbf.setValidating(false);
+        return dbf;
+    }
+
+    /**
+     * Returns a SAXParserFactory instance.
+     *
+     * @param overrideDefaultParser a flag indicating whether the system-default
+     * implementation may be overridden. If the system property of the
+     * DOM factory ID is set, override is always allowed.
+     *
+     * @return a SAXParserFactory instance.
+     */
+    public static SAXParserFactory getSAXFactory(boolean overrideDefaultParser) {
+        boolean override = overrideDefaultParser;
+        String spSAXFactory = SecuritySupport.getJAXPSystemProperty(SAX_FACTORY_ID);
+        if (spSAXFactory != null && System.getSecurityManager() == null) {
+            override = true;
+        }
+
+        SAXParserFactory factory
+                = !override
+                        ? new SAXParserFactoryImpl()
+                        : SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        return factory;
+    }
+
+    public static SAXTransformerFactory getSAXTransformFactory(boolean overrideDefaultParser) {
+        SAXTransformerFactory tf = overrideDefaultParser
+                ? (SAXTransformerFactory) SAXTransformerFactory.newInstance()
+                : (SAXTransformerFactory) new TransformerFactoryImpl();
+        try {
+            tf.setFeature(OVERRIDE_PARSER, overrideDefaultParser);
+        } catch (TransformerConfigurationException ex) {
+            // ignore since it'd never happen with the JDK impl.
+        }
+        return tf;
+    }
+
+    private static XMLReader getXMLReaderWSAXFactory(boolean overrideDefaultParser) {
+        SAXParserFactory saxFactory = getSAXFactory(overrideDefaultParser);
+        try {
+            return saxFactory.newSAXParser().getXMLReader();
+        } catch (ParserConfigurationException | SAXException ex) {
+            return getXMLReaderWXMLReaderFactory();
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private static XMLReader getXMLReaderWXMLReaderFactory() {
+        try {
+            return org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
+        } catch (SAXException ex1) {
+        }
+        return null;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk/xml/internal/SecuritySupport.java	Thu Oct 19 17:03:20 2017 +0100
@@ -0,0 +1,168 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 jdk.xml.internal;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Properties;
+
+/**
+ * This class contains utility methods for reading resources in the JAXP packages
+ */
+class SecuritySupport {
+    /**
+     * Cache for properties in java.home/lib/jaxp.properties
+     */
+    static final Properties cacheProps = new Properties();
+
+    /**
+     * Flag indicating whether java.home/lib/jaxp.properties has been read
+     */
+    static volatile boolean firstTime = true;
+
+    private SecuritySupport() {}
+
+    /**
+     * Reads JAXP system property with privilege
+     *
+     * @param propName the name of the property
+     * @return the value of the property
+     */
+    public static String getSystemProperty(final String propName) {
+        return AccessController.doPrivileged(new PrivilegedAction<String>() {
+            @Override
+            public String run() {
+                return System.getProperty(propName);
+            }
+        });
+    }
+
+    /**
+     * Reads a system property.
+     *
+     * @param <T> the type of the property value
+     * @param type the type of the property value
+     * @param propName the name of the property
+     * @param defValue the default value
+     * @return the value of the property, or the default value of no system
+     * property is found
+     */
+    public static <T> T getJAXPSystemProperty(Class<T> type, String propName, String defValue) {
+        String value = getJAXPSystemProperty(propName);
+        if (value == null) {
+            value = defValue;
+        }
+        if (Integer.class.isAssignableFrom(type)) {
+            return type.cast(Integer.parseInt(value));
+        } else if (Boolean.class.isAssignableFrom(type)) {
+            return type.cast(Boolean.parseBoolean(value));
+        }
+        return type.cast(value);
+    }
+
+    /**
+     * Reads JAXP system property in this order: system property,
+     * $java.home/lib/jaxp.properties if the system property is not specified
+     *
+     * @param propName the name of the property
+     * @return the value of the property
+     */
+    public static String getJAXPSystemProperty(String propName) {
+        String value = getSystemProperty(propName);
+        if (value == null) {
+            value = readJAXPProperty(propName);
+        }
+        return value;
+    }
+
+    /**
+     * Reads the specified property from $java.home/lib/jaxp.properties
+     *
+     * @param propName the name of the property
+     * @return the value of the property
+     */
+    public static String readJAXPProperty(String propName) {
+        String value = null;
+        InputStream is = null;
+        try {
+            if (firstTime) {
+                synchronized (cacheProps) {
+                    if (firstTime) {
+                        String configFile = getSystemProperty("java.home") + File.separator
+                                + "lib" + File.separator + "jaxp.properties";
+                        File f = new File(configFile);
+                        if (getFileExists(f)) {
+                            is = getFileInputStream(f);
+                            cacheProps.load(is);
+                        }
+                        firstTime = false;
+                    }
+                }
+            }
+            value = cacheProps.getProperty(propName);
+
+        } catch (IOException ex) {
+        } finally {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (IOException ex) {}
+            }
+        }
+
+        return value;
+    }
+
+//------------------- private methods ---------------------------
+    static boolean getFileExists(final File f) {
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+            @Override
+            public Boolean run() {
+                return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+            }
+        });
+    }
+
+    static FileInputStream getFileInputStream(final File file) throws FileNotFoundException {
+        try {
+            return AccessController.doPrivileged(new PrivilegedExceptionAction<FileInputStream>() {
+                @Override
+                public FileInputStream run() throws Exception {
+                    return new FileInputStream(file);
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            throw (FileNotFoundException) e.getException();
+        }
+    }
+}