From aff9cea05468daf60fa80c7d9993b3aa8497b0c5 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 2 Jun 2023 20:09:44 +0000 Subject: [PATCH] 8303530: Redefine JAXP Configuration File Reviewed-by: naoto, lancea, alanb, smarks --- make/modules/java.xml/Copy.gmk | 37 ++ .../internal/utils/FeaturePropertyBase.java | 6 +- .../jaxp/DocumentBuilderFactoryImpl.java | 6 +- .../internal/utils/XMLSecurityManager.java | 60 ++- .../utils/XMLSecurityPropertyManager.java | 4 +- .../share/classes/javax/xml/XMLConstants.java | 218 +++----- .../javax/xml/catalog/CatalogFeatures.java | 47 +- .../javax/xml/catalog/package-info.java | 4 +- .../javax/xml/datatype/FactoryFinder.java | 44 +- .../javax/xml/parsers/FactoryFinder.java | 44 +- .../javax/xml/stream/FactoryFinder.java | 56 +- .../javax/xml/stream/XMLEventFactory.java | 25 +- .../javax/xml/stream/XMLInputFactory.java | 23 +- .../javax/xml/stream/XMLOutputFactory.java | 23 +- .../javax/xml/transform/FactoryFinder.java | 46 +- .../xml/validation/SchemaFactoryFinder.java | 52 +- .../javax/xml/xpath/XPathFactoryFinder.java | 38 +- .../jdk/xml/internal/JdkConstants.java | 8 +- .../jdk/xml/internal/JdkXmlFeatures.java | 4 +- .../jdk/xml/internal/SecuritySupport.java | 103 ++-- .../jdk/xml/internal/XMLSecurityManager.java | 60 ++- src/java.xml/share/classes/module-info.java | 502 ++++++++++-------- src/java.xml/share/conf/jaxp.properties | 180 +++++++ .../common/config/ConfigurationTest.java | 115 ++++ .../unittest/common/config/DOMImplTest.java | 91 ++++ .../unittest/common/config/DOMImplTest0.java | 64 +++ .../common/config/DOMPropertyTest.java | 47 ++ .../common/config/DOMPropertyTest0.java | 50 ++ .../common/config/EventFactoryTest.java | 204 +++++++ .../common/config/EventFactoryTest0.java | 58 ++ .../common/config/InputFactoryTest.java | 190 +++++++ .../common/config/InputFactoryTest0.java | 58 ++ .../common/config/OutputFactoryTest.java | 119 +++++ .../common/config/OutputFactoryTest0.java | 58 ++ .../jaxp/unittest/common/config/PathTest.java | 80 +++ .../unittest/common/config/SAXImplTest.java | 79 +++ .../unittest/common/config/SAXImplTest0.java | 57 ++ .../common/config/SAXPropertyTest.java | 52 ++ .../common/config/SAXPropertyTest0.java | 55 ++ .../common/config/SchemaFactoryTest.java | 99 ++++ .../common/config/SchemaFactoryTest0.java | 59 ++ .../common/config/SchemaPropertyTest.java | 49 ++ .../common/config/SchemaPropertyTest0.java | 52 ++ .../common/config/StAXPropertyTest.java | 47 ++ .../common/config/StAXPropertyTest0.java | 50 ++ .../common/config/TransformerFactoryTest.java | 125 +++++ .../config/TransformerFactoryTest0.java | 58 ++ .../config/TransformerPropertyTest.java | 47 ++ .../config/TransformerPropertyTest0.java | 50 ++ .../common/config/XPathFactoryTest.java | 93 ++++ .../common/config/XPathFactoryTest0.java | 58 ++ .../common/config/XPathPropertyTest.java | 62 +++ .../common/config/XPathPropertyTest0.java | 65 +++ .../common/config/files/customJaxp.properties | 31 ++ .../common/config/files/jaxp.properties | 180 +++++++ .../common/config/files/jaxpImpls.properties | 48 ++ 56 files changed, 3368 insertions(+), 772 deletions(-) create mode 100644 make/modules/java.xml/Copy.gmk create mode 100644 src/java.xml/share/conf/jaxp.properties create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/ConfigurationTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/DOMImplTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/DOMImplTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/DOMPropertyTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/DOMPropertyTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/EventFactoryTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/EventFactoryTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/InputFactoryTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/InputFactoryTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/OutputFactoryTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/OutputFactoryTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/PathTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/SAXImplTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/SAXImplTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/SAXPropertyTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/SAXPropertyTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaFactoryTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaFactoryTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaPropertyTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaPropertyTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/StAXPropertyTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/StAXPropertyTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerFactoryTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerFactoryTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerPropertyTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerPropertyTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/XPathFactoryTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/XPathFactoryTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/XPathPropertyTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/XPathPropertyTest0.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/files/customJaxp.properties create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/files/jaxp.properties create mode 100644 test/jaxp/javax/xml/jaxp/unittest/common/config/files/jaxpImpls.properties diff --git a/make/modules/java.xml/Copy.gmk b/make/modules/java.xml/Copy.gmk new file mode 100644 index 00000000000..3b6c66e42c5 --- /dev/null +++ b/make/modules/java.xml/Copy.gmk @@ -0,0 +1,37 @@ +# +# Copyright (c) 2023, 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. +# + +include CopyCommon.gmk + +################################################################################ + +XML_LIB_SRC := $(TOPDIR)/src/java.xml/share/conf + +$(CONF_DST_DIR)/jaxp.properties: $(XML_LIB_SRC)/jaxp.properties + $(call install-file) + +TARGETS := $(CONF_DST_DIR)/jaxp.properties + +################################################################################ diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/FeaturePropertyBase.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/FeaturePropertyBase.java index 61c8b6514dd..1ba2190b65f 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/FeaturePropertyBase.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/FeaturePropertyBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2023, 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 @@ -31,7 +31,7 @@ import jdk.xml.internal.SecuritySupport; /** * This is the base class for features and properties * - * @LastModified: May 2021 + * @LastModified: Mar 2023 */ public abstract class FeaturePropertyBase { @@ -205,7 +205,7 @@ public abstract class FeaturePropertyBase { return; } - value = SecuritySupport.readJAXPProperty(systemProperty); + value = SecuritySupport.readConfig(systemProperty); if (value != null) { values[property.ordinal()] = value; states[property.ordinal()] = State.JAXPDOTPROPERTIES; diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderFactoryImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderFactoryImpl.java index 1bffeba6ac6..f3ab76285db 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderFactoryImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/DocumentBuilderFactoryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -39,7 +39,7 @@ import org.xml.sax.SAXNotSupportedException; /** * @author Rajiv Mordani * @author Edwin Goei - * @LastModified: May 2021 + * @LastModified: Mar 2023 */ public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { /** These are DocumentBuilderFactory attributes not DOM attributes */ @@ -148,7 +148,7 @@ public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory { //check if the property is managed by security manager String pName; if ((pName = fSecurityManager.find(name)) != null) { - return attributes.get(pName); + return fSecurityManager.getLimitAsString(pName); } else if ((pName = fSecurityPropertyMgr.find(name)) != null) { return attributes.get(pName); } diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityManager.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityManager.java index f4140b8eb41..0d02974c605 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityManager.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -512,22 +512,17 @@ public final class XMLSecurityManager { } /** - * Read from system properties, or those in jaxp.properties + * Read system properties, or the configuration file */ private void readSystemProperties() { - for (Limit limit : Limit.values()) { - if (!getSystemProperty(limit, limit.systemProperty())) { - //if system property is not found, try the older form if any - for (NameMap nameMap : NameMap.values()) { - String oldName = nameMap.getOldName(limit.systemProperty()); - if (oldName != null) { - getSystemProperty(limit, oldName); - } - } + // attempts to read both the current and old system propery + if (!getSystemProperty(limit, limit.systemProperty()) + && (!getOldSystemProperty(limit))) { + //if system property is not found, try the config file + getPropertyConfig(limit, limit.systemProperty()); } } - } // Array list to store printed warnings for each SAX parser used @@ -548,9 +543,9 @@ public final class XMLSecurityManager { } /** - * Read from system properties, or those in jaxp.properties + * Reads a system property, sets value and state if found. * - * @param property the type of the property + * @param limit the limit property * @param sysPropertyName the name of system property */ private boolean getSystemProperty(Limit limit, String sysPropertyName) { @@ -561,8 +556,42 @@ public final class XMLSecurityManager { states[limit.ordinal()] = State.SYSTEMPROPERTY; return true; } + } catch (NumberFormatException e) { + //invalid setting + throw new NumberFormatException("Invalid setting for system property: " + limit.systemProperty()); + } + return false; + } - value = SecuritySupport.readJAXPProperty(sysPropertyName); + /** + * Reads the legacy system property. + * @param limit a limit object + * @return true if found, false otherwise + */ + private boolean getOldSystemProperty(Limit limit) { + boolean found = false; + for (NameMap nameMap : NameMap.values()) { + String oldName = nameMap.getOldName(limit.systemProperty()); + if (oldName != null) { + if (getSystemProperty(limit, oldName)) { + found = true; + break; + } + } + } + return found; + } + + /** + * Reads a property from a configuration file, if any. + * + * @param limit the limit property + * @param sysPropertyName the name of system property + * @return + */ + private boolean getPropertyConfig(Limit limit, String sysPropertyName) { + try { + String value = SecuritySupport.readConfig(sysPropertyName); if (value != null && !value.equals("")) { values[limit.ordinal()] = Integer.parseInt(value); states[limit.ordinal()] = State.JAXPDOTPROPERTIES; @@ -575,7 +604,6 @@ public final class XMLSecurityManager { return false; } - /** * Convert a value set through setProperty to XMLSecurityManager. * If the value is an instance of XMLSecurityManager, use it to override the default; diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityPropertyManager.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityPropertyManager.java index 24f4980348f..d89072fe277 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityPropertyManager.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/XMLSecurityPropertyManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -231,7 +231,7 @@ public final class XMLSecurityPropertyManager { return; } - value = SecuritySupport.readJAXPProperty(systemProperty); + value = SecuritySupport.readConfig(systemProperty); if (value != null) { values[property.ordinal()] = value; states[property.ordinal()] = State.JAXPDOTPROPERTIES; diff --git a/src/java.xml/share/classes/javax/xml/XMLConstants.java b/src/java.xml/share/classes/javax/xml/XMLConstants.java index 7de589087e7..d9851d88972 100644 --- a/src/java.xml/share/classes/javax/xml/XMLConstants.java +++ b/src/java.xml/share/classes/javax/xml/XMLConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2023, 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,55 @@ package javax.xml; /** - *

Utility class to contain basic XML values as constants. + * Defines constants for XML Processing APIs. + * + *

External Access Properties

