Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk13u-dev Public archive

Commit

Permalink
8249867: XML declaration is not followed by a newline
Browse files Browse the repository at this point in the history
Reviewed-by: bae
Backport-of: 69ee314
  • Loading branch information
Yuri Nesterenko committed Feb 16, 2022
1 parent d7b8c97 commit b9c0ba8
Show file tree
Hide file tree
Showing 5 changed files with 474 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand All @@ -20,6 +20,7 @@

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

import com.sun.org.apache.xml.internal.serializer.dom3.DOMConstants;
import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
import com.sun.org.apache.xml.internal.serializer.utils.Utils;
import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
Expand Down Expand Up @@ -502,8 +503,10 @@ void setProp(String name, String val, boolean defaultVal) {
if (OutputPropertiesFactory.S_KEY_INDENT_AMOUNT.equals(name)) {
setIndentAmount(Integer.parseInt(val));
} else if (OutputKeys.INDENT.equals(name)) {
boolean b = val.endsWith("yes") ? true : false;
m_doIndent = b;
m_doIndent = val.endsWith("yes");
} else if ((DOMConstants.S_JDK_PROPERTIES_NS + DOMConstants.S_IS_STANDALONE)
.equals(name)) {
m_isStandalone = val.endsWith("yes");
}

break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -22,26 +21,34 @@

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

import com.sun.org.apache.xerces.internal.impl.Constants;

/**
* DOM Constants used by the DOM Level 3 LSSerializer implementation.
*
* @xsl.usage internal
* @LastModified: Jan 2021
*/
final class DOMConstants {
public final class DOMConstants {
//
// Constants: DOM Level 3 feature ids
//
public static final String DOM3_REC_URL = "http://www.w3.org/TR/DOM-Level-3-LS";

public static final String XERCES_URL = "http://xml.apache.org/xerces-2j";

public static final String ORACLE_URL = "http://www.oracle.com/xml";

// The namespace used to qualified DOM Level 3 DOMConfiguration parameters
public static final String S_DOM3_PROPERTIES_NS = "{"
+ DOMConstants.DOM3_REC_URL + "}";

public static final String S_XERCES_PROPERTIES_NS = "{"
+ DOMConstants.XERCES_URL + "}";

// The namespace used for the JDK-only parameters
public static final String S_JDK_PROPERTIES_NS = "{" + ORACLE_URL + "}";

// xmlns namespaces
private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";

Expand Down Expand Up @@ -113,6 +120,25 @@ final class DOMConstants {
// The xerces serializer specific 'omit-xml-declaration' property used in LSSerializer
public static final String S_XML_VERSION = "xml-version";

/**
* Indicates that the serializer should treat the output as a standalone document.
* The JDK specific standalone property controls whether a newline should be
* added after the XML header.
*
* @see similar property ORACLE_IS_STANDALONE in OutputPropertiesFactory.
*/
public static final String S_IS_STANDALONE = "isStandalone";

// Fully-qualified property name with the JDK Impl prefix
public static final String FQ_IS_STANDALONE =
Constants.ORACLE_JAXP_PROPERTY_PREFIX + S_IS_STANDALONE;

// The property with namespace as the internal DOMConfiguration format
public static final String NS_IS_STANDALONE = S_JDK_PROPERTIES_NS + S_IS_STANDALONE;

// Corresponding System property
public static final String SP_IS_STANDALONE = "jdk.xml.isStandalone";

//
public static final String S_XSL_VALUE_ENTITIES = "com/sun/org/apache/xml/internal/serializer/XMLEntities";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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 All @@ -33,7 +34,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;

import jdk.xml.internal.SecuritySupport;
import com.sun.org.apache.xml.internal.serializer.DOM3Serializer;
import com.sun.org.apache.xml.internal.serializer.Encodings;
import com.sun.org.apache.xml.internal.serializer.Serializer;
Expand Down Expand Up @@ -159,6 +160,10 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {

// Parameter discard-default-content, true [required] (default)
private final static int XMLDECL = 0x1 << 18;

// Parameter is-standalone, jdk specific, not required
private final static int IS_STANDALONE = 0x1 << 19;

// ************************************************************************

// Recognized parameters for which atleast one value can be set
Expand All @@ -182,6 +187,7 @@ final public class LSSerializerImpl implements DOMConfiguration, LSSerializer {
DOMConstants.DOM_FORMAT_PRETTY_PRINT,
DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS,
DOMConstants.DOM_XMLDECL,
DOMConstants.FQ_IS_STANDALONE,
DOMConstants.DOM_ERROR_HANDLER
};

Expand Down Expand Up @@ -351,6 +357,20 @@ public void initializeSerializerProps () {
// xml-declaration
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);
}
// the system property is true only if it is "true" and false otherwise
if (p != null && p.equals("true")) {
fFeatures |= IS_STANDALONE;
fDOMConfigProperties.setProperty(DOMConstants.NS_IS_STANDALONE,
DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.NS_IS_STANDALONE,
DOMConstants.DOM3_DEFAULT_FALSE);
}
}

// ************************************************************************
Expand Down Expand Up @@ -378,7 +398,8 @@ public boolean canSetParameter(String name, Object value) {
|| name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)
|| name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)
|| name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)
|| name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)){
|| name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)
|| name.equalsIgnoreCase(DOMConstants.FQ_IS_STANDALONE)){
// both values supported
return true;
}
Expand All @@ -390,11 +411,11 @@ else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)
// || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
) {
// true is not supported
return !((Boolean)value).booleanValue();
return !((Boolean)value);
}
else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
// false is not supported
return ((Boolean)value).booleanValue();
return ((Boolean)value);
}
}
else if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) &&
Expand Down Expand Up @@ -436,6 +457,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.FQ_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;
} else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
Expand Down Expand Up @@ -606,6 +629,10 @@ 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.FQ_IS_STANDALONE)) {
fFeatures = state ? fFeatures | IS_STANDALONE : fFeatures & ~IS_STANDALONE;
fDOMConfigProperties.setProperty(DOMConstants.NS_IS_STANDALONE, state ? "yes" : "no");

} else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fFeatures = state ? fFeatures | ELEM_CONTENT_WHITESPACE : fFeatures
& ~ELEM_CONTENT_WHITESPACE;
Expand Down
Loading

1 comment on commit b9c0ba8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.