diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java index ce092f0e9f2..58d49da59a6 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -83,6 +83,7 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import jdk.xml.internal.JdkXmlFeatures; import jdk.xml.internal.JdkXmlUtils; +import jdk.xml.internal.SecuritySupport; import jdk.xml.internal.TransformErrorListener; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; @@ -94,7 +95,7 @@ import org.xml.sax.ext.LexicalHandler; * @author Morten Jorgensen * @author G. Todd Miller * @author Santiago Pericas-Geertsen - * @LastModified: Aug 2019 + * @LastModified: Feb 2021 */ public final class TransformerImpl extends Transformer implements DOMCache @@ -278,6 +279,10 @@ public final class TransformerImpl extends Transformer _translet.setMessageHandler(new MessageHandler(_errorListener)); } _properties = createOutputProperties(outputProperties); + String v = SecuritySupport.getJAXPSystemProperty(OutputPropertiesFactory.SP_IS_STANDALONE); + if (v != null) { + _properties.setProperty(OutputPropertiesFactory.JDK_IS_STANDALONE, v); + } _propertiesClone = (Properties) _properties.clone(); _indentNumber = indentNumber; _tfactory = tfactory; @@ -1032,7 +1037,7 @@ public final class TransformerImpl extends Transformer } } } - else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) { + else if (isStandaloneProperty(name)) { if (value != null && value.equals("yes")) { translet._isStandalone = true; } @@ -1096,7 +1101,7 @@ public final class TransformerImpl extends Transformer handler.setIndentAmount(Integer.parseInt(value)); } } - else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) { + else if (isStandaloneProperty(name)) { if (value != null && value.equals("yes")) { handler.setIsStandalone(true); } @@ -1214,10 +1219,20 @@ public final class TransformerImpl extends Transformer name.equals(OutputKeys.OMIT_XML_DECLARATION) || name.equals(OutputKeys.STANDALONE) || name.equals(OutputKeys.VERSION) || - name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE) || + isStandaloneProperty(name) || name.charAt(0) == '{'); } + /** + * Checks whether the property requested is the isStandalone property. Both + * the new and legacy property names are supported. + * @param name the property name + * @return true if the property is "isStandalone", false otherwise + */ + private boolean isStandaloneProperty(String name) { + return (name.equals(OutputPropertiesFactory.JDK_IS_STANDALONE) || + name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)); + } /** * Checks if a given output property is default (2nd layer only) */ diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java index 090fb3d6b40..3e5dd9825a7 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -20,6 +20,7 @@ package com.sun.org.apache.xml.internal.serializer; +import com.sun.org.apache.xerces.internal.impl.Constants; import java.util.Properties; import javax.xml.transform.OutputKeys; import jdk.xml.internal.SecuritySupport; @@ -70,7 +71,7 @@ import jdk.xml.internal.SecuritySupport; * @see SerializerFactory * @see Method * @see Serializer - * @LastModified: Mar 2019 + * @LastModified: Feb 2021 */ public final class OutputPropertiesFactory { @@ -186,6 +187,13 @@ public final class OutputPropertiesFactory */ public static final String ORACLE_IS_STANDALONE = "http://www.oracle.com/xml/is-standalone"; + // standardized property, refer to the definition in java.xml module-info + public static final String JDK_IS_STANDALONE = Constants.ORACLE_JAXP_PROPERTY_PREFIX + + "xsltcIsStandalone"; + + // Corresponding System property + public static final String SP_IS_STANDALONE = "jdk.xml.xsltcIsStandalone"; + //************************************************************ //* PRIVATE CONSTANTS //************************************************************ @@ -212,7 +220,8 @@ public final class OutputPropertiesFactory "media-type", "{http://xml.apache.org/xalan}indent-amount", "{http://xml.apache.org/xalan}content-handler", - "{http://xml.apache.org/xalan}entities" + "{http://xml.apache.org/xalan}entities", + JDK_IS_STANDALONE }; private static final String[] PROP_XML_VALUE = { @@ -225,7 +234,8 @@ public final class OutputPropertiesFactory "text/xml", "0", "com.sun.org.apache.xml.internal.serializer.ToXMLStream", - "com/sun/org/apache/xml/internal/serializer/XMLEntities" + "com/sun/org/apache/xml/internal/serializer/XMLEntities", + "no" }; private static final String[] PROP_HTML = { diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java index da5500a6c59..b4edf277f39 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java @@ -494,7 +494,7 @@ abstract public class ToStream extends SerializerBase { setIndentAmount(Integer.parseInt(val)); } else if (OutputKeys.INDENT.equals(name)) { m_doIndent = val.endsWith("yes"); - } else if ((DOMConstants.S_JDK_PROPERTIES_NS + DOMConstants.S_IS_STANDALONE) + } else if ((DOMConstants.NS_IS_STANDALONE) .equals(name)) { m_isStandalone = val.endsWith("yes"); } diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java index 8153ba084af..8247c075bcf 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -49,7 +49,7 @@ import org.xml.sax.SAXException; * * This class is not a public API, it is public because it is used within Xalan. * @xsl.usage internal - * @LastModified: Aug 2019 + * @LastModified: Feb 2021 */ public final class ToUnknownStream extends SerializerBase { @@ -655,6 +655,11 @@ public final class ToUnknownStream extends SerializerBase m_handler.setStandalone(standalone); } + @Override + public void setIsStandalone(boolean isStandalone) { + super.setIsStandalone(isStandalone); + m_handler.setIsStandalone(isStandalone); + } /** * Pass the call on to the underlying handler * @see org.xml.sax.ext.DeclHandler#attributeDecl(String, String, String, String, String) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/LSSerializerImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/LSSerializerImpl.java index e4928a4f06e..238b7fc9828 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/LSSerializerImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/LSSerializerImpl.java @@ -358,10 +358,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer { fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no"); // JDK specific property isStandalone - String p = SecuritySupport.getSystemProperty(DOMConstants.SP_IS_STANDALONE); - if (p == null || p.isEmpty()) { - p = SecuritySupport.readJAXPProperty(DOMConstants.SP_IS_STANDALONE); - } + String p = SecuritySupport.getJAXPSystemProperty(DOMConstants.SP_IS_STANDALONE); // the system property is true only if it is "true" and false otherwise if (p != null && p.equals("true")) { fFeatures |= IS_STANDALONE; diff --git a/src/java.xml/share/classes/module-info.java b/src/java.xml/share/classes/module-info.java index d4d147dbac4..7508faba62f 100644 --- a/src/java.xml/share/classes/module-info.java +++ b/src/java.xml/share/classes/module-info.java @@ -174,6 +174,13 @@ * {@code factory.setAttribute(name, value);} * * + *
+ * This property behaves similar to that for DOMLS above, + * except that it is for the XSLTC Serializer + * and its value is a String. + *
@@ -241,8 +270,12 @@ * *
* [3] The value must be exactly as listed in this table, case-sensitive. - * The value type for the corresponding System Property is String. For boolean - * type, the system property is true only if it is "true" and false otherwise. + * 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 + * it is exactly the same string representing the positive value (e.g. "yes" for + * {@code xsltcIsStandalone}); The system property is false otherwise. + * *
* [4] A value "yes" indicates the property is a Security Property. Refer
* to the Scope and Order on how secure processing
diff --git a/test/jaxp/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java b/test/jaxp/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java
index 1c356e74fd6..2f59315ad7b 100644
--- a/test/jaxp/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java
+++ b/test/jaxp/javax/xml/jaxp/unittest/common/prettyprint/PrettyPrintTest.java
@@ -20,9 +20,9 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-
package common.prettyprint;
+import java.io.ByteArrayInputStream;
import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
import static jaxp.library.JAXPTestUtilities.setSystemProperty;
@@ -66,7 +66,7 @@ import org.xml.sax.SAXException;
/*
* @test
- * @bug 6439439 8087303 8174025 8223291 8249867 8261209
+ * @bug 6439439 8087303 8174025 8223291 8249867 8261209 8260858
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @run testng/othervm -DrunSecMngr=true common.prettyprint.PrettyPrintTest
* @run testng/othervm common.prettyprint.PrettyPrintTest
@@ -74,10 +74,15 @@ import org.xml.sax.SAXException;
*/
@Listeners({jaxp.library.FilePolicy.class})
public class PrettyPrintTest {
+
private static final String DOM_FORMAT_PRETTY_PRINT = "format-pretty-print";
- private static final String JDK_IS_STANDALONE =
- "http://www.oracle.com/xml/jaxp/properties/isStandalone";
+ private static final String JDK_IS_STANDALONE
+ = "http://www.oracle.com/xml/jaxp/properties/isStandalone";
private static final String SP_JDK_IS_STANDALONE = "jdk.xml.isStandalone";
+ private static final String XSLTC_IS_STANDALONE
+ = "http://www.oracle.com/xml/jaxp/properties/xsltcIsStandalone";
+ private static final String SP_XSLTC_IS_STANDALONE = "jdk.xml.xsltcIsStandalone";
+
// pretty-print=true, isStandalone=true, linebreak added after header
private static final String XML_LB
= "\n