+ * The value of the external access properties, including {@link #ACCESS_EXTERNAL_DTD}, + * {@link #ACCESS_EXTERNAL_SCHEMA}, and {@link #ACCESS_EXTERNAL_STYLESHEET}, + * is defined as follows. + * + *

Value:

+ * A list of protocols separated by comma. A protocol is the scheme portion of a + * {@link java.net.URI}, or in the case of the JAR protocol, "jar" plus the scheme + * portion separated by colon. A scheme is defined as: + * + *
+ * scheme = alpha *( alpha | digit | "+" | "-" | "." )
+ * where alpha = a-z and A-Z.

+ * + * And the JAR protocol:
+ * + * jar[:scheme]

+ * + * Protocols including the keyword "jar" are case-insensitive. Any whitespaces as defined by + * {@link java.lang.Character#isSpaceChar } in the value will be ignored. + * Examples of protocols are file, http, jar:file. + * + *
+ * + *

Default value:

+ * The default value is implementation specific and therefore not specified. + * The following options are provided for consideration: + *
+ *
+ * When FEATURE_SECURE_PROCESSING is enabled, it is recommended that implementations + * restrict external connections by default, though this may cause problems for applications + * that process XML/XSD/XSL with external references. + *
+ * + *

Granting all access:

+ * The keyword "all" grants permission to all protocols. + * + *

Property Precedence

+ * Properties, including the External Access Properties and + * {@link #USE_CATALOG}, can be specified through multiple configuration sources. + * They follow the configuration process as defined in the + * Configuration section + * of the module summary. * * @author Jeff Suttor * @see Extensible Markup Language (XML) 1.1 @@ -184,6 +232,10 @@ public final class XMLConstants { * ignoring security issues such as limits on XML constructs to avoid conditions such as denial of service attacks. * * + * + * @implNote + * when the Java Security Manager is present, the JDK sets the value of + * this feature to true and does not allow it to be turned off. */ public static final String FEATURE_SECURE_PROCESSING = "http://javax.xml.XMLConstants/feature/secure-processing"; @@ -198,54 +250,15 @@ public final class XMLConstants { * for example, {@link org.xml.sax.SAXException} is thrown. * *

- * Value: a list of protocols separated by comma. A protocol is the scheme portion of a - * {@link java.net.URI}, or in the case of the JAR protocol, "jar" plus the scheme portion - * separated by colon. - * A scheme is defined as: - * - *

- * scheme = alpha *( alpha | digit | "+" | "-" | "." )
- * where alpha = a-z and A-Z.

- * - * And the JAR protocol:
- * - * jar[:scheme]

- * - * Protocols including the keyword "jar" are case-insensitive. Any whitespaces as defined by - * {@link java.lang.Character#isSpaceChar } in the value will be ignored. - * Examples of protocols are file, http, jar:file. - * - *
- * - *

- * Default value: The default value is implementation specific and therefore not specified. - * The following options are provided for consideration: - *

- *
- * When FEATURE_SECURE_PROCESSING is enabled, it is recommended that implementations - * restrict external connections by default, though this may cause problems for applications - * that process XML/XSD/XSL with external references. - *
+ * Value: as defined in the class description. * *

- * Granting all access: the keyword "all" grants permission to all protocols. + * System Property: {@code javax.xml.accessExternalDTD}. * *

- * System Property: The value of this property can be set or overridden by - * system property {@code javax.xml.accessExternalDTD}. - * - * - *

- * jaxp.properties: This configuration file is in standard - * {@link java.util.Properties} format and typically located in the {@code conf} - * directory of the Java installation. If the file exists and the system - * property is specified, its value will be used to override the default - * of the property. - * + * Configuration File: + * Yes. The property can be set in the + * configuration file. * * @since 1.7 */ @@ -262,53 +275,16 @@ public final class XMLConstants { * for example, org.xml.sax.SAXException is thrown. * *

- * Value: a list of protocols separated by comma. A protocol is the scheme portion of a - * {@link java.net.URI}, or in the case of the JAR protocol, "jar" plus the scheme portion - * separated by colon. - * A scheme is defined as: - * - *

- * scheme = alpha *( alpha | digit | "+" | "-" | "." )
- * where alpha = a-z and A-Z.

- * - * And the JAR protocol:
- * - * jar[:scheme]

- * - * Protocols including the keyword "jar" are case-insensitive. Any whitespaces as defined by - * {@link java.lang.Character#isSpaceChar } in the value will be ignored. - * Examples of protocols are file, http, jar:file. - * - *
+ * Value: as defined in the class description. * *

- * Default value: The default value is implementation specific and therefore not specified. - * The following options are provided for consideration: - *

- *
- * When FEATURE_SECURE_PROCESSING is enabled, it is recommended that implementations - * restrict external connections by default, though this may cause problems for applications - * that process XML/XSD/XSL with external references. - *
+ * System Property: {@code javax.xml.accessExternalSchema} * *

- * Granting all access: the keyword "all" grants permission to all protocols. - * - *

- * System Property: The value of this property can be set or overridden by - * system property {@code javax.xml.accessExternalSchema} - * - *

- * jaxp.properties: This configuration file is in standard - * {@link java.util.Properties} format and typically located in the {@code conf} - * directory of the Java installation. If the file exists and the system - * property is specified, its value will be used to override the default - * of the property. - * + * Configuration File: + * Yes. The property can be set in the + * configuration file. + * * @since 1.7 */ public static final String ACCESS_EXTERNAL_SCHEMA = "http://javax.xml.XMLConstants/property/accessExternalSchema"; @@ -326,52 +302,15 @@ public final class XMLConstants { * will be thrown by the {@link javax.xml.transform.TransformerFactory}. * *

- * Value: a list of protocols separated by comma. A protocol is the scheme portion of a - * {@link java.net.URI}, or in the case of the JAR protocol, "jar" plus the scheme portion - * separated by colon. - * A scheme is defined as: - * - *

- * scheme = alpha *( alpha | digit | "+" | "-" | "." )
- * where alpha = a-z and A-Z.

- * - * And the JAR protocol:
- * - * jar[:scheme]

- * - * Protocols including the keyword "jar" are case-insensitive. Any whitespaces as defined by - * {@link java.lang.Character#isSpaceChar } in the value will be ignored. - * Examples of protocols are file, http, jar:file. - * - *
+ * Value: as defined in the class description. * *

- * Default value: The default value is implementation specific and therefore not specified. - * The following options are provided for consideration: - *

- *
- * When FEATURE_SECURE_PROCESSING is enabled, it is recommended that implementations - * restrict external connections by default, though this may cause problems for applications - * that process XML/XSD/XSL with external references. - *
+ * System Property: {@code javax.xml.accessExternalStylesheet} * *

- * Granting all access: the keyword "all" grants permission to all protocols. - * - *

- * System Property: The value of this property can be set or overridden by - * system property {@code javax.xml.accessExternalStylesheet} - * - *

- * jaxp.properties: This configuration file is in standard - * {@link java.util.Properties} format and typically located in the {@code conf} - * directory of the Java installation. If the file exists and the system - * property is specified, its value will be used to override the default - * of the property. + * Configuration File: + * Yes. The property can be set in the + * configuration file. * * @since 1.7 */ @@ -384,15 +323,15 @@ public final class XMLConstants { *

* Instructs XML processors to use XML Catalogs to resolve entity references. * Catalogs may be set through JAXP factories, system properties, or - * jaxp.properties by using the {@code javax.xml.catalog.files} property + * configuration file by using the {@code javax.xml.catalog.files} property * defined in {@link javax.xml.catalog.CatalogFeatures}. * The following code enables Catalog on SAX parser: - *

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

* Value: a boolean. If the value is true, and a catalog is set, @@ -401,15 +340,12 @@ public final class XMLConstants { * XML Catalog is ignored even if one is set. The default value is true. * *

- * System Property: The value of this property can be set or overridden by - * system property {@code javax.xml.useCatalog} + * System Property: {@code javax.xml.useCatalog} * *

- * jaxp.properties: This configuration file is in standard - * {@link java.util.Properties} format and typically located in the {@code conf} - * directory of the Java installation. If the file exists and the system - * property is specified, its value will be used to override the default - * value of the property. + * Configuration File: + * Yes. The property can be set in the + * configuration file. * * @since 9 */ diff --git a/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java b/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java index 3e740c2a413..5d4c9c58215 100644 --- a/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java +++ b/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,8 +24,6 @@ */ package javax.xml.catalog; -import java.net.MalformedURLException; -import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; import jdk.xml.internal.SecuritySupport; @@ -42,7 +40,6 @@ import jdk.xml.internal.SecuritySupport; * Description * Property Name * System Property [1] - * jaxp.properties [1] * Value [2] * Action * @@ -61,7 +58,6 @@ import jdk.xml.internal.SecuritySupport; * * javax.xml.catalog.files * javax.xml.catalog.files - * javax.xml.catalog.files * String * URIs * @@ -76,7 +72,6 @@ import jdk.xml.internal.SecuritySupport; * identifiers. The default value is public [3]. * javax.xml.catalog.prefer * N/A - * N/A * String * {@code system} * @@ -97,7 +92,6 @@ import jdk.xml.internal.SecuritySupport; * needed. The default value is true. * javax.xml.catalog.defer [4] * javax.xml.catalog.defer - * javax.xml.catalog.defer * String * {@code true} * @@ -116,7 +110,6 @@ import jdk.xml.internal.SecuritySupport; * all of the specified catalogs are exhausted. The default is strict. * javax.xml.catalog.resolve [4] * javax.xml.catalog.resolve - * javax.xml.catalog.resolve * String * {@code strict} * @@ -140,7 +133,6 @@ import jdk.xml.internal.SecuritySupport; * *

* [1] There is no System property for the features that marked as "N/A". - * *

* [2] The value shall be exactly as listed in this table, case-sensitive. * Any unspecified value will result in {@link IllegalArgumentException}. @@ -164,33 +156,22 @@ import jdk.xml.internal.SecuritySupport; * set the property {@code javax.xml.catalog.defer} to false to allow the entire * catalog to be pre-loaded. * - *

Scope and Order

- * Features and properties can be set through the catalog file, the Catalog API, - * system properties, and {@code jaxp.properties}, with a preference in the same order. - *

- * Properties that are specified as attributes in the catalog file for the - * catalog and group entries shall take preference over any of the other settings. + *

Property Precedence

+ * The Catalog Features follow the + * Property Precedence + * as described in the module summary with regards to the priority with which + * their values are retrieved from the various configuration sources such as the + * JAXP configuration file, + * system and API properties. In addition to the general configuration sources, + * the Catalog Features are further supported in the catalog file itself where + * they can be specified as attributes of the catalog and group entries. When the + * attributes are specified, they shall take preference over any of the other + * configuration sources. * For example, if a {@code prefer} attribute is set in the catalog file as in * {@code }, any other input for the "prefer" property * is not necessary or will be ignored. - *

- * Properties set through the Catalog API override those that may have been set - * by system properties and/or in {@code jaxp.properties}. In case of multiple - * interfaces, the latest in a procedure shall take preference. For - * {@link Feature#FILES}, this means that the URI(s) specified through the methods - * of the {@link CatalogManager} will override any that may have been entered - * through the {@link Builder}. * *

- * System properties when set shall override those in {@code jaxp.properties}. - *

- * The {@code jaxp.properties} file is typically in the conf directory of the Java - * installation. The file is read only once by the JAXP implementation and - * its values are then cached for future use. If the file does not exist - * when the first attempt is made to read from it, no further attempts are - * made to check for its existence. It is not possible to change the value - * of any properties in {@code jaxp.properties} after it has been read. - *

* A CatalogFeatures instance can be created through its builder as illustrated * in the following sample code: *

{@code
@@ -489,7 +470,7 @@ public class CatalogFeatures {
 
     /**
      * States of the settings of a property, in the order: default value,
-     * jaxp.properties file, jaxp system properties, and jaxp api properties
+     * configuration file, jaxp system properties, and jaxp api properties
      */
     static enum State {
         /** represents the default state of a feature. */
@@ -622,7 +603,7 @@ public class CatalogFeatures {
                 return true;
             }
 
-            value = SecuritySupport.readJAXPProperty(sysPropertyName);
+            value = SecuritySupport.readConfig(sysPropertyName);
             if (value != null && !value.isEmpty()) {
                 setProperty(cf, State.JAXPDOTPROPERTIES, value);
                 return true;
diff --git a/src/java.xml/share/classes/javax/xml/catalog/package-info.java b/src/java.xml/share/classes/javax/xml/catalog/package-info.java
index b727bca77ef..70db1b31a6c 100644
--- a/src/java.xml/share/classes/javax/xml/catalog/package-info.java
+++ b/src/java.xml/share/classes/javax/xml/catalog/package-info.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2023, 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
@@ -33,7 +33,7 @@
  * The Catalog API defines a standard solution for resolving external resources
  * referenced by XML documents. It is fully supported by the XML Processors
  * allowing application developers to configure a catalog through an XML processor
- * or system property or the jaxp.properties file to take advantage of the feature.
+ * or system property or the configuration file to take advantage of the feature.
  * 

* The XML Catalog API defines the following interfaces: *

    diff --git a/src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java b/src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java index e3334bec59d..9074ea2e44f 100644 --- a/src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java +++ b/src/java.xml/share/classes/javax/xml/datatype/FactoryFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,11 +25,9 @@ package javax.xml.datatype; -import java.io.File; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Iterator; -import java.util.Properties; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.function.Supplier; @@ -51,17 +49,6 @@ class FactoryFinder { */ private static boolean debug = false; - /** - * Cache for properties in java.home/conf/jaxp.properties - */ - private final static Properties cacheProps = new Properties(); - - /** - * Flag indicating if properties from java.home/conf/jaxp.properties - * have been cached. - */ - private static volatile boolean firstTime = true; - // Define system property "jaxp.debug" to get output static { // Use try/catch block to support applets, which throws @@ -233,31 +220,10 @@ class FactoryFinder { if (debug) se.printStackTrace(); } - // try to read from $java.home/conf/jaxp.properties - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - String configFile = SecuritySupport.getSystemProperty("java.home") + File.separator + - "conf" + File.separator + "jaxp.properties"; - File f = new File(configFile); - firstTime = false; - if (SecuritySupport.doesFileExist(f)) { - dPrint(()->"Read properties file "+f); - cacheProps.load(SecuritySupport.getFileInputStream(f)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(factoryId); - - if (factoryClassName != null) { - dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName); - return newInstance(type, factoryClassName, null, true); - } - } - catch (Exception ex) { - if (debug) ex.printStackTrace(); + // try to read from the configuration file + String factoryClassName = SecuritySupport.readConfig(factoryId); + if (factoryClassName != null) { + return newInstance(type, factoryClassName, null, true); } // Try Jar Service Provider Mechanism diff --git a/src/java.xml/share/classes/javax/xml/parsers/FactoryFinder.java b/src/java.xml/share/classes/javax/xml/parsers/FactoryFinder.java index b8945fd57c0..b11f030d4f6 100644 --- a/src/java.xml/share/classes/javax/xml/parsers/FactoryFinder.java +++ b/src/java.xml/share/classes/javax/xml/parsers/FactoryFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,11 +25,9 @@ package javax.xml.parsers; -import java.io.File; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Iterator; -import java.util.Properties; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.function.Supplier; @@ -50,17 +48,6 @@ class FactoryFinder { */ private static boolean debug = false; - /** - * Cache for properties in java.home/conf/jaxp.properties - */ - private static final Properties cacheProps = new Properties(); - - /** - * Flag indicating if properties from java.home/conf/jaxp.properties - * have been cached. - */ - static volatile boolean firstTime = true; - // Define system property "jaxp.debug" to get output static { // Use try/catch block to support applets, which throws @@ -231,31 +218,10 @@ class FactoryFinder { if (debug) se.printStackTrace(); } - // try to read from $java.home/conf/jaxp.properties - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - String configFile = SecuritySupport.getSystemProperty("java.home") + File.separator + - "conf" + File.separator + "jaxp.properties"; - File f = new File(configFile); - firstTime = false; - if (SecuritySupport.doesFileExist(f)) { - dPrint(()->"Read properties file "+f); - cacheProps.load(SecuritySupport.getFileInputStream(f)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(factoryId); - - if (factoryClassName != null) { - dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName); - return newInstance(type, factoryClassName, null, true); - } - } - catch (Exception ex) { - if (debug) ex.printStackTrace(); + // try to read from the configuration file + String factoryClassName = SecuritySupport.readConfig(factoryId); + if (factoryClassName != null) { + return newInstance(type, factoryClassName, null, true); } // Try Jar Service Provider Mechanism diff --git a/src/java.xml/share/classes/javax/xml/stream/FactoryFinder.java b/src/java.xml/share/classes/javax/xml/stream/FactoryFinder.java index 52630eb32ec..d3375a3db62 100644 --- a/src/java.xml/share/classes/javax/xml/stream/FactoryFinder.java +++ b/src/java.xml/share/classes/javax/xml/stream/FactoryFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,11 +25,9 @@ package javax.xml.stream; -import java.io.File; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Iterator; -import java.util.Properties; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.function.Supplier; @@ -52,17 +50,6 @@ class FactoryFinder { */ private static boolean debug = false; - /** - * Cache for properties in java.home/conf/jaxp.properties - */ - final private static Properties cacheProps = new Properties(); - - /** - * Flag indicating if properties from java.home/conf/jaxp.properties - * have been cached. - */ - private static volatile boolean firstTime = true; - // Define system property "jaxp.debug" to get output static { // Use try/catch block to support applets, which throws @@ -266,43 +253,10 @@ class FactoryFinder { "Failed to read factoryId '" + factoryId + "'", se); } - // Try read $java.home/conf/stax.properties followed by - // $java.home/conf/jaxp.properties if former not present - String configFile = null; - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - configFile = SecuritySupport.getSystemProperty("java.home") + File.separator + - "conf" + File.separator + "stax.properties"; - final File fStax = new File(configFile); - firstTime = false; - if (SecuritySupport.doesFileExist(fStax)) { - dPrint(()->"Read properties file "+fStax); - cacheProps.load(SecuritySupport.getFileInputStream(fStax)); - } - else { - configFile = SecuritySupport.getSystemProperty("java.home") + File.separator + - "conf" + File.separator + "jaxp.properties"; - final File fJaxp = new File(configFile); - if (SecuritySupport.doesFileExist(fJaxp)) { - dPrint(()->"Read properties file "+fJaxp); - cacheProps.load(SecuritySupport.getFileInputStream(fJaxp)); - } - } - } - } - } - final String factoryClassName = cacheProps.getProperty(factoryId); - - if (factoryClassName != null) { - final String foundIn = configFile; - dPrint(()->"found in " + foundIn + " value=" + factoryClassName); - return newInstance(type, factoryClassName, cl, true); - } - } - catch (Exception ex) { - if (debug) ex.printStackTrace(); + // try to read from the configuration file + String factoryClassName = SecuritySupport.readConfig(factoryId, true); + if (factoryClassName != null) { + return newInstance(type, factoryClassName, cl, true); } if (type.getName().equals(factoryId)) { diff --git a/src/java.xml/share/classes/javax/xml/stream/XMLEventFactory.java b/src/java.xml/share/classes/javax/xml/stream/XMLEventFactory.java index 8a545f05b1f..5c8713f614d 100644 --- a/src/java.xml/share/classes/javax/xml/stream/XMLEventFactory.java +++ b/src/java.xml/share/classes/javax/xml/stream/XMLEventFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2023, 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 @@ -82,7 +82,7 @@ public abstract class XMLEventFactory { /** * Creates a new instance of the factory. This method uses the - * JAXP Lookup Mechanism + * JAXP Lookup Mechanism * to determine the {@code XMLEventFactory} implementation class to load. *

    * Once an application has obtained a reference to a {@code XMLEventFactory}, it @@ -134,23 +134,10 @@ public abstract class XMLEventFactory { * *

  • *

    - * Use the configuration file "stax.properties". The file is in standard - * {@link java.util.Properties} format and typically located in the - * conf directory of the Java installation. It contains the fully qualified - * name of the implementation class with the key being the system property - * defined above. - * - *

    - * The stax.properties file is read only once by the implementation - * and its values are then cached for future use. If the file does not exist - * when the first attempt is made to read from it, no further attempts are - * made to check for its existence. It is not possible to change the value - * of any property in stax.properties after it has been read for the first time. - * - *

    - * Use the jaxp configuration file "jaxp.properties". The file is in the same - * format as stax.properties and will only be read if stax.properties does - * not exist. + * Use the value of the property {@code factoryId} set in the + * configuration file, + * jaxp.properties by default. If the file exists and the property {@code factoryId} + * is specified in the file, its value will be used as the implementation class. *

  • *
  • *

    diff --git a/src/java.xml/share/classes/javax/xml/stream/XMLInputFactory.java b/src/java.xml/share/classes/javax/xml/stream/XMLInputFactory.java index 12bc032a40e..1d6c1bfac53 100644 --- a/src/java.xml/share/classes/javax/xml/stream/XMLInputFactory.java +++ b/src/java.xml/share/classes/javax/xml/stream/XMLInputFactory.java @@ -168,7 +168,7 @@ public abstract class XMLInputFactory { /** * Creates a new instance of the factory. This method uses the - * JAXP Lookup Mechanism + * JAXP Lookup Mechanism * to determine the {@code XMLInputFactory} implementation class to load. *

    * Once an application has obtained a reference to a {@code XMLInputFactory}, it @@ -221,23 +221,10 @@ public abstract class XMLInputFactory { *

  • *
  • *

    - * Use the configuration file "stax.properties". The file is in standard - * {@link java.util.Properties} format and typically located in the - * {@code conf} directory of the Java installation. It contains the fully qualified - * name of the implementation class with the key being the system property - * defined above. - * - *

    - * The stax.properties file is read only once by the implementation - * and its values are then cached for future use. If the file does not exist - * when the first attempt is made to read from it, no further attempts are - * made to check for its existence. It is not possible to change the value - * of any property in stax.properties after it has been read for the first time. - * - *

    - * Use the jaxp configuration file "jaxp.properties". The file is in the same - * format as stax.properties and will only be read if stax.properties does - * not exist. + * Use the value of the property {@code factoryId} set in the + * configuration file, + * jaxp.properties by default. If the file exists and the property {@code factoryId} + * is specified in the file, its value will be used as the implementation class. *

  • *
  • *

    diff --git a/src/java.xml/share/classes/javax/xml/stream/XMLOutputFactory.java b/src/java.xml/share/classes/javax/xml/stream/XMLOutputFactory.java index 161249a8550..7b70e2ba6cb 100644 --- a/src/java.xml/share/classes/javax/xml/stream/XMLOutputFactory.java +++ b/src/java.xml/share/classes/javax/xml/stream/XMLOutputFactory.java @@ -145,7 +145,7 @@ public abstract class XMLOutputFactory { /** * Creates a new instance of the factory. This method uses the - * JAXP Lookup Mechanism + * JAXP Lookup Mechanism * to determine the {@code XMLOutputFactory} implementation class to load. *

    * Once an application has obtained a reference to a {@code XMLOutputFactory}, it @@ -196,23 +196,10 @@ public abstract class XMLOutputFactory { *

  • *
  • *

    - * Use the configuration file "stax.properties". The file is in standard - * {@link java.util.Properties} format and typically located in the - * {@code conf} directory of the Java installation. It contains the fully qualified - * name of the implementation class with the key being the system property - * defined above. - * - *

    - * The stax.properties file is read only once by the implementation - * and its values are then cached for future use. If the file does not exist - * when the first attempt is made to read from it, no further attempts are - * made to check for its existence. It is not possible to change the value - * of any property in stax.properties after it has been read for the first time. - * - *

    - * Use the jaxp configuration file "jaxp.properties". The file is in the same - * format as stax.properties and will only be read if stax.properties does - * not exist. + * Use the value of the property {@code factoryId} set in the + * configuration file, + * jaxp.properties by default. If the file exists and the property {@code factoryId} + * is specified in the file, its value will be used as the implementation class. *

  • *
  • *

    diff --git a/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java b/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java index b9e499c0c12..3b1944fa8de 100644 --- a/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java +++ b/src/java.xml/share/classes/javax/xml/transform/FactoryFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,13 +25,9 @@ package javax.xml.transform; -import java.io.File; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Iterator; -import java.util.Properties; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.function.Supplier; @@ -53,17 +49,6 @@ class FactoryFinder { */ private static boolean debug = false; - /** - * Cache for properties in java.home/conf/jaxp.properties - */ - private final static Properties cacheProps = new Properties(); - - /** - * Flag indicating if properties from java.home/conf/jaxp.properties - * have been cached. - */ - static volatile boolean firstTime = true; - // Define system property "jaxp.debug" to get output static { // Use try/catch block to support applets, which throws @@ -217,31 +202,10 @@ class FactoryFinder { if (debug) se.printStackTrace(); } - // try to read from $java.home/conf/jaxp.properties - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - String configFile = SecuritySupport.getSystemProperty("java.home") + File.separator + - "conf" + File.separator + "jaxp.properties"; - File f = new File(configFile); - firstTime = false; - if (SecuritySupport.doesFileExist(f)) { - dPrint(()->"Read properties file "+f); - cacheProps.load(SecuritySupport.getFileInputStream(f)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(factoryId); - - if (factoryClassName != null) { - dPrint(()->"found in ${java.home}/conf/jaxp.properties, value=" + factoryClassName); - return newInstance(type, factoryClassName, null, true); - } - } - catch (Exception ex) { - if (debug) ex.printStackTrace(); + // try to read from the configuration file + String factoryClassName = SecuritySupport.readConfig(factoryId); + if (factoryClassName != null) { + return newInstance(type, factoryClassName, null, true); } // Try Jar Service Provider Mechanism diff --git a/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java b/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java index ec80c2b5283..7140483ae5a 100644 --- a/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java +++ b/src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2023, 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,14 +26,10 @@ 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; -import java.lang.reflect.Modifier; import java.security.AccessControlContext; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.Properties; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.function.Supplier; @@ -51,15 +47,6 @@ class SchemaFactoryFinder { private static boolean debug = false; private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xerces.internal"; - /** - *

    Cache properties for performance.

    - */ - private static final Properties cacheProps = new Properties(); - - /** - *

    First time requires initialization overhead.

    - */ - private static volatile boolean firstTime = true; static { // Use try/catch block to support applets @@ -179,37 +166,12 @@ class SchemaFactoryFinder { } } - String javah = SecuritySupport.getSystemProperty( "java.home" ); - String configFile = javah + File.separator + - "conf" + File.separator + "jaxp.properties"; - - - // try to read from $java.home/conf/jaxp.properties - try { - if(firstTime){ - synchronized(cacheProps){ - if(firstTime){ - File f=new File( configFile ); - firstTime = false; - if(SecuritySupport.doesFileExist(f)){ - debugPrintln(()->"Read properties file " + f); - cacheProps.load(SecuritySupport.getFileInputStream(f)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(propertyName); - debugPrintln(()->"found " + factoryClassName + " in $java.home/conf/jaxp.properties"); - - if (factoryClassName != null) { - sf = createInstance(factoryClassName); - if(sf != null){ - return sf; - } - } - } catch (Exception ex) { - if (debug) { - ex.printStackTrace(); + // try to read from the configuration file + String factoryClassName = SecuritySupport.readConfig(propertyName); + if (factoryClassName != null) { + sf = createInstance(factoryClassName); + if(sf != null){ + return sf; } } diff --git a/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java b/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java index f6d7d9152bd..c6cdb6d4098 100644 --- a/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java +++ b/src/java.xml/share/classes/javax/xml/xpath/XPathFactoryFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2023, 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 javax.xml.xpath; import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl; -import java.io.File; import java.lang.reflect.InvocationTargetException; import java.security.AccessControlContext; import java.security.AccessController; @@ -174,36 +173,11 @@ class XPathFactoryFinder { } } - String javah = SecuritySupport.getSystemProperty( "java.home" ); - String configFile = javah + File.separator + - "conf" + File.separator + "jaxp.properties"; - - // try to read from $java.home/conf/jaxp.properties - try { - if(firstTime){ - synchronized(cacheProps){ - if(firstTime){ - File f=new File( configFile ); - firstTime = false; - if(SecuritySupport.doesFileExist(f)){ - debugPrintln(()->"Read properties file " + f); - cacheProps.load(SecuritySupport.getFileInputStream(f)); - } - } - } - } - final String factoryClassName = cacheProps.getProperty(propertyName); - debugPrintln(()->"found " + factoryClassName + " in $java.home/conf/jaxp.properties"); - - if (factoryClassName != null) { - xpathFactory = createInstance(factoryClassName); - if(xpathFactory != null){ - return xpathFactory; - } - } - } catch (Exception ex) { - if (debug) { - ex.printStackTrace(); + String factoryClassName = SecuritySupport.readConfig(propertyName); + if (factoryClassName != null) { + xpathFactory = createInstance(factoryClassName); + if(xpathFactory != null){ + return xpathFactory; } } diff --git a/src/java.xml/share/classes/jdk/xml/internal/JdkConstants.java b/src/java.xml/share/classes/jdk/xml/internal/JdkConstants.java index d01b799e57a..939687f7dfd 100644 --- a/src/java.xml/share/classes/jdk/xml/internal/JdkConstants.java +++ b/src/java.xml/share/classes/jdk/xml/internal/JdkConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2023, 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 @@ -283,6 +283,12 @@ public final class JdkConstants { public static final String XML_SECURITY_PROPERTY_MANAGER = "jdk.xml.xmlSecurityPropertyManager"; + /** + * System Property for the Configuration File + * @since 21 + */ + public static final String CONFIG_FILE = "java.xml.config.file"; + /** * Values for a feature */ diff --git a/src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java b/src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java index 1632e55c0f8..bfb43f47d0e 100644 --- a/src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java +++ b/src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, 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 @@ -407,7 +407,7 @@ public class JdkXmlFeatures { return true; } - value = SecuritySupport.readJAXPProperty(sysPropertyName); + value = SecuritySupport.readConfig(sysPropertyName); if (value != null && !value.isEmpty()) { setFeature(feature, State.JAXPDOTPROPERTIES, Boolean.parseBoolean(value)); return true; diff --git a/src/java.xml/share/classes/jdk/xml/internal/SecuritySupport.java b/src/java.xml/share/classes/jdk/xml/internal/SecuritySupport.java index 78962261de1..6ee4bc0b8ac 100644 --- a/src/java.xml/share/classes/jdk/xml/internal/SecuritySupport.java +++ b/src/java.xml/share/classes/jdk/xml/internal/SecuritySupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.file.Paths; import java.security.AccessController; import java.security.CodeSource; import java.security.PrivilegedAction; @@ -159,47 +160,87 @@ public class SecuritySupport { public static String getJAXPSystemProperty(String propName) { String value = getSystemProperty(propName); if (value == null) { - value = readJAXPProperty(propName); + value = readConfig(propName); } return value; } /** - * Reads the specified property from $java.home/conf/jaxp.properties + * Returns the value of the specified property from the Configuration file. + * The method reads the System Property "java.xml.config.file" for a custom + * configuration file, if doesn't exist, falls back to the JDK default that + * is typically located at $java.home/conf/jaxp.properties. * - * @param propName the name of the property - * @return the value of the property + * @param propName the specified property + * @return the value of the specified property, null if the property is not + * found */ - public static String readJAXPProperty(String propName) { - String value = null; - InputStream is = null; - try { - if (firstTime) { - synchronized (cacheProps) { - if (firstTime) { - String configFile = getSystemProperty("java.home") + File.separator - + "conf" + File.separator + "jaxp.properties"; - File f = new File(configFile); - if (isFileExists(f)) { - is = getFileInputStream(f); - cacheProps.load(is); - } - firstTime = false; - } - } - } - value = cacheProps.getProperty(propName); + public static String readConfig(String propName) { + return readConfig(propName, false); + } - } catch (IOException ex) { - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException ex) {} + /** + * Returns the value of the specified property from the Configuration file. + * The method reads the JDK default configuration that is typically located + * at $java.home/conf/jaxp.properties. On top of the default, if the System + * Property "java.xml.config.file" exists, the configuration file it points + * to will also be read. Any settings in it will then override those in the + * default. + * + * @param propName the specified property + * @param stax a flag indicating whether to read stax.properties + * @return the value of the specified property, null if the property is not + * found + */ + public static String readConfig(String propName, boolean stax) { + // always load the default configuration file + if (firstTime) { + synchronized (cacheProps) { + if (firstTime) { + boolean found = loadProperties( + Paths.get(SecuritySupport.getSystemProperty("java.home"), + "conf", "jaxp.properties") + .toAbsolutePath().normalize().toString()); + + // attempts to find stax.properties only if jaxp.properties is not available + if (stax && !found) { + found = loadProperties( + Paths.get(SecuritySupport.getSystemProperty("java.home"), + "conf", "stax.properties") + .toAbsolutePath().normalize().toString() + ); + } + + // load the custom configure on top of the default if any + String configFile = SecuritySupport.getSystemProperty(JdkConstants.CONFIG_FILE); + if (configFile != null) { + loadProperties(configFile); + } + + firstTime = false; + } } } - return value; + return cacheProps.getProperty(propName); + } + + /** + * Loads the properties from the specified file into the cache. + * @param file the specified file + * @return true if success, false otherwise + */ + private static boolean loadProperties(String file) { + File f = new File(file); + if (SecuritySupport.doesFileExist(f)) { + try (final InputStream in = SecuritySupport.getFileInputStream(f)) { + cacheProps.load(in); + return true; + } catch (IOException e) { + // shouldn't happen, but required by method getFileInputStream + } + } + return false; } /** diff --git a/src/java.xml/share/classes/jdk/xml/internal/XMLSecurityManager.java b/src/java.xml/share/classes/jdk/xml/internal/XMLSecurityManager.java index cf803eca3d4..1afc95776cf 100644 --- a/src/java.xml/share/classes/jdk/xml/internal/XMLSecurityManager.java +++ b/src/java.xml/share/classes/jdk/xml/internal/XMLSecurityManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -535,22 +535,17 @@ public final class XMLSecurityManager { } /** - * Read from system properties, or those in jaxp.properties + * Read system properties, or the configuration file */ private void readSystemProperties() { - for (Limit limit : Limit.values()) { - if (!getSystemProperty(limit, limit.systemProperty())) { - //if system property is not found, try the older form if any - for (NameMap nameMap : NameMap.values()) { - String oldName = nameMap.getOldName(limit.systemProperty()); - if (oldName != null) { - getSystemProperty(limit, oldName); - } - } + // attempts to read both the current and old system propery + if (!getSystemProperty(limit, limit.systemProperty()) + && (!getOldSystemProperty(limit))) { + //if system property is not found, try the config file + getPropertyConfig(limit, limit.systemProperty()); } } - } // Array list to store printed warnings for each SAX parser used @@ -571,9 +566,9 @@ public final class XMLSecurityManager { } /** - * Read from system properties, or those in jaxp.properties + * Reads a system property, sets value and state if found. * - * @param property the type of the property + * @param limit the limit property * @param sysPropertyName the name of system property */ private boolean getSystemProperty(Limit limit, String sysPropertyName) { @@ -584,8 +579,42 @@ public final class XMLSecurityManager { states[limit.ordinal()] = State.SYSTEMPROPERTY; return true; } + } catch (NumberFormatException e) { + //invalid setting + throw new NumberFormatException("Invalid setting for system property: " + limit.systemProperty()); + } + return false; + } - value = SecuritySupport.readJAXPProperty(sysPropertyName); + /** + * Reads the legacy system property. + * @param limit a limit object + * @return true if found, false otherwise + */ + private boolean getOldSystemProperty(Limit limit) { + boolean found = false; + for (NameMap nameMap : NameMap.values()) { + String oldName = nameMap.getOldName(limit.systemProperty()); + if (oldName != null) { + if (getSystemProperty(limit, oldName)) { + found = true; + break; + } + } + } + return found; + } + + /** + * Reads a property from a configuration file, if any. + * + * @param limit the limit property + * @param sysPropertyName the name of system property + * @return + */ + private boolean getPropertyConfig(Limit limit, String sysPropertyName) { + try { + String value = SecuritySupport.readConfig(sysPropertyName); if (value != null && !value.equals("")) { values[limit.ordinal()] = Integer.parseInt(value); states[limit.ordinal()] = State.JAXPDOTPROPERTIES; @@ -598,7 +627,6 @@ public final class XMLSecurityManager { return false; } - /** * Convert a value set through setProperty to XMLSecurityManager. * If the value is an instance of XMLSecurityManager, use it to override the default; diff --git a/src/java.xml/share/classes/module-info.java b/src/java.xml/share/classes/module-info.java index c5eeffa08a2..a39b490a9cb 100644 --- a/src/java.xml/share/classes/module-info.java +++ b/src/java.xml/share/classes/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,14 +24,222 @@ */ /** - * Defines the Java API for XML Processing (JAXP), the Streaming API for XML (StAX), - * the Simple API for XML (SAX), and the W3C Document Object Model (DOM) API. + * Defines the Java APIs for XML Processing (JAXP). + * + * + * + *

    The JAXP APIs

    + * JAXP comprises a set of APIs built upon a number of XML technologies and + * standards that are essential for XML processing. These include APIs for: + * + *
      + *
    • Parsing: the {@link javax.xml.parsers JAXP Parsing API} based on + * {@link org.w3c.dom Document Object Model (DOM)} and + * {@link org.xml.sax Simple API for XML Parsing (SAX)}, and + * {@link javax.xml.stream Streaming API for XML (StAX)}; + *
    • + *
    • Serializing: StAX and + * {@link javax.xml.transform Extensible Stylesheet Language Transformations (XSLT)}; + *
    • + *
    • Validation: the {@link javax.xml.validation JAXP Validation API} + * based on the XML Schema Definition Language;
    • + *
    • Transformation: the {@link javax.xml.transform JAXP Transformation API} + * or XSLT (Extensible Stylesheet Language Transformations);
    • + *
    • Querying and traversing XML documents: the + * {@link javax.xml.xpath XML XPath Language API (XPath)};
    • + *
    • Resolving external resources: the {@link javax.xml.catalog XML Catalog API};
    • + *
    + * + *

    Factories and Processors

    + * Factories are the entry points of each API, providing methods to allow applications + * to set JAXP Properties programmatically, before + * creating processors. The Configuration section provides more + * details on this. Factories also support the + * JAXP Lookup Mechanism, in which applications can be + * deployed with third party implementations to use instead of JDK implementations + *

    + * + * Processors are aggregates of parsers (or readers), serializers (or writers), + * validators, and transformers that control and perform the processing in their + * respective areas. They are defined in their relevant packages. + * In the {@link javax.xml.parsers parsers} package for example, + * are the {@link javax.xml.parsers.DocumentBuilder DocumentBuilder} and + * {@link javax.xml.parsers.SAXParser SAXParser}, that represent the DOM and + * SAX processors. + *

    + * The processors are configured and instantiated with their corresponding factories. + * The DocumentBuilder and SAXParser for example are constructed with the + * {@link javax.xml.parsers.DocumentBuilderFactory DocumentBuilderFactory} + * and {@link javax.xml.parsers.SAXParserFactory SAXParserFactory} respectively. + * + *

    Configuration

    + * When a JAXP factory is invoked for the first time, it performs a configuration + * process to determine the implementation to be used and its subsequent behaviors. + * During configuration, the factory examines configuration sources such as the + * JAXP Properties, + * System Properties, + * and the JAXP Configuration File, and sets the values + * following the Property Precedence. The terminologies and + * process are defined below. + * + *

    JAXP Properties

    + * JAXP properties are configuration settings that are applied to XML processors. + * They can be used to control and customize the behavior of a processor. + * Depending on the JAXP API that is being used, JAXP properties may be referred + * to as Attributes, Properties, or Features. + * + *

    System Properties

    + * Select JAXP properties have corresponding System Properties allowing the properties + * to be set at runtime, on the command line, or within the + * JAXP Configuration File. + * For example, the System Property {@code javax.xml.catalog.resolve} may be used + * to set the {@link javax.xml.catalog.CatalogFeatures CatalogFeatures}' RESOLVE + * property. + *

    + * The exact time at which system properties are read is unspecified. In order to + * ensure that the desired values are properly applied, applications should ensure + * that system properties are set appropriately prior to the creation of the first + * JAXP factory and are not modified thereafter. + * + *

    Configuration File

    + * JAXP supports the use of configuration files for + * specifying the implementation class to load for the JAXP factories + * as well as for setting JAXP properties. + *

    + * Configuration files are Java {@link java.util.Properties} files that consist + * of mappings between system properties and their values defined by various APIs + * or processes. The following configuration file entries demonstrate setting the + * {@code javax.xml.parsers.DocumentBuilderFactory} + * and {@code CatalogFeatures.RESOLVE} properties: + * + * {@snippet : + * javax.xml.parsers.DocumentBuilderFactory=packagename.DocumentBuilderFactoryImpl + * javax.xml.catalog.resolve=strict + * } + * + *

    {@code jaxp.properties} File

    + * By default, JAXP looks for the configuration file {@code jaxp.properties}, + * located in the ${java.home}/conf directory; and if the file exists, loads the + * specified properties to customize the behavior of the XML factories and processors. + *

    + * The {@code jaxp.properties} file will be read only once during the initialization + * of the JAXP implementation and cached in memory. If there is an error accessing + * or reading the file, the configuration process proceeds as if the file does not exist. + * + *

    User-defined Configuration File

    + * In addition to the {@code jaxp.properties} file, the system property + * {@systemProperty java.xml.config.file} can be set to specify the location of + * a configuration file. If the {@code java.xml.config.file} property is included + * within a configuration file, it will be ignored. + * + *

    + * When the {@code java.xml.config.file} is specified, the configuration file will be + * read and the included properties will override the same properties that were + * defined in the {@code jaxp.properties} file. If the {@code java.xml.config.file} + * has not been set when the JAXP implementation is initialized, no further attempt + * will be made to check for its existence. + *

    + * The {@code java.xml.config.file} value must contain a valid pathname + * to a configuration file. If the pathname is not absolute, it will be considered + * relative to the working directory of the JVM. + * If there is an error reading the configuration file, the configuration process + * proceeds as if the {@code java.xml.config.file} property was not set. + * Implementations may optionally issue a warning message. + * + *

    Property Precedence

    + * JAXP properties can be set in multiple ways, including by API methods, system + * properties, and the JAXP Configuration File. When not + * explicitly set, they will be initialized with default values or more restrictive + * values when + * {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING FEATURE_SECURE_PROCESSING} + * (FSP) is enabled. The configuration order of precedence for properties is as + * follows, from highest to lowest: + * + *
      + *
    • + * The APIs for factories or processors + *

    • + *
    • + * System Property + *

    • + *
    • + * User-defined Configuration File + *

    • + *
    • + * The default JAXP Configuration File {@code jaxp.properties} + *

    • + *
    • + * The default values for JAXP Properties. If the + * {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING FSP} is true, + * the default values will be set to process XML securely. + *

    • + *
    + * + * Using the {@link javax.xml.catalog.CatalogFeatures CatalogFeatures}' RESOLVE + * property as an example, the following illustrates how these rules are applied: + *
      + *
    • + * Properties specified with factory or processor APIs have the highest + * precedence. The following code effectively sets the RESOLVE property to + * {@code strict}, regardless of settings in any other configuration sources. + * + * {@snippet : + * DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + * dbf.setAttribute(CatalogFeatures.Feature.RESOLVE.getPropertyName(), "strict"); + * } + * + *

    • + *
    • + * If the property is not set on the factory as in the above code, a + * system property setting will be in effect. + * {@snippet : + * // in the following example, the RESOLVE property is set to 'continue' + * // for the entire application + * java -Djavax.xml.catalog.resolve=continue myApp + * } + *

    • + *
    • + * If the property is not set on the factory, or using a system property, + * the setting in a configuration file will take effect. The following entry + * sets the property to '{@code continue}'. + * {@snippet : + * javax.xml.catalog.resolve=continue + * } + * + *

    • + *
    • + * If the property is not set anywhere, it will be resolved to its + * default value that is '{@code strict}'. + *

    • + *
    * *

    JAXP Lookup Mechanism

    * JAXP defines an ordered lookup procedure to determine the implementation class * to load for the JAXP factories. Factories that support the mechanism are listed - * in the table below along with the method, System Property name, Configuration - * File, and System Default method to be used in the procedure. + * in the table below along with the method, System Property, and System + * Default method to be used in the procedure. * * * @@ -39,8 +247,7 @@ * * * - * - * + * * * * @@ -52,7 +259,6 @@ * * * - * * * * @@ -61,7 +267,6 @@ * * * - * * * * @@ -70,7 +275,6 @@ * * * - * * * * @@ -79,10 +283,6 @@ * * * - * * * * @@ -91,10 +291,6 @@ * * * - * * * * @@ -103,10 +299,6 @@ * * * - * * * * @@ -115,7 +307,6 @@ * * * - * * * * @@ -124,7 +315,6 @@ * * * - * * * * @@ -133,7 +323,6 @@ * * * - * * * * @@ -147,42 +336,21 @@ * {@link javax.xml.xpath.XPathFactory#newInstance(java.lang.String) newInstance(uri)} * method. * - *

    jaxp.properties

    - * {@code jaxp.properties} is a configuration file in standard - * {@link java.util.Properties} format and typically located in the {@code conf} - * directory of the Java installation. It contains the fully qualified - * name of the implementation class with the key being the system property name - * defined in the table above. - *

    - * The {@code jaxp.properties} file is read only once by the implementation and - * the values are then cached for future use. If the file does not exist when - * the first attempt is made to read from it, no further attempts - * are made to check for its existence. It is not possible to change the value - * of any property after it has been read for the first time. - * - *

    stax.properties

    - * {@code stax.properties} is a configuration file that functions the same as - * {@code jaxp.properties} except that it is only used by StAX factory lookup. - * *

    Lookup Procedure

    - * The JAXP Factories follow the procedure described - * below in order to locate and load the implementation class: - * + * The order of precedence for locating the implementation class of a + * JAXP Factory is as follows, from highest to lowest: *
      *
    • - * Use the system property as described in column System Property of the table - * JAXP Factories above. + * The system property as listed in the column System Property of the table + * JAXP Factories above *
    • *
    • *

      - * Use the configuration file jaxp.properties as - * indicated in the table JAXP Factories. For StAX, - * if stax.properties exists, the factories will - * first attempt to read from it instead of jaxp.properties. + * The Configuration File *

    • *
    • *

      - * Use the service-provider loading facility, defined by the + * The service-provider loading facility, defined by the * {@link java.util.ServiceLoader} class, to attempt to locate and load an * implementation of the service using the {@linkplain * java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}: @@ -229,87 +397,34 @@ *

    • *
    * + * + *
    * @implNote - *

    Implementation Specific Features and Properties

    * - * In addition to the standard features and properties described within the public - * APIs of this module, the JDK implementation supports a further number of - * implementation specific features and properties. This section describes the - * naming convention, System Properties, jaxp.properties, scope and order, - * and processors to which a property applies. A table listing the implementation - * specific features and properties which the implementation currently supports - * can be found at the end of this note. + * * - *

    Naming Convention

    - * The names of the features and properties are fully qualified, composed of a - * prefix and name. - * - *

    Prefix

    - * The prefix for JDK features and properties, as well as their corresponding - * System Properties if any, is defined as: - *
    - *     {@code jdk.xml.}
    - * 
    - * - *

    Name

    - * A name may consist of one or multiple words that are case-sensitive. - * All letters of the first word are in lowercase, while the first letter of - * each subsequent word is capitalized. + *

    Implementation Specific Properties

    + * In addition to the standard JAXP Properties, + * the JDK implementation supports a number of implementation specific properties + * whose name is prefixed by "{@code jdk.xml.}". These properties also follow the + * configuration process as defined in the Configuration section. *

    - * An example of a property that indicates whether an XML document is standalone - * would thus have a format: - *

    - *     {@code jdk.xml.isStandalone}
    - * 
    - * and a corresponding System Property: - *
    - *     {@systemProperty jdk.xml.isStandalone}
    - * 
    - * - *

    System Properties

    - * A property may have a corresponding System Property with the same name. - * A System Property should be set prior to the creation of a processor and - * may be cleared afterwards. - * - *

    jaxp.properties

    - * A system property can be specified in the jaxp.properties - * file to set the behavior for all invocations of the JDK. The format is - * {@code system-property-name=value}. For example: - *
    - *     {@code jdk.xml.isStandalone=true}
    - * 
    - * - *

    Scope and Order

    - * The {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature - * (hereafter referred to as secure processing) is required for XML processors - * including DOM, SAX, Schema Validation, XSLT, and XPath. When secure processing - * is set to true, security related features and properties, such as those flagged - * as {@code "security: yes"} (hereafter referred to as security properties) in - * table Implementation Specific Features and - * Properties, - * are enforced. Such enforcement includes setting security properties and features - * to more restrictive values and limits as shown in {@code "Value"}'s - * subcolumn {@code "Enforced"} in the tables. When secure processing - * is set to false, however, the property values will not be affected. - *

    - * When the Java Security Manager is present, secure processing is set to true - * and can not be turned off. The security properties are therefore enforced. - *

    - * Properties specified in the jaxp.properties file affect all invocations of - * the JDK, and will override their default values, or those that may have been - * set by secure processing. - *

    - * System properties, when set, affect the invocation of the JDK and override - * the default settings or those that may have been set in jaxp.properties or - * by secure processing. - *

    - * JAXP properties specified through JAXP factories or processors (e.g. SAXParser) - * take preference over system properties, the jaxp.properties file, as well as - * secure processing. + * Refer to the Implementation Specific Properties table + * for the list of properties supported by the JDK implementation. * *

    Processor Support

    - * Features and properties may be supported by one or more processors. The - * following table lists the processors by IDs that can be used for reference. + * The properties may be supported by one or more processors as listed in the table + * below. Depending on the type of the property, they may be set via + * Method 1: setAttribute/Parameter/Property or 2: setFeature as illustrated + * in the relevant columns. * *
    JAXP Factories
    FactoryMethodSystem Property NameConfiguration FileSystem PropertySystem Default
    {@link javax.xml.datatype.DatatypeFactory#newInstance() newInstance()}{@code javax.xml.datatype.DatatypeFactory}jaxp.properties{@link javax.xml.datatype.DatatypeFactory#newDefaultInstance() newDefaultInstance()}
    {@link javax.xml.parsers.DocumentBuilderFactory#newInstance() newInstance()}{@code javax.xml.parsers.DocumentBuilderFactory}jaxp.properties{@link javax.xml.parsers.DocumentBuilderFactory#newDefaultInstance() newDefaultInstance()}
    {@link javax.xml.parsers.SAXParserFactory#newInstance() newInstance()}{@code javax.xml.parsers.SAXParserFactory}jaxp.properties{@link javax.xml.parsers.SAXParserFactory#newDefaultInstance() newDefaultInstance()}
    {@link javax.xml.stream.XMLEventFactory#newFactory() newFactory()}{@code javax.xml.stream.XMLEventFactory} - * stax.properties and then - * jaxp.properties - * {@link javax.xml.stream.XMLEventFactory#newDefaultFactory() newDefaultFactory()}
    {@link javax.xml.stream.XMLInputFactory#newFactory() newFactory()}{@code javax.xml.stream.XMLInputFactory} - * stax.properties and then - * jaxp.properties - * {@link javax.xml.stream.XMLInputFactory#newDefaultFactory() newDefaultFactory()}
    {@link javax.xml.stream.XMLOutputFactory#newFactory() newFactory()}{@code javax.xml.stream.XMLOutputFactory} - * stax.properties and then - * jaxp.properties - * {@link javax.xml.stream.XMLOutputFactory#newDefaultFactory() newDefaultFactory()}
    {@link javax.xml.transform.TransformerFactory#newInstance() newInstance()}{@code javax.xml.transform.TransformerFactory}jaxp.properties{@link javax.xml.transform.TransformerFactory#newDefaultInstance() newDefaultInstance()}
    {@link javax.xml.validation.SchemaFactory#newInstance(java.lang.String) newInstance(schemaLanguage)}{@code javax.xml.validation.SchemaFactory:}schemaLanguage[1]jaxp.properties{@link javax.xml.validation.SchemaFactory#newDefaultInstance() newDefaultInstance()}
    {@link javax.xml.xpath.XPathFactory#newInstance(java.lang.String) newInstance(uri)}{@link javax.xml.xpath.XPathFactory#DEFAULT_PROPERTY_NAME DEFAULT_PROPERTY_NAME} + ":uri"[2]jaxp.properties{@link javax.xml.xpath.XPathFactory#newDefaultInstance() newDefaultInstance()}
    * @@ -317,8 +432,8 @@ * * * - * - * + * + * * * * @@ -419,34 +534,27 @@ * *
    Processors
    IDNameHow to set the propertyHow to set the featureMethod 1: setAttribute/Parameter/PropertyMethod 2: setFeature
    * - *

    Implementation Specific Features and Properties

    - * The Implementation Specific Features and Properties reflect JDK's choice to - * manage the limitations on resources while complying with the API specification, - * or allow applications to alter behaviors beyond those required by the standards. - *

    - * The table below lists the Implementation Specific Properties currently supported - * by the JDK. More properties may be added in the future if necessary. - * + *

    * * * * - * * - * - * - * - * - * - * - * + * + * + * + * + * * * * * * * + * + * * * * @@ -456,9 +564,7 @@ * * - * - * - * + * * * + * * * * @@ -546,9 +653,6 @@ * {@link org.w3c.dom.ls.LSSerializer#getDomConfig() xml-declaration}, this property * does not have an effect on whether an XML declaration should be written out. * - * - * - * * * * @@ -570,9 +674,6 @@ * except that it is for the XSLTC Serializer * and its value is a String. * - * - * - * * * * @@ -589,8 +690,6 @@ * larger than the specified size to ones that are equal to or smaller than the size. * * - * - * * * - * - * * * * @@ -621,11 +718,6 @@ * * - * - * * * * * * - * + * * * @@ -650,49 +742,17 @@ * * - * * * * * - * - *
    Implementation Specific Properties
    Full Name (prefix + name) + * Full Name (prefix {@code jdk.xml.}) * [1]DescriptionAPI Property [2]System Property [3]jaxp.properties [3]Value [4]Security [5]Supported Processor [6]Since [7]System Property [2]Value [3]Security [4]Supported Processor [5]Since [6]
    TypeValueDefaultEnforcedIDSet Method
    {@systemProperty jdk.xml.entityExpansionLimit}Limits the number of entity expansions. * yesyesyesyesInteger * A positive integer. A value less than or equal to 0 indicates no limit. @@ -474,6 +580,7 @@ * Validation
    * Transform *
    Method 18
    yesyesyesbooleantrue/falsefalseyesyesyesStringyes/nonoyesyesyesIntegerA positive integer. A value less than * or equal to 0 indicates that the property is not specified. If the value is not @@ -606,8 +705,6 @@ * Sets a non-null ClassLoader instance to be used for loading XSLTC java * extension functions. * yesnonoObjectA reference to a ClassLoader object. Null if the value is not specified.jdk.xml.xpathExprGrpLimitLimits the number of groups an XPath expression can contain. * - * Transform:yes
    - * XPath:no - *
    yesyesIntegerA positive integer. A value less than or equal to 0 indicates no limit. @@ -640,7 +732,7 @@ * 19
    jdk.xml.xpathExprGrpLimitjdk.xml.xpathExprOpLimitLimits the number of operators an XPath expression can contain. * 100jdk.xml.xpathTotalOpLimitLimits the total number of XPath operators in an XSL Stylesheet. * yes1000010000 * Transform
    *
    - *

    - * The table below lists the Implementation Specific Features currently supported - * by the JDK. More features may be added in the future if necessary. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * * * * * - * - * * * + * * * * @@ -725,6 +786,7 @@ * Validation
    * XPath * + * * * * @@ -743,6 +805,7 @@ * + * * * * @@ -750,14 +813,12 @@ *

    * [1] The full name of a property should be used to set the property. *

    - * [2] A value "yes" indicates that the property can be set through the - * processor or its factory, "no" otherwise. - *

    - * [3] A value "yes" indicates there is a corresponding System Property - * for the property, "no" otherwise. + * [2] A value "yes" indicates there is a corresponding System Property + * for the property, "no" otherwise. The name of the System Property is the same + * as that of the property. * - *

    - * [4] The value must be exactly as listed in this table, case-sensitive. + *

    + * [3] The value must be exactly as listed in this table, case-sensitive. * The value of the corresponding System Property is the String representation of * the property value. If the type is boolean, the system property is true only * if it is "true"; If the type is String, the system property is true only if @@ -766,31 +827,32 @@ * is Integer, the value of the System Property is the String representation of * the value (e.g. "64000" for {@code entityExpansionLimit}). * - *

    - * [5] A value "yes" indicates the property is a Security Property. Refer - * to the Scope and Order on how secure processing - * may affect the value of a Security Property. - *

    - * [6] One or more processors that support the property. The values of the - * field are IDs described in table Processors. - *

    - * [7] Indicates the initial release the property is introduced. + *

    + * [4] A value "yes" indicates the property is a Security Property. As indicated + * in the Property Precedence, the values listed in the column + * {@code enforced} will be used to initialize these properties when + * {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING FSP} is true. * - *

    Legacy Property Names (deprecated)

    + *

    + * [5] One or more processors that support the property. The IDs and Set Method + * are as shown in the table Processors. + *

    + * [6] Indicates the initial release the property is introduced. + * + *

    Legacy Property Names (deprecated)

    * JDK releases prior to JDK 17 support the use of URI style prefix for properties. * These legacy property names are deprecated as of JDK 17 and may be removed * in future releases. If both new and legacy properties are set, the new property * names take precedence regardless of how and where they are set. The overriding order - * as defined in Scope and Order thus becomes, in - * descending order: + * as defined in Property Precedence thus becomes: * *
      - *
    • The default value;
    • - *
    • Value set by FEATURE_SECURE_PROCESSING;
    • - *
    • Value set in jaxp.properties;
    • - *
    • Value set as System Property;
    • - *
    • Value set on factories or processors using legacy property names;
    • *
    • Value set on factories or processors using new property names.
    • + *
    • Value set on factories or processors using legacy property names;
    • + *
    • Value set as System Property;
    • + *
    • Value set in the configuration file;
    • + *
    • Value set by FEATURE_SECURE_PROCESSING;
    • + *
    • The default value;
    • *
    *

    * The following table lists the properties and their corresponding legacy names. diff --git a/src/java.xml/share/conf/jaxp.properties b/src/java.xml/share/conf/jaxp.properties new file mode 100644 index 00000000000..b43b5a3e8d1 --- /dev/null +++ b/src/java.xml/share/conf/jaxp.properties @@ -0,0 +1,180 @@ +################################################################################ +# JAXP Configuration File +# +# jaxp.properties (this file) is the default configuration file for JAXP, the API +# defined in the java.xml module. It is in java.util.Properties format and typically +# located in the {java.home}/conf directory. It may contain key/value pairs for +# specifying the implementation classes of JAXP factories and/or properties +# that have corresponding system properties. +# +# A user-specified configuration file can be set up using the system property +# java.xml.config.file to override any or all of the entries in jaxp.properties. +# The following statement provides myConfigurationFile as a custom configuration +# file: +# java -Djava.xml.config.file=myConfigurationFile +################################################################################ + +# ---- JAXP Default Configuration ---- +# +# The JAXP default configuration (jaxp.properties) contains entries for the +# Factory Lookup Mechanism and properties with corresponding system properties. +# The values are generally set to the default values of the properties. +# +# +# JAXP Lookup Mechanism: +# +# The JAXP configuration file ranks 2nd to the System Property in the precedent +# order of the JAXP Lookup Mechanism. When the System Property is not specified, +# a JAXP factory reads the configuration file in order to locate an implementation +# class. If found, the class specified will be used as the factory implementation +# class. +# +# The format of an entry is key=value where the key is the fully qualified name +# of the factory and value that of the implementation class. The following entry +# set a DocumentBuilderFactory implementation class: +# +# javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl +# +# +# Java SE and JDK Implementation Specific Properties: +# +# The JAXP configuration file ranks above the default settings in the Property +# Precedence in that its entries will override the default values of the corresponding +# properties. +# +# All properties that have System Properties defined in Java SE or supported +# by the JDK Implementation can be placed in the configuration file to override +# the default property values. The format is: +# system-property-name=value +# +# For example, the FILES property in CatalogFeatures has an associated system +# property called javax.xml.catalog.files. An entry for the FILES property in the +# configuration file would therefore use javax.xml.catalog.files as the key, that +# is: +# javax.xml.catalog.files=strict +# +# +# Extension Functions: +# +# This property determines whether XSLT and XPath extension functions are allowed. +# The value type is boolean and the default value is true (allowing +# extension functions). The following entry would override the default value and +# disallow extension functions: +# +# jdk.xml.enableExtensionFunctions=false +# +# +# Overriding the default parser: +# +# This property allows using a third party implementation to override the default +# parser provided by the JDK. The value type is boolean and the default value is +# false, disallowing overriding the default parser. The setting below reflects +# the default property setting: +# +jdk.xml.overrideDefaultParser=false +# +# +# External Access Properties: +# +# The External Access Properties are defined in javax.xml.XMLConstants. Their +# system properties are javax.xml.accessExternalDTD, javax.xml.accessExternalSchema, +# and javax.xml.accessExternalStylesheet. The values are a list of protocols separated +# by comma, plus empty string ("") to represent no protocol allowed and the key +# word "all" for all access. The default is "all", allowing all external resources +# to be fetched. The followings are example of external access settings: +# +# allow local (file) DTDs to be retrieved +# javax.xml.accessExternalDTD=file +# +# allow local (file) and remote (http) external schemas +# javax.xml.accessExternalSchema=file, http +# +# reject any external stylesheets +# javax.xml.accessExternalStylesheet="" +# +# allow all external stylesheets +# javax.xml.accessExternalStylesheet="all" +# +# +# Catalog Properties: +# +# The Catalog API defines four features: FILES, PREFER, DEFER and RESOLVE. +# Except PREFER, all other properties can be placed in the configuration file +# using the system properties defined for them. +# +# FILES: A semicolon-delimited list of URIs to locate the catalog files. The URIs +# must be absolute and have a URL protocol handler for the URI scheme. The following +# is an example of setting up a catalog file: +# +# javax.xml.catalog.files = file:///users/auser/catalog/catalog.xml +# +# DEFER: Indicates that the alternative catalogs including those specified in +# delegate entries or nextCatalog are not read until they are needed. The value +# is a boolean and the default value is true. +# +# javax.xml.catalog.defer=true +# +# RESOLVE: Determines the action if there is no matching entry found after all of +# the specified catalogs are exhausted. The values are key words: strict, continue, +# and ignore. The default is strict. The following setting reflects the default +# setting. +# +# javax.xml.catalog.resolve=strict +# +# +# useCatalog: +# This property instructs XML processors to use XML Catalogs to resolve entity +# references. The value is a boolean and the default value is true. +# +# javax.xml.useCatalog=true +# +# +# Implementation Specific Properties - Limits +# +# Limits have a value type Integer. The values must be positive integers. Zero +# means no limit. +# +# Limits the number of entity expansions. The default value is 64000 +# jdk.xml.entityExpansionLimit=64000 +# +# Limits the total size of all entities that include general and parameter entities. +# The size is calculated as an aggregation of all entities. The default value is 5x10^7. +# jdk.xml.totalEntitySizeLimit=5E7 +# +# Limits the maximum size of any general entities. The default value is 0. +# jdk.xml.maxGeneralEntitySizeLimit=0 +# +# Limits the maximum size of any parameter entities, including the result of +# nesting multiple parameter entities. The default value is 10^6. +# jdk.xml.maxParameterEntitySizeLimit=1E6 +# +# Limits the total number of nodes in all entity references. The default value is 3x10^6. +# jdk.xml.entityReplacementLimit=3E6 +# +# Limits the number of attributes an element can have. The default value is 10000. +# jdk.xml.elementAttributeLimit=10000 +# +# Limits the number of content model nodes that may be created when building a +# grammar for a W3C XML Schema that contains maxOccurs attributes with values +# other than "unbounded". The default value is 5000. +# jdk.xml.maxOccurLimit=5000 +# +# Limits the maximum element depth. The default value is 0. +# jdk.xml.maxElementDepth=0 +# +# Limits the maximum size of XML names, including element name, attribute name +# and namespace prefix and URI. The default value is 1000. +jdk.xml.maxXMLNameLimit=1000 +# +# +# XPath Limits +# +# Limits the number of groups an XPath expression can contain. The default value is 10. +jdk.xml.xpathExprGrpLimit=10 +# +# Limits the number of operators an XPath expression can contain. The default value is 100. +jdk.xml.xpathExprOpLimit=100 +# +# Limits the total number of XPath operators in an XSL Stylesheet. The default value is 10000. +jdk.xml.xpathTotalOpLimit=10000 + diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/ConfigurationTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/ConfigurationTest.java new file mode 100644 index 00000000000..70cc92d67a2 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/ConfigurationTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import org.testng.annotations.DataProvider; + +/** + * Verifies the configuration file and precedence: + * settings in the configuration file are used as the default values of properties; + * any settings in a custom configuration file override those in the default + * configuration. + */ +public class ConfigurationTest { + // system property for custom configuration file + static final String SP_CONFIG = "java.xml.config.file"; + // Impl-Specific Property: entity expansion + static final String ISP_ENTITY_EXPANSION = "jdk.xml.entityExpansionLimit"; + // Impl-Specific Property: parameter entity limit + static final String ISP_PARAMETER_ENTITY = "jdk.xml.maxParameterEntitySizeLimit"; + // Impl-Specific Property: element attribute limit + static final String ISP_ELEMENT_ATTRIBUTE = "jdk.xml.elementAttributeLimit"; + // Impl-Specific Property: XML name limit + static final String ISP_NAME_LIMIT = "jdk.xml.maxXMLNameLimit"; + + // Impl-Specific Feature: extension functions + static final String ISF_EXTENSION_FUNCTIONS = "jdk.xml.enableExtensionFunctions"; + // Catalog feature: resolve + static final String CATALOG_RESOLVE = "javax.xml.catalog.resolve"; + // The USE_CATALOG property indicates whether Catalog is enabled for a processor + static final String USE_CATALOG = "http://javax.xml.XMLConstants/feature/useCatalog"; + static final String SP_USE_CATALOG = "javax.xml.useCatalog"; + + + static final boolean IS_WINDOWS = System.getProperty("os.name").contains("Windows"); + static final String SRC_DIR; + static final String TEST_SOURCE_DIR; + static { + String srcDir = System.getProperty("test.src", "."); + if (IS_WINDOWS) { + srcDir = srcDir.replace('\\', '/'); + } + SRC_DIR = srcDir; + TEST_SOURCE_DIR = srcDir + "/files/"; + } + + static enum PropertyType { FEATURE, PROPERTY }; + + /* + * DataProvider for testing the configuration file and system property. + * + * Fields: + * configuration file, property name, property type, property value + */ + @DataProvider(name = "getProperty") + public Object[][] getProperty() { + /** + * Test cases for verifying the configuration file + */ + return new Object[][]{ + // default value is expected for property (PARAMETER_ENTITY) not + // set in the default and custom configuration files + {null, ISP_PARAMETER_ENTITY, "1000000"}, + // this property is set in the default (jaxp.properties), + // but not the custom configuration file. Expects readings from the + // default config + {null, ISP_NAME_LIMIT, "1000"}, + // the property in the default configuration file (jaxp.properties) + // will be read and used as the default value of the property + {null, ISP_ENTITY_EXPANSION, "64000"}, + }; + } + + @DataProvider(name = "getProperty0") + public Object[][] getProperty0() { + /** + * Duplicate of getProperty to include the case that uses the system + * property to set up a custom configuration file. This is to avoid + * interfering with other test cases. + */ + return new Object[][]{ + // the setting in the custom configuration file will override that + // in the default one + {"customJaxp.properties", ISP_ENTITY_EXPANSION, "1000"}, + }; + } + + + static String getPath(String file) { + String temp = TEST_SOURCE_DIR + file; + if (IS_WINDOWS) { + temp = "/" + temp; + } + return temp; + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMImplTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMImplTest.java new file mode 100644 index 00000000000..5836bac7a2e --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMImplTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.SP_CONFIG; +import static common.config.ConfigurationTest.getPath; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.DOMImplTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class DOMImplTest extends DocumentBuilderFactory { + /* + * DataProvider for testing the configuration file and system property. + * + * Fields: + * configuration file, factory implementation class + */ + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {"jaxpImpls.properties", "common.config.DOMImplTest"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testDOMImpl(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(SP_CONFIG, getPath(config)); + } + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + System.clearProperty(SP_CONFIG); + Assert.assertEquals(dbf.getClass().getName(), expected); + } + + @Override + public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { + return null; + } + + @Override + public void setAttribute(String name, Object value) throws IllegalArgumentException { + // do nothing + } + + @Override + public Object getAttribute(String name) throws IllegalArgumentException { + return null; + } + + @Override + public void setFeature(String name, boolean value) throws ParserConfigurationException { + // do nothing + } + + @Override + public boolean getFeature(String name) throws ParserConfigurationException { + return false; + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMImplTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMImplTest0.java new file mode 100644 index 00000000000..2443f08b5d2 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMImplTest0.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.SP_CONFIG; +import static common.config.ConfigurationTest.getPath; +import javax.xml.parsers.DocumentBuilderFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.DOMImplTest0 + * @summary the tests with the default and custom configurations files have to be + * separate because they both are loaded once. + */ +public class DOMImplTest0 { + /* + * DataProvider for testing the configuration file and system property. + * + * Fields: + * configuration file, factory implementation class + */ + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testDOMImpl(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(SP_CONFIG, getPath(config)); + } + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + System.clearProperty(SP_CONFIG); + Assert.assertEquals(dbf.getClass().getName(), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMPropertyTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMPropertyTest.java new file mode 100644 index 00000000000..cfa1a7a4bdf --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMPropertyTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.parsers.DocumentBuilderFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.DOMPropertyTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class DOMPropertyTest extends ConfigurationTest { + + @Test(dataProvider = "getProperty") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(SP_CONFIG, getPath(config)); + } + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + Assert.assertEquals(dbf.getAttribute(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMPropertyTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMPropertyTest0.java new file mode 100644 index 00000000000..7e46822ac00 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/DOMPropertyTest0.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.parsers.DocumentBuilderFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.DOMPropertyTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + * Note: this test is a duplicate of DOMPropertyTest. This test runs the + * case with a custom configuration file only to avoid interfering with other + * test cases. + */ +public class DOMPropertyTest0 extends ConfigurationTest { + + @Test(dataProvider = "getProperty0") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(SP_CONFIG, getPath(config)); + } + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + Assert.assertEquals(dbf.getAttribute(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/EventFactoryTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/EventFactoryTest.java new file mode 100644 index 00000000000..130cf3edafb --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/EventFactoryTest.java @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import java.util.Iterator; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLEventFactory; +import javax.xml.stream.events.Attribute; +import javax.xml.stream.events.Characters; +import javax.xml.stream.events.Comment; +import javax.xml.stream.events.DTD; +import javax.xml.stream.events.EndDocument; +import javax.xml.stream.events.EndElement; +import javax.xml.stream.events.EntityDeclaration; +import javax.xml.stream.events.EntityReference; +import javax.xml.stream.events.Namespace; +import javax.xml.stream.events.ProcessingInstruction; +import javax.xml.stream.events.StartDocument; +import javax.xml.stream.events.StartElement; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.EventFactoryTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class EventFactoryTest extends XMLEventFactory { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {"jaxpImpls.properties", "common.config.EventFactoryTest"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testEventFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + XMLEventFactory ef = XMLEventFactory.newFactory(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(ef.getClass().getName(), expected); + } + + @Override + public void setLocation(Location location) { + // do nothing + } + + @Override + public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) { + return null; + } + + @Override + public Attribute createAttribute(String localName, String value) { + return null; + } + + @Override + public Attribute createAttribute(QName name, String value) { + return null; + } + + @Override + public Namespace createNamespace(String namespaceURI) { + return null; + } + + @Override + public Namespace createNamespace(String prefix, String namespaceUri) { + return null; + } + + @Override + public StartElement createStartElement(QName name, Iterator attributes, Iterator namespaces) { + return null; + } + + @Override + public StartElement createStartElement(String prefix, String namespaceUri, String localName) { + return null; + } + + @Override + public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces) { + return null; + } + + @Override + public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces, NamespaceContext context) { + return null; + } + + @Override + public EndElement createEndElement(QName name, Iterator namespaces) { + return null; + } + + @Override + public EndElement createEndElement(String prefix, String namespaceUri, String localName) { + return null; + } + + @Override + public EndElement createEndElement(String prefix, String namespaceUri, String localName, Iterator namespaces) { + return null; + } + + @Override + public Characters createCharacters(String content) { + return null; + } + + @Override + public Characters createCData(String content) { + return null; + } + + @Override + public Characters createSpace(String content) { + return null; + } + + @Override + public Characters createIgnorableSpace(String content) { + return null; + } + + @Override + public StartDocument createStartDocument() { + return null; + } + + @Override + public StartDocument createStartDocument(String encoding, String version, boolean standalone) { + return null; + } + + @Override + public StartDocument createStartDocument(String encoding, String version) { + return null; + } + + @Override + public StartDocument createStartDocument(String encoding) { + return null; + } + + @Override + public EndDocument createEndDocument() { + return null; + } + + @Override + public EntityReference createEntityReference(String name, EntityDeclaration declaration) { + return null; + } + + @Override + public Comment createComment(String text) { + return null; + } + + @Override + public ProcessingInstruction createProcessingInstruction(String target, String data) { + return null; + } + + @Override + public DTD createDTD(String dtd) { + return null; + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/EventFactoryTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/EventFactoryTest0.java new file mode 100644 index 00000000000..7f1c8d2b734 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/EventFactoryTest0.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.stream.XMLEventFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.EventFactoryTest0 + * @summary the tests with the default and custom configurations files have to be + * separate because they both are loaded once. + */ +public class EventFactoryTest0 { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.xml.internal.stream.events.XMLEventFactoryImpl"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testEventFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + XMLEventFactory ef = XMLEventFactory.newFactory(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(ef.getClass().getName(), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/InputFactoryTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/InputFactoryTest.java new file mode 100644 index 00000000000..a7cf2a83a10 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/InputFactoryTest.java @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import java.io.InputStream; +import java.io.Reader; +import javax.xml.stream.EventFilter; +import javax.xml.stream.StreamFilter; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLReporter; +import javax.xml.stream.XMLResolver; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.util.XMLEventAllocator; +import javax.xml.transform.Source; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.InputFactoryTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class InputFactoryTest extends XMLInputFactory { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {"jaxpImpls.properties", "common.config.InputFactoryTest"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testInputFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + XMLInputFactory xif = XMLInputFactory.newFactory(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xif.getClass().getName(), expected); + } + + @Override + public XMLStreamReader createXMLStreamReader(Reader reader) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamReader createXMLStreamReader(Source source) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamReader createXMLStreamReader(InputStream stream) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamReader createXMLStreamReader(InputStream stream, String encoding) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamReader createXMLStreamReader(String systemId, InputStream stream) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamReader createXMLStreamReader(String systemId, Reader reader) throws XMLStreamException { + return null; + } + + @Override + public XMLEventReader createXMLEventReader(Reader reader) throws XMLStreamException { + return null; + } + + @Override + public XMLEventReader createXMLEventReader(String systemId, Reader reader) throws XMLStreamException { + return null; + } + + @Override + public XMLEventReader createXMLEventReader(XMLStreamReader reader) throws XMLStreamException { + return null; + } + + @Override + public XMLEventReader createXMLEventReader(Source source) throws XMLStreamException { + return null; + } + + @Override + public XMLEventReader createXMLEventReader(InputStream stream) throws XMLStreamException { + return null; + } + + @Override + public XMLEventReader createXMLEventReader(InputStream stream, String encoding) throws XMLStreamException { + return null; + } + + @Override + public XMLEventReader createXMLEventReader(String systemId, InputStream stream) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException { + return null; + } + + @Override + public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter) throws XMLStreamException { + return null; + } + + @Override + public XMLResolver getXMLResolver() { + return null; + } + + @Override + public void setXMLResolver(XMLResolver resolver) { + // do nothing + } + + @Override + public XMLReporter getXMLReporter() { + return null; + } + + @Override + public void setXMLReporter(XMLReporter reporter) { + // do nothing + } + + @Override + public void setProperty(String name, Object value) throws IllegalArgumentException { + // do nothing + } + + @Override + public Object getProperty(String name) throws IllegalArgumentException { + return null; + } + + @Override + public boolean isPropertySupported(String name) { + return false; + } + + @Override + public void setEventAllocator(XMLEventAllocator allocator) { + // do nothing + } + + @Override + public XMLEventAllocator getEventAllocator() { + return null; + } + +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/InputFactoryTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/InputFactoryTest0.java new file mode 100644 index 00000000000..f4c61d49cad --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/InputFactoryTest0.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.stream.XMLInputFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.InputFactoryTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class InputFactoryTest0 { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.xml.internal.stream.XMLInputFactoryImpl"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testInputFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + XMLInputFactory xif = XMLInputFactory.newFactory(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xif.getClass().getName(), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/OutputFactoryTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/OutputFactoryTest.java new file mode 100644 index 00000000000..ae4ced78125 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/OutputFactoryTest.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import java.io.OutputStream; +import java.io.Writer; +import javax.xml.stream.XMLEventWriter; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.Result; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.OutputFactoryTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class OutputFactoryTest extends XMLOutputFactory { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {"jaxpImpls.properties", "common.config.OutputFactoryTest"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testOutputFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + XMLOutputFactory xof = XMLOutputFactory.newFactory(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xof.getClass().getName(), expected); + } + + @Override + public XMLStreamWriter createXMLStreamWriter(Writer stream) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamWriter createXMLStreamWriter(OutputStream stream) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding) throws XMLStreamException { + return null; + } + + @Override + public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException { + return null; + } + + @Override + public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException { + return null; + } + + @Override + public XMLEventWriter createXMLEventWriter(OutputStream stream) throws XMLStreamException { + return null; + } + + @Override + public XMLEventWriter createXMLEventWriter(OutputStream stream, String encoding) throws XMLStreamException { + return null; + } + + @Override + public XMLEventWriter createXMLEventWriter(Writer stream) throws XMLStreamException { + return null; + } + + @Override + public void setProperty(String name, Object value) throws IllegalArgumentException { + // do nothing + } + + @Override + public Object getProperty(String name) throws IllegalArgumentException { + return null; + } + + @Override + public boolean isPropertySupported(String name) { + return false; + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/OutputFactoryTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/OutputFactoryTest0.java new file mode 100644 index 00000000000..83ca23af2b2 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/OutputFactoryTest0.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.stream.XMLOutputFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.OutputFactoryTest0 + * @summary the tests with the default and custom configurations files have to be + * separate because they both are loaded once. + */ +public class OutputFactoryTest0 { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.xml.internal.stream.XMLOutputFactoryImpl"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testOutputFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + XMLOutputFactory xof = XMLOutputFactory.newFactory(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xof.getClass().getName(), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/PathTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/PathTest.java new file mode 100644 index 00000000000..2d4c4ce69fc --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/PathTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.SP_CONFIG; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import javax.xml.parsers.DocumentBuilderFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.PathTest + * @summary verifies that the system property "java.xml.config.file" may be set + * with a relative path. + */ +public class PathTest extends ConfigurationTest { + private static final String FILE_DIR = "files"; + private static final String CUSTOM_CONFIG = "customJaxp.properties"; + + /* + * Sets up the test environment by copying the customJaxp.properties file + * to a directory under the current working directory of the JVM. + */ + @BeforeClass + public static void setup() throws IOException { + Path userDir = Paths.get(System.getProperty("user.dir", ".")); + Path fileDir = Paths.get(userDir.toString(), FILE_DIR); + + if (Files.notExists(fileDir)) { + Files.createDirectory(fileDir); + } + + Path source = Paths.get(TEST_SOURCE_DIR, CUSTOM_CONFIG); + Path dest = Paths.get(fileDir.toString(), CUSTOM_CONFIG); + Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING); + } + + /* + * Verifies a user-defined configuration file can be set with a relative path. + * This test is the same as other Property tests, except the java.xml.config.file + * system property is set with a relative path. + */ + @Test(dataProvider = "getProperty0") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + // set with a relative path instead of the absolute path from getPath + System.setProperty(SP_CONFIG, FILE_DIR + "/" + config); + } + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + Assert.assertEquals(dbf.getAttribute(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXImplTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXImplTest.java new file mode 100644 index 00000000000..951573cc252 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXImplTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.SAXImplTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class SAXImplTest extends SAXParserFactory { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {"jaxpImpls.properties", "common.config.SAXImplTest"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testSAXImpl(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + SAXParserFactory spf = SAXParserFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(spf.getClass().getName(), expected); + } + + @Override + public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { + return null; + } + + @Override + public void setFeature(String name, boolean value) + throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { + // + } + + @Override + public boolean getFeature(String name) + throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { + return false; + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXImplTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXImplTest0.java new file mode 100644 index 00000000000..ac5c4e59d03 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXImplTest0.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.parsers.SAXParserFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.SAXImplTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class SAXImplTest0 { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testSAXImpl(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + SAXParserFactory spf = SAXParserFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(spf.getClass().getName(), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXPropertyTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXPropertyTest.java new file mode 100644 index 00000000000..4758f18d99f --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXPropertyTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.testng.Assert; +import org.testng.annotations.Test; +import org.xml.sax.XMLReader; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.SAXPropertyTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class SAXPropertyTest extends ConfigurationTest { + @Test(dataProvider = "getProperty") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser sp = spf.newSAXParser(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(sp.getProperty(property), expected); + XMLReader reader = sp.getXMLReader(); + Assert.assertEquals(reader.getProperty(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXPropertyTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXPropertyTest0.java new file mode 100644 index 00000000000..a2b1a364c8d --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/SAXPropertyTest0.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.testng.Assert; +import org.testng.annotations.Test; +import org.xml.sax.XMLReader; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.SAXPropertyTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + * Note: this test is a duplicate of SAXPropertyTest. This test runs the + * case with a custom configuration file only to avoid interfering with other + * test cases. + */ +public class SAXPropertyTest0 extends ConfigurationTest { + @Test(dataProvider = "getProperty0") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser sp = spf.newSAXParser(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(sp.getProperty(property), expected); + XMLReader reader = sp.getXMLReader(); + Assert.assertEquals(reader.getProperty(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaFactoryTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaFactoryTest.java new file mode 100644 index 00000000000..e1ecce40a30 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaFactoryTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.XMLConstants; +import javax.xml.transform.Source; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.ls.LSResourceResolver; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.SchemaFactoryTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class SchemaFactoryTest extends SchemaFactory { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {"jaxpImpls.properties", "common.config.SchemaFactoryTest"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(sf.getClass().getName(), expected); + } + + @Override + public boolean isSchemaLanguageSupported(String schemaLanguage) { + return false; + } + + @Override + public void setErrorHandler(ErrorHandler errorHandler) { + // do nothing + } + + @Override + public ErrorHandler getErrorHandler() { + return null; + } + + @Override + public void setResourceResolver(LSResourceResolver resourceResolver) { + // do nothing + } + + @Override + public LSResourceResolver getResourceResolver() { + return null; + } + + @Override + public Schema newSchema(Source[] schemas) throws SAXException { + return null; + } + + @Override + public Schema newSchema() throws SAXException { + return null; + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaFactoryTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaFactoryTest0.java new file mode 100644 index 00000000000..5c9e45cdf83 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaFactoryTest0.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.XMLConstants; +import javax.xml.validation.SchemaFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.SchemaFactoryTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class SchemaFactoryTest0 { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(sf.getClass().getName(), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaPropertyTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaPropertyTest.java new file mode 100644 index 00000000000..eb754d66788 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaPropertyTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.XMLConstants; +import javax.xml.validation.SchemaFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.SchemaPropertyTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class SchemaPropertyTest extends ConfigurationTest { + @Test(dataProvider = "getProperty") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(sf.getProperty(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaPropertyTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaPropertyTest0.java new file mode 100644 index 00000000000..81c1d339cca --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/SchemaPropertyTest0.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.XMLConstants; +import javax.xml.validation.SchemaFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.SchemaPropertyTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + * Note: this test is a duplicate of SchemaPropertyTest. This test runs the + * case with a custom configuration file only to avoid interfering with other + * test cases. + */ +public class SchemaPropertyTest0 extends ConfigurationTest { + @Test(dataProvider = "getProperty0") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(sf.getProperty(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/StAXPropertyTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/StAXPropertyTest.java new file mode 100644 index 00000000000..5f34de85e97 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/StAXPropertyTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.stream.XMLInputFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.StAXPropertyTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class StAXPropertyTest extends ConfigurationTest { + @Test(dataProvider = "getProperty") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + XMLInputFactory xif = XMLInputFactory.newFactory(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xif.getProperty(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/StAXPropertyTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/StAXPropertyTest0.java new file mode 100644 index 00000000000..1dd0bf527a6 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/StAXPropertyTest0.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.stream.XMLInputFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.StAXPropertyTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + * Note: this test is a duplicate of DOMPropertyTest. This test runs the + * case with a custom configuration file only to avoid interfering with other + * test cases. + */ +public class StAXPropertyTest0 extends ConfigurationTest { + @Test(dataProvider = "getProperty0") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + XMLInputFactory xif = XMLInputFactory.newFactory(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xif.getProperty(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerFactoryTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerFactoryTest.java new file mode 100644 index 00000000000..5c73e9a2a6b --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerFactoryTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +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.TransformerFactory; +import javax.xml.transform.URIResolver; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.TransformerFactoryTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class TransformerFactoryTest extends TransformerFactory { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + TransformerFactory tf = TransformerFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(tf.getClass().getName(), expected); + } + + @Override + public Transformer newTransformer(Source source) throws TransformerConfigurationException { + return null; + } + + @Override + public Transformer newTransformer() throws TransformerConfigurationException { + return null; + } + + @Override + public Templates newTemplates(Source source) throws TransformerConfigurationException { + return null; + } + + @Override + public Source getAssociatedStylesheet(Source source, String media, String title, String charset) throws TransformerConfigurationException { + return null; + } + + @Override + public void setURIResolver(URIResolver resolver) { + // do nothing + } + + @Override + public URIResolver getURIResolver() { + return null; + } + + @Override + public void setFeature(String name, boolean value) throws TransformerConfigurationException { + // do nothing + } + + @Override + public boolean getFeature(String name) { + return false; + } + + @Override + public void setAttribute(String name, Object value) { + // do nothing + } + + @Override + public Object getAttribute(String name) { + return null; + } + + @Override + public void setErrorListener(ErrorListener listener) { + // do nothing + } + + @Override + public ErrorListener getErrorListener() { + return null; + } + +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerFactoryTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerFactoryTest0.java new file mode 100644 index 00000000000..a52072cba7d --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerFactoryTest0.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.transform.TransformerFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.TransformerFactoryTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class TransformerFactoryTest0 { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + TransformerFactory tf = TransformerFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(tf.getClass().getName(), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerPropertyTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerPropertyTest.java new file mode 100644 index 00000000000..58c4631249d --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerPropertyTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.transform.TransformerFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.TransformerPropertyTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class TransformerPropertyTest extends ConfigurationTest { + @Test(dataProvider = "getProperty") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + TransformerFactory tf = TransformerFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(tf.getAttribute(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerPropertyTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerPropertyTest0.java new file mode 100644 index 00000000000..592c1df29e7 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/TransformerPropertyTest0.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.transform.TransformerFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.TransformerPropertyTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + * Note: this test is a duplicate of TransformerPropertyTest. This test runs the + * case with a custom configuration file only to avoid interfering with other + * test cases. + */ +public class TransformerPropertyTest0 extends ConfigurationTest { + @Test(dataProvider = "getProperty0") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + TransformerFactory tf = TransformerFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(tf.getAttribute(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathFactoryTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathFactoryTest.java new file mode 100644 index 00000000000..d819bf566d8 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathFactoryTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; +import javax.xml.xpath.XPathFactoryConfigurationException; +import javax.xml.xpath.XPathFunctionResolver; +import javax.xml.xpath.XPathVariableResolver; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.XPathFactoryTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class XPathFactoryTest extends XPathFactory { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {"jaxpImpls.properties", "common.config.XPathFactoryTest"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + XPathFactory xf = XPathFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xf.getClass().getName(), expected); + } + + @Override + public boolean isObjectModelSupported(String objectModel) { + return false; + } + + @Override + public void setFeature(String name, boolean value) throws XPathFactoryConfigurationException { + // do nothing + } + + @Override + public boolean getFeature(String name) throws XPathFactoryConfigurationException { + return false; + } + + @Override + public void setXPathVariableResolver(XPathVariableResolver resolver) { + // do nothing + } + + @Override + public void setXPathFunctionResolver(XPathFunctionResolver resolver) { + // do nothing + } + + @Override + public XPath newXPath() { + return null; + } + +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathFactoryTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathFactoryTest0.java new file mode 100644 index 00000000000..ac332652534 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathFactoryTest0.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import static common.config.ConfigurationTest.getPath; +import javax.xml.xpath.XPathFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.XPathFactoryTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class XPathFactoryTest0 { + @DataProvider(name = "getImpl") + public Object[][] getImpl() { + + return new Object[][]{ + {null, "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl"}, + }; + } + + @Test(dataProvider = "getImpl") + public void testFactory(String config, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + + XPathFactory xf = XPathFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xf.getClass().getName(), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathPropertyTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathPropertyTest.java new file mode 100644 index 00000000000..359a160ae94 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathPropertyTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.xpath.XPathFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.XPathPropertyTest + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + */ +public class XPathPropertyTest extends ConfigurationTest { + /* + * DataProvider for testing the configuration file and system property. + * + * Fields: + * configuration file, property name, property value + */ + @DataProvider(name = "getProperty") + public Object[][] getProperty() { + + return new Object[][]{ + {null, "jdk.xml.xpathExprOpLimit", "100"}, + }; + } + + @Test(dataProvider = "getProperty") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + XPathFactory xf = XPathFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xf.getProperty(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathPropertyTest0.java b/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathPropertyTest0.java new file mode 100644 index 00000000000..e8f0dd82edb --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/XPathPropertyTest0.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package common.config; + +import javax.xml.xpath.XPathFactory; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * @test @bug 8303530 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @modules java.xml/jdk.xml.internal + * @run testng/othervm common.config.XPathPropertyTest0 + * @summary verifies that JAXP configuration file is customizable with a system + * property "java.xml.config.file". + * Note: this test is a duplicate of XPathPropertyTest. This test runs the + * case with a custom configuration file only to avoid interfering with other + * test cases. + */ +public class XPathPropertyTest0 extends ConfigurationTest { + /* + * DataProvider for testing the configuration file and system property. + * + * Fields: + * configuration file, property name, property value + */ + @DataProvider(name = "getProperty") + public Object[][] getProperty() { + + return new Object[][]{ + {"customJaxp.properties", "jdk.xml.xpathExprOpLimit", "200"}, + }; + } + + @Test(dataProvider = "getProperty") + public void testProperty(String config, String property, String expected) throws Exception { + if (config != null) { + System.setProperty(ConfigurationTest.SP_CONFIG, getPath(config)); + } + XPathFactory xf = XPathFactory.newInstance(); + System.clearProperty(ConfigurationTest.SP_CONFIG); + Assert.assertEquals(xf.getProperty(property), expected); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/files/customJaxp.properties b/test/jaxp/javax/xml/jaxp/unittest/common/config/files/customJaxp.properties new file mode 100644 index 00000000000..610e0d08d12 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/files/customJaxp.properties @@ -0,0 +1,31 @@ +################################################################################ +# XML Library (java.xml) Configuration File +# +# This file is in java.util.Properties format and typically located in the conf +# directory of the Java installation. It may contain key/value pairs for specifying +# the implementation class of a factory and/or properties that have corresponding +# system properties. +# +# This file can be replaced by specifying a filename with the jdk.xml.config.file +# system property. For example java -Djava.xml.config.file=myfile +################################################################################ + +# ---- Custom Configuration File ---- +# Sets more restrictive values for: extension functions, overriding default +# parsers, and DTD related limits. +# +# Disable Extension Functions +jdk.xml.enableExtensionFunctions=false +# Disallow overriding the default parser +jdk.xml.overrideDefaultParser=false +# +# Implementation specific limits: +jdk.xml.entityExpansionLimit=1000 +jdk.xml.totalEntitySizeLimit=100000 +jdk.xml.maxGeneralEntitySizeLimit=1024 +jdk.xml.maxParameterEntitySizeLimit=1024 +jdk.xml.entityReplacementLimit=10000 +# +# XPath limits +jdk.xml.xpathExprOpLimit=200 + diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/files/jaxp.properties b/test/jaxp/javax/xml/jaxp/unittest/common/config/files/jaxp.properties new file mode 100644 index 00000000000..b43b5a3e8d1 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/files/jaxp.properties @@ -0,0 +1,180 @@ +################################################################################ +# JAXP Configuration File +# +# jaxp.properties (this file) is the default configuration file for JAXP, the API +# defined in the java.xml module. It is in java.util.Properties format and typically +# located in the {java.home}/conf directory. It may contain key/value pairs for +# specifying the implementation classes of JAXP factories and/or properties +# that have corresponding system properties. +# +# A user-specified configuration file can be set up using the system property +# java.xml.config.file to override any or all of the entries in jaxp.properties. +# The following statement provides myConfigurationFile as a custom configuration +# file: +# java -Djava.xml.config.file=myConfigurationFile +################################################################################ + +# ---- JAXP Default Configuration ---- +# +# The JAXP default configuration (jaxp.properties) contains entries for the +# Factory Lookup Mechanism and properties with corresponding system properties. +# The values are generally set to the default values of the properties. +# +# +# JAXP Lookup Mechanism: +# +# The JAXP configuration file ranks 2nd to the System Property in the precedent +# order of the JAXP Lookup Mechanism. When the System Property is not specified, +# a JAXP factory reads the configuration file in order to locate an implementation +# class. If found, the class specified will be used as the factory implementation +# class. +# +# The format of an entry is key=value where the key is the fully qualified name +# of the factory and value that of the implementation class. The following entry +# set a DocumentBuilderFactory implementation class: +# +# javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl +# +# +# Java SE and JDK Implementation Specific Properties: +# +# The JAXP configuration file ranks above the default settings in the Property +# Precedence in that its entries will override the default values of the corresponding +# properties. +# +# All properties that have System Properties defined in Java SE or supported +# by the JDK Implementation can be placed in the configuration file to override +# the default property values. The format is: +# system-property-name=value +# +# For example, the FILES property in CatalogFeatures has an associated system +# property called javax.xml.catalog.files. An entry for the FILES property in the +# configuration file would therefore use javax.xml.catalog.files as the key, that +# is: +# javax.xml.catalog.files=strict +# +# +# Extension Functions: +# +# This property determines whether XSLT and XPath extension functions are allowed. +# The value type is boolean and the default value is true (allowing +# extension functions). The following entry would override the default value and +# disallow extension functions: +# +# jdk.xml.enableExtensionFunctions=false +# +# +# Overriding the default parser: +# +# This property allows using a third party implementation to override the default +# parser provided by the JDK. The value type is boolean and the default value is +# false, disallowing overriding the default parser. The setting below reflects +# the default property setting: +# +jdk.xml.overrideDefaultParser=false +# +# +# External Access Properties: +# +# The External Access Properties are defined in javax.xml.XMLConstants. Their +# system properties are javax.xml.accessExternalDTD, javax.xml.accessExternalSchema, +# and javax.xml.accessExternalStylesheet. The values are a list of protocols separated +# by comma, plus empty string ("") to represent no protocol allowed and the key +# word "all" for all access. The default is "all", allowing all external resources +# to be fetched. The followings are example of external access settings: +# +# allow local (file) DTDs to be retrieved +# javax.xml.accessExternalDTD=file +# +# allow local (file) and remote (http) external schemas +# javax.xml.accessExternalSchema=file, http +# +# reject any external stylesheets +# javax.xml.accessExternalStylesheet="" +# +# allow all external stylesheets +# javax.xml.accessExternalStylesheet="all" +# +# +# Catalog Properties: +# +# The Catalog API defines four features: FILES, PREFER, DEFER and RESOLVE. +# Except PREFER, all other properties can be placed in the configuration file +# using the system properties defined for them. +# +# FILES: A semicolon-delimited list of URIs to locate the catalog files. The URIs +# must be absolute and have a URL protocol handler for the URI scheme. The following +# is an example of setting up a catalog file: +# +# javax.xml.catalog.files = file:///users/auser/catalog/catalog.xml +# +# DEFER: Indicates that the alternative catalogs including those specified in +# delegate entries or nextCatalog are not read until they are needed. The value +# is a boolean and the default value is true. +# +# javax.xml.catalog.defer=true +# +# RESOLVE: Determines the action if there is no matching entry found after all of +# the specified catalogs are exhausted. The values are key words: strict, continue, +# and ignore. The default is strict. The following setting reflects the default +# setting. +# +# javax.xml.catalog.resolve=strict +# +# +# useCatalog: +# This property instructs XML processors to use XML Catalogs to resolve entity +# references. The value is a boolean and the default value is true. +# +# javax.xml.useCatalog=true +# +# +# Implementation Specific Properties - Limits +# +# Limits have a value type Integer. The values must be positive integers. Zero +# means no limit. +# +# Limits the number of entity expansions. The default value is 64000 +# jdk.xml.entityExpansionLimit=64000 +# +# Limits the total size of all entities that include general and parameter entities. +# The size is calculated as an aggregation of all entities. The default value is 5x10^7. +# jdk.xml.totalEntitySizeLimit=5E7 +# +# Limits the maximum size of any general entities. The default value is 0. +# jdk.xml.maxGeneralEntitySizeLimit=0 +# +# Limits the maximum size of any parameter entities, including the result of +# nesting multiple parameter entities. The default value is 10^6. +# jdk.xml.maxParameterEntitySizeLimit=1E6 +# +# Limits the total number of nodes in all entity references. The default value is 3x10^6. +# jdk.xml.entityReplacementLimit=3E6 +# +# Limits the number of attributes an element can have. The default value is 10000. +# jdk.xml.elementAttributeLimit=10000 +# +# Limits the number of content model nodes that may be created when building a +# grammar for a W3C XML Schema that contains maxOccurs attributes with values +# other than "unbounded". The default value is 5000. +# jdk.xml.maxOccurLimit=5000 +# +# Limits the maximum element depth. The default value is 0. +# jdk.xml.maxElementDepth=0 +# +# Limits the maximum size of XML names, including element name, attribute name +# and namespace prefix and URI. The default value is 1000. +jdk.xml.maxXMLNameLimit=1000 +# +# +# XPath Limits +# +# Limits the number of groups an XPath expression can contain. The default value is 10. +jdk.xml.xpathExprGrpLimit=10 +# +# Limits the number of operators an XPath expression can contain. The default value is 100. +jdk.xml.xpathExprOpLimit=100 +# +# Limits the total number of XPath operators in an XSL Stylesheet. The default value is 10000. +jdk.xml.xpathTotalOpLimit=10000 + diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/config/files/jaxpImpls.properties b/test/jaxp/javax/xml/jaxp/unittest/common/config/files/jaxpImpls.properties new file mode 100644 index 00000000000..787543f185e --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/common/config/files/jaxpImpls.properties @@ -0,0 +1,48 @@ +################################################################################ +# XML Library (java.xml) Configuration File +# +# This file is in java.util.Properties format and typically located in the conf +# directory of the Java installation. It may contain key/value pairs for specifying +# the implementation class of a factory and/or properties that have corresponding +# system properties. +# +# This file can be replaced by specifying a filename with the jdk.xml.config.file +# system property. For example java -Djava.xml.config.file=myfile +################################################################################ + +# ---- Configuration for test ---- +# +# Factory implementation class +javax.xml.parsers.DocumentBuilderFactory=common.config.DOMImplTest +javax.xml.parsers.SAXParserFactory=common.config.SAXImplTest +javax.xml.stream.XMLEventFactory=common.config.EventFactoryTest +javax.xml.stream.XMLInputFactory=common.config.InputFactoryTest +javax.xml.stream.XMLOutputFactory=common.config.OutputFactoryTest +javax.xml.transform.TransformerFactory=common.config.TransformerFactoryTest +javax.xml.validation.SchemaFactory\:http\://www.w3.org/2001/XMLSchema=common.config.SchemaFactoryTest +javax.xml.xpath.XPathFactory\:http\://java.sun.com/jaxp/xpath/dom=common.config.XPathFactoryTest +# +# Disable Extension Functions +jdk.xml.enableExtensionFunctions=false +# Disallow overriding the default parser +jdk.xml.overrideDefaultParser=false +# +# Implementation specific limits: +# +jdk.xml.entityExpansionLimit=1000 +jdk.xml.totalEntitySizeLimit=100000 +jdk.xml.maxGeneralEntitySizeLimit=1024 +jdk.xml.maxParameterEntitySizeLimit=1024 +jdk.xml.entityReplacementLimit=10000 +# +# General XML limits +jdk.xml.elementAttributeLimit=100 +jdk.xml.maxOccurLimit=5000 +jdk.xml.maxElementDepth=0 +jdk.xml.maxXMLNameLimit=1000 +# +# XPath Limits +jdk.xml.xpathExprGrpLimit=10 +jdk.xml.xpathExprOpLimit=100 +jdk.xml.xpathTotalOpLimit=10000 +

    Implementation Specific Features
    Full Name (prefix + name) - * [1]DescriptionAPI Property [2]System Property [3]jaxp.properties [3]Value [4]Security [5]Supported Processor [6]Since [7]
    TypeValueDefaultEnforced
    {@systemProperty jdk.xml.enableExtensionFunctions}Determines if XSLT and XPath extension functions are to be allowed. * yesyesyesBoolean * true or false. True indicates that extension functions are allowed; False otherwise. @@ -704,6 +764,7 @@ * Transform
    * XPath *
    Method 28
    Method 29
    * SAX * Method 29