--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltDynamic.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltDynamic.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -36,6 +35,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;
@@ -410,10 +410,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/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -22,12 +21,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;
@@ -51,7 +46,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.
@@ -226,7 +220,7 @@
token = str.substring(fromIndex);
}
- Document doc = getDocument();
+ Document doc = JdkXmlUtils.getDOMDocument();
synchronized (doc)
{
Element element = doc.createElement("token");
@@ -290,7 +284,7 @@
{
StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
- Document doc = getDocument();
+ Document doc = JdkXmlUtils.getDOMDocument();
synchronized (doc)
{
while (lTokenizer.hasMoreTokens())
@@ -306,7 +300,7 @@
else
{
- Document doc = getDocument();
+ Document doc = JdkXmlUtils.getDOMDocument();
synchronized (doc)
{
for (int i = 0; i < toTokenize.length(); i++)
@@ -328,23 +322,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/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/Extensions.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/Extensions.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,14 +22,12 @@
import java.util.StringTokenizer;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
import com.sun.org.apache.xpath.internal.NodeSet;
import com.sun.org.apache.xpath.internal.objects.XBoolean;
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.DocumentFragment;
@@ -51,7 +48,6 @@
*/
public class Extensions
{
- static final String JDK_DEFAULT_DOM = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
/**
* Constructor Extensions
*
@@ -110,7 +106,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 +232,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();
@@ -269,23 +265,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/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/FactoryImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2011, 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 com.sun.org.apache.xalan.internal.utils;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.SAXParserFactory;
-
-/**
- *
- * @author huizhe wang
- */
-public class FactoryImpl {
-
- static final String DBF = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
- static final String SF = "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl";
-
- static public DocumentBuilderFactory getDOMFactory(boolean useServicesMechanism) {
- DocumentBuilderFactory dbf =
- useServicesMechanism ?
- DocumentBuilderFactory.newInstance() :
- DocumentBuilderFactory.newInstance( DBF,
- FactoryImpl.class.getClassLoader());
-
- return dbf;
- }
- static public SAXParserFactory getSAXFactory(boolean useServicesMechanism) {
- SAXParserFactory factory =
- useServicesMechanism ?
- SAXParserFactory.newInstance() :
- SAXParserFactory.newInstance(SF,
- FactoryImpl.class.getClassLoader());
- return factory;
- }
-}
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/Translet.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/Translet.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * @LastModified: Oct 2017
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -49,7 +50,7 @@
public String[] getUrisArray();
public int[] getTypesArray();
public String[] getNamespaceArray();
- public boolean useServicesMechnism();
- public void setServicesMechnism(boolean flag);
+ public boolean overrideDefaultParser();
+ public void setOverrideDefaultParser(boolean flag);
}
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java Wed Oct 04 10:33:08 2017 -0700
@@ -22,7 +22,6 @@
import com.sun.java_cup.internal.runtime.Symbol;
import com.sun.org.apache.xalan.internal.XalanConstants;
-import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
@@ -43,9 +42,6 @@
import java.util.StringTokenizer;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
@@ -56,7 +52,6 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.AttributesImpl;
@@ -101,11 +96,11 @@
private int _currentImportPrecedence;
- private boolean _useServicesMechanism = true;
+ private boolean _overrideDefaultParser;
- public Parser(XSLTC xsltc, boolean useServicesMechanism) {
+ public Parser(XSLTC xsltc, boolean useOverrideDefaultParser) {
_xsltc = xsltc;
- _useServicesMechanism = useServicesMechanism;
+ _overrideDefaultParser = useOverrideDefaultParser;
}
public void init() {
@@ -465,56 +460,35 @@
*/
public SyntaxTreeNode parse(InputSource input) {
try {
- // Create a SAX parser and get the XMLReader object it uses
- final SAXParserFactory factory = FactoryImpl.getSAXFactory(_useServicesMechanism);
-
- if (_xsltc.isSecureProcessing()) {
- try {
- factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- }
- catch (SAXException e) {}
- }
+ final XMLReader reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser,
+ _xsltc.isSecureProcessing());
- try {
- factory.setFeature(Constants.NAMESPACE_FEATURE,true);
- }
- catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
- factory.setNamespaceAware(true);
- }
+ JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, XMLConstants.ACCESS_EXTERNAL_DTD,
+ _xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD), true);
- final SAXParser parser = factory.newSAXParser();
- try {
- parser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD,
- _xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD));
- } catch (SAXNotRecognizedException e) {
- ErrorMsg err = new ErrorMsg(ErrorMsg.WARNING_MSG,
- parser.getClass().getName() + ": " + e.getMessage());
- reportError(WARNING, err);
- }
boolean supportCatalog = true;
boolean useCatalog = _xsltc.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG);
try {
- factory.setFeature(JdkXmlUtils.USE_CATALOG,useCatalog);
+ reader.setFeature(JdkXmlUtils.USE_CATALOG, useCatalog);
}
- catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
+ catch (SAXNotRecognizedException | SAXNotSupportedException e) {
supportCatalog = false;
}
if (supportCatalog && useCatalog) {
try {
CatalogFeatures cf = (CatalogFeatures)_xsltc.getProperty(JdkXmlFeatures.CATALOG_FEATURES);
- if (cf != null) {
- for (CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) {
- parser.setProperty(f.getPropertyName(), cf.get(f));
+ if (cf != null) {
+ for (CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) {
+ reader.setProperty(f.getPropertyName(), cf.get(f));
+ }
}
- }
} catch (SAXNotRecognizedException e) {
//shall not happen for internal settings
}
}
- final XMLReader reader = parser.getXMLReader();
String lastProperty = "";
try {
XMLSecurityManager securityManager =
@@ -525,7 +499,7 @@
}
if (securityManager.printEntityCountInfo()) {
lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
- parser.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
+ reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
}
} catch (SAXException se) {
XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);
@@ -537,13 +511,6 @@
return(parse(reader, input));
}
- catch (ParserConfigurationException e) {
- ErrorMsg err = new ErrorMsg(ErrorMsg.SAX_PARSER_CONFIG_ERR);
- reportError(ERROR, err);
- }
- catch (SAXParseException e){
- reportError(ERROR, new ErrorMsg(e.getMessage(),e.getLineNumber()));
- }
catch (SAXException e) {
reportError(ERROR, new ErrorMsg(e.getMessage()));
}
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java Wed Oct 04 10:33:08 2017 -0700
@@ -135,7 +135,7 @@
*/
private boolean _isSecureProcessing = false;
- private boolean _useServicesMechanism = true;
+ private boolean _overrideDefaultParser;
/**
* protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
@@ -175,8 +175,10 @@
/**
* XSLTC compiler constructor
*/
- public XSLTC(boolean useServicesMechanism, JdkXmlFeatures featureManager) {
- _parser = new Parser(this, useServicesMechanism);
+ public XSLTC(JdkXmlFeatures featureManager) {
+ _overrideDefaultParser = featureManager.getFeature(
+ JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
+ _parser = new Parser(this, _overrideDefaultParser);
_xmlFeatures = featureManager;
_extensionClassLoader = null;
_externalExtensionFunctions = new HashMap<>();
@@ -195,19 +197,6 @@
public boolean isSecureProcessing() {
return _isSecureProcessing;
}
- /**
- * Return the state of the services mechanism feature.
- */
- public boolean useServicesMechnism() {
- return _useServicesMechanism;
- }
-
- /**
- * Set the state of the services mechanism feature.
- */
- public void setServicesMechnism(boolean flag) {
- _useServicesMechanism = flag;
- }
/**
* Return the value of the specified feature
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java Wed Oct 04 10:33:08 2017 -0700
@@ -21,7 +21,6 @@
package com.sun.org.apache.xalan.internal.xsltc.runtime;
import com.sun.org.apache.xalan.internal.XalanConstants;
-import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
import com.sun.org.apache.xalan.internal.xsltc.DOMEnhancedForDTM;
@@ -45,6 +44,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;
@@ -106,7 +106,7 @@
// This is the name of the index used for ID attributes
private final static String ID_INDEX_NAME = "##id";
- private boolean _useServicesMechanism;
+ private boolean _overrideDefaultParser;
// The OutputStream for redirect function
private FileOutputStream output = null;
@@ -559,7 +559,7 @@
{
try {
final TransletOutputHandlerFactory factory
- = TransletOutputHandlerFactory.newInstance();
+ = TransletOutputHandlerFactory.newInstance(_overrideDefaultParser);
String dirStr = new File(filename).getParent();
if ((null != dirStr) && (dirStr.length() > 0)) {
@@ -761,15 +761,15 @@
/**
* Return the state of the services mechanism feature.
*/
- public boolean useServicesMechnism() {
- return _useServicesMechanism;
+ public boolean overrideDefaultParser() {
+ return _overrideDefaultParser;
}
/**
* Set the state of the services mechanism feature.
*/
- public void setServicesMechnism(boolean flag) {
- _useServicesMechanism = flag;
+ public void setOverrideDefaultParser(boolean flag) {
+ _overrideDefaultParser = flag;
}
/**
@@ -795,7 +795,7 @@
throws ParserConfigurationException
{
if (_domImplementation == null) {
- DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(_useServicesMechanism);
+ DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(_overrideDefaultParser);
_domImplementation = dbf.newDocumentBuilder().getDOMImplementation();
}
return _domImplementation.createDocument(uri, qname, null);
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/output/TransletOutputHandlerFactory.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/output/TransletOutputHandlerFactory.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * @LastModified: Oct 2017
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -70,17 +71,17 @@
private ContentHandler _handler = null;
private LexicalHandler _lexHandler = null;
- private boolean _useServicesMechanism;
+ private boolean _overrideDefaultParser;
static public TransletOutputHandlerFactory newInstance() {
return new TransletOutputHandlerFactory(true);
}
- static public TransletOutputHandlerFactory newInstance(boolean useServicesMechanism) {
- return new TransletOutputHandlerFactory(useServicesMechanism);
+ static public TransletOutputHandlerFactory newInstance(boolean overrideDefaultParser) {
+ return new TransletOutputHandlerFactory(overrideDefaultParser);
}
- public TransletOutputHandlerFactory(boolean useServicesMechanism) {
- _useServicesMechanism = useServicesMechanism;
+ public TransletOutputHandlerFactory(boolean overrideDefaultParser) {
+ _overrideDefaultParser = overrideDefaultParser;
}
public void setOutputType(int outputType) {
_outputType = outputType;
@@ -195,7 +196,9 @@
return result;
case DOM :
- _handler = (_node != null) ? new SAX2DOM(_node, _nextSibling, _useServicesMechanism) : new SAX2DOM(_useServicesMechanism);
+ _handler = (_node != null) ?
+ new SAX2DOM(_node, _nextSibling, _overrideDefaultParser) :
+ new SAX2DOM(_overrideDefaultParser);
_lexHandler = (LexicalHandler) _handler;
// falls through
case STAX :
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/SAX2DOM.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/SAX2DOM.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * @LastModified: Oct 2017
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,15 +26,18 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
-import javax.xml.parsers.DocumentBuilder;
+
import javax.xml.parsers.DocumentBuilderFactory;
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.ProcessingInstruction;
-import org.w3c.dom.Text;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
@@ -66,16 +70,16 @@
* synchronization because the Javadoc is not explicit about
* thread safety.
*/
- private DocumentBuilderFactory _factory =
- DocumentBuilderFactory.newInstance();
+ private DocumentBuilderFactory _factory;
private boolean _internal = true;
- public SAX2DOM(boolean useServicesMechanism) throws ParserConfigurationException {
- _document = createDocument(useServicesMechanism);
+ public SAX2DOM(boolean overrideDefaultParser) throws ParserConfigurationException {
+ _document = createDocument(overrideDefaultParser);
_root = _document;
}
- public SAX2DOM(Node root, Node nextSibling, boolean useServicesMechanism) throws ParserConfigurationException {
+ public SAX2DOM(Node root, Node nextSibling, boolean overrideDefaultParser)
+ throws ParserConfigurationException {
_root = root;
if (root instanceof Document) {
_document = (Document)root;
@@ -84,15 +88,16 @@
_document = root.getOwnerDocument();
}
else {
- _document = createDocument(useServicesMechanism);
+ _document = createDocument(overrideDefaultParser);
_root = _document;
}
_nextSibling = nextSibling;
}
- public SAX2DOM(Node root, boolean useServicesMechanism) throws ParserConfigurationException {
- this(root, null, useServicesMechanism);
+ public SAX2DOM(Node root, boolean overrideDefaultParser)
+ throws ParserConfigurationException {
+ this(root, null, overrideDefaultParser);
}
public Node getDOM() {
@@ -304,18 +309,13 @@
public void startDTD(String name, String publicId, String systemId)
throws SAXException {}
- private Document createDocument(boolean useServicesMechanism) throws ParserConfigurationException {
+ private Document createDocument(boolean overrideDefaultParser)
+ throws ParserConfigurationException {
if (_factory == null) {
- if (useServicesMechanism) {
- _factory = DocumentBuilderFactory.newInstance();
- if (!(_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl)) {
- _internal = false;
- }
- } else {
- _factory = DocumentBuilderFactory.newInstance(
- "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl",
- SAX2DOM.class.getClassLoader()
- );
+ _factory = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
+ _internal = true;
+ if (!(_factory instanceof com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl)) {
+ _internal = false;
}
}
Document doc;
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2016, 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
@@ -98,7 +98,7 @@
_tfactory = tfactory;
// Instantiate XSLTC and get reference to parser object
- XSLTC xsltc = new XSLTC(tfactory.useServicesMechnism(), tfactory.getJdkXmlFeatures());
+ XSLTC xsltc = new XSLTC(tfactory.getJdkXmlFeatures());
if (tfactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING))
xsltc.setSecureProcessing(true);
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -142,9 +142,9 @@
private transient TransformerFactoryImpl _tfactory = null;
/**
- * A flag to determine whether the Service Mechanism is used
+ * A flag to determine whether the system-default parser may be overridden
*/
- private transient boolean _useServicesMechanism;
+ private transient boolean _overrideDefaultParser;
/**
* protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
@@ -241,7 +241,7 @@
_outputProperties = outputProperties;
_indentNumber = indentNumber;
_tfactory = tfactory;
- _useServicesMechanism = tfactory.useServicesMechnism();
+ _overrideDefaultParser = tfactory.overrideDefaultParser();
_accessExternalStylesheet = (String) tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET);
}
/**
@@ -324,8 +324,8 @@
/**
* Return the state of the services mechanism feature.
*/
- public boolean useServicesMechnism() {
- return _useServicesMechanism;
+ public boolean overrideDefaultParser() {
+ return _overrideDefaultParser;
}
/**
@@ -556,7 +556,7 @@
_class[_transletIndex].getConstructor().newInstance();
translet.postInitialization();
translet.setTemplates(this);
- translet.setServicesMechnism(_useServicesMechanism);
+ translet.setOverrideDefaultParser(_overrideDefaultParser);
translet.setAllowedProtocols(_accessExternalStylesheet);
if (_auxClasses != null) {
translet.setAuxiliaryClasses(_auxClasses);
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TrAXFilter.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TrAXFilter.java Wed Oct 04 10:33:08 2017 -0700
@@ -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
@@ -23,11 +23,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;
@@ -35,13 +30,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.
@@ -53,7 +48,7 @@
private Templates _templates;
private TransformerImpl _transformer;
private TransformerHandlerImpl _transformerHandler;
- private boolean _useServicesMechanism = true;
+ private boolean _overrideDefaultParser;
public TrAXFilter(Templates templates) throws
TransformerConfigurationException
@@ -61,7 +56,7 @@
_templates = templates;
_transformer = (TransformerImpl) templates.newTransformer();
_transformerHandler = new TransformerHandlerImpl(_transformer);
- _useServicesMechanism = _transformer.useServicesMechnism();
+ _overrideDefaultParser = _transformer.overrideDefaultParser();
}
public Transformer getTransformer() {
@@ -69,36 +64,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 +79,7 @@
try {
if (getParent() == null) {
try {
- managedReader = XMLReaderManager.getInstance(_useServicesMechanism)
+ managedReader = XMLReaderManager.getInstance(_overrideDefaultParser)
.getXMLReader();
setParent(managedReader);
} catch (SAXException e) {
@@ -118,7 +91,7 @@
getParent().parse(input);
} finally {
if (managedReader != null) {
- XMLReaderManager.getInstance(_useServicesMechanism).releaseXMLReader(managedReader);
+ XMLReaderManager.getInstance(_overrideDefaultParser).releaseXMLReader(managedReader);
}
}
}
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -21,7 +21,6 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
-import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase;
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
@@ -55,15 +54,12 @@
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogManager;
import javax.xml.catalog.CatalogResolver;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
@@ -79,18 +75,17 @@
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import org.xml.sax.XMLFilter;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
- * Implementation of a JAXP1.1 TransformerFactory for Translets.
+ * Implementation of a JAXP TransformerFactory for Translets.
* @author G. Todd Miller
* @author Morten Jorgensen
* @author Santiago Pericas-Geertsen
* @LastModified: Nov 2017
*/
-@SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory
public class TransformerFactoryImpl
extends SAXTransformerFactory implements SourceLoader, ErrorListener
{
@@ -216,11 +211,11 @@
private boolean _isSecureMode = false;
/**
- * Indicates whether implementation parts should use
- * service loader (or similar).
- * Note the default value (false) is the safe option..
+ * 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 _useServicesMechanism;
+ private boolean _overrideDefaultParser;
/**
* protocols allowed for external references set by the stylesheet
@@ -259,15 +254,6 @@
* javax.xml.transform.sax.TransformerFactory implementation.
*/
public TransformerFactoryImpl() {
- this(true);
- }
-
- public static TransformerFactory newTransformerFactoryNoServiceLoader() {
- return new TransformerFactoryImpl(false);
- }
-
- private TransformerFactoryImpl(boolean useServicesMechanism) {
- this._useServicesMechanism = useServicesMechanism;
if (System.getSecurityManager() != null) {
_isSecureMode = true;
@@ -275,6 +261,8 @@
}
_xmlFeatures = new JdkXmlFeatures(!_isNotSecureProcessing);
+ _overrideDefaultParser = _xmlFeatures.getFeature(
+ JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
_xmlSecurityPropertyMgr = new XMLSecurityPropertyManager();
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue(
Property.ACCESS_EXTERNAL_DTD);
@@ -594,14 +582,20 @@
JdkXmlFeatures.State.FSP, false);
}
}
- else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
- //in secure mode, let _useServicesMechanism be determined by the constructor
- if (!_isSecureMode)
- _useServicesMechanism = value;
- }
else {
+ if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
+ // for compatibility, in secure mode, useServicesMechanism is determined by the constructor
+ if (_isSecureMode) {
+ return;
+ }
+ }
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;
}
@@ -666,8 +660,8 @@
/**
* Return the state of the services mechanism feature.
*/
- public boolean useServicesMechnism() {
- return _useServicesMechanism;
+ public boolean overrideDefaultParser() {
+ return _overrideDefaultParser;
}
/**
@@ -726,10 +720,9 @@
throws TransformerConfigurationException {
String baseId;
- XMLReader reader;
+ XMLReader reader = null;
InputSource isource;
-
/**
* Fix for bugzilla bug 24187
*/
@@ -748,24 +741,15 @@
dom2sax.setContentHandler( _stylesheetPIHandler);
dom2sax.parse();
} else {
+ if (source instanceof SAXSource) {
+ reader = ((SAXSource)source).getXMLReader();
+ }
isource = SAXSource.sourceToInputSource(source);
baseId = isource.getSystemId();
- SAXParserFactory factory = FactoryImpl.getSAXFactory(_useServicesMechanism);
- 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);
@@ -781,7 +765,7 @@
} catch (StopParseException e ) {
// startElement encountered so do not parse further
- } catch (javax.xml.parsers.ParserConfigurationException | org.xml.sax.SAXException | IOException e) {
+ } catch (SAXException | IOException e) {
throw new TransformerConfigurationException(
"getAssociatedStylesheets failed", e);
}
@@ -962,7 +946,7 @@
}
// Create and initialize a stylesheet compiler
- final XSLTC xsltc = new XSLTC(_useServicesMechanism, _xmlFeatures);
+ final XSLTC xsltc = new XSLTC(_xmlFeatures);
if (_debug) xsltc.setDebug(true);
if (_enableInlining)
xsltc.setTemplateInlining(true);
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -21,7 +21,6 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
-import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.DOMCache;
@@ -102,8 +101,6 @@
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}.
@@ -200,15 +197,10 @@
private boolean _isSecureProcessing = false;
/**
- * Indicates whether implementation parts should use
- * service loader (or similar).
- * Note the default value (false) is the safe option..
+ * Indicates whether 3rd party parser may be used to override the system-default
*/
- private boolean _useServicesMechanism;
- /**
- * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
- */
- private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
+ private boolean _overrideDefaultParser;
+
/**
* protocols allowed for external DTD references in source file and/or stylesheet.
*/
@@ -276,11 +268,10 @@
_propertiesClone = (Properties) _properties.clone();
_indentNumber = indentNumber;
_tfactory = tfactory;
- _useServicesMechanism = _tfactory.useServicesMechnism();
- _accessExternalStylesheet = (String)_tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET);
+ _overrideDefaultParser = _tfactory.overrideDefaultParser();
_accessExternalDTD = (String)_tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_DTD);
_securityManager = (XMLSecurityManager)_tfactory.getAttribute(XalanConstants.SECURITY_MANAGER);
- _readerManager = XMLReaderManager.getInstance(_useServicesMechanism);
+ _readerManager = XMLReaderManager.getInstance(_overrideDefaultParser);
_readerManager.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
_readerManager.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _isSecureProcessing);
_readerManager.setProperty(XalanConstants.SECURITY_MANAGER, _securityManager);
@@ -317,15 +308,15 @@
/**
* Return the state of the services mechanism feature.
*/
- public boolean useServicesMechnism() {
- return _useServicesMechanism;
+ public boolean overrideDefaultParser() {
+ return _overrideDefaultParser;
}
/**
* Set the state of the services mechanism feature.
*/
- public void setServicesMechnism(boolean flag) {
- _useServicesMechanism = flag;
+ public void setOverrideDefaultParser(boolean flag) {
+ _overrideDefaultParser = flag;
}
/**
@@ -409,7 +400,7 @@
// Get encoding using getProperty() to use defaults
_encoding = _properties.getProperty(OutputKeys.ENCODING);
- _tohFactory = TransletOutputHandlerFactory.newInstance(_useServicesMechanism);
+ _tohFactory = TransletOutputHandlerFactory.newInstance(_overrideDefaultParser);
_tohFactory.setEncoding(_encoding);
if (_method != null) {
_tohFactory.setOutputMethod(_method);
@@ -579,7 +570,7 @@
if (_dtmManager == null) {
_dtmManager =
_tfactory.createNewDTMManagerInstance();
- _dtmManager.setServicesMechnism(_useServicesMechanism);
+ _dtmManager.setOverrideDefaultParser(_overrideDefaultParser);
}
dom = (DOM)_dtmManager.getDTM(source, false, wsfilter, true,
false, false, 0, hasIdCall);
@@ -754,7 +745,7 @@
boolean supportCatalog = true;
- DocumentBuilderFactory builderF = FactoryImpl.getDOMFactory(_useServicesMechanism);
+ DocumentBuilderFactory builderF = JdkXmlUtils.getDOMFactory(_overrideDefaultParser);
try {
builderF.setFeature(XMLConstants.USE_CATALOG, _useCatalog);
} catch (ParserConfigurationException e) {
--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/Util.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/Util.java Wed Oct 04 10:33:08 2017 -0700
@@ -21,7 +21,6 @@
package com.sun.org.apache.xalan.internal.xsltc.trax;
import com.sun.org.apache.xalan.internal.XalanConstants;
-import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
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;
@@ -30,8 +29,6 @@
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogFeatures.Feature;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
@@ -42,13 +39,13 @@
import javax.xml.transform.stream.StreamSource;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
+import jdk.xml.internal.SecuritySupport;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
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
@@ -57,6 +54,7 @@
*/
@SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory
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);
@@ -89,54 +87,18 @@
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 = FactoryImpl.getSAXFactory(xsltc.useServicesMechnism());
- 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);
- }
- }
+ 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);
JdkXmlUtils.setXMLReaderPropertyIfSupport(reader, XMLConstants.ACCESS_EXTERNAL_DTD,
xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD), true);
@@ -192,9 +154,6 @@
}catch (SAXNotSupportedException snse ) {
throw new TransformerConfigurationException
("SAXNotSupportedException ",snse);
- }catch (SAXException se ) {
- throw new TransformerConfigurationException
- ("SAXException ",se);
}
}
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -259,7 +259,8 @@
SEND_PSVI,
NAMESPACE_GROWTH,
TOLERATE_DUPLICATES,
- XMLConstants.USE_CATALOG
+ XMLConstants.USE_CATALOG,
+ JdkXmlUtils.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
@@ -273,6 +274,7 @@
setFeature(SEND_PSVI, true);
setFeature(NAMESPACE_GROWTH, false);
setFeature(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
+ setFeature(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties = {
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java Wed Oct 04 10:33:08 2017 -0700
@@ -75,6 +75,7 @@
import java.util.StringTokenizer;
import java.util.WeakHashMap;
import javax.xml.XMLConstants;
+import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
import org.w3c.dom.DOMConfiguration;
@@ -160,7 +161,7 @@
protected static final String SCHEMA_DV_FACTORY =
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
- protected static final String USE_SERVICE_MECHANISM = Constants.ORACLE_FEATURE_SERVICE_MECHANISM;
+ protected static final String OVERRIDE_PARSER = JdkXmlUtils.OVERRIDE_PARSER;
// recognized features:
private static final String[] RECOGNIZED_FEATURES = {
@@ -175,7 +176,7 @@
HONOUR_ALL_SCHEMALOCATIONS,
NAMESPACE_GROWTH,
TOLERATE_DUPLICATES,
- USE_SERVICE_MECHANISM,
+ OVERRIDE_PARSER,
XMLConstants.USE_CATALOG
};
@@ -313,18 +314,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);
@@ -1231,7 +1228,7 @@
name.equals(HONOUR_ALL_SCHEMALOCATIONS) ||
name.equals(NAMESPACE_GROWTH) ||
name.equals(TOLERATE_DUPLICATES) ||
- name.equals(USE_SERVICE_MECHANISM)) {
+ name.equals(OVERRIDE_PARSER)) {
return true;
}
@@ -1310,7 +1307,7 @@
v.add(HONOUR_ALL_SCHEMALOCATIONS);
v.add(NAMESPACE_GROWTH);
v.add(TOLERATE_DUPLICATES);
- v.add(USE_SERVICE_MECHANISM);
+ v.add(OVERRIDE_PARSER);
fRecognizedParameters = new DOMStringListImpl(v);
}
return fRecognizedParameters;
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java Wed Oct 04 10:33:08 2017 -0700
@@ -265,7 +265,7 @@
private static final String XML_SECURITY_PROPERTY_MANAGER =
Constants.XML_SECURITY_PROPERTY_MANAGER;
- protected static final String USE_SERVICE_MECHANISM = Constants.ORACLE_FEATURE_SERVICE_MECHANISM;
+ protected static final String OVERRIDE_PARSER = JdkXmlUtils.OVERRIDE_PARSER;
protected static final String USE_CATALOG = XMLConstants.USE_CATALOG;
@@ -291,8 +291,8 @@
UNPARSED_ENTITY_CHECKING,
NAMESPACE_GROWTH,
TOLERATE_DUPLICATES,
- USE_SERVICE_MECHANISM,
- USE_CATALOG
+ OVERRIDE_PARSER,
+ USE_CATALOG,
};
/** Feature defaults. */
@@ -323,7 +323,7 @@
null,
null,
null,
- Boolean.TRUE,
+ JdkXmlUtils.OVERRIDE_PARSER_DEFAULT,
JdkXmlUtils.USE_CATALOG_DEFAULT
};
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/opti/SchemaParsingConfig.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/opti/SchemaParsingConfig.java Wed Oct 04 10:33:08 2017 -0700
@@ -304,7 +304,8 @@
ALLOW_JAVA_ENCODINGS, CONTINUE_AFTER_FATAL_ERROR,
LOAD_EXTERNAL_DTD, NOTIFY_BUILTIN_REFS,
NOTIFY_CHAR_REFS, GENERATE_SYNTHETIC_ANNOTATIONS,
- XMLConstants.USE_CATALOG
+ XMLConstants.USE_CATALOG,
+ JdkXmlUtils.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
@@ -319,6 +320,7 @@
fFeatures.put(NOTIFY_CHAR_REFS, Boolean.FALSE);
fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE);
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
+ fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties = {
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java Wed Oct 04 10:33:08 2017 -0700
@@ -115,7 +115,6 @@
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* The purpose of this class is to co-ordinate the construction of a
@@ -422,6 +421,8 @@
private String fPrefer;
private String fResolve;
+ private boolean fOverrideDefaultParser;
+
//************ Traversers **********
XSDAttributeGroupTraverser fAttributeGroupTraverser;
XSDAttributeTraverser fAttributeTraverser;
@@ -2244,7 +2245,8 @@
XSDKey key = null;
String schemaId = null;
if (referType != XSDDescription.CONTEXT_PREPARSE) {
- schemaId = XMLEntityManager.expandSystemId(inputSource.getSystemId(), schemaSource.getBaseSystemId(), false);
+ schemaId = XMLEntityManager.expandSystemId(inputSource.getSystemId(),
+ schemaSource.getBaseSystemId(), false);
key = new XSDKey(schemaId, referType, schemaNamespace);
if ((schemaElement = fTraversed.get(key)) != null) {
fLastSchemaWasDuplicate = true;
@@ -2260,17 +2262,10 @@
catch (SAXException se) {}
}
else {
+ parser = JdkXmlUtils.getXMLReader(fOverrideDefaultParser,
+ fSecurityManager.isSecureProcessing());
+
try {
- parser = XMLReaderFactory.createXMLReader();
- }
- // If something went wrong with the factory
- // just use our own SAX parser.
- catch (SAXException se) {
- parser = new SAXParser();
- }
- try {
- parser.setFeature(NAMESPACE_PREFIXES, true);
- namespacePrefixes = true;
// If this is a Xerces SAX parser set the security manager if there is one
if (parser instanceof SAXParser) {
if (fSecurityManager != null) {
@@ -3629,6 +3624,9 @@
fAccessExternalSchema = fSecurityPropertyMgr.getValue(
XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
+ fOverrideDefaultParser = componentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER);
+ fSchemaParser.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
+ fEntityManager.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
// Passing the Catalog settings to the parser
fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG);
fSchemaParser.setFeature(XMLConstants.USE_CATALOG, fUseCatalog);
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/DOMValidatorHelper.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/DOMValidatorHelper.java Wed Oct 04 10:33:08 2017 -0700
@@ -45,6 +45,7 @@
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
+import jdk.xml.internal.JdkXmlUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
@@ -380,9 +381,8 @@
}
if (result.getNode() == null) {
try {
- DocumentBuilderFactory factory = fComponentManager.getFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM) ?
- DocumentBuilderFactory.newInstance() : new DocumentBuilderFactoryImpl();
- factory.setNamespaceAware(true);
+ DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory(
+ fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
DocumentBuilder builder = factory.newDocumentBuilder();
result.setNode(builder.newDocument());
}
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/StAXValidatorHelper.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/StAXValidatorHelper.java Wed Oct 04 10:33:08 2017 -0700
@@ -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;
import java.io.IOException;
@@ -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;
@@ -50,7 +52,6 @@
* @author Sunitha Reddy
*/
public final class StAXValidatorHelper implements ValidatorHelper {
- private static final String DEFAULT_TRANSFORMER_IMPL = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
/** Component manager. **/
private XMLSchemaValidatorComponentManager fComponentManager;
@@ -71,10 +72,11 @@
if( identityTransformer1==null ) {
try {
- SAXTransformerFactory tf = fComponentManager.getFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM) ?
- (SAXTransformerFactory)SAXTransformerFactory.newInstance()
- : (SAXTransformerFactory) TransformerFactory.newInstance(DEFAULT_TRANSFORMER_IMPL, StAXValidatorHelper.class.getClassLoader());
- 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/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java Wed Oct 04 10:33:08 2017 -0700
@@ -98,9 +98,6 @@
private static final String VALIDATION_MANAGER
= Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
- private static final String DEFAULT_TRANSFORMER_IMPL
- = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
-
/**
* Property id: security manager.
*/
@@ -141,12 +138,9 @@
if (result != null) {
try {
- SAXTransformerFactory tf = fComponentManager.getFeature(
- Constants.ORACLE_FEATURE_SERVICE_MECHANISM) ?
- (SAXTransformerFactory) SAXTransformerFactory.newInstance() :
- (SAXTransformerFactory) TransformerFactory.newInstance(
- DEFAULT_TRANSFORMER_IMPL,
- StreamValidatorHelper.class.getClassLoader());
+ SAXTransformerFactory tf = JdkXmlUtils.getSAXTransformFactory(
+ fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
+
identityTransformerHandler = tf.newTransformerHandler();
} catch (TransformerConfigurationException e) {
throw new TransformerFactoryConfigurationError(e);
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorHandlerImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorHandlerImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -675,16 +675,14 @@
XMLReader reader = saxSource.getXMLReader();
if( reader==null ) {
// create one now
- SAXParserFactory spf = fComponentManager.getFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM) ?
- SAXParserFactory.newInstance() : new SAXParserFactoryImpl();
- 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/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2016, 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
@@ -51,6 +51,7 @@
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 org.w3c.dom.Node;
import org.w3c.dom.ls.LSResourceResolver;
@@ -127,22 +128,16 @@
/** Whether or not to allow new schemas to be added to the grammar pool */
private boolean fUseGrammarPoolOnly;
+ private final JdkXmlFeatures fXmlFeatures;
/**
- * Indicates whether implementation parts should use
- * service loader (or similar).
- * Note the default value (false) is the safe option..
+ * 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 fUseServicesMechanism;
+ private final boolean fOverrideDefaultParser;
public XMLSchemaFactory() {
- this(true);
- }
- public static XMLSchemaFactory newXMLSchemaFactoryNoServiceLoader() {
- return new XMLSchemaFactory(false);
- }
- private XMLSchemaFactory(boolean useServicesMechanism) {
- fUseServicesMechanism = useServicesMechanism;
fErrorHandlerWrapper = new ErrorHandlerWrapper(DraconianErrorHandler.getInstance());
fDOMEntityResolverWrapper = new DOMEntityResolverWrapper();
fXMLGrammarPoolWrapper = new XMLGrammarPoolWrapper();
@@ -167,6 +162,10 @@
}
fXMLSchemaLoader.setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT);
+ fXmlFeatures = new JdkXmlFeatures(fSecurityManager.isSecureProcessing());
+ fOverrideDefaultParser = fXmlFeatures.getFeature(
+ JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
+ fXMLSchemaLoader.setFeature(JdkXmlUtils.OVERRIDE_PARSER, fOverrideDefaultParser);
}
/**
@@ -363,6 +362,11 @@
else if (name.equals(USE_GRAMMAR_POOL_ONLY)) {
return fUseGrammarPoolOnly;
}
+ /** 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.getFeature(name);
}
@@ -452,10 +456,20 @@
return;
}
else if (name.equals(Constants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
- //in secure mode, let _useServicesMechanism be determined by the constructor
+ //in secure mode, let useServicesMechanism be determined by the constructor
if (System.getSecurityManager() != null)
return;
}
+
+ if ((fXmlFeatures != null) &&
+ fXmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) {
+ if (name.equals(JdkXmlUtils.OVERRIDE_PARSER)
+ || name.equals(Constants.ORACLE_FEATURE_SERVICE_MECHANISM)
+ || name.equals(JdkXmlUtils.USE_CATALOG)) {
+ fXMLSchemaLoader.setFeature(name, value);
+ }
+ return;
+ }
try {
fXMLSchemaLoader.setFeature(name, value);
}
@@ -528,7 +542,7 @@
private void propagateFeatures(AbstractXMLSchema schema) {
schema.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,
(fSecurityManager != null && fSecurityManager.isSecureProcessing()));
- schema.setFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM, fUseServicesMechanism);
+ 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/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaValidatorComponentManager.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaValidatorComponentManager.java Wed Oct 04 10:33:08 2017 -0700
@@ -264,7 +264,8 @@
NORMALIZE_DATA,
SCHEMA_ELEMENT_DEFAULT,
SCHEMA_AUGMENT_PSVI,
- XMLConstants.USE_CATALOG
+ XMLConstants.USE_CATALOG,
+ JdkXmlUtils.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
fFeatures.put(DISALLOW_DOCTYPE_DECL_FEATURE, Boolean.FALSE);
@@ -272,6 +273,7 @@
fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.FALSE);
fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
fFeatures.put(XMLConstants.USE_CATALOG, grammarContainer.getFeature(XMLConstants.USE_CATALOG));
+ fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, grammarContainer.getFeature(JdkXmlUtils.OVERRIDE_PARSER));
addRecognizedParamsAndSetDefaults(fEntityManager, grammarContainer);
addRecognizedParamsAndSetDefaults(fErrorReporter, grammarContainer);
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/DTDConfiguration.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/DTDConfiguration.java Wed Oct 04 10:33:08 2017 -0700
@@ -310,7 +310,8 @@
//NOTIFY_BUILTIN_REFS, // from XMLDocumentFragmentScannerImpl
//NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl
//WARN_ON_DUPLICATE_ENTITYDEF, // from XMLEntityManager
- XMLConstants.USE_CATALOG
+ XMLConstants.USE_CATALOG,
+ JdkXmlUtils.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
@@ -324,6 +325,7 @@
//setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl
//setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
+ fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties = {
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/NonValidatingConfiguration.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/NonValidatingConfiguration.java Wed Oct 04 10:33:08 2017 -0700
@@ -294,7 +294,8 @@
//NOTIFY_BUILTIN_REFS, // from XMLDocumentFragmentScannerImpl
//NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl
//WARN_ON_DUPLICATE_ENTITYDEF // from XMLEntityManager
- XMLConstants.USE_CATALOG
+ XMLConstants.USE_CATALOG,
+ JdkXmlUtils.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
@@ -310,6 +311,7 @@
//setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl
//setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
+ fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties = {
--- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java Wed Oct 04 10:33:08 2017 -0700
@@ -508,7 +508,8 @@
PARSER_SETTINGS,
XMLConstants.FEATURE_SECURE_PROCESSING,
XMLConstants.USE_CATALOG,
- JdkXmlUtils.RESET_SYMBOL_TABLE
+ JdkXmlUtils.RESET_SYMBOL_TABLE,
+ JdkXmlUtils.OVERRIDE_PARSER
};
addRecognizedFeatures(recognizedFeatures);
// set state for default features
@@ -535,6 +536,7 @@
fFeatures.put(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT);
fFeatures.put(JdkXmlUtils.RESET_SYMBOL_TABLE, JdkXmlUtils.RESET_SYMBOL_TABLE_DEFAULT);
+ fFeatures.put(JdkXmlUtils.OVERRIDE_PARSER, JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
// add default recognized properties
final String[] recognizedProperties =
--- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/DTMManager.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/DTMManager.java Wed Oct 04 10:33:08 2017 -0700
@@ -52,7 +52,7 @@
*/
protected XMLStringFactory m_xsf = null;
- private boolean _useServicesMechanism;
+ private boolean _overrideDefaultParser;
/**
* Default constructor is protected on purpose.
*/
@@ -297,15 +297,15 @@
/**
* Return the state of the services mechanism feature.
*/
- public boolean useServicesMechnism() {
- return _useServicesMechanism;
+ public boolean overrideDefaultParser() {
+ return _overrideDefaultParser;
}
/**
* Set the state of the services mechanism feature.
*/
- public void setServicesMechnism(boolean flag) {
- _useServicesMechanism = flag;
+ public void setOverrideDefaultParser(boolean flag) {
+ _overrideDefaultParser = flag;
}
// -------------------- private methods --------------------
--- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMManagerDefault.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMManagerDefault.java Wed Oct 04 10:33:08 2017 -0700
@@ -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
@@ -20,7 +20,6 @@
package com.sun.org.apache.xml.internal.dtm.ref;
-import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
@@ -43,6 +42,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(super.useServicesMechnism());
+ m_readerManager = XMLReaderManager.getInstance(super.overrideDefaultParser());
}
reader = m_readerManager.getXMLReader();
@@ -765,8 +765,7 @@
try
{
- DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(super.useServicesMechnism());
- dbf.setNamespaceAware(true);
+ DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(super.overrideDefaultParser());
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
--- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/AttList.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/AttList.java Wed Oct 04 10:33:08 2017 -0700
@@ -45,9 +45,7 @@
/**
* Constructor AttList
*
- *
* @param attrs List of attributes this will contain
- * @param dh DOMHelper
*/
public AttList(NamedNodeMap attrs)
{
--- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java Wed Oct 04 10:33:08 2017 -0700
@@ -21,14 +21,10 @@
package com.sun.org.apache.xml.internal.utils;
import com.sun.org.apache.xalan.internal.XalanConstants;
-import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
import java.util.HashMap;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
import jdk.xml.internal.JdkXmlFeatures;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.SecuritySupport;
@@ -36,7 +32,6 @@
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* Creates XMLReader objects and caches them for re-use.
@@ -44,32 +39,23 @@
*
* @LastModified: Sep 2017
*/
-@SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory
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<XMLReader> m_readers;
+ private ThreadLocal<ReaderWrapper> m_readers;
/**
* Keeps track of whether an XMLReader object is in use.
*/
private HashMap<XMLReader, Boolean> m_inUse;
- private boolean m_useServicesMechanism = true;
+ private boolean m_overrideDefaultParser;
private boolean _secureProcessing;
/**
@@ -94,8 +80,8 @@
/**
* Retrieves the singleton reader manager
*/
- public static XMLReaderManager getInstance(boolean useServicesMechanism) {
- m_singletonManager.setServicesMechnism(useServicesMechanism);
+ public static XMLReaderManager getInstance(boolean overrideDefaultParser) {
+ m_singletonManager.setOverrideDefaultParser(overrideDefaultParser);
return m_singletonManager;
}
@@ -118,61 +104,30 @@
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 = 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.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 (SAXException e) {
- try {
- // If unable to create an instance, let's try to use
- // the XMLReader from JAXP
- if (m_parserFactory == null) {
- m_parserFactory = FactoryImpl.getSAXFactory(m_useServicesMechanism);
- 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 | AbstractMethodError ex2) {
- }
+ 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);
}
}
@@ -230,22 +185,23 @@
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 useServicesMechnism() {
- return m_useServicesMechanism;
+ public boolean overrideDefaultParser() {
+ return m_overrideDefaultParser;
}
/**
* Set the state of the services mechanism feature.
*/
- public void setServicesMechnism(boolean flag) {
- m_useServicesMechanism = flag;
+ public void setOverrideDefaultParser(boolean flag) {
+ m_overrideDefaultParser = flag;
}
/**
@@ -285,4 +241,14 @@
_cdataChunkSize = JdkXmlUtils.getValue(value, _cdataChunkSize);
}
}
+
+ class ReaderWrapper {
+ XMLReader reader;
+ boolean overrideDefaultParser;
+
+ public ReaderWrapper(XMLReader reader, boolean overrideDefaultParser) {
+ this.reader = reader;
+ this.overrideDefaultParser = overrideDefaultParser;
+ }
+ }
}
--- a/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/CachedXPathAPI.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/CachedXPathAPI.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,6 +25,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;
@@ -73,7 +73,7 @@
*/
public CachedXPathAPI()
{
- xpathSupport = new XPathContext();
+ xpathSupport = new XPathContext(JdkXmlUtils.OVERRIDE_PARSER_DEFAULT);
}
/**
@@ -328,7 +328,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/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/XPathAPI.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/XPathAPI.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,6 +25,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;
@@ -221,7 +221,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
@@ -276,7 +276,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/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/XPathContext.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/XPathContext.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * @LastModified: Oct 2017
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -49,6 +50,7 @@
import javax.xml.transform.ErrorListener;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.URIResolver;
+import jdk.xml.internal.JdkXmlUtils;
import org.xml.sax.XMLReader;
/**
@@ -92,7 +94,7 @@
*/
private boolean m_isSecureProcessing = false;
- private boolean m_useServicesMechanism = true;
+ private boolean m_overrideDefaultParser;
/**
* Though XPathContext context extends
@@ -305,11 +307,11 @@
*/
public XPathContext()
{
- this(true);
+ this(false);
}
- public XPathContext(boolean useServicesMechanism) {
- init(useServicesMechanism);
+ public XPathContext(boolean overrideDefaultParser) {
+ init(overrideDefaultParser);
}
/**
**This constructor doesn't seem to be used anywhere -- huizhe wang**
@@ -324,15 +326,15 @@
m_ownerGetErrorListener = m_owner.getClass().getMethod("getErrorListener", new Class<?>[] {});
}
catch (NoSuchMethodException nsme) {}
- init(true);
+ init(false);
}
- private void init(boolean useServicesMechanism) {
+ private void init(boolean overrideDefaultParser) {
m_prefixResolvers.push(null);
m_currentNodes.push(DTM.NULL);
m_currentExpressionNodes.push(DTM.NULL);
m_saxLocations.push(null);
- m_useServicesMechanism = useServicesMechanism;
+ m_overrideDefaultParser = overrideDefaultParser;
m_dtmManager = DTMManager.newInstance(
com.sun.org.apache.xpath.internal.objects.XMLStringFactoryImpl.getFactory()
);
@@ -1082,15 +1084,15 @@
/**
* Return the state of the services mechanism feature.
*/
- public boolean useServicesMechnism() {
- return m_useServicesMechanism;
+ public boolean overrideDefaultParser() {
+ return m_overrideDefaultParser;
}
/**
* Set the state of the services mechanism feature.
*/
- public void setServicesMechnism(boolean flag) {
- m_useServicesMechanism = flag;
+ public void setOverrideDefaultParser(boolean flag) {
+ m_overrideDefaultParser = flag;
}
/**
--- a/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathExpressionImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathExpressionImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -31,7 +31,6 @@
import javax.xml.xpath.XPathVariableResolver;
import jdk.xml.internal.JdkXmlFeatures;
import org.w3c.dom.Document;
-import org.w3c.dom.Node;
import org.xml.sax.InputSource;
/**
@@ -47,8 +46,7 @@
* from the context.
*/
protected XPathExpressionImpl() {
- this(null, null, null, null,
- false, true, new JdkXmlFeatures(false));
+ this(null, null, null, null, false, new JdkXmlFeatures(false));
};
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath,
@@ -56,19 +54,20 @@
XPathFunctionResolver functionResolver,
XPathVariableResolver variableResolver) {
this(xpath, prefixResolver, functionResolver, variableResolver,
- false, true, new JdkXmlFeatures(false));
+ false, new JdkXmlFeatures(false));
};
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath,
JAXPPrefixResolver prefixResolver,XPathFunctionResolver functionResolver,
XPathVariableResolver variableResolver, boolean featureSecureProcessing,
- boolean useServiceMechanism, JdkXmlFeatures featureManager) {
+ JdkXmlFeatures featureManager) {
this.xpath = xpath;
this.prefixResolver = prefixResolver;
this.functionResolver = functionResolver;
this.variableResolver = variableResolver;
this.featureSecureProcessing = featureSecureProcessing;
- this.useServiceMechanism = useServiceMechanism;
+ this.overrideDefaultParser = featureManager.getFeature(
+ JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
this.featureManager = featureManager;
};
--- a/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -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
@@ -60,29 +60,21 @@
* <p>State of secure mode.</p>
*/
private boolean _isSecureMode = false;
+
+ /**
+ * XML Features manager
+ */
+ private final JdkXmlFeatures _featureManager;
+
/**
* javax.xml.xpath.XPathFactory implementation.
*/
-
- private boolean _useServicesMechanism = true;
-
- private final JdkXmlFeatures _featureManager;
-
public XPathFactoryImpl() {
- this(true);
- }
-
- public static XPathFactory newXPathFactoryNoServiceLoader() {
- return new XPathFactoryImpl(false);
- }
-
- public XPathFactoryImpl(boolean useServicesMechanism) {
if (System.getSecurityManager() != null) {
_isSecureMode = true;
_isNotSecureProcessing = false;
}
_featureManager = new JdkXmlFeatures(!_isNotSecureProcessing);
- this._useServicesMechanism = useServicesMechanism;
}
/**
* <p>Is specified object model supported by this
@@ -132,8 +124,7 @@
public javax.xml.xpath.XPath newXPath() {
return new com.sun.org.apache.xpath.internal.jaxp.XPathImpl(
xPathVariableResolver, xPathFunctionResolver,
- !_isNotSecureProcessing, _useServicesMechanism,
- _featureManager );
+ !_isNotSecureProcessing, _featureManager );
}
/**
@@ -192,10 +183,9 @@
return;
}
if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
- //in secure mode, let _useServicesMechanism be determined by the constructor
- if (!_isSecureMode)
- _useServicesMechanism = value;
- return;
+ // for compatibility, in secure mode, useServicesMechanism is determined by the constructor
+ if (_isSecureMode)
+ return;
}
if (_featureManager != null &&
@@ -248,9 +238,6 @@
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return !_isNotSecureProcessing;
}
- if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
- return _useServicesMechanism;
- }
/** Check to see if the property is managed by the feature manager **/
int index = _featureManager.getIndex(name);
--- a/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -54,17 +54,18 @@
private NamespaceContext namespaceContext=null;
XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr) {
- this(vr, fr, false, true, new JdkXmlFeatures(false));
+ this(vr, fr, false, new JdkXmlFeatures(false));
}
XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr,
- boolean featureSecureProcessing, boolean useServiceMechanism,
- JdkXmlFeatures featureManager) {
+ boolean featureSecureProcessing, JdkXmlFeatures featureManager) {
this.origVariableResolver = this.variableResolver = vr;
this.origFunctionResolver = this.functionResolver = fr;
this.featureSecureProcessing = featureSecureProcessing;
- this.useServiceMechanism = useServiceMechanism;
this.featureManager = featureManager;
+ overrideDefaultParser = featureManager.getFeature(
+ JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER);
+
}
@@ -163,7 +164,7 @@
// Can have errorListener
XPathExpressionImpl ximpl = new XPathExpressionImpl (xpath,
prefixResolver, functionResolver, variableResolver,
- featureSecureProcessing, useServiceMechanism, featureManager);
+ featureSecureProcessing, featureManager);
return ximpl;
} catch (TransformerException te) {
throw new XPathExpressionException (te) ;
--- a/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImplUtil.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImplUtil.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
package com.sun.org.apache.xpath.internal.jaxp;
import com.sun.org.apache.xalan.internal.res.XSLMessages;
-import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
import com.sun.org.apache.xml.internal.dtm.DTM;
import com.sun.org.apache.xpath.internal.axes.LocPathIterator;
import com.sun.org.apache.xpath.internal.objects.XObject;
@@ -43,6 +42,7 @@
import javax.xml.xpath.XPathNodes;
import javax.xml.xpath.XPathVariableResolver;
import jdk.xml.internal.JdkXmlFeatures;
+import jdk.xml.internal.JdkXmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.traversal.NodeIterator;
@@ -57,7 +57,7 @@
XPathFunctionResolver functionResolver;
XPathVariableResolver variableResolver;
JAXPPrefixResolver prefixResolver;
- boolean useServiceMechanism = true;
+ boolean overrideDefaultParser;
// By default Extension Functions are allowed in XPath Expressions. If
// Secure Processing Feature is set on XPathFactory then the invocation of
// extensions function need to throw XPathFunctionException
@@ -125,9 +125,7 @@
//
// so we really have to create a fresh DocumentBuilder every time we need one
// - KK
- DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(useServiceMechanism);
- dbf.setNamespaceAware(true);
- dbf.setValidating(false);
+ DocumentBuilderFactory dbf = JdkXmlUtils.getDOMFactory(overrideDefaultParser);
return dbf.newDocumentBuilder().parse(source);
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new XPathExpressionException (e);
--- a/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java Wed Oct 04 10:33:08 2017 -0700
@@ -143,10 +143,11 @@
* @param doFallback True if the current ClassLoader should be tried as
* a fallback if the class is not found using cl
*
- * @param useServicesMechanism True use services mechanism
+ * @param overrideDefaultParser True to allow overriding the system-default
+ * parser.
*/
static <T> T newInstance(Class<T> type, String className, ClassLoader cl,
- boolean doFallback, boolean useServicesMechanism)
+ boolean doFallback)
throws TransformerFactoryConfigurationError
{
assert type != null;
@@ -165,13 +166,8 @@
if (!type.isAssignableFrom(providerClass)) {
throw new ClassCastException(className + " cannot be cast to " + type.getName());
}
- Object instance = null;
- if (!useServicesMechanism) {
- instance = newInstanceNoServiceLoader(type, providerClass);
- }
- if (instance == null) {
- instance = providerClass.getConstructor().newInstance();
- }
+ Object instance = providerClass.getConstructor().newInstance();
+
final ClassLoader clD = cl;
dPrint(()->"created new instance of " + providerClass +
" using ClassLoader: " + clD);
@@ -188,48 +184,6 @@
}
/**
- * Try to construct using newTransformerFactoryNoServiceLoader
- * method if available.
- */
- private static <T> T newInstanceNoServiceLoader(Class<T> type, Class<?> providerClass) {
- // Retain maximum compatibility if no security manager.
- if (System.getSecurityManager() == null) {
- return null;
- }
- try {
- final Method creationMethod =
- providerClass.getDeclaredMethod(
- "newTransformerFactoryNoServiceLoader"
- );
- final int modifiers = creationMethod.getModifiers();
-
- // Do not call the method if it's not public static.
- if (!Modifier.isPublic(modifiers) || !Modifier.isStatic(modifiers)) {
- return null;
- }
-
- // Only call the method if it's declared to return an instance of
- // TransformerFactory
- final Class<?> returnType = creationMethod.getReturnType();
- if (type.isAssignableFrom(returnType)) {
- final Object result = creationMethod.invoke(null, (Object[])null);
- return type.cast(result);
- } else {
- // This should not happen, as
- // TransformerFactoryImpl.newTransformerFactoryNoServiceLoader is
- // declared to return TransformerFactory.
- throw new ClassCastException(returnType + " cannot be cast to " + type);
- }
- } catch (ClassCastException e) {
- throw new TransformerFactoryConfigurationError(e, e.getMessage());
- } catch (NoSuchMethodException exc) {
- return null;
- } catch (Exception exc) {
- return null;
- }
- }
-
- /**
* Finds the implementation Class object in the specified order. Main
* entry point.
* @return Class object of factory, never null
@@ -255,7 +209,7 @@
String systemProp = SecuritySupport.getSystemProperty(factoryId);
if (systemProp != null) {
dPrint(()->"found system property, value=" + systemProp);
- return newInstance(type, systemProp, null, true, true);
+ return newInstance(type, systemProp, null, true);
}
}
catch (SecurityException se) {
@@ -282,7 +236,7 @@
if (factoryClassName != null) {
dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName);
- return newInstance(type, factoryClassName, null, true, true);
+ return newInstance(type, factoryClassName, null, true);
}
}
catch (Exception ex) {
@@ -300,7 +254,7 @@
}
dPrint(()->"loaded from fallback value: " + fallbackClassName);
- return newInstance(type, fallbackClassName, null, true, true);
+ return newInstance(type, fallbackClassName, null, true);
}
/*
--- a/src/java.xml/share/classes/javax/xml/transform/TransformerFactory.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/javax/xml/transform/TransformerFactory.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2015, 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
@@ -62,7 +62,7 @@
* @since 9
*/
public static TransformerFactory newDefaultInstance() {
- return TransformerFactoryImpl.newTransformerFactoryNoServiceLoader();
+ return new TransformerFactoryImpl();
}
/**
@@ -170,7 +170,7 @@
//do not fallback if given classloader can't find the class, throw exception
return FactoryFinder.newInstance(TransformerFactory.class,
- factoryClassName, classLoader, false, false);
+ factoryClassName, classLoader, false);
}
/**
* Process the {@code Source} into a {@code Transformer}
--- a/src/java.xml/share/classes/javax/xml/validation/SchemaFactory.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/javax/xml/validation/SchemaFactory.java Wed Oct 04 10:33:08 2017 -0700
@@ -139,7 +139,7 @@
* @since 9
*/
public static SchemaFactory newDefaultInstance() {
- return XMLSchemaFactory.newXMLSchemaFactoryNoServiceLoader();
+ return new XMLSchemaFactory();
}
/**
--- a/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java Wed Oct 04 10:33:08 2017 -0700
@@ -25,6 +25,7 @@
package javax.xml.validation;
+import com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -167,7 +168,7 @@
String r = SecuritySupport.getSystemProperty(propertyName);
if(r!=null) {
debugPrintln(()->"The value is '"+r+"'");
- sf = createInstance(r, true);
+ sf = createInstance(r);
if(sf!=null) return sf;
} else
debugPrintln(()->"The property is undefined.");
@@ -201,7 +202,7 @@
debugPrintln(()->"found " + factoryClassName + " in $java.home/conf/jaxp.properties");
if (factoryClassName != null) {
- sf = createInstance(factoryClassName, true);
+ sf = createInstance(factoryClassName);
if(sf != null){
return sf;
}
@@ -226,7 +227,7 @@
// platform default
if(schemaLanguage.equals("http://www.w3.org/2001/XMLSchema")) {
debugPrintln(()->"attempting to use the platform default XML Schema validator");
- return createInstance("com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory", true);
+ return new XMLSchemaFactory();
}
debugPrintln(()->"all things were tried, but none was found. bailing out.");
@@ -273,11 +274,7 @@
* @return null
* if it fails. Error messages will be printed by this method.
*/
- SchemaFactory createInstance( String className ) {
- return createInstance( className, false );
- }
-
- SchemaFactory createInstance( String className, boolean useServicesMechanism ) {
+ SchemaFactory createInstance(String className) {
SchemaFactory schemaFactory = null;
debugPrintln(()->"createInstance(" + className + ")");
@@ -296,12 +293,7 @@
throw new ClassCastException(clazz.getName()
+ " cannot be cast to " + SchemaFactory.class);
}
- if (!useServicesMechanism) {
- schemaFactory = newInstanceNoServiceLoader(clazz);
- }
- if (schemaFactory == null) {
- schemaFactory = (SchemaFactory) clazz.getConstructor().newInstance();
- }
+ schemaFactory = (SchemaFactory) clazz.getConstructor().newInstance();
} catch (ClassCastException | IllegalAccessException | IllegalArgumentException |
InstantiationException | InvocationTargetException | NoSuchMethodException |
SecurityException ex) {
@@ -315,50 +307,6 @@
return schemaFactory;
}
- /**
- * Try to construct using newXMLSchemaFactoryNoServiceLoader
- * method if available.
- */
- private static SchemaFactory newInstanceNoServiceLoader(
- Class<?> providerClass
- ) {
- // Retain maximum compatibility if no security manager.
- if (System.getSecurityManager() == null) {
- return null;
- }
- try {
- final Method creationMethod =
- providerClass.getDeclaredMethod(
- "newXMLSchemaFactoryNoServiceLoader"
- );
- final int modifiers = creationMethod.getModifiers();
-
- // Do not call the method if it's not public static.
- if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {
- return null;
- }
-
- // Only calls "newXMLSchemaFactoryNoServiceLoader" if it's
- // declared to return an instance of SchemaFactory.
- final Class<?> returnType = creationMethod.getReturnType();
- if (SERVICE_CLASS.isAssignableFrom(returnType)) {
- return SERVICE_CLASS.cast(creationMethod.invoke(null, (Object[])null));
- } else {
- // Should not happen since
- // XMLSchemaFactory.newXMLSchemaFactoryNoServiceLoader is
- // declared to return XMLSchemaFactory.
- throw new ClassCastException(returnType
- + " cannot be cast to " + SERVICE_CLASS);
- }
- } catch(ClassCastException e) {
- throw new SchemaFactoryConfigurationError(e.getMessage(), e);
- } catch (NoSuchMethodException exc) {
- return null;
- } catch (Exception exc) {
- return null;
- }
- }
-
// Call isSchemaLanguageSupported with initial context.
private boolean isSchemaLanguageSupportedBy(final SchemaFactory factory,
final String schemaLanguage,
--- a/src/java.xml/share/classes/javax/xml/xpath/XPathFactory.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/javax/xml/xpath/XPathFactory.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2016, 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
@@ -87,7 +87,7 @@
* @since 9
*/
public static XPathFactory newDefaultInstance() {
- return XPathFactoryImpl.newXPathFactoryNoServiceLoader();
+ return new XPathFactoryImpl();
}
/**
--- a/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java Wed Oct 04 10:33:08 2017 -0700
@@ -25,10 +25,9 @@
package javax.xml.xpath;
+import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -162,7 +161,7 @@
String r = SecuritySupport.getSystemProperty(propertyName);
if(r!=null) {
debugPrintln(()->"The value is '"+r+"'");
- xpathFactory = createInstance(r, true);
+ xpathFactory = createInstance(r);
if (xpathFactory != null) {
return xpathFactory;
}
@@ -197,7 +196,7 @@
debugPrintln(()->"found " + factoryClassName + " in $java.home/conf/jaxp.properties");
if (factoryClassName != null) {
- xpathFactory = createInstance(factoryClassName, true);
+ xpathFactory = createInstance(factoryClassName);
if(xpathFactory != null){
return xpathFactory;
}
@@ -223,7 +222,7 @@
// platform default
if(uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) {
debugPrintln(()->"attempting to use the platform default W3C DOM XPath lib");
- return createInstance("com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", true);
+ return new XPathFactoryImpl();
}
debugPrintln(()->"all things were tried, but none was found. bailing out.");
@@ -271,13 +270,7 @@
* @return null
* if it fails. Error messages will be printed by this method.
*/
- XPathFactory createInstance( String className )
- throws XPathFactoryConfigurationException
- {
- return createInstance( className, false );
- }
-
- XPathFactory createInstance( String className, boolean useServicesMechanism )
+ XPathFactory createInstance(String className)
throws XPathFactoryConfigurationException
{
XPathFactory xPathFactory = null;
@@ -294,12 +287,7 @@
// instantiate Class as a XPathFactory
try {
- if (!useServicesMechanism) {
- xPathFactory = newInstanceNoServiceLoader(clazz);
- }
- if (xPathFactory == null) {
- xPathFactory = (XPathFactory) clazz.getConstructor().newInstance();
- }
+ xPathFactory = (XPathFactory) clazz.getConstructor().newInstance();
} catch (ClassCastException | IllegalAccessException | IllegalArgumentException |
InstantiationException | InvocationTargetException | NoSuchMethodException |
SecurityException ex) {
@@ -312,50 +300,6 @@
return xPathFactory;
}
- /**
- * Try to construct using newXPathFactoryNoServiceLoader
- * method if available.
- */
- private static XPathFactory newInstanceNoServiceLoader(
- Class<?> providerClass
- ) throws XPathFactoryConfigurationException {
- // Retain maximum compatibility if no security manager.
- if (System.getSecurityManager() == null) {
- return null;
- }
- try {
- Method creationMethod =
- providerClass.getDeclaredMethod(
- "newXPathFactoryNoServiceLoader"
- );
- final int modifiers = creationMethod.getModifiers();
-
- // Do not call "newXPathFactoryNoServiceLoader" if it's
- // not public static.
- if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {
- return null;
- }
-
- // Only calls "newXPathFactoryNoServiceLoader" if it's
- // declared to return an instance of XPathFactory.
- final Class<?> returnType = creationMethod.getReturnType();
- if (SERVICE_CLASS.isAssignableFrom(returnType)) {
- return SERVICE_CLASS.cast(creationMethod.invoke(null, (Object[])null));
- } else {
- // Should not happen since
- // XPathFactoryImpl.newXPathFactoryNoServiceLoader is
- // declared to return XPathFactory.
- throw new ClassCastException(returnType
- + " cannot be cast to " + SERVICE_CLASS);
- }
- } catch (ClassCastException e) {
- throw new XPathFactoryConfigurationException(e);
- } catch (NoSuchMethodException exc) {
- return null;
- } catch (Exception exc) {
- return null;
- }
- }
// Call isObjectModelSupportedBy with initial context.
private boolean isObjectModelSupportedBy(final XPathFactory factory,
--- a/src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
package jdk.xml.internal;
import javax.xml.XMLConstants;
+import static jdk.xml.internal.JdkXmlUtils.OVERRIDE_PARSER;
import static jdk.xml.internal.JdkXmlUtils.SP_USE_CATALOG;
import static jdk.xml.internal.JdkXmlUtils.RESET_SYMBOL_TABLE;
@@ -36,6 +37,13 @@
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
*/
@@ -56,22 +64,37 @@
* 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, true, false, true, true),
+ ENABLE_EXTENSION_FUNCTION(ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION_SPEC,
+ ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION,
+ true, false, true, true),
/**
* The {@link javax.xml.XMLConstants.USE_CATALOG} feature.
* FSP: USE_CATALOG is not enforced by FSP.
*/
- USE_CATALOG(PROPERTY_USE_CATALOG, SP_USE_CATALOG, true, false, true, false),
+ USE_CATALOG(PROPERTY_USE_CATALOG, SP_USE_CATALOG,
+ null, null,
+ true, false, true, false),
/**
* Feature resetSymbolTable
* FSP: RESET_SYMBOL_TABLE_FEATURE is not enforced by FSP.
*/
- RESET_SYMBOL_TABLE_FEATURE(RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE, false, false, true, false);
+ RESET_SYMBOL_TABLE_FEATURE(RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE,
+ null, null,
+ false, false, true, false),
+
+ /**
+ * 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;
@@ -81,15 +104,20 @@
* 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, boolean value, boolean valueEnforced, boolean hasSystem, boolean enforced) {
+ 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;
@@ -103,7 +131,8 @@
* otherwise
*/
boolean equalsPropertyName(String propertyName) {
- return name.equals(propertyName);
+ return name.equals(propertyName) ||
+ (nameOld != null && nameOld.equals(propertyName));
}
/**
@@ -125,6 +154,15 @@
}
/**
+ * 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
*/
@@ -159,30 +197,6 @@
}
/**
- * Maps old property names with the new ones. This map is used to keep track of
- * name changes so that old or incorrect names continue to be supported for compatibility.
- */
- public static enum NameMap {
-
- ENABLE_EXTENSION_FUNCTION(SP_ENABLE_EXTENSION_FUNCTION_SPEC, SP_ENABLE_EXTENSION_FUNCTION);
-
- final String newName;
- final String oldName;
-
- NameMap(String newName, String oldName) {
- this.newName = newName;
- this.oldName = oldName;
- }
-
- String getOldName(String newName) {
- if (newName.equals(this.newName)) {
- return oldName;
- }
- return null;
- }
- }
-
- /**
* 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
@@ -207,12 +221,12 @@
/**
* Values of the features
*/
- private boolean[] featureValues;
+ private final boolean[] featureValues;
/**
* States of the settings for each property
*/
- private State[] states;
+ private final State[] states;
/**
* Flag indicating if secure processing is set
@@ -349,14 +363,11 @@
*/
private void readSystemProperties() {
for (XmlFeature feature : XmlFeature.values()) {
- getSystemProperty(feature, feature.systemProperty());
if (!getSystemProperty(feature, feature.systemProperty())) {
//if system property is not found, try the older form if any
- for (NameMap nameMap : NameMap.values()) {
- String oldName = nameMap.getOldName(feature.systemProperty());
- if (oldName != null) {
- getSystemProperty(feature, oldName);
- }
+ String oldName = feature.systemPropertyOld();
+ if (oldName != null) {
+ getSystemProperty(feature, oldName);
}
}
}
@@ -367,6 +378,7 @@
*
* @param property the type of the property
* @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 {
--- a/src/java.xml/share/classes/jdk/xml/internal/JdkXmlUtils.java Mon Sep 25 19:44:28 2017 +0530
+++ b/src/java.xml/share/classes/jdk/xml/internal/JdkXmlUtils.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -22,16 +22,26 @@
* 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 com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import javax.xml.XMLConstants;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogFeatures.Feature;
+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;
@@ -40,6 +50,18 @@
* 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;
+
/**
* Catalog features
@@ -52,12 +74,20 @@
public final static String CATALOG_RESOLVE = CatalogFeatures.Feature.RESOLVE.getPropertyName();
/**
- * Reset SymbolTable feature
- * System property name is identical to feature name
+ * Reset SymbolTable feature System property name is identical to feature
+ * name
*/
public final static String RESET_SYMBOL_TABLE = "jdk.xml.resetSymbolTable";
/**
+ * 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";
@@ -75,7 +105,6 @@
public static final boolean RESET_SYMBOL_TABLE_DEFAULT
= SecuritySupport.getJAXPSystemProperty(Boolean.class, RESET_SYMBOL_TABLE, "false");
-
/**
* JDK features (will be consolidated in the next major feature revamp
*/
@@ -84,6 +113,11 @@
= SecuritySupport.getJAXPSystemProperty(Integer.class, CDATA_CHUNK_SIZE, "0");
/**
+ * The system-default factory
+ */
+ private static final SAXParserFactory defaultSAXFactory = getSAXFactory(false);
+
+ /**
* Returns the value.
*
* @param value the specified value
@@ -227,4 +261,153 @@
}
}
}
+
+ /**
+ * 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
+ * @param useXMLReaderFactory a flag indicating when the XMLReader should be
+ * created using XMLReaderFactory. True is a compatibility mode that honors
+ * the property org.xml.sax.driver (see JDK-6490921).
+ * @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;
+ }
}
--- a/test/jaxp/javax/xml/jaxp/unittest/common/Bug6941169Test.java Mon Sep 25 19:44:28 2017 +0530
+++ b/test/jaxp/javax/xml/jaxp/unittest/common/Bug6941169Test.java Wed Oct 04 10:33:08 2017 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -364,6 +364,14 @@
@Test
public void testXPath_DOM_withServiceMech() {
+ /**
+ * This is in conflict with the test testXPath_DOM_withSM where the system
+ * default parser is used when the security manager is present. The test
+ * is therefore skipped when the security manager is present.
+ */
+ if (System.getSecurityManager() != null) {
+ return;
+ }
final String XPATH_EXPRESSION = "/fooTest";
System.out.println("Evaluate DOM Source; Service mechnism is on by default; It would try to use MyDOMFactoryImpl:");
InputStream input = getClass().getResourceAsStream("Bug6941169.xml");