Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8249867: xml declaration is not followed by a newline #2041

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -494,11 +494,7 @@ void setProp(String name, String val, boolean defaultVal) {
setIndentAmount(Integer.parseInt(val));
} else if (OutputKeys.INDENT.equals(name)) {
m_doIndent = val.endsWith("yes");
}

break;
case 'j':
if ((DOMConstants.S_JDK_PROPERTIES_NS + DOMConstants.S_IS_STANDALONE)
} else if ((DOMConstants.S_JDK_PROPERTIES_NS + DOMConstants.S_IS_STANDALONE)
.equals(name)) {
m_isStandalone = val.endsWith("yes");
}
Expand Down
Expand Up @@ -125,7 +125,7 @@ public final class DOMConstants {
*
* @see similar property ORACLE_IS_STANDALONE in OutputPropertiesFactory.
*/
public static final String S_IS_STANDALONE = "jdk-is-standalone";
public static final String S_IS_STANDALONE = "isStandalone";

// Corresponding System property
public static final String SP_IS_STANDALONE = "jdk.xml.isStandalone";
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Expand Up @@ -21,6 +21,7 @@

package com.sun.org.apache.xml.internal.serializer.dom3;

import com.sun.org.apache.xerces.internal.impl.Constants;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -186,7 +187,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
DOMConstants.DOM_FORMAT_PRETTY_PRINT,
DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS,
DOMConstants.DOM_XMLDECL,
DOMConstants.S_IS_STANDALONE,
Constants.ORACLE_JAXP_PROPERTY_PREFIX + DOMConstants.S_IS_STANDALONE,
DOMConstants.DOM_ERROR_HANDLER
};

