This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch AOO50X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 8b9013724dd07fa97d4caec54c69a6829e17c53d
Author: Pedro Giffuni <[email protected]>
AuthorDate: Thu Sep 3 23:32:14 2026 -0500

    XMerge: use standard JAXP XML serialization
    
    Update the code to use the modern JAXP solution. This removes the need
    for Xerces, Xalan serializer, xml-apis, Crimson, and GNU XML, which we
    don't carry since a long time.
    
    As a result, XMerge still builds and works, however the small devices it
    targets (Palm, pocketPC) are of little value nowadays and the implementation
    is candidate for deprecation in  the future.
    
    (cherry picked from commit 02b7814fde0d794dfe3ee37c8b439b0be3345910)
---
 main/xmerge/java/xmerge/build.xml                  |   3 -
 .../xmerge/converter/dom/DOMDocument.java          | 117 ++------------------
 .../xmerge/converter/xml/OfficeDocument.java       | 122 ++-------------------
 .../org/openoffice/xmerge/util/registry/build.xml  |   6 -
 main/xmerge/util/build.xml                         |   2 -
 main/xmerge/util/xmerge.mf                         |   2 -
 main/xmerge/workben/build.xml                      |   6 -
 7 files changed, 17 insertions(+), 241 deletions(-)

diff --git a/main/xmerge/java/xmerge/build.xml 
b/main/xmerge/java/xmerge/build.xml
index 10be10b73c..f2f423b00d 100644
--- a/main/xmerge/java/xmerge/build.xml
+++ b/main/xmerge/java/xmerge/build.xml
@@ -28,12 +28,9 @@
     <import file="${SRC_ROOT}/solenv/ant/aoo-ant.xml"/>
 
     <target name="init-project">
-        <property name="jar.classpath" value="xml-apis.jar xercesImpl.jar 
serializer.jar"/>
         <property name="jar.manifest" value="manifest.mf"/>
 
         <path id="main.classpath">
-<!--            <pathelement location="${OUTDIR}/bin/xml-apis.jar"/> -->
-<!--            <pathelement location="${OUTDIR}/bin/xercesImpl.jar"/> -->
             <pathelement location="${OUTDIR}/bin/unoil.jar"/>
             <pathelement location="${OUTDIR}/bin/ridl.jar"/>
             <pathelement location="${OUTDIR}/bin/juh.jar"/>
diff --git 
a/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/converter/dom/DOMDocument.java
 
b/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/converter/dom/DOMDocument.java
index ce6750b719..5264d3d493 100644
--- 
a/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/converter/dom/DOMDocument.java
+++ 
b/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/converter/dom/DOMDocument.java
@@ -25,7 +25,6 @@ package org.openoffice.xmerge.converter.dom;
 
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.StringWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
@@ -232,9 +231,6 @@ public class DOMDocument
      *  <p>Write out a <code>org.w3c.dom.Document</code> object into a
      *  <code>byte</code> array.</p>
      *
-     *  <p>TODO: remove dependency on com.sun.xml.tree.XmlDocument
-     *  package!</p>
-     *
      *  @param  doc  DOM <code>Document</code> object.
      *
      *  @return  <code>byte</code> array of DOM <code>Document</code>
