diff --git a/openide.util/src/org/openide/xml/XMLUtil.java b/openide.util/src/org/openide/xml/XMLUtil.java
--- a/openide.util/src/org/openide/xml/XMLUtil.java
+++ b/openide.util/src/org/openide/xml/XMLUtil.java
@@ -44,34 +44,23 @@
import java.io.CharConversionException;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Map;
-import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;
import org.openide.util.Exceptions;
import org.w3c.dom.Attr;
-import org.w3c.dom.CDATASection;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
@@ -81,6 +70,9 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
@@ -355,27 +347,6 @@
}
/**
- * Identity transformation in XSLT with indentation added.
- * Just using the identity transform and calling
- * t.setOutputProperty(OutputKeys.INDENT, "yes");
- * t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
- * does not work currently.
- * You really have to use this bogus stylesheet.
- * @see "JDK bug #5064280"
- */
- private static final String IDENTITY_XSLT_WITH_INDENT =
- "" + // NOI18N
- "" + // NOI18N
- "" + // NOI18N
- "" + // NOI18N
- "" + // NOI18N
- "" + // NOI18N
- "" + // NOI18N
- ""; // NOI18N
- /**
* Writes a DOM document to a stream.
* The precise output format is not guaranteed but this method will attempt to indent it sensibly.
*
@@ -398,58 +369,17 @@
throw new NullPointerException("You must set an encoding; use \"UTF-8\" unless you have a good reason not to!"); // NOI18N
}
Document doc2 = normalize(doc);
- try {
- Transformer t = TransformerFactory.newInstance().newTransformer(
- new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
- DocumentType dt = doc2.getDoctype();
- if (dt != null) {
- String pub = dt.getPublicId();
- if (pub != null) {
- t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pub);
- }
- String sys = dt.getSystemId();
- if (sys != null) {
- t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, sys);
- }
- }
- t.setOutputProperty(OutputKeys.ENCODING, enc);
-
- // See #123816
- Set cdataQNames = new HashSet();
- collectCDATASections(doc2, cdataQNames);
- if (cdataQNames.size() > 0) {
- StringBuilder cdataSections = new StringBuilder();
- for(String s : cdataQNames) {
- cdataSections.append(s).append(' '); //NOI18N
- }
- t.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, cdataSections.toString());
- }
-
- Source source = new DOMSource(doc2);
- Result result = new StreamResult(out);
- t.transform(source, result);
- } catch (Exception e) {
- throw new IOException(e);
+ DOMImplementationLS ls = (DOMImplementationLS) doc2.getImplementation().getFeature("LS", "3.0"); // NOI18N
+ assert ls != null : "No DOM 3 LS supported in " + doc2.getClass().getName();
+ LSOutput output = ls.createLSOutput();
+ output.setEncoding(enc);
+ output.setByteStream(out);
+ LSSerializer ser = ls.createLSSerializer();
+ String fpp = "format-pretty-print"; // NOI18N
+ if (ser.getDomConfig().canSetParameter(fpp, true)) {
+ ser.getDomConfig().setParameter(fpp, true);
}
- }
-
- private static void collectCDATASections(Node node, Set cdataQNames) {
- if (node instanceof CDATASection) {
- Node parent = node.getParentNode();
- if (parent != null) {
- String uri = parent.getNamespaceURI();
- if (uri != null) {
- cdataQNames.add("{" + uri + "}" + parent.getNodeName()); //NOI18N
- } else {
- cdataQNames.add(parent.getNodeName());
- }
- }
- }
-
- NodeList children = node.getChildNodes();
- for(int i = 0; i < children.getLength(); i++) {
- collectCDATASections(children.item(i), cdataQNames);
- }
+ ser.write(doc2, output);
}
/**