Expand Down Expand Up @@ -357,7 +358,10 @@ public void initializeSerializerProps () {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no");

// JDK specific property jdk-is-standalone
String p = SecuritySupport.getSystemProperty(DOMConstants.SP_IS_STANDALONE, "false");
String p = SecuritySupport.getSystemProperty(DOMConstants.SP_IS_STANDALONE);
if (p == null || p.equals("")) {
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
p = SecuritySupport.readJAXPProperty(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;
Expand Down Expand Up @@ -395,7 +399,8 @@ public boolean canSetParameter(String name, Object value) {
|| name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)
|| name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)
|| name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)
|| name.equalsIgnoreCase(DOMConstants.S_IS_STANDALONE)){
|| name.equalsIgnoreCase(Constants.ORACLE_JAXP_PROPERTY_PREFIX
+ DOMConstants.S_IS_STANDALONE)){
// both values supported
return true;
}
Expand Down Expand Up @@ -453,7 +458,8 @@ public Object getParameter(String name) throws DOMException {
return ((fFeatures & PRETTY_PRINT) != 0) ? Boolean.TRUE : Boolean.FALSE;
} else if (name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)) {
return ((fFeatures & XMLDECL) != 0) ? Boolean.TRUE : Boolean.FALSE;
} else if (name.equalsIgnoreCase(DOMConstants.S_IS_STANDALONE)) {
} else if (name.equalsIgnoreCase(Constants.ORACLE_JAXP_PROPERTY_PREFIX
+ DOMConstants.S_IS_STANDALONE)) {
return ((fFeatures & IS_STANDALONE) != 0) ? Boolean.TRUE : Boolean.FALSE;
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
return ((fFeatures & ELEM_CONTENT_WHITESPACE) != 0) ? Boolean.TRUE : Boolean.FALSE;
Expand Down Expand Up @@ -625,7 +631,8 @@ public void setParameter(String name, Object value) throws DOMException {
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "yes");
}
} else if (name.equalsIgnoreCase(DOMConstants.S_IS_STANDALONE)) {
} else if (name.equalsIgnoreCase(Constants.ORACLE_JAXP_PROPERTY_PREFIX
+ DOMConstants.S_IS_STANDALONE)) {
fFeatures = state ? fFeatures | IS_STANDALONE : fFeatures & ~IS_STANDALONE;
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_JDK_PROPERTIES_NS
Expand Down
227 changes: 226 additions & 1 deletion src/java.xml/share/classes/module-info.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
Expand Down Expand Up @@ -27,6 +27,231 @@
* 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.
*
* @implNote
* <h2>Implementation Specific Features and Properties</h2>
*
* 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.
*
* <h3>Naming Convention</h3>
* The names of the features and properties are fully qualified, composed of a
* prefix and name.
* <p>
* <h4>Prefix</h4>
* The prefix for JDK properties is defined as:
* <pre>
* {@code http://www.oracle.com/xml/jaxp/properties/}
* </pre>
*
* The prefix for features:
* <pre>
* {@code http://www.oracle.com/xml/jaxp/features/}
* </pre>
*
* The prefix for System Properties:
* <pre>
* {@systemProperty jdk.xml.}
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
* </pre>
* <p>
* <h4>Name</h4>
* A name may consist of one or multiple words that are case-sensitive.
* All letters of the first word shall be in lowercase, while the first letter of
* each subsequent word capitalized.
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
* <p>
* An example of a property that indicates whether an XML document is standalone
* would thus have a format:
* <pre>
* {@code http://www.oracle.com/xml/jaxp/properties/isStandalone}
* </pre>
* and a corresponding System Property:
* <pre>
* {@systemProperty jdk.xml.isStandalone}
* </pre>
*
* <h3>System Properties</h3>
* A property may have a corresponding System Property that has the same name
* except the prefix as shown above. A System Property should be set prior to
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
* the creation of a processor and may be cleared afterwards.
*
* <h3>jaxp.properties</h3>
* A system property can be specified in the {@code jaxp.properties} file to
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
* set the behavior for all invocations of the JDK or JRE. The format is
* {@code system-property-name=value}. For example:
* <pre>
* {@code jdk.xml.isStandalone=true}
* </pre>
*
* <h3 id="ScopeAndOrder">Scope and Order</h3>
* The {@link javax.xml.XMLConstants#FEATURE_SECURE_PROCESSING} feature
* (hereafter referred to as FSP) is required for XML processors including DOM,
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
* SAX, Schema Validation, XSLT, and XPath. Any properties flagged as
* {@code "security: yes"} (hereafter referred to as security properties) in table
* <a href="#FeaturesAndProperties">Features And Properties</a>
* are enforced when FSP is set to true. Such enforcement includes setting security
* features to true and limits to the defined values shown in the table.
* The property values will not be affected, however, when setting FSP to false.
* <p>
* When the Java Security Manager is present, FSP is set to true and can not be
* turned off. The security properties are therefore enforced.
* <p>
* Properties specified in the jaxp.properties file affect all invocations of
* the JDK and JRE, and will override their default values, or those that may
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
* have been set by FSP.
* <p>
* System properties, when set, affect the invocation of the JDK and JRE, and
* override the default settings or that set in jaxp.properties, or those that
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
* may have been set by FSP.
* <p>
* JAXP properties specified through JAXP factories or processors (e.g. SAXParser)
* take preference over system properties, the jaxp.properties file, as well as FSP.
* <p>
*
* <h3 id="Processor">Processor Support</h3>
* 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.
* <p>
*
* <table class="plain" id="Processors">
* <caption>Processors</caption>
* <thead>
* <tr>
* <th scope="col">ID</th>
* <th scope="col">Name</th>
* <th scope="col">How to set the property</th>
* </tr>
* </thead>
*
* <tbody>
* <tr>
* <th scope="row" style="font-weight:normal" id="DOM">DOM</th>
* <td>DOM Parser</td>
* <td>
* DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();<br>
* dbf.setAttribute(name, value);
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="SAX">SAX</th>
* <td>SAX Parser</td>
* <td>
* SAXParserFactory spf = SAXParserFactory.newInstance();<br>
* SAXParser parser = spf.newSAXParser();<br>
* parser.setProperty(name, value);
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="StAX">StAX</th>
* <td>StAX Parser</td>
* <td>
* XMLInputFactory xif = XMLInputFactory.newInstance();<br>
* xif.setProperty(name, value);
* </td>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="Validation">Validation</th>
* <td>Schema Validator</td>
* <td>
* SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);<br>
* schemaFactory.setProperty(name, value);
* </td>
* </tr>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="Transform">Transform</th>
* <td>Schema Validator</td>
* <td>
* TransformerFactory factory = TransformerFactory.newInstance();<br>
* factory.setAttribute(name, value);
* </td>
* </tr>
* </tr>
* <tr>
* <th scope="row" style="font-weight:normal" id="DOMLS">DOMLS</th>
* <td>DOM Load and Save</td>
* <td>
* LSSerializer serializer = domImplementation.createLSSerializer(); <br>
* serializer.getDomConfig().setParameter(name, value);
* </td>
* </tr>
* </tbody>
* </table>
*
JoeWang-Java marked this conversation as resolved.
Show resolved Hide resolved
* <p>
* <h3>Implementation Specific Features and Properties</h3>
* This section lists features and properties supported by the JDK implementation.
*
* <p>
* <table class="plain" id="FeaturesAndProperties">
* <caption>Features and Properties</caption>
* <thead>
* <tr>
* <th scope="col" rowspan="2">Name [1]</th>
* <th scope="col" rowspan="2">Description</th>
* <th scope="col" rowspan="2">System Property [2]</th>
* <th scope="col" rowspan="2">jaxp.properties [2]</th>
* <th scope="col" colspan="3" style="text-align:center">Value [3]</th>
* <th scope="col" rowspan="2">Security [4]</th>
* <th scope="col" rowspan="2">Supported Processor [5]</th>
* <th scope="col" rowspan="2">Since [6]</th>
* </tr>
* <tr>
* <th scope="col">Type</th>
* <th scope="col">Value</th>
* <th scope="col">Default</th>
* </tr>
* </thead>
*
* <tbody>
*
* <tr>
* <th scope="row" style="font-weight:normal" id="ISSTANDALONE">isStandalone</th>
* <td>indicates that the serializer should treat the output as a
* standalone document. The property can be used to ensure a newline is written
* after the XML declaration when the property
* {@link org.w3c.dom.ls.LSSerializer#getDomConfig() format-pretty-print} is set
* to true. Unlike the property
* {@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.
* </td>
* <td>yes</td>
* <td>yes</td>
* <td>boolean</td>
* <th id="Value" scope="row" style="font-weight:normal">true/false</th>
* <th id="Default" scope="row" style="font-weight:normal">false</th>
* <td>No</td>
* <td><a href="#DOMLS">DOMLS</a></td>
* <td>17</td>
* </tr>
* </tbody>
* </table>
* <p>
* <b>[1]</b> The name of a property. The fully-qualified name, prefix + name,
* should be used when setting the property.
* <p>
* <b>[2]</b> A value "yes" indicates there is a corresponding System Property
* for the property, "no" otherwise.
*
* <p>
* <b>[3]</b> 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.
* <p>
* <b>[4]</b> A value "yes" indicates the property is a Security Property. Refer
* to the <a href="#ScopeAndOrder">Scope and Order</a> on how FSP may affect the
* value of a Security Property.
* <p>
* <b>[5]</b> One or more processors that support the property. The values of the
* field are IDs described in table <a href="#Processor">Processors</a>.
* <p>
* <b>[6]</b> Indicates the initial release the property is introduced.
*
*
*
* @uses javax.xml.datatype.DatatypeFactory
* @uses javax.xml.parsers.DocumentBuilderFactory
* @uses javax.xml.parsers.SAXParserFactory
Expand Down
Expand Up @@ -75,7 +75,8 @@
@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 = "jdk-is-standalone";
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 XML_LB
= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sometag/>\n";
Expand All @@ -99,7 +100,7 @@ public Object[][] xmlData() throws Exception {

/*
* Bug: 8249867
* DataProvider: for testing the jdk-is-standalone property
* DataProvider: for testing the isStandalone property
* Data columns: property, system property, value, expected result
*/
@DataProvider(name = "setting")
Expand Down Expand Up @@ -131,7 +132,7 @@ Object[][] getSystemProperty() throws Exception {

/*
* Bug: 8249867
* Verifies the use of the new property "jdk-is-standalone" and the
* Verifies the use of the new property "isStandalone" and the
* corresponding System property "jdk.xml.isStandalone".
*/
@Test(dataProvider = "setting")
Expand Down Expand Up @@ -579,7 +580,6 @@ private Transformer getTransformer(boolean html, boolean pretty) throws Exceptio
return transformer;
}


private String read(String filename) throws Exception {
try (InputStream in = PrettyPrintTest.class.getResourceAsStream(filename)) {
return new String(in.readAllBytes());
Expand Down