@@ -244,115 +240,18 @@ public class DOMDocument
      */
     private byte[] docToBytes(Document doc)
         throws IOException {
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
-        java.lang.reflect.Constructor con;
-        java.lang.reflect.Method meth;
-
-        String domImpl = doc.getClass().getName();
-
-        System.err.println("type b " + domImpl);
-
-        /*
-         * We may have multiple XML parsers in the Classpath.
-         * Depending on which one is first, the actual type of
-         * doc may vary.  Need a way to find out which API is being
-         * used and use an appropriate serialization method.
-         */
         try {
-            // First of all try for JAXP 1.0
-            if (domImpl.equals("com.sun.xml.tree.XmlDocument")) {
-                System.out.println("Using JAXP");
-                Class jaxpDoc = Class.forName("com.sun.xml.tree.XmlDocument");
-
-                // The method is in the XMLDocument class itself, not a helper
-                meth = jaxpDoc.getMethod("write",
-                            new Class[] { 
Class.forName("java.io.OutputStream") } );
-
-                meth.invoke(doc, new Object [] { baos } );
-            }
-           else if (domImpl.equals("org.apache.crimson.tree.XmlDocument"))
-           {
-                System.out.println("Using Crimson");
-                Class crimsonDoc = 
Class.forName("org.apache.crimson.tree.XmlDocument");
-                // The method is in the XMLDocument class itself, not a helper
-                meth = crimsonDoc.getMethod("write",
-                            new Class[] { 
Class.forName("java.io.OutputStream") } );
-
-                meth.invoke(doc, new Object [] { baos } );
-           }
-            else if (domImpl.equals("org.apache.xerces.dom.DocumentImpl")
-            || domImpl.equals("org.apache.xerces.dom.DeferredDocumentImpl")) {
-                System.out.println("Using Xerces");
-                // Try for Xerces
-                Class xercesSer =
-                        
Class.forName("org.apache.xml.serialize.XMLSerializer");
-
-                // Get the OutputStream constructor
-                // May want to use the OutputFormat parameter at some stage too
-                con = xercesSer.getConstructor(new Class []
-                        { Class.forName("java.io.OutputStream"),
-                          
Class.forName("org.apache.xml.serialize.OutputFormat") } );
-
-
-                // Get the serialize method
-                meth = xercesSer.getMethod("serialize",
-                            new Class [] { 
Class.forName("org.w3c.dom.Document") } );
-
-
-                // Get an instance
-                Object serializer = con.newInstance(new Object [] { baos, null 
} );
-
-
-                // Now call serialize to write the document
-                meth.invoke(serializer, new Object [] { doc } );
-            }
-            else if (domImpl.equals("gnu.xml.dom.DomDocument")) {
-                System.out.println("Using GNU");
-
-                Class gnuSer = Class.forName("gnu.xml.dom.ls.DomLSSerializer");
-
-                // Get the serialize method
-                meth = gnuSer.getMethod("serialize",
-                            new Class [] { Class.forName("org.w3c.dom.Node"),
-                            Class.forName("java.io.OutputStream") } );
-
-                // Get an instance
-                Object serializer = gnuSer.newInstance();
-
-                // Now call serialize to write the document
-                meth.invoke(serializer, new Object [] { doc, baos } );
-            }
-            else {
-                // We dont have another parser
-                try {
-                        DOMSource domSource = new DOMSource(doc);
-                        StringWriter writer = new StringWriter();
-                        StreamResult result = new StreamResult(writer);
-                        TransformerFactory tf = 
TransformerFactory.newInstance();
-                        Transformer transformer = tf.newTransformer();
-                        transformer.transform(domSource, result);
-                        return writer.toString().getBytes();
-                    }
-                catch (Exception e) {
-                    // We don't have another parser
-                    throw new IOException("No appropriate API (JAXP/Xerces) to 
serialize XML document: " + domImpl);
-                }
-            }
-        }
-        catch (ClassNotFoundException cnfe) {
-            throw new IOException(cnfe.toString());
+            DOMSource domSource = new DOMSource(doc);
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            StreamResult result = new StreamResult(output);
+            TransformerFactory tf = TransformerFactory.newInstance();
+            Transformer transformer = tf.newTransformer();
+            transformer.transform(domSource, result);
+            return output.toByteArray();
         }
         catch (Exception e) {
-            // We may get some other errors, but the bottom line is that
-            // the steps being executed no longer work
-            throw new IOException(e.toString());
+            throw new IOException("Unable to serialize XML document: " + e);
         }
-
-        byte bytes[] = baos.toByteArray();
-
-        return bytes;
     }
 
 
diff --git 
a/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
 
b/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
index 5f25220099..573baab580 100644
--- 
a/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
+++ 
b/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
@@ -28,9 +28,8 @@ import java.io.OutputStream;
 import java.io.Reader;
 import java.io.BufferedReader;
 import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.InputStreamReader;
 import java.io.ByteArrayOutputStream;
+import java.io.InputStreamReader;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.Iterator;
@@ -840,9 +839,6 @@ public abstract class OfficeDocument
      *  <p>Write out a <code>org.w3c.dom.Document</code> object into a
      *  <code>byte</code> array.</p>
      *
-     *  <p>TODO: remove dependency on com.sun.xml.tree.XmlDocument
-     *  package!</p>
-     *
      *  @param  doc  DOM <code>Document</code> object.
      *
      *  @return  <code>byte</code> array of DOM <code>Document</code>
@@ -852,118 +848,18 @@ public abstract class OfficeDocument
      */
     static byte[] docToBytes(Document doc)
         throws IOException {
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
-        java.lang.reflect.Constructor con;
-        java.lang.reflect.Method meth;
-
-        String domImpl = doc.getClass().getName();
-
-        /*
-         * We may have multiple XML parsers in the Classpath.
-         * Depending on which one is first, the actual type of
-         * doc may vary.  Need a way to find out which API is being
-         * used and use an appropriate serialization method.
-         */
-
         try {
-            // First of all try for JAXP 1.0
-            if (domImpl.equals("com.sun.xml.tree.XmlDocument")) {
-
-                Debug.log(Debug.INFO, "Using JAXP");
-
-                Class jaxpDoc = Class.forName("com.sun.xml.tree.XmlDocument");
-
-                // The method is in the XMLDocument class itself, not a helper
-                meth = jaxpDoc.getMethod("write",
-                            new Class[] { 
Class.forName("java.io.OutputStream") } );
-
-                meth.invoke(doc, new Object [] { baos } );
-            }
-            else if (domImpl.equals("org.apache.crimson.tree.XmlDocument"))
-           {
-                Debug.log(Debug.INFO, "Using Crimson");
-
-                Class crimsonDoc = 
Class.forName("org.apache.crimson.tree.XmlDocument");
-                // The method is in the XMLDocument class itself, not a helper
-                meth = crimsonDoc.getMethod("write",
-                            new Class[] { 
Class.forName("java.io.OutputStream") } );
-
-                meth.invoke(doc, new Object [] { baos } );
-           }
-            else if (domImpl.equals("org.apache.xerces.dom.DocumentImpl")
-            || domImpl.equals("org.apache.xerces.dom.DeferredDocumentImpl")) {
-
-                Debug.log(Debug.INFO, "Using Xerces");
-
-                // Try for Xerces
-                Class xercesSer =
-                        
Class.forName("org.apache.xml.serialize.XMLSerializer");
-
-                // Get the OutputStream constructor
-                // May want to use the OutputFormat parameter at some stage too
-                con = xercesSer.getConstructor(new Class []
-                        { Class.forName("java.io.OutputStream"),
-                          
Class.forName("org.apache.xml.serialize.OutputFormat") } );
-
-
-                // Get the serialize method
-                meth = xercesSer.getMethod("serialize",
-                            new Class [] { 
Class.forName("org.w3c.dom.Document") } );
-
-
-                // Get an instance
-                Object serializer = con.newInstance(new Object [] { baos, null 
} );
-
-
-                // Now call serialize to write the document
-                meth.invoke(serializer, new Object [] { doc } );
-            }
-            else if (domImpl.equals("gnu.xml.dom.DomDocument")) {
-                Debug.log(Debug.INFO, "Using GNU");
-
-                Class gnuSer = Class.forName("gnu.xml.dom.ls.DomLSSerializer");
-
-                // Get the serialize method
-                meth = gnuSer.getMethod("serialize",
-                            new Class [] { Class.forName("org.w3c.dom.Node"),
-                            Class.forName("java.io.OutputStream") } );
-
-                // Get an instance
-                Object serializer = gnuSer.newInstance();
-
-                // Now call serialize to write the document
-                meth.invoke(serializer, new Object [] { doc, baos } );
-            }
-            else {
-               try {
-                       DOMSource domSource = new DOMSource(doc);
-                       StringWriter writer = new StringWriter();
-                       StreamResult result = new StreamResult(writer);
-                       TransformerFactory tf = 
TransformerFactory.newInstance();
-                       Transformer transformer = tf.newTransformer();
-                       transformer.transform(domSource, result);
-                       return writer.toString().getBytes();
-                   }
-                catch (Exception e) {
-                    // We don't have another parser
-                    throw new IOException("No appropriate API (JAXP/Xerces) to 
serialize XML document: " + domImpl);
-                }
-            }
-        }
-        catch (ClassNotFoundException cnfe) {
-            throw new IOException(cnfe.toString());
+            DOMSource domSource = new DOMSource(doc);
+            ByteArrayOutputStream output = new ByteArrayOutputStream();
+            StreamResult result = new StreamResult(output);
+            TransformerFactory tf = TransformerFactory.newInstance();
+            Transformer transformer = tf.newTransformer();
+            transformer.transform(domSource, result);
+            return output.toByteArray();
         }
         catch (Exception e) {
-            // We may get some other errors, but the bottom line is that
-            // the steps being executed no longer work
-            throw new IOException(e.toString());
+            throw new IOException("Unable to serialize XML document: " + e);
         }
-
-        byte bytes[] = baos.toByteArray();
-
-        return bytes;
     }
 
 
diff --git 
a/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/util/registry/build.xml
 
b/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/util/registry/build.xml
index f9d5be4cb2..03f5a309b2 100644
--- 
a/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/util/registry/build.xml
+++ 
b/main/xmerge/java/xmerge/src/main/java/org/openoffice/xmerge/util/registry/build.xml
@@ -45,15 +45,9 @@
     <!-- define how to handle CLASSPATH environment -->
     <property name="build.sysclasspath" value="ignore"/>
 
-    <property environment="env"/>
-    <property name="env.XML_APIS_JAR" value="${solar.jar}/xml-apis.jar"/>
-    <property name="env.XERCES_JAR" value="${solar.jar}/xercesImpl.jar"/>
-
     <!-- classpath settings for javac tasks -->
     <path id="classpath">
         <pathelement location="${build.class}"/>
-        <pathelement location="${env.XML_APIS_JAR}"/>
-        <pathelement location="${env.XERCES_JAR}"/>
     </path>
 
     <!-- set whether we want to compile with or without deprecation -->
diff --git a/main/xmerge/util/build.xml b/main/xmerge/util/build.xml
index a0a952bfaa..fd8a969727 100644
--- a/main/xmerge/util/build.xml
+++ b/main/xmerge/util/build.xml
@@ -31,8 +31,6 @@
     <property name="javadoc.dir" location="${WORKDIR}/Ant/xmerge-javadoc"/>
 
     <path id="main.classpath">
-<!--        <pathelement location="${OUTDIR}/bin/xml-apis.jar"/> -->
-<!--        <pathelement location="${OUTDIR}/bin/xercesImpl.jar"/> -->
         <pathelement location="${OUTDIR}/bin/unoil.jar"/>
         <pathelement location="${OUTDIR}/bin/ridl.jar"/>
         <pathelement location="${OUTDIR}/bin/jurt.jar"/>
diff --git a/main/xmerge/util/xmerge.mf b/main/xmerge/util/xmerge.mf
index 9699a69aa4..0786be6e12 100644
--- a/main/xmerge/util/xmerge.mf
+++ b/main/xmerge/util/xmerge.mf
@@ -1,8 +1,6 @@
 Manifest-Version: 1.0
 Main-Class: org.openoffice.xmerge.test.Driver
-Class-Path: xml-apis.jar xercesImpl.jar serializer.jar
 Specification-Title: Apache OpenOffice XMerge Framework
 Specification-Vendor: Apache OpenOffice
 Specification-Version: 0.6.0
 Implementation-Version: #IMPL-VERSION#
-
diff --git a/main/xmerge/workben/build.xml b/main/xmerge/workben/build.xml
index 9b140d090b..56599f82a2 100644
--- a/main/xmerge/workben/build.xml
+++ b/main/xmerge/workben/build.xml
@@ -45,15 +45,9 @@
     <!-- define how to handle CLASSPATH environment -->
     <property name="build.sysclasspath" value="ignore"/>
 
-    <property environment="env"/>
-    <property name="env.XML_APIS_JAR" value="${solar.jar}/xml-apis.jar"/>
-    <property name="env.XERCES_JAR" value="${solar.jar}/xercesImpl.jar"/>
-
     <!-- classpath settings for javac tasks -->
     <path id="classpath">
         <pathelement location="${build.class}"/>
-        <pathelement location="${env.XML_APIS_JAR}"/>
-        <pathelement location="${env.XERCES_JAR}"/>
     </path>
 
     <!-- set whether we want to compile with or without deprecation -->

Reply via email to