summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordkenny <dkenny@openoffice.org>2002-03-07 15:45:23 +0000
committerdkenny <dkenny@openoffice.org>2002-03-07 15:45:23 +0000
commit5acbb755f3f8dedf51904b711ff78f5e1aa498cf (patch)
tree25d659a61141e04d298ac396e865f6d5df52277f
Initial Import
-rw-r--r--xmerge/build.xml263
-rw-r--r--xmerge/java/build.xml175
-rw-r--r--xmerge/java/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/Convert.java276
-rw-r--r--xmerge/java/org/openoffice/xmerge/ConvertData.java145
-rw-r--r--xmerge/java/org/openoffice/xmerge/ConvertException.java73
-rw-r--r--xmerge/java/org/openoffice/xmerge/ConverterCapabilities.java95
-rw-r--r--xmerge/java/org/openoffice/xmerge/ConverterFactory.java152
-rw-r--r--xmerge/java/org/openoffice/xmerge/Document.java127
-rw-r--r--xmerge/java/org/openoffice/xmerge/DocumentDeserializer.java93
-rw-r--r--xmerge/java/org/openoffice/xmerge/DocumentDeserializerFactory.java93
-rw-r--r--xmerge/java/org/openoffice/xmerge/DocumentMerger.java121
-rw-r--r--xmerge/java/org/openoffice/xmerge/DocumentMergerFactory.java91
-rw-r--r--xmerge/java/org/openoffice/xmerge/DocumentSerializer.java95
-rw-r--r--xmerge/java/org/openoffice/xmerge/DocumentSerializerFactory.java91
-rw-r--r--xmerge/java/org/openoffice/xmerge/MergeException.java73
-rw-r--r--xmerge/java/org/openoffice/xmerge/PluginFactory.java192
-rw-r--r--xmerge/java/org/openoffice/xmerge/Version.java116
-rw-r--r--xmerge/java/org/openoffice/xmerge/build.xml166
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/dom/DOMDocument.java397
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/dom/build.xml153
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/dom/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/dom/package.html80
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/OfficeConstants.java289
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java604
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocumentException.java159
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/OfficeZip.java369
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/ParaStyle.java635
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/Style.java263
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/StyleCatalog.java425
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/StyleTest01.xml169
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java712
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/build.xml160
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/package.html66
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/DocumentMergerImpl.java227
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/Format.java314
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SpreadsheetDecoder.java181
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SpreadsheetEncoder.java142
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocument.java111
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentDeserializer.java622
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentSerializer.java809
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcPluginFactory.java101
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/build.xml161
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/package.html65
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxw/SxwDocument.java113
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxw/SxwPluginFactory.java97
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxw/build.xml154
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxw/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxw/package.html65
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentDeserializerImpl.java238
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java235
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/PluginFactoryImpl.java200
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/XsltPlugin.properties63
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/build.xml161
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/converter.xml77
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/htmltosoff.xsl201
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/package.html92
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/xslt/sofftohtml.xsl193
-rw-r--r--xmerge/java/org/openoffice/xmerge/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/DiffAlgorithm.java79
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/Difference.java270
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/Iterator.java151
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/MergeAlgorithm.java89
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/NodeMergeAlgorithm.java83
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/build.xml157
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/CellNodeIterator.java144
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/CharArrayLCSAlgorithm.java263
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/CharacterParser.java171
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/IteratorLCSAlgorithm.java264
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/IteratorRowCompare.java271
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/NodeIterator.java414
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/ObjectArrayIterator.java238
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/ParaNodeIterator.java123
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/RowIterator.java112
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeEntry.java116
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeIterator.java118
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/build.xml163
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/diff/package.html68
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/merge/CharacterBaseParagraphMerge.java338
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/merge/DocumentMerge.java278
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/merge/PositionBaseRowMerge.java295
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/merge/SheetMerge.java120
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/merge/SheetUtil.java136
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/merge/build.xml157
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/merge/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/merge/package.html68
-rw-r--r--xmerge/java/org/openoffice/xmerge/merger/package.html100
-rw-r--r--xmerge/java/org/openoffice/xmerge/package.html138
-rw-r--r--xmerge/java/org/openoffice/xmerge/test/ConverterInfoList.java136
-rw-r--r--xmerge/java/org/openoffice/xmerge/test/ConverterInfoList.properties59
-rw-r--r--xmerge/java/org/openoffice/xmerge/test/Driver.java349
-rw-r--r--xmerge/java/org/openoffice/xmerge/test/build.xml157
-rw-r--r--xmerge/java/org/openoffice/xmerge/test/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/Debug.java369
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/Debug.properties65
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/IntArrayList.java175
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/Resources.java128
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/XmlUtil.java217
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/build.xml161
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/package.html64
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfo.java464
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfoMgr.java554
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfoReader.java307
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/registry/RegistryException.java75
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/registry/build.xml156
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/registry/converter.dtd121
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/registry/makefile.mk59
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/registry/package.html107
-rw-r--r--xmerge/java/org/openoffice/xmerge/util/resources.properties95
-rw-r--r--xmerge/prj/build.lst2
-rw-r--r--xmerge/prj/d.lst5
-rw-r--r--xmerge/util/build.xml151
-rw-r--r--xmerge/util/makefile.mk59
-rw-r--r--xmerge/util/minicalc.mf3
-rw-r--r--xmerge/util/xmerge.mf8
-rw-r--r--xmerge/workben/XmlDiff.java486
-rw-r--r--xmerge/workben/XmlDiff.properties66
-rw-r--r--xmerge/workben/build.xml151
-rw-r--r--xmerge/workben/jstyle.pl568
-rw-r--r--xmerge/workben/makefile.mk59
126 files changed, 22548 insertions, 0 deletions
diff --git a/xmerge/build.xml b/xmerge/build.xml
new file mode 100644
index 000000000000..ecdf194b7d0b
--- /dev/null
+++ b/xmerge/build.xml
@@ -0,0 +1,263 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmerge" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used to generate build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmerge"/>
+
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <!-- used by init to set build directory -->
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${basedir}/${inpath}"/>
+ </target>
+
+ <target name="build_class" depends="build_dir">
+ <property name="build.class" value="${build.dir}/class"/>
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ <copy file="util/solar.properties" todir="${build.class}"/>
+ </target>
+
+ <!-- used by init to set up 'solar' build environment -->
+ <target name="solar" depends="build_dir,build_class" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ <property name="build.dir" value="${basedir}/${out}"/>
+ </target>
+
+
+ <!-- initialize build environment -->
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ <property file="${solar.properties}"/>
+ </target>
+
+ <!-- show information about current sub target in recursive builds -->
+ <target name="info">
+ <echo message="----------------------------------------"/>
+ <echo message="${target}"/>
+ <echo message="----------------------------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!--- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- names for targets build by release engineering -->
+ <!-- must start with project prefix and an underscore -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,xmrg_util,xmrg_javadoc"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init"/>
+
+
+
+ <!-- java package -->
+ <target name="xmrg_joo_xmerge" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge" target="main">
+ <property name="target" value="xmrg_joo_xmerge"/>
+ <property name="prj" value="../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_jooxc_xml" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/converter/xml" target="main">
+ <property name="target" value="xmrg_jooxc_xml"/>
+ <property name="prj" value="../../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_jooxcx_sxc" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/converter/xml/sxc" target="main">
+ <property name="target" value="xmrg_jooxcx_sxc"/>
+ <property name="prj" value="../../../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_jooxcx_sxw" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/converter/xml/sxw" target="main">
+ <property name="target" value="xmrg_jooxcx_sxw"/>
+ <property name="prj" value="../../../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_jooxcx_xslt" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/converter/xml/xslt" target="main">
+ <property name="target" value="xmrg_jooxcx_xslt"/>
+ <property name="prj" value="../../../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_joox_merger" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/merger" target="main">
+ <property name="target" value="xmrg_joox_merger"/>
+ <property name="prj" value="../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_jooxm_diff" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/merger/diff" target="main">
+ <property name="target" value="xmrg_jooxm_diff"/>
+ <property name="prj" value="../../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_jooxm_merge" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/merger/merge" target="main">
+ <property name="target" value="xmrg_jooxm_merge"/>
+ <property name="prj" value="../../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_joox_test" depends="prepare,xmrg_joox_util,xmrg_joo_xmerge">
+ <ant dir="java/org/openoffice/xmerge/test" target="main">
+ <property name="target" value="xmrg_joox_test"/>
+ <property name="prj" value="../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_joox_util" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/util" target="main">
+ <property name="target" value="xmrg_joox_util"/>
+ <property name="prj" value="../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_jooxu_registry" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/util/registry" target="main">
+ <property name="target" value="xmrg_jooxu_registry"/>
+ <property name="prj" value="../../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_jooxc_dom" depends="prepare">
+ <ant dir="java/org/openoffice/xmerge/converter/dom" target="main">
+ <property name="target" value="xmrg_jooxc_dom"/>
+ <property name="prj" value="../../../../../.."/>
+ </ant>
+ </target>
+
+
+ <!-- java package -->
+ <target name="xmrg_javadoc" depends="prepare">
+ <ant dir="java" target="main">
+ <property name="target" value="javadoc"/>
+ <property name="prj" value=".."/>
+ </ant>
+ </target>
+
+
+ <!-- util -->
+ <target name="xmrg_util" depends="prepare,xmrg_joo_xmerge,xmrg_jooxc_xml,xmrg_jooxcx_sxc,xmrg_jooxcx_sxw,xmrg_jooxcx_xslt,xmrg_joox_merger,xmrg_jooxm_diff,xmrg_jooxm_merge,xmrg_joox_test,xmrg_joox_util,xmrg_jooxu_registry,xmrg_jooxc_dom,xmrg_javadoc">
+ <ant dir="util" target="main">
+ <property name="target" value="xmrg_util"/>
+ <property name="prj" value="."/>
+ </ant>
+ </target>
+
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.dir}">
+ <patternset>
+ <include name="**"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+ <!-- handle dependencies -->
+ <target name="depend"/>
+
+</project>
+
diff --git a/xmerge/java/build.xml b/xmerge/java/build.xml
new file mode 100644
index 000000000000..6b2f7a566121
--- /dev/null
+++ b/xmerge/java/build.xml
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+
+<project name="xmrg_java" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_java"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value=".."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package" value="."/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ <pathelement location="${solar.jar}/xalan.jar"/>
+ <pathelement location="${solar.jar}/jurt.jar"/>
+ <pathelement location="${solar.jar}/unoil.jar"/>
+ <pathelement location="${solar.jar}/ridl.jar"/>
+ <pathelement location="${solar.jar}/sandbox.jar"/>
+ <pathelement location="${solar.jar}/juh.jar"/>
+ <pathelement location="${solar.jar}/jmc.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,javadoc,zipdoc"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.dir}/doc/javadoc"/>
+ </target>
+
+ <!-- compile java sources in ${package} and sub packages -->
+ <target name="javadoc" depends="prepare" if="build.dir">
+ <javadoc packagenames="org.openoffice.xmerge.*"
+ destdir="${build.dir}/doc/javadoc"
+ verbose="false"
+ author="false"
+ nodeprecated="true"
+ nodeprecatedlist="true"
+ use="true"
+ Doctitle="OpenOffice XMerge API"
+ windowtitle="OpenOffice XMerge API"
+ sourcepath="${prj}/java"
+ excludepackagenames="org.openoffice.xmerge.test"
+ classpathref="classpath">
+ <link offline="true" href="http://java.sun.com/j2se/1.3/docs/api" packagelistLoc="${solar.doc}/jdk13"/>
+ <bottom><![CDATA[<i>Copyright &#169 2002 OpenOffice.org</i>]]></bottom>
+ <header><![CDATA[<b>OpenOffice.org<br>XMerge API</b>]]></header>
+ </javadoc>
+ </target>
+
+ <!-- zip together all the javadocs -->
+ <target name="zipdoc" depends="javadoc" if="build.dir">
+ <zip zipfile="${build.dir}/doc/xmerge_javadoc.zip"
+ basedir="${build.dir}/doc/javadoc"
+ update="true"/>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.dir}/doc">
+ <patternset>
+ <include name="**"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/makefile.mk b/xmerge/java/makefile.mk
new file mode 100644
index 000000000000..b3e077feeba0
--- /dev/null
+++ b/xmerge/java/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_java
+PRJ=..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/Convert.java b/xmerge/java/org/openoffice/xmerge/Convert.java
new file mode 100644
index 000000000000..20161a3ff91a
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/Convert.java
@@ -0,0 +1,276 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+
+/**
+ * The <code>Convert</code> class manages a conversion from one
+ * mime-type to another. The <code>ConvertFactory</code> is
+ * responsible for returning the appropriate <code>Convert</code>
+ * class for a specified conversion. This class is responsible
+ * for all interactions with the <code>PluginFactory</code>
+ * implementation.
+ *
+ * @see ConverterFactory
+ * @see PluginFactory
+ * @see org.openoffice.xmerge.util.registry.ConverterInfo
+ *
+ * @author Martin Maher
+ */
+public class Convert implements Cloneable {
+
+ /**
+ * ConvertInfo that corresponds to the from-mime/to-mime
+ * conversion.
+ */
+ private ConverterInfo ci;
+
+ /**
+ * true if converting to the Office format, false if converting
+ * to the device format.
+ */
+ private boolean toOffice;
+
+ /**
+ * Holds the convert input data.
+ */
+ private ConvertData inputCD = new ConvertData();
+
+
+ /**
+ * Construct a Convert class with specified <code>ConvertInfo</code>
+ * registry information.
+ *
+ * @param ci A <code>ConvertInfo</code> object containing
+ * registry information corresponding to a
+ * specific plug-in.
+ * @param toOffice true if converting to the Office format,
+ * false if converting to the device format.
+ */
+ public Convert(ConverterInfo ci, boolean toOffice) {
+ this.ci = ci;
+ this.toOffice = toOffice;
+ }
+
+
+ /**
+ * Adds an <code>InputStream</code> to be used as input by the
+ * <code>Convert</code> class. It is possible that many files
+ * need to be converted into a single output <code>Documetn</code>,
+ * so this function may be called more than one time. It is the
+ * plug-in's responsibility to know how to handle the input.
+ *
+ * @param name The name corresponding to the <code>InputStream</code>.
+ * @param is <code>InputStream</code> to be used as input.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public void addInputStream(String name, InputStream is)
+ throws IOException {
+
+ Document inputDoc;
+
+ if (toOffice == true) {
+ inputDoc = ci.getPluginFactory().createDeviceDocument(name, is);
+ } else {
+ inputDoc = ci.getPluginFactory().createOfficeDocument(name, is);
+ }
+ inputCD.addDocument(inputDoc);
+ }
+
+
+ /**
+ * Adds the original Document to the Convert Class. This
+ * is to be used for merges. If this Document is added then
+ * it is assumed that a convert with merge is the desired
+ * operation.
+ *
+ * @param name The <code>Document</code> name.
+ * @param is <code>InputStream</code> object corresponding
+ * to the <code>Document</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public DocumentMerger getDocumentMerger(Document origDoc)
+ throws IOException {
+
+ DocumentMergerFactory myDocMergerFactory = ci.getDocMergerFactory();
+ DocumentMerger merger = myDocMergerFactory.createDocumentMerger(origDoc);
+ return merger;
+ }
+
+ /**
+ * Resets the input queue, so that the user can use this class to
+ * perform another conversion. This causes the
+ * <code>addInputStream</code> method to accept input for the next
+ * conversion.
+ */
+ public void reset() {
+ inputCD.reset();
+ }
+
+
+ /**
+ * Clones a Convert object so another Convert object can
+ * do the same conversion. <code>InputStream<code> objects passed
+ * in via calls to the <code>addInputStream</code> method are not
+ * copied.
+ *
+ * @return The cloned <code>Convert</code> object.
+ */
+ public Object clone() {
+
+ Convert aClone = null;
+
+ try {
+ aClone = (Convert) super.clone();
+ aClone.reset();
+ }
+ catch (CloneNotSupportedException e) {
+ System.out.println("Convert clone could not be created");
+ }
+ return aClone;
+ }
+
+
+ /**
+ * Convert the input specified in calls to the <code>addInputStream</code>
+ * method to the output format specified by this <code>Convert</code>
+ * class.
+ *
+ * @return The output data.
+ *
+ * @throws ConvertException If any conversion error occurs.
+ * @throws IOException If any I/O error occurs.
+ */
+ public ConvertData convert() throws ConvertException, IOException {
+
+ ConvertData dataOut = new ConvertData();
+
+ if (toOffice) {
+
+ // From device format to Office format
+ //
+ DocumentDeserializerFactory myDocDeserializerFactory =
+ ci.getDocDeserializerFactory();
+ DocumentDeserializer deser =
+ myDocDeserializerFactory.createDocumentDeserializer(inputCD);
+ Document deviceDoc = deser.deserialize();
+
+
+ dataOut.addDocument(deviceDoc);
+ return dataOut;
+
+ } else {
+
+ // From Office format to device format
+ //
+ DocumentSerializerFactory myDocSerializerFactory =
+ ci.getDocSerializerFactory();
+
+ Enumeration e = inputCD.getDocumentEnumeration();
+
+ Document doc = (Document) e.nextElement();
+ DocumentSerializer ser = myDocSerializerFactory.createDocumentSerializer(doc);
+ dataOut = ser.serialize();
+
+ return dataOut;
+ }
+ }
+
+ /**
+ * Returns the appropriate &quot;Office&quot; <code>Document</code>
+ * object for this plug-in.
+ *
+ * @param name The name of the <code>Document</code> to create.
+ * @param is The <code>InputStream</code> corresponding to the
+ * <code>Document</code> to create.
+ *
+ * @return The appropriate &quot;Office&quot; <code>Document</code>
+ * object for this plug-in.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public Document getOfficeDocument(String name, InputStream is)
+ throws IOException {
+ return(ci.getPluginFactory().createOfficeDocument(name, is));
+ }
+
+
+ /**
+ * Returns the appropriate &quot;Device&quot; <code>Document</code>
+ * object for this plug-in.
+ *
+ * @param name The name of the <code>Document</code> to create.
+ * @param is The <code>InputStream</code> corresponding to the
+ * <code>Document</code> to create.
+ *
+ * @return The appropriate &quot;Device&quot; <code>Document</code>
+ * object for this plug-in.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public Document getDeviceDocument(String name, InputStream is)
+ throws IOException {
+ return(ci.getPluginFactory().createDeviceDocument(name, is));
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/ConvertData.java b/xmerge/java/org/openoffice/xmerge/ConvertData.java
new file mode 100644
index 000000000000..721e0cdf661d
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/ConvertData.java
@@ -0,0 +1,145 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+import java.util.Vector;
+import java.util.Enumeration;
+
+/**
+ * <p><code>ConvertData</code> is used as a container for passing
+ * <code>Document</code> objects in and out of the <code>Convert</code>
+ * class. The <code>ConvertData</code> contains a <code>String</code>
+ * name and a <code>Vector</code> of <code>Document</code> objects.</p>
+ *
+ * @author Martin Maher
+ */
+public class ConvertData {
+
+ /**
+ * Vector of <code>Document</code> objects.
+ */
+ private Vector v = new Vector();
+
+ /**
+ * Name of the <code>ConvertData</code> object.
+ */
+ private String name;
+
+
+ /**
+ * Resets ConvertData. This empties all <code>Document</code>
+ * objects from this class. This allows reuse of a
+ * <code>ConvertData</code>.
+ */
+ public void reset() {
+ name = null;
+ v.removeAllElements();
+ }
+
+ /**
+ * Returns the <code>Document</code> name.
+ *
+ * @return The <code>Document</code> name.
+ */
+ public String getName() {
+ return name;
+ }
+
+
+ /**
+ * Sets the <code>Document</code> name.
+ *
+ * @param docName The name of the <code>Document</code>.
+ */
+ public void setName(String docName) {
+ name = docName;
+ }
+
+
+ /**
+ * Adds a <code>Document</code> to the vector.
+ *
+ * @param doc The <code>Document</code> to add.
+ */
+ public void addDocument(Document doc) {
+ v.add(doc);
+ }
+
+
+ /**
+ * Gets an <code>Enumeration</code> to access the <code>Vector</code>
+ * of <code>Document</code> objects.
+ *
+ * @return The <code>Enumeration</code> to access the
+ * <code>Vector</code> of <code>Document</code> objects.
+ */
+ public Enumeration getDocumentEnumeration() {
+ Enumeration enum = v.elements();
+ return (enum);
+ }
+
+
+ /**
+ * Gets the number of <code>Document</code> objects currently stored
+ *
+ * @return The number of <code>Document</code> objects currently
+ * stored.
+ */
+ public int getNumDocuments() {
+ return (v.size());
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/ConvertException.java b/xmerge/java/org/openoffice/xmerge/ConvertException.java
new file mode 100644
index 000000000000..7cca135fec7b
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/ConvertException.java
@@ -0,0 +1,73 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+/**
+ * This <code>Exception</code> is thrown by convert algorithms.
+ */
+public class ConvertException extends Exception {
+
+ /**
+ * Exception thrown by convert algorithms.
+ *
+ * @param message Message to be included in the
+ * <code>Exception</code>.
+ */
+ public ConvertException(String message) {
+ super(message);
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/ConverterCapabilities.java b/xmerge/java/org/openoffice/xmerge/ConverterCapabilities.java
new file mode 100644
index 000000000000..13bffc67395a
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/ConverterCapabilities.java
@@ -0,0 +1,95 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+/**
+ * <p>A <code>ConverterCapabilities</code> object is used by
+ * <code>DocumentMerger</code> implementations. The
+ * <code>ConverterCapabilities</code> indicates which
+ * &quot;Office&quot; XML tags are supported by the
+ * &quot;Device&quot; format.</p>
+ *
+ * @see org.openoffice.xmerge.PluginFactory
+ * @see org.openoffice.xmerge.DocumentMerger
+ */
+public interface ConverterCapabilities {
+
+
+ /**
+ * Test to see if the device document format supports the
+ * tag in question.
+ *
+ * @param tag The tag to check.
+ *
+ * @return true if the device format supports the
+ * tag, false otherwise.
+ */
+ boolean canConvertTag(String tag);
+
+
+ /**
+ * Test to see if the device document format supports the
+ * tag attribute in question.
+ *
+ * @param tag The tag to check.
+ * @param attribute The tag attribute to check.
+ *
+ * @return true if the device format supports the
+ * attribute, false otherwise.
+ */
+ boolean canConvertAttribute(String tag, String attribute);
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/ConverterFactory.java b/xmerge/java/org/openoffice/xmerge/ConverterFactory.java
new file mode 100644
index 000000000000..ca8683ab3e47
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/ConverterFactory.java
@@ -0,0 +1,152 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+import org.openoffice.xmerge.util.registry.ConverterInfoMgr;
+
+/**
+ * Factory that provides access to <code>Convert</code> objects, which
+ * are used to do a conversion. The <code>ConvertFactory</code> does
+ * this via the <code>ConvertInfoMgr</code> which maintains a list of
+ * which <code>Convert</code> objects are available and their
+ * capabilities.
+ *
+ * @see Convert
+ * @see org.openoffice.xmerge.util.registry.ConverterInfoMgr
+ *
+ * @author Martin Maher
+ */
+public class ConverterFactory {
+
+ /**
+ * Confirms whether or not a particular conversion can be done
+ * based on the Mime types of the files to be converted to and
+ * from.
+ *
+ * @param mimeTypeIn The mime input type.
+ * @param mimeTypeOut The mime output type.
+ *
+ * @return true if the conversion is possible, false otherwise.
+ */
+ public boolean canConvert(String mimeTypeIn, String mimeTypeOut) {
+
+ ConverterInfo foundInfo = null;
+
+ // findConverterInfo expects the second paramenter to be the
+ // destination MimeType
+ if (foundInfo.isValidOfficeType(mimeTypeOut))
+ foundInfo = ConverterInfoMgr.findConverterInfo(mimeTypeIn, mimeTypeOut);
+ else
+ foundInfo = ConverterInfoMgr.findConverterInfo(mimeTypeOut, mimeTypeIn);
+
+ if (foundInfo != null)
+ return true;
+ else
+ return false;
+ }
+
+
+ /**
+ * Returns the <code>Convert</code> object that converts
+ * the specified device/office mime type conversion. If there
+ * are multiple <code>Converter</code> objects registered
+ * that support this conversion, only the first is returned.
+ *
+ * @param mimeTypeIn The mime input type.
+ * @param mimeTypeOut The mime output type.
+ *
+ * @return The first <code>Convert</code> object that supports
+ * the specified conversion.
+ */
+ public Convert getConverter(String mimeTypeIn, String mimeTypeOut) {
+
+ ConverterInfo foundInfo = null;
+ boolean toOffice;
+
+ toOffice = foundInfo.isValidOfficeType(mimeTypeOut);
+
+ // findConverterInfo expects the second paramenter to be the
+ // destination MimeType
+ if (toOffice)
+ foundInfo = ConverterInfoMgr.findConverterInfo(mimeTypeIn, mimeTypeOut);
+ else
+ foundInfo = ConverterInfoMgr.findConverterInfo(mimeTypeOut, mimeTypeIn);
+
+ if (foundInfo != null)
+ return getConverter(foundInfo, toOffice);
+ else
+ return null;
+ }
+
+
+ /**
+ * Returns the <code>Convert</code> object that is described
+ * by the <code>ConverterInfo</code> parameter.
+ *
+ * @param ci The <code>ConverterInfo</code> describing the converter.
+ *
+ * @param toOffice true to convert to office, false to convert to device.
+ *
+ * @return The <code>Convert</code> object
+ */
+ public Convert getConverter(ConverterInfo ci, boolean toOffice) {
+
+ Convert myConvert = new Convert(ci, toOffice);
+ return myConvert;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/Document.java b/xmerge/java/org/openoffice/xmerge/Document.java
new file mode 100644
index 000000000000..9cfc0b878e63
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/Document.java
@@ -0,0 +1,127 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * <p>A <code>Document</code> represents any <code>Document</code>
+ * to be converted and the resulting <code>Document</code> from any
+ * conversion.</p>
+ *
+ * <p>It is created by the <code>PluginFactory</code> object's {@link
+ * org.openoffice.xmerge.PluginFactory#createOfficeDocument
+ * createOfficeDocument} method or the {@link
+ * org.openoffice.xmerge.PluginFactory#createDeviceDocument
+ * createDeviceDocument} method.</p>
+ *
+ * @author Herbie Ong
+ * @see org.openoffice.xmerge.PluginFactory
+ */
+public interface Document {
+
+ /**
+ * <p>Writes out the <code>Document</code> content to the specified
+ * <code>OutputStream</code>.</p>
+ *
+ * <p>This method may not be thread-safe.
+ * Implementations may or may not synchronize this
+ * method. User code (i.e. caller) must make sure that
+ * calls to this method are thread-safe.</p>
+ *
+ * @param os <code>OutputStream</code> to write out the
+ * <code>Document</code> content.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public void write(OutputStream os) throws IOException;
+
+
+ /**
+ * <p>Reads the content from the <code>InputStream</code> into
+ * the <code>Document</code>.</p>
+ *
+ * <p>This method may not be thread-safe.
+ * Implementations may or may not synchronize this
+ * method. User code (i.e. caller) must make sure that
+ * calls to this method are thread-safe.</p>
+ *
+ * @param is <code>InputStream</code> to read in the
+ * <code>Document</code> content.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public void read(InputStream is) throws IOException;
+
+
+ /**
+ * Returns the <code>Document</code> name with no file extension.
+ *
+ * @return The <code>Document</code> name with no file extension.
+ */
+ public String getName();
+
+
+ /**
+ * Returns the <code>Document</code> name with file extension.
+ *
+ * @return The <code>Document</code> name with file extension.
+ */
+ public String getFileName();
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/DocumentDeserializer.java b/xmerge/java/org/openoffice/xmerge/DocumentDeserializer.java
new file mode 100644
index 000000000000..ae0c896b2415
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/DocumentDeserializer.java
@@ -0,0 +1,93 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+import java.io.IOException;
+
+/**
+ * <p>A <code>DocumentDeserializer</code> represents a converter that
+ * converts &quot;Device&quot; <code>Document</code> objects into the
+ * &quot;Office&quot; <code>Document</code> format.</p>
+ *
+ * <p>The <code>DocumentDeserializer</code> object is created by
+ * the </code>PluginFactory</code> {@link
+ * org.openoffice.xmerge.DocumentDeserializerFactory#createDocumentDeserializer
+ * createDocumentDeserializer} method. When it is constructed, a
+ * <code>ConvertData</code> object is passed in to be used as input.</p>
+ *
+ * @author Herbie Ong
+ * @see org.openoffice.xmerge.PluginFactory
+ * @see org.openoffice.xmerge.DocumentDeserializerFactory
+ */
+public interface DocumentDeserializer {
+
+ /**
+ * <p>Convert the data passed into the <code>DocumentDeserializer</code>
+ * constructor into the &quot;Office&quot; <code>Document</code>
+ * format.</p>
+ *
+ * <p>This method may or may not be thread-safe. It is expected
+ * that the user code does not call this method in more than one
+ * thread. And for most cases, this method is only done once.</p>
+ *
+ * @return The resulting <code>Document</code> object from conversion.
+ *
+ * @throws ConvertException If any Convert error occurs.
+ * @throws IOException If any I/O error occurs.
+ */
+ public Document deserialize() throws ConvertException, IOException;
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/DocumentDeserializerFactory.java b/xmerge/java/org/openoffice/xmerge/DocumentDeserializerFactory.java
new file mode 100644
index 000000000000..0e3974c65c46
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/DocumentDeserializerFactory.java
@@ -0,0 +1,93 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+/**
+ * <p>A <code>DocumentDeserializer</code> object is used to convert
+ * from the &quot;Device&quot; <code>Documetn</code> format to the
+ * &quot;Office&quot; <code>Document</code> format.</p>
+ *
+ * <p>All plug-in implementations of the <code>PluginFactory</code>
+ * interface that also support deserialization must also
+ * implement this interface.</p>
+ *
+ * @see PluginFactory
+ * @see DocumentDeserializer
+ */
+public interface DocumentDeserializerFactory {
+
+ /**
+ * The <code>DocumentDeserializer</code> is used to convert
+ * from the &quot;Device&quot; <code>Document</code> format to
+ * the &quot;Office&quot; <code>Document</code> format.</p>
+ *
+ * The <code>ConvertData</code> object is passed along to the
+ * created <code>DocumentDeserializer</code> via its constructor.
+ * The <code>ConvertData</code> is read and converted when the
+ * the <code>DocumentDeserializer</code> object's
+ * <code>deserialize</code> method is called.
+ * </p>
+ *
+ * @param cd <code>ConvertData</code> object that the created
+ * <code>DocumentDeserializer</code> object uses as
+ * input.
+ *
+ * @return A <code>DocumentDeserializer</code> object.
+ */
+
+ public DocumentDeserializer createDocumentDeserializer(ConvertData cd);
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/DocumentMerger.java b/xmerge/java/org/openoffice/xmerge/DocumentMerger.java
new file mode 100644
index 000000000000..6f5a86b73582
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/DocumentMerger.java
@@ -0,0 +1,121 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+/**
+ * <p>A <code>DocumentMerger</code> can merge changes from a modified
+ * &quot;Device&quot; <code>Document</code> to the assigned original
+ * &quot;Office&quot; <code>Document</code>.</p>
+ *
+ * <p>Merge is useful when an <code>OfficeDocument</code>
+ * is converted to a &quot;Device&quot; <code>Document</code> format,
+ * and the &quot;Device&quot; <code>Document</code> version is modified.
+ * Those changes can be merged back into the original
+ * <code>OfficeDocument</code> with the merger. The merger is capable
+ * of doing this even if the &quot;Device&quot; format is lossy in
+ * comparison to the <code>OfficeDocument</code> format.</p>
+ *
+ * <p>The <code>ConverterCapabilities</code> object is what the
+ * DocumentMerger utilizes to know how the &quot;Office&quot;
+ * <code>Document</code> tags are supported in the &quot;Device&quot;
+ * format.</p>
+ *
+ * <p>The <code>DocumentMerger</code> object is created by a
+ * the <code>DocumentMergerFactory</code> {@link
+ * org.openoffice.xmerge.DocumentMergerFactory#createDocumentMerger
+ * createDocumenMerger} method. When it is constructed, the
+ * &quot;Original Office&quot; <code>Document</code> object is
+ * passed in to be used as input.</p>
+ *
+ * @author Herbie Ong
+ * @see org.openoffice.xmerge.PluginFactory
+ * @see org.openoffice.xmerge.DocumentMergerFactory
+ * @see org.openoffice.xmerge.ConverterCapabilities
+ */
+public interface DocumentMerger {
+
+ /**
+ * <p>This method will find the changes that had happened
+ * in the <code>modifiedDoc</code> <code>Document</code>
+ * object given the designated original <code>Document</code>.</p>
+ *
+ * <p>Note that this process may need the knowledge of the
+ * conversion process since some conversion process are lossy.
+ * Items/Data that are lost during the conversion process are not
+ * classified as changes. The main target of this method
+ * is to apply the changes done in <code>modifiedDoc</code>
+ * into the assigned original <code>Document</code> object, thus
+ * it also will try to preserve items that were originally in
+ * the original <code>Document</code>, but never got transferred
+ * during the
+ * {@link org.openoffice.xmerge.DocumentSerializer#serialize
+ * serialize} process/method call. After this method call, the
+ * original <code>Document</code> object will contain the changes
+ * applied.</p>
+ *
+ * <p>This method may or may not be thread-safe.
+ * Also, it is expected that the user uses only one instance
+ * of a <code>DocumentMerger</code> object per merge process.
+ * Create another <code>DocumentMerger</code> object for another
+ * merge process.</p>
+ *
+ * @param modifiedDoc device <code>Document</code> object.
+ *
+ * @throws MergeException If any merge error occurs.
+ */
+ public void merge(Document modifiedDoc) throws MergeException;
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/DocumentMergerFactory.java b/xmerge/java/org/openoffice/xmerge/DocumentMergerFactory.java
new file mode 100644
index 000000000000..fc7ce5b58a78
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/DocumentMergerFactory.java
@@ -0,0 +1,91 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+/**
+ * <p>All plug-in implementations of the <code>PluginFactory</code>
+ * interface that also support merging must also implement
+ * this interface.</p>
+ *
+ * <p>Merge is useful when an <code>OfficeDocument</code>
+ * is converted to a &quot;Device&quot; <code>Document</code> format,
+ * and the &quot;Device&quot; <code>Document</code> version is modified.
+ * Those changes can be merged back into the original
+ * <code>OfficeDocument</code> with the merger. The merger is capable
+ * of doing this even if the &quot;Device&quot; format is lossy in
+ * comparison to the <code>OfficeDocument</code> format.</p>
+ *
+ * @see PluginFactory
+ * @see DocumentMerger
+ * @see ConverterCapabilities
+ *
+ */
+public interface DocumentMergerFactory {
+
+ /**
+ * <p>Create a <code>DocumentMerger</code> object given a
+ * <code>Document</code> object.</p>
+ *
+ * @param doc <code>Document</code> object that the created
+ * <code>DocumentMerger</code> object uses as a base
+ * <code>Document</code> for merging changes into.
+ *
+ * @return A <code>DocumentMerger</code> object or null if none
+ * exists.
+ */
+ public DocumentMerger createDocumentMerger(Document doc);
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/DocumentSerializer.java b/xmerge/java/org/openoffice/xmerge/DocumentSerializer.java
new file mode 100644
index 000000000000..9617658ed3f5
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/DocumentSerializer.java
@@ -0,0 +1,95 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+import java.io.IOException;
+
+/**
+ * <p>A <code>DocumentSerializer</code> represents a converter that
+ * converts a &quot;Office&quot; <code>Document</code> to a
+ * &quot;Device&quot; <code>Document</code> format.</p>
+ *
+ * <p>The <code>DocumentSerializer</code> object is created by a
+ * the <code>PluginFactory</code> {@link
+ * org.openoffice.xmerge.DocumentSerializerFactory#createDocumentSerializer
+ * createDocumentSerializer} method. When it is constructed, a
+ * &quot;Office&quot; <code>Document</code> object is passed in to
+ * be used as input.</p>
+ *
+ * @author Herbie Ong
+ * @see org.openoffice.xmerge.PluginFactory
+ * @see org.openoffice.xmerge.DocumentSerializerFactory
+ */
+public interface DocumentSerializer {
+
+ /**
+ * <p>Convert the data passed into the <code>DocumentSerializer</code>
+ * constructor into the &quot;Device&quot; <code>Document</code>
+ * format.</p>
+ *
+ * <p>This method may or may not be thread-safe. It is expected
+ * that the user code does not call this method in more than one
+ * thread. And for most cases, this method is only done once.</p>
+ *
+ * @return <code>ConvertData</code> object to pass back the
+ * converted data.
+ *
+ * @throws ConvertException If any conversion error occurs.
+ * @throws IOException If any I/O error occurs.
+ */
+ public ConvertData serialize() throws ConvertException, IOException;
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/DocumentSerializerFactory.java b/xmerge/java/org/openoffice/xmerge/DocumentSerializerFactory.java
new file mode 100644
index 000000000000..a7881c56683e
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/DocumentSerializerFactory.java
@@ -0,0 +1,91 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+/**
+ * <p>A <code>DocumentSerializer</code> object is used to convert
+ * from the &quot;Office&quot; <code>Document</code> format to the
+ * &quot;Device&quot; <code>Document</code> format.</p>
+ *
+ * <p>All plug-in implementations of the <code>PluginFactory</code>
+ * interface that also support serialization must also
+ * implement this interface.</p>
+ *
+ * @see PluginFactory
+ * @see DocumentSerializer
+ */
+public interface DocumentSerializerFactory {
+
+ /**
+ * <p>The <code>DocumentSerializer</code> is used to convert
+ * from the &quot;Office&quot; <code>Document</code> format
+ * to the &quot;Device&quot; <code>Document</code> format.</p>
+ *
+ * The <code>ConvertData</code> object is passed along to the
+ * created <code>DocumentSerializer</code> via its constructor.
+ * The <code>ConvertData</code> is read and converted when the
+ * the <code>DocumentSerializer</code> object's
+ * <code>serialize</code> method is called.
+ *
+ * @param doc <code>Document</code> object that the created
+ * <code>DocumentSerializer</code> object uses
+ * as input.
+ *
+ * @return A <code>DocumentSerializer</code> object.
+ */
+ public DocumentSerializer createDocumentSerializer(Document doc);
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/MergeException.java b/xmerge/java/org/openoffice/xmerge/MergeException.java
new file mode 100644
index 000000000000..85b940a2aa57
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/MergeException.java
@@ -0,0 +1,73 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+/**
+ * This <code>Exception</code> is thrown by merge algorithms.
+ */
+public class MergeException extends Exception {
+
+ /**
+ * Exception thrown by merge algorithms.
+ *
+ * @param message Message to be included in the
+ * <code>Exception</code>.
+ */
+ public MergeException(String message) {
+ super(message);
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/PluginFactory.java b/xmerge/java/org/openoffice/xmerge/PluginFactory.java
new file mode 100644
index 000000000000..5a012617118b
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/PluginFactory.java
@@ -0,0 +1,192 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * <p>A <code>PluginFactory</code> encapsulates the
+ * conversions from one <code>Document</code> format to another.
+ * It provides conversions in both directions. Refer to the
+ * <a href="package-summary.html#package_description">
+ * package description</a> for its usage.</p>
+ *
+ * <p>Conversion from the &quot;Office&quot; <code>Document</code>
+ * format to a &quot;Device&quot; <code>Document</code> format may
+ * be lossy, i.e. some information may be lost. If a plug-in
+ * implements the <code>DocumentMergerFactory</code> interface,
+ * then there is the possibility for merging the changes done on the
+ * &quot;Device&quot; <code>Document</code> back to the original
+ * &quot;Office&quot; <code>Document</code> via the
+ * <code>DocumentMerger</code> interface.</p>
+ *
+ * <p>Plug-ins that convert from the &quot;Device&quot;
+ * <code>Document</code> format to the &quot;Office&quot;
+ * <code>Document</code> format must implement the
+ * <code>DocumentDeserializerFactory</code> interface. Plug-ins
+ * that convert from the &quot;Office&quot; <code>Document</code>
+ * format to the &quot;Device&quot; format must implement the
+ * <code>DocumentSerializerFactory</code> interface.
+ *
+ * <p>All plug-ins should have an associated Plugin Configuration XML
+ * File which describes the capabilities of the plug-in. If the
+ * plug-in is bundled in a jarfile, then this XML file is also bundled
+ * with the jarfile. The data in the XML file is managed by the
+ * <code>ConverterInfo</code> object. The <code>ConverterInfoMgr</code>
+ * manages a registry of all <code>ConverterInfo</code> objects. For
+ * more information about this XML file, refer to
+ * <a href="converter/xml/sxc/package-summary.html">
+ * org.openoffice.xmerge.util.registry</a>.</p>
+ *
+ * @author Herbie Ong
+ * @see Document
+ * @see DocumentSerializer
+ * @see DocumentSerializerFactory
+ * @see DocumentDeserializer
+ * @see DocumentDeserializerFactory
+ * @see DocumentMerger
+ * @see DocumentMergerFactory
+ * @see ConverterInfo
+ * @see org.openoffice.xmerge.util.registry.ConverterInfoMgr
+ */
+
+public abstract class PluginFactory {
+
+ /**
+ * Cached <code>ConvertInfo</code> object.
+ */
+ private ConverterInfo ciCache;
+
+
+ /**
+ * Constructor that caches the <code>ConvertInfo</code> that
+ * corresponds to the registry information for this plug-in.
+ *
+ * @param ci <code>ConvertInfo</code> object.
+ */
+ public PluginFactory(ConverterInfo ci) {
+ ciCache=ci;
+ }
+
+
+ /**
+ * Returns the <code>ConvertInfo</code> that corresponds to this
+ * plug-in.
+ *
+ * @return The <code>ConvertInfo</code> that corresponds to this
+ * plug-in.
+ */
+ public ConverterInfo getConverterInfo () {
+ return ciCache;
+ }
+
+
+ /**
+ * <p>Create a <code>Document</code> object that corresponds to
+ * the Office data passed in via the <code>InputStream</code>
+ * object. This abstract method must be implemented for each
+ * plug-in.</p>
+ *
+ * <p>This method will read from the given <code>InputStream</code>
+ * object. The returned <code>Document</code> object will contain
+ * the necessary data for the other objects created by the
+ * <code>PluginFactory</code> to process, like a
+ * <code>DocumentSerializer</code> object and a
+ * <code>DocumentMerger</code> object.</p>
+ *
+ * @param name The <code>Document</code> name.
+ * @param is <code>InputStream</code> object corresponding
+ * to the <code>Document</code>.
+ *
+ * @return A <code>Document</code> object representing the
+ * particular <code>Document</code> format for the
+ * <code>PluginFactory</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public abstract Document createOfficeDocument(String name, InputStream is)
+ throws IOException;
+
+
+ /**
+ * <p>Create a <code>Document</code> object that corresponds to
+ * the device data passed in via the <code>InputStream</code>
+ * object. This abstract method must be implemented for each
+ * plug-in.</p>
+ *
+ * <p>This method will read from the given <code>InputStream</code>
+ * object. The returned <code>Document</code> object will contain
+ * the necessary data for the other objects created by the
+ * <code>PluginFactory</code> to process, like a
+ * <code>DocumentSerializer</code> object and a
+ * <code>DocumentMerger</code> object.</p>
+ *
+ * @param name The <code>Document</code> name.
+ * @param is <code>InputStream</code> object corresponding
+ * to the <code>Document</code>.
+ *
+ * @return A <code>Document</code> object representing the
+ * particular <code>Document</code> format for the
+ * <code>PluginFactory</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public abstract Document createDeviceDocument(String name, InputStream is)
+ throws IOException;
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/Version.java b/xmerge/java/org/openoffice/xmerge/Version.java
new file mode 100644
index 000000000000..e0ead1dd7df5
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/Version.java
@@ -0,0 +1,116 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge;
+
+/**
+ * This class provides a quick utility to check the version of the
+ * jar file. It has a main method that prints out the version
+ * info. It also provides two static methods for runtime classes
+ * to query.
+ *
+ * @author Herbie Ong
+ */
+public final class Version {
+
+ private static Package pkg;
+
+ private static Version version;
+
+ static {
+
+ version = new Version();
+ pkg = version.getClass().getPackage();
+ }
+
+ /**
+ * Private constructor to provide a singleton instance.
+ */
+ private Version() {
+ }
+
+ /**
+ * Returns specification version.
+ *
+ * @return The specification version.
+ */
+ public static String getSpecificationVersion() {
+ return pkg.getSpecificationVersion();
+ }
+
+ /**
+ * Returns implementation version.
+ *
+ * @return The implementation version.
+ */
+
+ public static String getImplementationVersion() {
+ return pkg.getImplementationVersion();
+ }
+
+ /**
+ * Main method for printing out version info.
+ *
+ * @param args Array of arguments, not used.
+ */
+ public static void main(String args[]) {
+
+ System.out.println("Specification-Title: " + pkg.getSpecificationTitle());
+ System.out.println("Specification-Vendor: " + pkg.getSpecificationVendor());
+ System.out.println("Specification-Version: " + pkg.getSpecificationVersion());
+ System.out.println("Implementation-Version: " + pkg.getImplementationVersion());
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/build.xml b/xmerge/java/org/openoffice/xmerge/build.xml
new file mode 100644
index 000000000000..c955fd905f9e
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/build.xml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_joo_xmerge" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_joo_xmerge"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package" value="org/openoffice/xmerge"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set whether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/Convert.java"/>
+ <include name="${package}/ConverterCapabilities.java"/>
+ <include name="${package}/ConverterFactory.java"/>
+ <include name="${package}/ConvertData.java"/>
+ <include name="${package}/PluginFactory.java"/>
+ <include name="${package}/Document.java"/>
+ <include name="${package}/DocumentDeserializer.java"/>
+ <include name="${package}/DocumentDeserializerFactory.java"/>
+ <include name="${package}/DocumentMerger.java"/>
+ <include name="${package}/DocumentMergerFactory.java"/>
+ <include name="${package}/DocumentSerializer.java"/>
+ <include name="${package}/DocumentSerializerFactory.java"/>
+ <include name="${package}/Version.java"/>
+ <include name="${package}/ConvertException.java"/>
+ <include name="${package}/MergeException.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/dom/DOMDocument.java b/xmerge/java/org/openoffice/xmerge/converter/dom/DOMDocument.java
new file mode 100644
index 000000000000..a56ba482cb40
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/dom/DOMDocument.java
@@ -0,0 +1,397 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.dom;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import org.openoffice.xmerge.util.Resources;
+import org.openoffice.xmerge.util.Debug;
+
+/**
+ * An implementation of <code>Document</code> for
+ * StarOffice documents.
+ */
+public class DOMDocument
+ implements org.openoffice.xmerge.Document {
+
+ /** Factory for <code>DocumentBuilder</code> objects. */
+ private static DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+
+ /** DOM <code>Document</code> of content.xml. */
+ private Document contentDoc = null;
+
+ /** DOM <code>Document</code> of content.xml. */
+ private Document styleDoc = null;
+
+ private String documentName = null;
+ private String fileName = null;
+ private String fileExt = null;
+
+ /** Resources object. */
+ private Resources res = null;
+
+
+ /**
+ * Default constructor.
+ *
+ * @param name <code>Document</code> name.
+ * @param ext <code>Document</code> extension.
+ */
+ public DOMDocument(String name,String ext)
+ {
+ this(name,ext,true, false);
+ }
+
+ /**
+ * Returns the file extension of the <code>Document</code>
+ * represented.
+ *
+ * @return file extension of the <code>Document</code>.
+ */
+ protected String getFileExtension() {
+ return fileExt;
+ }
+
+
+ /**
+ * Constructor with arguments to set <code>namespaceAware</code>
+ * and <code>validating</code> flags.
+ *
+ * @param name <code>Document</code> name (may or may not
+ * contain extension).
+ * @param ext <code>Document</code> extension.
+ * @param namespaceAware Value for <code>namespaceAware</code> flag.
+ * @param validating Value for <code>validating</code> flag.
+ */
+ public DOMDocument(String name, String ext,boolean namespaceAware, boolean validating) {
+
+ res = Resources.getInstance();
+ factory.setValidating(validating);
+ factory.setNamespaceAware(namespaceAware);
+ this.fileExt = ext;
+ this.documentName = trimDocumentName(name);
+ this.fileName = documentName + getFileExtension();
+ }
+
+
+ /**
+ * Removes the file extension from the <code>Document</code>
+ * name.
+ *
+ * @param name Full <code>Document</code> name with extension.
+ *
+ * @return Name of <code>Document</code> without the extension.
+ */
+ private String trimDocumentName(String name) {
+ String temp = name.toLowerCase();
+ String ext = getFileExtension();
+
+ if (temp.endsWith(ext)) {
+ // strip the extension
+ int nlen = name.length();
+ int endIndex = nlen - ext.length();
+ name = name.substring(0,endIndex);
+ }
+
+ return name;
+ }
+
+
+ /**
+ * Return a DOM <code>Document</code> object of the document content
+ * file. Note that a content DOM is not created when the constructor
+ * is called. So, either the <code>read</code> method or the
+ * <code>initContentDOM</code> method will need to be called ahead
+ * on this object before calling this method.
+ *
+ * @return DOM <code>Document</code> object.
+ */
+ public Document getContentDOM() {
+
+ return contentDoc;
+ }
+
+ /**
+ * Sets the Content of the <code>Document</code> to the contents of the
+ * supplied <code>Node</code> list.
+ *
+ * @return DOM <code>Document</code> object.
+ */
+ public void setContentDOM( Node newDom) {
+ contentDoc=(Document)newDom;
+ }
+
+
+ /**
+ * Return the name of the <code>Document</code>.
+ *
+ * @return The name of <code>Document</code>.
+ */
+ public String getName() {
+
+ return documentName;
+ }
+
+
+ /**
+ * Return the file name of the <code>Document</code>, possibly
+ * with the standard extension.
+ *
+ * @return The file name of <code>Document</code>.
+ */
+ public String getFileName() {
+
+ return fileName;
+ }
+
+
+ /**
+ * Read the Office <code>Document</code> from the specified
+ * <code>InputStream</code>.
+ *
+ * @param is Office document <code>InputStream</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public void read(InputStream is) throws IOException {
+ Debug.log(Debug.INFO, "reading file");
+ DocumentBuilder builder = null;
+ try {
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException ex) {
+ System.out.println("Error:"+ ex);
+ //throw new OfficeDocumentException(ex);
+ }
+ try {
+
+ contentDoc= builder.parse(is);
+
+
+ } catch (SAXException ex) {
+ System.out.println("Error:"+ ex);
+ //throw new OfficeDocumentException(ex);
+ }
+ }
+
+
+ /**
+ * Write out content to the supplied <code>OutputStream</code>.
+ *
+ * @param os XML <code>OutputStream</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public void write(OutputStream os) throws IOException {
+
+ // set bytes for writing to output stream
+ byte contentBytes[] = docToBytes(contentDoc);
+
+ os.write(contentBytes);
+ }
+
+
+ /**
+ * <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 Document DOM <code>Document</code> object.
+ *
+ * @return <code>byte</code> array of DOM <code>Document</code>
+ * object.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ 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();
+
+ /*
+ * 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.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 {
+ // 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());
+ }
+ 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());
+ }
+
+ byte bytes[] = baos.toByteArray();
+
+ return bytes;
+ }
+
+
+ /**
+ * Initializes a new DOM <code>Document</code> with the content
+ * containing minimum XML tags.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public final void initContentDOM() throws IOException {
+ contentDoc = createDOM("");
+
+ }
+
+ /**
+ * <p>Creates a new DOM <code>Document</code> containing minimum
+ * OpenOffice XML tags.</p>
+ *
+ * <p>This method uses the subclass
+ * <code>getOfficeClassAttribute</code> method to get the
+ * attribute for <i>office:class</i>.</p>
+ *
+ * @param rootName root name of <code>Document</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ private final Document createDOM(String rootName) throws IOException {
+
+ Document doc = null;
+
+ try {
+
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ doc = builder.newDocument();
+
+ } catch (ParserConfigurationException ex) {
+ System.out.println("Error:"+ ex);
+
+
+ }
+
+ Element root = (Element) doc.createElement(rootName);
+ doc.appendChild(root);
+
+
+ return doc;
+ }
+
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/dom/build.xml b/xmerge/java/org/openoffice/xmerge/converter/dom/build.xml
new file mode 100644
index 000000000000..d110ac8c5eb5
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/dom/build.xml
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_jooxc_dom" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_jooxc_dom"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package"
+ value="org/openoffice/xmerge/converter/dom"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set whether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/DOMDocument.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/dom/makefile.mk b/xmerge/java/org/openoffice/xmerge/converter/dom/makefile.mk
new file mode 100644
index 000000000000..a95e1a8989fb
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/dom/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_jooxc_dom
+PRJ=../../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/converter/dom/package.html b/xmerge/java/org/openoffice/xmerge/converter/dom/package.html
new file mode 100644
index 000000000000..9cb9e629d514
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/dom/package.html
@@ -0,0 +1,80 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+ <!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+
+ <title>org.openoffice.xmerge.converter.palm package</title>
+
+</head>
+ <body bgcolor="white">
+<p>Provides classes for converting basic document types to/from a <code>
+DOMDocument</code> object, which can be used by the framework. </p>
+<p>This package provides classes that handle the writing of data to an <code>
+ OutputStream</code> object for the {@link org.openoffice.xmerge.DocumentSerializer
+DocumentSerializer} interface for; as well as the reading of data from an
+<code>InputStream</code> object for the framework's {@link org.openoffice.xmerge.DocumentDeserializer
+DocumentDeserializer} interface. Both these framework interfaces are simply
+converters from server-side documents to device specific documents and vice-versa.
+ </p>
+<a name="streamformat">
+<h2></h2>
+</a>
+<p></p>
+<h2>Important Note</h2>
+<p>Methods in these classes are not thread safe for performance reasons.
+Users of these classes will have to make sure that the usage of these classes
+are done in a proper manner. Possibly more on this later.</p>
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeConstants.java b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeConstants.java
new file mode 100644
index 000000000000..828f3bc184c3
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeConstants.java
@@ -0,0 +1,289 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml;
+
+/**
+ * This interface contains constants for StarOffice XML tags,
+ * attributes (StarCalc cell types, etc.).
+ *
+ * @author Herbie Ong, Paul Rank
+ */
+public interface OfficeConstants {
+
+ /** Element tag for <i>office:document</i>, this is the root tag. */
+ public final static String TAG_OFFICE_DOCUMENT = "office:document";
+
+ /**
+ * Element tag for <i>office:document-content</i>, this is the root
+ * tag in content.xml.
+ */
+ public final static String TAG_OFFICE_DOCUMENT_CONTENT = "office:document-content";
+
+ /**
+ * Element tag for <i>office:document-styles</i>, this is the root tag
+ * in styles.xml.
+ */
+ public final static String TAG_OFFICE_DOCUMENT_STYLES = "office:document-styles";
+
+ /**
+ * Attribute tag for <i>office:class</i> of element
+ * <i>office:document</i>.
+ */
+ public final static String ATTRIBUTE_OFFICE_CLASS = "office:class";
+
+ /** Element tag for <i>office:styles</i>. */
+ public final static String TAG_OFFICE_STYLES = "office:styles";
+
+ /** Element tag for <i>office:automatic-styles</i>. */
+ public final static String TAG_OFFICE_AUTOMATIC_STYLES = "office:automatic-styles";
+
+ /** Element tag for <i>office:master-styles</i>. */
+ public final static String TAG_OFFICE_MASTER_STYLES = "office:master-styles";
+
+ /** Element tag for <i>office:body</i>. */
+ public final static String TAG_OFFICE_BODY = "office:body";
+
+ /** Element tag for <i>office:font-decls</i>. */
+ public final static String TAG_OFFICE_FONT_DECLS = "office:font-decls";
+
+ /** Element tag for <i>style:font-decl</i>. */
+ public final static String TAG_STYLE_FONT_DECL = "style:font-decl";
+
+ /** Attribute tag for <i>style:name</i> of element <i>style:name</i>. */
+ public final static String ATTRIBUTE_STYLE_NAME = "style:name";
+
+ /**
+ * Attribute tag for <i>style:font-pitch</i> of element
+ * <i>style:font-pitch</i>.
+ */
+ public final static String ATTRIBUTE_STYLE_FONT_PITCH = "style:font-pitch";
+
+ /**
+ * Attribute tag for <i>fo:font-family</i> of element
+ * <i>fo:font-family</i>.
+ */
+ public final static String ATTRIBUTE_FO_FONT_FAMILY = "fo:font-family";
+
+ /** Element tag for <i>text:p</i>. */
+ public final static String TAG_PARAGRAPH = "text:p";
+
+ /** Element tag for <i>text:h</i>. */
+ public final static String TAG_HEADING = "text:h";
+
+ /** Element tag for <i>text:s</i>. */
+ public final static String TAG_SPACE = "text:s";
+
+ /** Element tag for <i>text:tab-stop</i>. */
+ public final static String TAG_TAB_STOP = "text:tab-stop";
+
+ /** Element tag for <i>text:line-break</i>. */
+ public final static String TAG_LINE_BREAK = "text:line-break";
+
+ /** Element tag for <i>text:span</i>. */
+ public final static String TAG_SPAN = "text:span";
+
+ /** Element tag for <i>text:a</i>. */
+ public final static String TAG_HYPERLINK = "text:a";
+
+ /** Element tag for <i>text:bookmark</i>. */
+ public final static String TAG_BOOKMARK = "text:bookmark";
+
+ /** Element tag for <i>text:bookmark-start</i>. */
+ public final static String TAG_BOOKMARK_START = "text:bookmark-start";
+
+ /** Element tag for <i>text:unordered-list</i>. */
+ public final static String TAG_UNORDERED_LIST = "text:unordered-list";
+
+ /** Element tag for <i>text:ordered-list</i>. */
+ public final static String TAG_ORDERED_LIST = "text:ordered-list";
+
+ /** Element tag for <i>text:list-header</i>. */
+ public final static String TAG_LIST_HEADER = "text:list-header";
+
+ /** Element tag for <i>text:list-item</i>. */
+ public final static String TAG_LIST_ITEM = "text:list-item";
+
+ /** Attribute tag for <i>text:c</i> of element <i>text:s</i>. */
+ public final static String ATTRIBUTE_SPACE_COUNT = "text:c";
+
+ /**
+ * Attribute tag for <i>text:style-name</i> of element
+ * <i>text:style-name</i>.
+ */
+ public final static String ATTRIBUTE_TEXT_STYLE_NAME = "text:style-name";
+
+ /** Element tag for <i>table:table</i>. */
+ public final static String TAG_TABLE = "table:table";
+
+ /**
+ * Attribute tag for <i>table:name</i> of element
+ * <i>table:table</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_NAME = "table:name";
+
+ /** Element tag for <i>table:table-row</i>. */
+ public final static String TAG_TABLE_ROW = "table:table-row";
+
+ /** Element tag for <i>table:table-column</i>. */
+ public final static String TAG_TABLE_COLUMN = "table:table-column";
+
+ /** Element tag for <i>table:scenario</i>. */
+ public final static String TAG_TABLE_SCENARIO = "table:scenario";
+
+ /** Element tag for <i>table:table-cell</i>. */
+ public final static String TAG_TABLE_CELL = "table:table-cell";
+
+ /**
+ * Attribute tag for <i>table:value-type</i> of element
+ * <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_VALUE_TYPE = "table:value-type";
+
+ /**
+ * Attribute tag for <i>table:number-columns-repeated</i>
+ * of element <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED =
+ "table:number-columns-repeated";
+
+ /**
+ * Attribute tag for <i>table:number-rows-repeated</i>
+ * of element <i>table:table-row</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_NUM_ROWS_REPEATED =
+ "table:number-rows-repeated";
+
+ /**
+ * Attribute tag for <i>table:formula</i> of element
+ * <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_FORMULA = "table:formula";
+
+ /**
+ * Attribute tag for <i>table:value</i> of element
+ * <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_VALUE = "table:value";
+
+ /**
+ * Attribute tag for <i>table:date-value</i> of element
+ * <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_DATE_VALUE = "table:date-value";
+
+ /**
+ * Attribute tag for <i>table:time-value</i> of element
+ * <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_TIME_VALUE = "table:time-value";
+
+ /**
+ * Attribute tag for <i>table:string-value</i> of element
+ * <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_STRING_VALUE =
+ "table:string-value";
+
+ /**
+ * Attribute tag for <i>table:time-boolean-value</i> of element
+ * <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_BOOLEAN_VALUE =
+ "table:boolean-value";
+
+ /** Attribute tag for <i>table:style-name</i> of table elements. */
+ public final static String ATTRIBUTE_TABLE_STYLE_NAME = "table:style-name";
+
+ /**
+ * Attribute tag for <i>table:currency</i> of element
+ * <i>table:table-cell</i>.
+ */
+ public final static String ATTRIBUTE_TABLE_CURRENCY = "table:currency";
+
+ /** The cell contains data of type <i>string</i>. */
+ public final static String CELLTYPE_STRING = "string";
+
+ /** The cell contains data of type <i>float</i>. */
+ public final static String CELLTYPE_FLOAT = "float";
+
+ /** The cell contains data of type <i>time</i>. */
+ public final static String CELLTYPE_TIME = "time";
+
+ /** The cell contains data of type <i>date</i>. */
+ public final static String CELLTYPE_DATE = "date";
+
+ /** The cell contains data of type <i>currency</i>. */
+ public final static String CELLTYPE_CURRENCY = "currency";
+
+ /** The cell contains data of type <i>boolean</i>. */
+ public final static String CELLTYPE_BOOLEAN = "boolean";
+
+ /** The cell contains data of type <i>percent</i>. */
+ public final static String CELLTYPE_PERCENT = "percentage";
+
+ /** StarWriter XML file extension. */
+ public final static String SXW_FILE_EXTENSION = ".sxw";
+
+ /** StarWriter XML <i>office:class</i> value. */
+ public final static String SXW_TYPE = "text";
+
+ /** StarCalc XML file extension. */
+ public final static String SXC_FILE_EXTENSION = ".sxc";
+
+ /** StarCalc XML <i>office:class</i> value. */
+ public final static String SXC_TYPE = "spreadsheet";
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
new file mode 100644
index 000000000000..a5fa56e2bf9f
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocument.java
@@ -0,0 +1,604 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.io.InputStreamReader;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import org.openoffice.xmerge.util.Resources;
+import org.openoffice.xmerge.util.Debug;
+
+/**
+ * An implementation of <code>Document</code> for
+ * StarOffice documents.
+ */
+public abstract class OfficeDocument
+ implements org.openoffice.xmerge.Document,
+ OfficeConstants {
+
+ /** Factory for <code>DocumentBuilder</code> objects. */
+ private static DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+
+ /** DOM <code>Document</code> of content.xml. */
+ private Document contentDoc = null;
+
+ /** DOM <code>Document</code> of content.xml. */
+ private Document styleDoc = null;
+
+ private String documentName = null;
+ private String fileName = null;
+
+ /** Resources object. */
+ private Resources res = null;
+
+ /**
+ * <code>OfficeZip</code> object to store zip contents from
+ * read <code>InputStream</code>. Note that this member
+ * will still be null if it was initialized using a template
+ * file instead of reading from a StarOffice zipped
+ * XML file.
+ */
+ private OfficeZip zip = null;
+
+
+ /**
+ * Default constructor.
+ *
+ * @param name <code>Document</code> name.
+ */
+ public OfficeDocument(String name)
+ {
+ this(name, true, false);
+ }
+
+
+ /**
+ * Constructor with arguments to set <code>namespaceAware</code>
+ * and <code>validating</code> flags.
+ *
+ * @param name <code>Document</code> name (may or may not
+ * contain extension).
+ * @param namespaceAware Value for <code>namespaceAware</code> flag.
+ * @param validating Value for <code>validating</code> flag.
+ */
+ public OfficeDocument(String name, boolean namespaceAware, boolean validating) {
+
+ res = Resources.getInstance();
+ factory.setValidating(validating);
+ factory.setNamespaceAware(namespaceAware);
+ this.documentName = trimDocumentName(name);
+ this.fileName = documentName + getFileExtension();
+ }
+
+
+ /**
+ * Removes the file extension from the <code>Document</code>
+ * name.
+ *
+ * @param name Full <code>Document</code> name with extension.
+ *
+ * @return Name of <code>Document</code> without the extension.
+ */
+ private String trimDocumentName(String name) {
+ String temp = name.toLowerCase();
+ String ext = getFileExtension();
+
+ if (temp.endsWith(ext)) {
+ // strip the extension
+ int nlen = name.length();
+ int endIndex = nlen - ext.length();
+ name = name.substring(0,endIndex);
+ }
+
+ return name;
+ }
+
+
+ /**
+ * Return a DOM <code>Document</code> object of the content.xml
+ * file. Note that a content DOM is not created when the constructor
+ * is called. So, either the <code>read</code> method or the
+ * <code>initContentDOM</code> method will need to be called ahead
+ * on this object before calling this method.
+ *
+ * @return DOM <code>Document</code> object.
+ */
+ public Document getContentDOM() {
+
+ return contentDoc;
+ }
+
+
+ public void setContentDOM( Node newDom) {
+
+ contentDoc=(Document)newDom;
+ }
+
+ /**
+ * Return a DOM <code>Document</code> object of the style.xml file.
+ * Note that this may return null if there is no style DOM.
+ * Note that a style DOM is not created when the constructor
+ * is called. Depending on the <code>InputStream</code>, a
+ * <code>read</code> method may or may not build a style DOM. When
+ * creating a new style DOM, call the <code>initStyleDOM</code> method
+ * first.
+ *
+ * @return DOM <code>Document</code> object.
+ */
+ public Document getStyleDOM() {
+
+ return styleDoc;
+ }
+
+
+ /**
+ * Return the name of the <code>Document</code>.
+ *
+ * @return The name of <code>Document</code>.
+ */
+ public String getName() {
+
+ return documentName;
+ }
+
+
+ /**
+ * Return the file name of the <code>Document</code>, possibly
+ * with the standard extension.
+ *
+ * @return The file name of <code>Document</code>.
+ */
+ public String getFileName() {
+
+ return fileName;
+ }
+
+
+ /**
+ * Returns the file extension for this type of
+ * <code>Document</code>.
+ *
+ * @return The file extension of <code>Document</code>.
+ */
+ protected abstract String getFileExtension();
+
+
+ /**
+ * Read the Office <code>Document</code> from the given
+ * <code>InputStream</code>.
+ *
+ * @param is Office document <code>InputStream</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public void read(InputStream is) throws IOException {
+
+ Debug.log(Debug.INFO, "reading Office file");
+
+ DocumentBuilder builder = null;
+
+ try {
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException ex) {
+ throw new OfficeDocumentException(ex);
+ }
+
+ // read in Office zip file format
+
+ zip = new OfficeZip();
+ zip.read(is);
+
+ // grab the content.xml and
+ // parse it into contentDoc.
+
+ byte contentBytes[] = zip.getContentXMLBytes();
+
+ if (contentBytes == null) {
+
+ throw new OfficeDocumentException("Entry content.xml not found in file");
+ }
+
+ try {
+
+ contentDoc = parse(builder, contentBytes);
+
+ } catch (SAXException ex) {
+
+ throw new OfficeDocumentException(ex);
+ }
+
+ // if style.xml exists, grab the style.xml
+ // parse it into styleDoc.
+
+ byte styleBytes[] = zip.getStyleXMLBytes();
+
+ if (styleBytes != null) {
+
+ try {
+
+ styleDoc = parse(builder, styleBytes);
+
+ } catch (SAXException ex) {
+
+ throw new OfficeDocumentException(ex);
+ }
+ }
+ }
+
+
+ /**
+ * Parse given <code>byte</code> array into a DOM
+ * <code>Document</code> object using the
+ * <code>DocumentBuilder</code> object.
+ *
+ * @param builder <code>DocumentBuilder</code> object for parsing.
+ * @param bytes <code>byte</code> array for parsing.
+ *
+ * @return Resulting DOM <code>Document</code> object.
+ *
+ * @throws SAXException If any parsing error occurs.
+ */
+ private Document parse(DocumentBuilder builder, byte bytes[])
+ throws SAXException, IOException {
+
+ Document doc = null;
+
+ ByteArrayInputStream is = new ByteArrayInputStream(bytes);
+
+ // TODO: replace hack with a more appropriate fix.
+
+ Reader r = hack(is);
+ InputSource ins = new InputSource(r);
+ doc = builder.parse(ins);
+
+ return doc;
+ }
+
+
+ /**
+ * Write out Office ZIP file format.
+ *
+ * @param os XML <code>OutputStream</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public void write(OutputStream os) throws IOException {
+
+ // create a OfficeZip object if one does not exist.
+ if (zip == null) {
+
+ zip = new OfficeZip();
+ }
+
+ // set bytes for content.xml in zip
+ byte contentBytes[] = docToBytes(contentDoc);
+ zip.setContentXMLBytes(contentBytes);
+
+ // if there is a styleDoc, set bytes
+ // for it in zip as well
+
+ if (styleDoc != null) {
+
+ byte styleBytes[] = docToBytes(styleDoc);
+ zip.setStyleXMLBytes(styleBytes);
+ }
+
+ zip.write(os);
+ }
+
+
+ /**
+ * <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 Document DOM <code>Document</code> object.
+ *
+ * @return <code>byte</code> array of DOM <code>Document</code>
+ * object.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ 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();
+
+ /*
+ * 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.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 {
+ // 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());
+ }
+ 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());
+ }
+
+ byte bytes[] = baos.toByteArray();
+
+ return bytes;
+ }
+
+
+ /**
+ * Initializes a new DOM <code>Document</code> with the content
+ * containing minimum OpenOffice XML tags.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public final void initContentDOM() throws IOException {
+
+ contentDoc = createDOM(TAG_OFFICE_DOCUMENT_CONTENT);
+
+ // this is a work-around for a bug in Office6.0 - not really
+ // needed but StarCalc 6.0 will crash without this tag.
+ Element root = contentDoc.getDocumentElement();
+
+ Element child = contentDoc.createElement(TAG_OFFICE_AUTOMATIC_STYLES);
+ root.appendChild(child);
+
+ child = contentDoc.createElement(TAG_OFFICE_BODY);
+ root.appendChild(child);
+ }
+
+
+ /**
+ * Initializes a new DOM Document with styles
+ * containing minimum OpenOffice XML tags.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public final void initStyleDOM() throws IOException {
+
+ styleDoc = createDOM(TAG_OFFICE_DOCUMENT_STYLES);
+ }
+
+
+ /**
+ * <p>Creates a new DOM <code>Document</code> containing minimum
+ * OpenOffice XML tags.</p>
+ *
+ * <p>This method uses the subclass
+ * <code>getOfficeClassAttribute</code> method to get the
+ * attribute for <i>office:class</i>.</p>
+ *
+ * @param rootName root name of <code>Document</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ private final Document createDOM(String rootName) throws IOException {
+
+ Document doc = null;
+
+ try {
+
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ doc = builder.newDocument();
+
+ } catch (ParserConfigurationException ex) {
+
+ throw new OfficeDocumentException(ex);
+
+ }
+
+ Element root = (Element) doc.createElement(rootName);
+ doc.appendChild(root);
+
+ root.setAttribute("xmlns:office", "http://openoffice.org/2000/office");
+ root.setAttribute("xmlns:style", "http://openoffice.org/2000/style");
+ root.setAttribute("xmlns:text", "http://openoffice.org/2000/text");
+ root.setAttribute("xmlns:table", "http://openoffice.org/2000/table");
+ root.setAttribute("xmlns:draw", "http://openoffice.org/2000/drawing");
+ root.setAttribute("xmlns:fo", "http://www.w3.org/1999/XSL/Format");
+ root.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
+ root.setAttribute("xmlns:number", "http://openoffice.org/2000/datastyle");
+ root.setAttribute("xmlns:svg", "http://www.w3.org/2000/svg");
+ root.setAttribute("xmlns:chart", "http://openoffice.org/2000/chart");
+ root.setAttribute("xmlns:dr3d", "http://openoffice.org/2000/dr3d");
+ root.setAttribute("xmlns:math", "http://www.w3.org/1998/Math/MathML");
+ root.setAttribute("xmlns:form", "http://openoffice.org/2000/form");
+ root.setAttribute("xmlns:script", "http://openoffice.org/2000/script");
+ root.setAttribute("office:class", getOfficeClassAttribute());
+ root.setAttribute("office:version", "1.0");
+
+ return doc;
+ }
+
+
+ /**
+ * Return the <i>office:class</i> attribute value.
+ *
+ * @return The attribute value.
+ */
+ protected abstract String getOfficeClassAttribute();
+
+
+ /**
+ * <p>Hacked code to filter <!DOCTYPE> tag before
+ * sending stream to parser.</p>
+ *
+ * <p>This hacked code needs to be changed later on.</p>
+ *
+ * <p>Issue: using current jaxp1.0 parser, there is no way
+ * to turn off processing of dtds. Current set of dtds
+ * have bugs, processing them will throw exceptions.</p>
+ *
+ * <p>This is a simple hack that assumes the whole <!DOCTYPE>
+ * tag are all in the same line. This is sufficient for
+ * current StarOffice 6.0 generated XML files. Since this
+ * hack really needs to go away, I don't want to spend
+ * too much time in making it a perfect hack.</p>
+ *
+ * @param is <code>InputStream</code> to be filtered.
+ *
+ * @return Reader value without the <!DOCTYPE> tag.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ private Reader hack(InputStream is) throws IOException {
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ StringBuffer buffer = new StringBuffer(is.available());
+
+ String str = null;
+
+ while ((str = br.readLine()) != null) {
+
+ int sIndex = str.indexOf("<!DOCTYPE");
+
+ if (sIndex > -1) {
+
+ buffer.append(str.substring(0, sIndex));
+
+ int eIndex = str.indexOf('>', sIndex + 8 );
+
+ if (eIndex > -1) {
+
+ buffer.append(str.substring(eIndex + 1, str.length()));
+
+ } else {
+
+ throw new IOException("Invalid XML");
+ }
+
+ } else {
+
+ buffer.append(str);
+ }
+ }
+
+ StringReader r = new StringReader(buffer.toString());
+ return r;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocumentException.java b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocumentException.java
new file mode 100644
index 000000000000..732ce8b927c4
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeDocumentException.java
@@ -0,0 +1,159 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import org.openoffice.xmerge.util.Resources;
+
+/**
+ * Used by OfficeDocument to encapsulate exceptions. It will add
+ * more details to the message string if it is of type
+ * <code>SAXParseException</code>.
+ *
+ * @author Herbie Ong
+ */
+
+public final class OfficeDocumentException extends IOException {
+
+ StringBuffer message = null;
+
+
+ /**
+ * Constructor, capturing additional information from the
+ * <code>SAXException</code>.
+ *
+ * @param e The <code>SAXException</code>.
+ */
+ public OfficeDocumentException(SAXException e) {
+ super(e.toString());
+ message = new StringBuffer();
+ if (e instanceof SAXParseException) {
+ String msgParseError =
+ Resources.getInstance().getString("PARSE_ERROR");
+ String msgLine =
+ Resources.getInstance().getString("LINE");
+ String msgColumn =
+ Resources.getInstance().getString("COLUMN");
+ String msgPublicId =
+ Resources.getInstance().getString("PUBLIC_ID");
+ String msgSystemId =
+ Resources.getInstance().getString("SYSTEM_ID");
+ SAXParseException spe = (SAXParseException) e;
+ message.append(msgParseError);
+ message.append(": ");
+ message.append(msgLine);
+ message.append(": ");
+ message.append(spe.getLineNumber());
+ message.append(", ");
+ message.append(msgColumn);
+ message.append(": ");
+ message.append(spe.getColumnNumber());
+ message.append(", ");
+ message.append(msgSystemId);
+ message.append(": ");
+ message.append(spe.getSystemId());
+ message.append(", ");
+ message.append(msgPublicId);
+ message.append(": ");
+ message.append(spe.getPublicId());
+ message.append("\n");
+ }
+
+ // if there exists an embedded exception
+ Exception ex = e.getException();
+ if (ex != null) {
+ message.append(ex.getMessage());
+ }
+ }
+
+
+ /**
+ * Constructor, creates exception with provided message.
+ *
+ * @param s Message value for the exception.
+ */
+ public OfficeDocumentException(String s) {
+ super(s);
+ }
+
+
+ /**
+ * Constructor, creates exception with the message
+ * corresponding to the message value of the provided
+ * exception.
+ *
+ * @param e The Exception.
+ */
+ public OfficeDocumentException(Exception e) {
+ super(e.getMessage());
+ }
+
+
+ /**
+ * Returns the message value for the <code>Exception</code>.
+ *
+ * @return The message value for the <code>Exception</code>.
+ */
+ public String getMessage() {
+ return message.toString() + super.getMessage();
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeZip.java b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeZip.java
new file mode 100644
index 000000000000..df02a838ed12
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeZip.java
@@ -0,0 +1,369 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml;
+
+import java.util.List;
+import java.util.ListIterator;
+import java.util.LinkedList;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.CRC32;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+
+import org.openoffice.xmerge.util.Debug;
+
+/**
+ * Class used by {@link
+ * org.openoffice.xmerge.converter.OfficeDocument
+ * OfficeDocument} to handle reading and writing
+ * from a ZIP file, as well as storing ZIP entries.
+ *
+ * @author Herbie Ong
+ */
+class OfficeZip {
+
+ /** File name of the XML file in a zipped document. */
+ private final static String CONTENTXML = "content.xml";
+
+ private final static String STYLEXML = "styles.xml";
+
+ private final static int BUFFERSIZE = 1024;
+
+ private List entryList = null;
+
+ private int contentIndex = -1;
+
+ private int styleIndex = -1;
+
+ /** Default constructor. */
+ OfficeZip() {
+
+ entryList = new LinkedList();
+ }
+
+
+ /**
+ * <p>Read each zip entry in the <code>InputStream</code> object
+ * and store in entryList both the <code>ZipEntry</code> object
+ * as well as the bits of each entry. Call this method before
+ * calling the <code>getContentXMLBytes</code> method or the
+ * <code>getStyleXMLBytes</code> method.</p>
+ *
+ * <p>Keep track of the CONTENTXML and STYLEXML using
+ * contentIndex and styleIndex, respectively.</p>
+ *
+ * @param is <code>InputStream</code> object to read.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ void read(InputStream is) throws IOException {
+
+ ZipInputStream zis = new ZipInputStream(is);
+ ZipEntry ze = null;
+ int i = -1;
+
+ while ((ze = zis.getNextEntry()) != null) {
+
+ String name = ze.getName();
+
+ Debug.log(Debug.TRACE, "reading entry: " + name);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ int len = 0;
+ byte buffer[] = new byte[BUFFERSIZE];
+
+ while ((len = zis.read(buffer)) > 0) {
+ baos.write(buffer, 0, len);
+ }
+
+ byte bytes[] = baos.toByteArray();
+ Entry entry = new Entry(ze,bytes);
+
+ entryList.add(entry);
+
+ i++;
+
+ if (isSameName(name, CONTENTXML)) {
+ contentIndex = i;
+ } else if (isSameName(name, STYLEXML)) {
+ styleIndex = i;
+ }
+ }
+
+ zis.close();
+ }
+
+
+ /**
+ * This method returns the CONTENTXML file in a
+ * <code>byte</code> array. It returns null if there is no
+ * CONTENTXML in this zip file.
+ *
+ * @return CONTENTXML in a <code>byte</code> array.
+ */
+ byte[] getContentXMLBytes() {
+
+ return getEntryBytes(contentIndex);
+ }
+
+
+ /**
+ * This method returns the STYLEXML file in a
+ * <code>byte</code> array. It returns null if there is
+ * no STYLEXML in this zip file.
+ *
+ * @return STYLEXML in a <code>byte</code> array.
+ */
+ byte[] getStyleXMLBytes() {
+
+ return getEntryBytes(styleIndex);
+ }
+
+
+ /**
+ * Used by the <code>getContentXMLBytes</code> method and the
+ * <code>getStyleXMLBytes</code> method to return the
+ * <code>byte</code> array from the corresponding
+ * <code>entry</code> in the <code>entryList</code>.
+ *
+ * @param index Index of <code>Entry</code> object in
+ * <code>entryList</code>.
+ *
+ * @return <code>byte</code> array associated in that
+ * <code>Entry</code> object or null, if there is
+ * not such <code>Entry</code>.
+ */
+ private byte[] getEntryBytes(int index) {
+
+ byte[] bytes = null;
+
+ if (index > -1) {
+ Entry entry = (Entry) entryList.get(index);
+ bytes = entry.bytes;
+ }
+
+ return bytes;
+ }
+
+
+ /**
+ * Set or replace the <code>byte</code> array for the
+ * CONTENTXML file.
+ *
+ * @param bytes <code>byte</code> array for the
+ * CONTENTXML file.
+ */
+ void setContentXMLBytes(byte bytes[]) {
+
+ contentIndex = setEntryBytes(contentIndex, bytes, CONTENTXML);
+ }
+
+
+ /**
+ * Set or replace the <code>byte</code> array for the
+ * STYLEXML file.
+ *
+ * @param bytes <code>byte</code> array for the
+ * STYLEXML file.
+ */
+ void setStyleXMLBytes(byte bytes[]) {
+
+ styleIndex = setEntryBytes(styleIndex, bytes, STYLEXML);
+ }
+
+
+ /**
+ * <p>Used by the <code>setContentXMLBytes</code> method and
+ * the <code>setStyleXMLBytes</code> to either replace an
+ * existing <code>Entry</code>, or create a new entry in
+ * <code>entryList</code>.</p>
+ *
+ * <p>If there is an <code>Entry</code> object within
+ * entryList that corresponds to the index, replace the
+ * <code>ZipEntry</code> info.</p>
+ *
+ * @param index Index of <code>Entry</code> to modify.
+ * @param bytes <code>Entry</code> value.
+ * @param name Name of <code>Entry</code>.
+ *
+ * @return Index of value added or modified in entryList
+ */
+ private int setEntryBytes(int index, byte bytes[], String name) {
+
+ if (index > -1) {
+
+ // replace existing entry in entryList
+
+ Entry entry = (Entry) entryList.get(index);
+ name = entry.zipEntry.getName();
+ int method = entry.zipEntry.getMethod();
+
+ ZipEntry ze = createZipEntry(name, bytes, method);
+
+ entry.zipEntry = ze;
+ entry.bytes= bytes;
+
+ } else {
+
+ // add a new entry into entryList
+ ZipEntry ze = createZipEntry(name, bytes, ZipEntry.DEFLATED);
+ Entry entry = new Entry(ze, bytes);
+ entryList.add(entry);
+ index = entryList.size() - 1;
+ }
+
+ return index;
+ }
+
+
+ /**
+ * Write out the ZIP entries into the <code>OutputStream</code>
+ * object.
+ *
+ * @param os <code>OutputStream</code> object to write ZIP.
+ *
+ * @throws IOException If any ZIP I/O error occurs.
+ */
+ void write(OutputStream os) throws IOException {
+
+ Debug.log(Debug.TRACE, "Writing out the following entries into zip.");
+
+ ZipOutputStream zos = new ZipOutputStream(os);
+
+ ListIterator iterator = entryList.listIterator();
+
+ while (iterator.hasNext()) {
+
+ Entry entry = (Entry) iterator.next();
+ ZipEntry ze = entry.zipEntry;
+
+ String name = ze.getName();
+
+ Debug.log(Debug.TRACE, "... " + name);
+
+ zos.putNextEntry(ze);
+ zos.write(entry.bytes);
+ }
+
+ zos.close();
+ }
+
+
+ /**
+ * Creates a <code>ZipEntry</code> object based on the given params.
+ *
+ * @param name Name for the <code>ZipEntry</code>.
+ * @param bytes <code>byte</code> array for <code>ZipEntry</code>.
+ * @param method ZIP method to be used for <code>ZipEntry</code>.
+ *
+ * @return A <code>ZipEntry</code> object.
+ */
+ private ZipEntry createZipEntry(String name, byte bytes[], int method) {
+
+ ZipEntry ze = new ZipEntry(name);
+
+ ze.setMethod(method);
+ ze.setSize(bytes.length);
+
+ CRC32 crc = new CRC32();
+ crc.reset();
+ crc.update(bytes);
+ ze.setCrc(crc.getValue());
+
+ ze.setTime(System.currentTimeMillis());
+
+ return ze;
+ }
+
+
+ /**
+ * Checks if name is the same as rName if case insensitive.
+ * Note that we assume here that rName is always in all lowercase.
+ *
+ * @param name First name to compare.
+ * @param rName Second name to compare.
+ *
+ * @return true if identical, false otherwise.
+ */
+ private boolean isSameName(String name, String rName) {
+
+ String lname = name.toLowerCase();
+ return lname.equals(rName);
+ }
+
+
+ /**
+ * This inner class is used as a data structure for holding
+ * a <code>ZipEntry</code> info and its corresponding bytes.
+ * These are stored in entryList.
+ */
+ private class Entry {
+
+ ZipEntry zipEntry = null;
+ byte bytes[] = null;
+
+ Entry(ZipEntry zipEntry, byte bytes[]) {
+ this.zipEntry = zipEntry;
+ this.bytes = bytes;
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/ParaStyle.java b/xmerge/java/org/openoffice/xmerge/converter/xml/ParaStyle.java
new file mode 100644
index 000000000000..fcbbbd3dca2d
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/ParaStyle.java
@@ -0,0 +1,635 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Element;
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.converter.xml.OfficeDocument;
+import java.io.IOException;
+import org.openoffice.xmerge.converter.xml.sxw.SxwDocument;
+import java.lang.reflect.Constructor;
+import org.openoffice.xmerge.util.Debug;
+
+
+abstract class conversionAlgorithm {
+ int I(String val) {
+ return 0;
+ }
+}
+
+ /*
+ * This algorithm expects only values in millimeters, e.g. "20.3mm".
+ */
+class horizSize extends conversionAlgorithm {
+ int I(String value) {
+ if (value.endsWith("mm")) {
+ float size = (float)0.0;
+ String num = value.substring(0, value.length() - 2);
+ try {
+ size = Float.parseFloat(num);
+ } catch (Exception e) {
+ Debug.log(Debug.ERROR, "Error parsing " + value, e);
+ }
+ size *= 100;
+ return (int)size;
+ } else {
+ Debug.log(Debug.ERROR, "Unexpected value (" + value
+ + ") in horizSize.I()");
+ return 0;
+ }
+ }
+}
+
+
+/*
+ * This algorithm does line height - can be either millimeters or
+ * a percentage.
+ */
+class lineHeight extends conversionAlgorithm {
+ int I(String value) {
+ if (value.endsWith("mm")) {
+ float size = (float)0.0;
+ String num = value.substring(0, value.length() - 2);
+ try {
+ size = Float.parseFloat(num);
+ } catch (Exception e) {
+ Debug.log(Debug.ERROR, "Error parsing " + value, e);
+ }
+ size *= 100;
+ return (int)size;
+ } else if (value.endsWith("%")) {
+ float size = (float)0.0;
+ String num = value.substring(0, value.length() - 1);
+ try {
+ size = Float.parseFloat(num);
+ } catch (Exception e) {
+ Debug.log(Debug.ERROR, "Error parsing " + value, e);
+ }
+ int retval = (int) size;
+ retval |= ParaStyle.LH_PCT;
+ return retval;
+ }
+ return 0;
+ }
+}
+
+
+/**
+ * This class converts alignment values.
+ */
+class alignment extends conversionAlgorithm {
+ int I(String value) {
+ if (value.equals("end"))
+ return ParaStyle.ALIGN_RIGHT;
+ if (value.equals("right"))
+ return ParaStyle.ALIGN_RIGHT;
+ if (value.equals("center"))
+ return ParaStyle.ALIGN_CENTER;
+ if (value.equals("justify"))
+ return ParaStyle.ALIGN_JUST;
+ if (value.equals("justified"))
+ return ParaStyle.ALIGN_JUST;
+ if (value.equals("start"))
+ return ParaStyle.ALIGN_LEFT;
+ if (value.equals("left"))
+ return ParaStyle.ALIGN_LEFT;
+ Debug.log(Debug.ERROR, "Unknown string ("
+ + value + ") in alignment.I()");
+ return ParaStyle.ALIGN_LEFT;
+ }
+}
+
+
+/**
+ * <p>This class represents a paragraph <code>Style</code>.</p>
+ *
+ * <p><table border="1" cellpadding="1"><tr><td>
+ * Attribute </td><td>Value
+ * </td></tr><tr><td>
+ * MARGIN_LEFT </td><td>mm * 100
+ * </td></tr><tr><td>
+ * MARGIN_RIGHT </td><td>mm * 100
+ * </td></tr><tr><td>
+ * MARGIN_TOP </td><td>mm * 100 (space on top of paragraph)
+ * </td></tr><tr><td>
+ * MARGIN_BOTTOM </td><td>mm * 100
+ * </td></tr><tr><td>
+ * TEXT_INDENT </td><td>mm * 100 (first line indent)
+ * </td></tr><tr><td>
+ * LINE_HEIGHT </td><td>mm * 100, unless or'ed with LH_PCT, in which
+ * case it is a percentage (e.g. 200% for double spacing)
+ * Can also be or'ed with LH_ATLEAST. Value is stored
+ * in bits indicated by LH_VALUEMASK.
+ * </td></tr><tr><td>
+ * TEXT_ALIGN </td><td>ALIGN_RIGHT, ALIGN_CENTER, ALIGN_JUST, ALIGN_LEFT
+ * </td></tr></table></p>
+ *
+ * @author David Proulx
+ */
+public class ParaStyle extends Style implements Cloneable {
+
+ /** The left margin property. */
+ public static final int MARGIN_LEFT = 0;
+ /** The right margin property. */
+ public static final int MARGIN_RIGHT = 1;
+ /** The top margin property. */
+ public static final int MARGIN_TOP = 2;
+ /** The bottom margin property. */
+ public static final int MARGIN_BOTTOM = 3;
+ /** Indent left property. */
+ public static final int TEXT_INDENT = 4;
+ /** Indent right property. */
+ public static final int LINE_HEIGHT = 5;
+ /** Align text property. */
+ public static final int TEXT_ALIGN = 6;
+ // This must always be one more than highest property
+ /** Total number of properties. */
+ protected static final int NR_PROPERTIES = 7;
+
+ /**
+ * Array of flags indicating which attributes are set for this
+ * paragraph <code>Style</code>.
+ */
+ protected boolean isSet[] = new boolean[NR_PROPERTIES];
+ /** Array of attribute values for this paragraph <code>tyle</code>. */
+ protected int value[] = new int[NR_PROPERTIES];
+ /** Array of attribute names for this paragraph <code>Style</code>. */
+ protected String attrName[] = {
+ "fo:margin-left",
+ "fo:margin-right",
+ "fo:margin-top",
+ "fo:margin-bottom",
+ "fo:text-indent",
+ "fo:line-height",
+ "fo:text-align"
+ };
+
+ /** Array of attribute structures for this paragraph <code>Style</code>. */
+ protected Class algor[] = {
+ horizSize.class,
+ horizSize.class,
+ horizSize.class,
+ horizSize.class,
+ horizSize.class,
+ lineHeight.class,
+ alignment.class
+ };
+
+ /** Align right. */
+ public static final int ALIGN_RIGHT = 1;
+ /** Align center. */
+ public static final int ALIGN_CENTER = 2;
+ /** Align justified. */
+ public static final int ALIGN_JUST = 3;
+ /** Align left. */
+ public static final int ALIGN_LEFT = 4;
+
+ /** Line height percentage. */
+ public static final int LH_PCT = 0x40000000;
+ /** Line height minimum value. */
+ public static final int LH_ATLEAST = 0x20000000;
+ /** Line height mask. */
+ public static final int LH_VALUEMASK = 0x00FFFFFF;
+
+ /** Ignored tags. */
+ private static String[] ignored = {
+ "style:font-name", "fo:font-size", "fo:font-weight", "fo:color",
+ "fo:language", "fo:country", "style:font-name-asian",
+ "style:font-size-asian", "style:language-asian",
+ "style:country-asian", "style:font-name-complex",
+ "style:font-size-complex", "style:language-complex",
+ "style:country-complex", "style:text-autospace", "style:punctuation-wrap",
+ "style:line-break", "fo:keep-with-next", "fo:font-style",
+ "text:number-lines", "text:line-number"
+ };
+
+
+ /**
+ * Constructor for use when going from DOM to client device format.
+ *
+ * @param node A <i>style:style</i> <code>Node</code> which, which
+ * is assumed to have <i>family</i> attribute of
+ * <i>paragraph</i>.
+ * @param sc The <code>StyleCatalog</code>, which is used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ public ParaStyle(Node node, StyleCatalog sc) {
+
+ super(node, sc);
+
+ // Look for children. Only ones we care about are "style:properties"
+ // nodes. If any are found, recursively traverse them, passing
+ // along the style element to add properties to.
+ //
+ if (node.hasChildNodes()) {
+ NodeList children = node.getChildNodes();
+ int len = children.getLength();
+ for (int i = 0; i < len; i++) {
+ Node child = children.item(i);
+ String name = child.getNodeName();
+ if (name.equals("style:properties")) {
+ NamedNodeMap childAttrNodes = child.getAttributes();
+ if (childAttrNodes != null) {
+ int nChildAttrNodes = childAttrNodes.getLength();
+ for (int j = 0; j < nChildAttrNodes; j++) {
+ Node attr = childAttrNodes.item(j);
+ setAttribute(attr.getNodeName(), attr.getNodeValue());
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Constructor for use when going from client device format to DOM.
+ *
+ * @param name Name of the <code>Style</code>. Can be null.
+ * @param family Family of the <code>Style</code> - usually
+ * <i>paragraph</i>, <i>text</i>, etc. Can be null.
+ * @param parent Name of the parent <code>Style</code>, or null
+ * if none.
+ * @param attribs Array of attributes to set.
+ * @param values Array of values to set.
+ * @param sc The <code>StyleCatalog</code>, which is used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ public ParaStyle(String name, String familyName, String parentName,
+ String attribs[], String values[], StyleCatalog sc) {
+ super(name, familyName, parentName, sc);
+ if (attribs != null)
+ for (int i = 0; i < attribs.length; i++)
+ setAttribute(attribs[i], values[i]);
+ }
+
+
+ /**
+ * Alternate constructor for use when going from client device
+ * format to DOM.
+ *
+ * @param name Name of the <code>Style</code>. Can be null.
+ * @param family Family of the <code>Style</code> - usually
+ * <i>paragraph</i>, <i>text</i>, etc. Can be null.
+ * @param parent Name of the parent <code>Style</code>, or
+ * null if none.
+ * @param attribs Array of attributes indices to set.
+ * @param values Array of values to set.
+ * @param sc The <code>StyleCatalog</code>, which is used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ public ParaStyle(String name, String familyName, String parentName,
+ int attribs[], String values[], StyleCatalog lookup) {
+ super(name, familyName, parentName, lookup);
+ if (attribs != null)
+ for (int i = 0; i < attribs.length; i++)
+ setAttribute(attribs[i], values[i]);
+ }
+
+
+ /**
+ * This code checks whether an attribute is one that we
+ * intentionally ignore.
+ *
+ * @param attribute The attribute to check.
+ *
+ * @return true if attribute can be ignored, false otherwise.
+ */
+ private boolean isIgnored(String attribute) {
+ for (int i = 0; i < ignored.length; i++) {
+ if (ignored[i].equals(attribute))
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Set an attribute for this paragraph <code>Style</code>.
+ *
+ * @param attr The attribute to set.
+ * @param value The attribute value to set.
+ */
+ public void setAttribute(String attr, String value) {
+ for (int i = 0; i < NR_PROPERTIES; i++) {
+ if (attr.equals(attrName[i])) {
+ setAttribute(i, value);
+ return;
+ }
+ }
+ if (!isIgnored(attr))
+ Debug.log(Debug.INFO, "ParaStyle Unhandled: " + attr + "=" + value);
+ }
+
+
+ /**
+ * Check whether an attribute is set in this <code>Style</code>.
+ *
+ * @param attrIndex The attribute index to check.
+ *
+ * @return true if the attribute at specified index is set,
+ * false otherwise.
+ */
+ public boolean isAttributeSet(int attrIndex) {
+ return isSet[attrIndex];
+ }
+
+
+ /**
+ * Get the value of an integer attribute.
+ *
+ * @param attrIndex Index of the attribute.
+ *
+ * @return Value of the attribute, 0 if not set.
+ */
+ public int getAttribute(int attrIndex) {
+ if (isSet[attrIndex])
+ return value[attrIndex];
+ else return 0;
+ }
+
+
+ /**
+ * Set an attribute for this paragraph <code>Style</code>.
+ *
+ * @param attr The attribute index to set.
+ * @apram value The attribute value to set.
+ */
+ public void setAttribute(int attr, String value) {
+ isSet[attr] = true;
+ try {
+ this.value[attr] = (((conversionAlgorithm)algor[attr].newInstance())).I(value);
+ } catch (Exception e) {
+ Debug.log(Debug.ERROR, "Instantiation error", e);
+ }
+ }
+
+
+ /**
+ * Return the <code>Style</code> in use.
+ *
+ * @return The fully-resolved copy of the <code>Style</code> in use.
+ */
+ public Style getResolved() {
+ ParaStyle resolved = null;
+ try {
+ resolved = (ParaStyle)this.clone();
+ } catch (Exception e) {
+ Debug.log(Debug.ERROR, "Can't clone", e);
+ }
+
+ // Look up the parent style. (If there is no style catalog
+ // specified, we can't do any lookups).
+ ParaStyle parentStyle = null;
+ if (sc != null) {
+ if (parent != null) {
+ parentStyle = (ParaStyle)sc.lookup(parent, family, null,
+ this.getClass());
+ if (parentStyle == null)
+ Debug.log(Debug.ERROR, "parent style lookup of "
+ + parent + " failed!");
+ else
+ parentStyle = (ParaStyle)parentStyle.getResolved();
+ } else if (!name.equals("DEFAULT_STYLE")) {
+ parentStyle = (ParaStyle)sc.lookup("DEFAULT_STYLE", null, null,
+ this.getClass());
+ }
+ }
+
+ // If we found a parent, for any attributes which we don't have
+ // set, try to get the values from the parent.
+ if (parentStyle != null) {
+ parentStyle = (ParaStyle)parentStyle.getResolved();
+ for (int i = 0; i < NR_PROPERTIES; i++) {
+ if (!isSet[i] && parentStyle.isSet[i]) {
+ resolved.isSet[i] = true;
+ resolved.value[i] = parentStyle.value[i];
+ }
+ }
+ }
+ return resolved;
+ }
+
+
+ /**
+ * Private function to return the value as an element in
+ * a Comma Separated Value (CSV) format.
+ *
+ * @param value The value to format.
+ *
+ * @return The formatted value.
+ */
+ private static String toCSV(String value) {
+ if (value != null)
+ return "\"" + value + "\",";
+ else
+ return "\"\",";
+ }
+
+
+ /**
+ * Private function to return the value as a last element in
+ * a Comma Separated Value (CSV) format.
+ *
+ * @param value The value to format.
+ *
+ * @return The formatted value.
+ */
+ private static String toLastCSV(String value) {
+ if (value != null)
+ return "\"" + value + "\"";
+ else
+ return "\"\"";
+ }
+
+
+ /**
+ * Print a Comma Separated Value (CSV) header line for the
+ * spreadsheet dump.
+ */
+ public static void dumpHdr() {
+ System.out.println(toCSV("Name") + toCSV("Family") + toCSV("parent")
+ + toCSV("left mgn") + toCSV("right mgn")
+ + toCSV("top mgn") + toCSV("bottom mgn") + toCSV("txt indent")
+ + toCSV("line height") + toLastCSV("txt align"));
+ }
+
+
+ /**
+ * Dump this <code>Style</code> as a Comma Separated Value (CSV)
+ * line.
+ */
+ public void dumpCSV() {
+ String attributes = "";
+ for (int index = 0; index <= 6; index++) {
+ if (isSet[index]) {
+ attributes += toCSV("" + value[index]);
+ }
+ else
+ attributes += toCSV(null); // unspecified
+ }
+ System.out.println(toCSV(name) + toCSV(family) + toCSV(parent)
+ + attributes + toLastCSV(null));
+ }
+
+
+ /**
+ * Create the <code>Node</code> with the specified elements.
+ *
+ * @parentDoc Parent <code>Document</code> of the
+ * <code>Node</code> to create.
+ * @param name Name of the <code>Node</code>.
+ *
+ * @return The created <code>Node</code>.
+ */
+ public Node createNode(org.w3c.dom.Document parentDoc, String name) {
+ Element node = parentDoc.createElement(name);
+ writeAttributes(node);
+ return node;
+ }
+
+
+ /**
+ * Return true if <code>style</code> is a subset of the
+ * <code>Style</code>.
+ *
+ * @param style <code>Style</code> to check.
+ *
+ * @return true if <code>style</code> is a subset, false
+ * otherwise.
+ */
+ public boolean isSubset(Style style) {
+
+ if (!super.isSubset(style))
+ return false;
+ if (!this.getClass().isAssignableFrom(style.getClass()))
+ return false;
+ ParaStyle ps = (ParaStyle)style;
+
+ for (int i = 0; i < NR_PROPERTIES; i++) {
+ if (ps.isSet[i]) {
+ // if (!isSet[i]) return false;
+
+ if (i < NR_PROPERTIES - 1) {
+ // Compare the actual values. We allow a margin of error
+ // here because the conversion loses precision.
+ int diff;
+ if (value[i] > ps.value[i])
+ diff = value[i] - ps.value[i];
+ else
+ diff = ps.value[i] - value[i];
+ if (diff > 32)
+ return false;
+ } else {
+ if (i == TEXT_ALIGN)
+ if ((value[i] == 0) && (ps.value[i] == 4))
+ continue;
+ if (value[i] != ps.value[i])
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * Add <code>Style</code> attributes to the given
+ * <code>Node</code>. This may involve writing child
+ * <code>Node</code> objects as well.
+ *
+ * @param node The <code>Node</code> to add <code>Style</code>
+ * attributes.
+ */
+ public void writeAttributes(Element node) {
+ for (int i = 0; i <= TEXT_INDENT; i++) {
+ if (isSet[i]) {
+ double temp = value[i] / 100.0;
+ String stringVal = (new Double(temp)).toString() + "mm";
+ node.setAttribute(attrName[i], stringVal);
+ }
+ }
+
+ if (isSet[LINE_HEIGHT]) {
+ String stringVal;
+ if ((value[LINE_HEIGHT] & LH_PCT) != 0)
+ stringVal = (new Integer(value[LINE_HEIGHT] & LH_VALUEMASK)).toString() + "%";
+ else {
+ double temp = (value[LINE_HEIGHT] & LH_VALUEMASK) / 100.0;
+ stringVal = (new Double(temp)).toString() + "mm";
+ }
+ node.setAttribute(attrName[LINE_HEIGHT], stringVal);
+ }
+
+ if (isSet[TEXT_ALIGN]) {
+ String val;
+ switch (value[TEXT_ALIGN]) {
+ case ALIGN_RIGHT: val = "end"; break;
+ case ALIGN_CENTER: val = "center"; break;
+ case ALIGN_JUST: val = "justify"; break;
+ case ALIGN_LEFT: val = "left"; break;
+ default: val = "unknown"; break;
+ }
+ node.setAttribute(attrName[TEXT_ALIGN], val);
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/Style.java b/xmerge/java/org/openoffice/xmerge/converter/xml/Style.java
new file mode 100644
index 000000000000..11c4ed3967a5
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/Style.java
@@ -0,0 +1,263 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Element;
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.converter.xml.OfficeDocument;
+import java.io.IOException;
+import org.openoffice.xmerge.converter.xml.sxw.SxwDocument;
+
+/**
+ * An object of class <code>Style</code> represents a <i>style</i>
+ * in an OpenOffice document. In practice subclasses of this
+ * <code>Style</code>, such as <code>TextStyle</code>,
+ * <code>ParaStyle</code> are used.
+ *
+ * @author David Proulx
+ * @see <a href="TextStyle.html">TextStyle</a>,
+ * <a href="ParaStyle.html">ParaStyle</a>
+ */
+public class Style {
+
+ /** Name of the <code>Style</code>. */
+ protected String name = null;
+ /** Family of the <code>Style</code>. */
+ protected String family = null;
+ /** Parent of the <code>Style</code>. */
+ protected String parent = null;
+
+ /**
+ * A reference to the <code>StyleCatalog</code> to be used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ protected StyleCatalog sc;
+
+
+ /**
+ * Constructor for use when going from DOM to client device format.
+ *
+ * @param node A <i>style:style</i> or <i>style:default-style</i>
+ * <code>Node</code> from the document being parsed.
+ * No checking of <code>Node</code> is done, so if it
+ * is not of the proper type the results will be
+ * unpredictable.
+ * @param sc The <code>StyleCatalog</code>, which is used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ public Style(Node node, StyleCatalog sc) {
+
+ this.sc = sc;
+
+ // Run through the attributes of this node, saving
+ // the ones we're interested in.
+ if (node.getNodeName().equals("style:default-style"))
+ name = "DEFAULT_STYLE";
+ NamedNodeMap attrNodes = node.getAttributes();
+ if (attrNodes != null) {
+ int len = attrNodes.getLength();
+ for (int i = 0; i < len; i++) {
+ Node attr = attrNodes.item(i);
+ if (attr.getNodeName().equals("style:family"))
+ family = attr.getNodeValue();
+ else if (attr.getNodeName().equals("style:name")) {
+ name = attr.getNodeValue();
+ } else if (attr.getNodeName().equals("style:parent-style-name"))
+ parent = attr.getNodeValue();
+
+ }
+ }
+ }
+
+
+ /**
+ * Constructor for use when going from client device format to DOM.
+ *
+ * @param name Name of the <code>Style</code>. Can be null.
+ * @param family Family of the <code>Style</code> - usually
+ * <i>paragraph</i>, <i>text</i>, etc. Can be null.
+ * @param parent Name of the parent <code>Style</code>, or null if none.
+ * @param sc The <code>StyleCatalog</code>, which is used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ public Style(String name, String family, String parent, StyleCatalog sc) {
+ this.sc = sc;
+ this.name = name;
+ this.family = family;
+ this.parent = parent;
+ }
+
+
+ /**
+ * Set the <code>StyleCatalog</code> to be used when looking up the
+ * <code>Style</code> parent.
+ *
+ * @param sc The <code>StyleCatalog</code>, which is used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ public void setCatalog(StyleCatalog sc) {
+ this.sc = sc;
+ }
+
+
+ /**
+ * Returns the name of this <code>Style</code>.
+ *
+ * @return The name of this <code>Style</code>.
+ */
+ public String getName() {
+ return name;
+ }
+
+
+ /**
+ * Sets the name of this <code>Style</code>.
+ *
+ * @param newName The new name of this <code>Style</code>.
+ */
+ public void setName(String newName) {
+ name = newName;
+ }
+
+
+ /**
+ * Return the family of this <code>Style</code>.
+ *
+ * @return The family of this <code>Style</code>.
+ */
+ public String getFamily() {
+ return family;
+ }
+
+ /**
+ * Return the name of the parent of this <code>Style</code>.
+ *
+ * @return The parent of this <code>Style</code>.
+ */
+ public String getParent() {
+ return parent;
+ }
+
+
+ /**
+ * Return a <code>Style</code> object corresponding to this one, but with
+ * all of the inherited information from parent <code>Style</code>
+ * objects filled in. The object returned will be a new object, not a
+ * reference to this object, even if it does not need any information
+ * added.
+ *
+ * @return A resolved <code>Style</code> object in which to look up
+ * ancestors.
+ */
+ public Style getResolved() {
+ return new Style(name, family, parent, sc);
+ }
+
+
+ /**
+ * Write a <code>Node</code> in <code>parentDoc</code>
+ * representing this <code>Style</code>. Note that the
+ * <code>Node</code> is returned unconnected.
+ *
+ * @param parentDoc Document to which new <code>Node</code> will
+ * belong.
+ * @param name Name to use for new <code>Node</code>.
+ */
+ public Node createNode(org.w3c.dom.Document parentDoc, String name) {
+ // DJP: write this! Should call writeAttributes()
+ return null;
+ }
+
+
+ /**
+ * Write this <code>Style</code> object's attributes to the given
+ * <code>Node</code>. This may involve writing child
+ * <code>Node</code> objects as well. This is similar to the
+ * <code>writeNode</code> method, but the <code>Node</code>
+ * already exists, and this does <b>not</b> write the name,
+ * family, and parent attributes, which are assumed to already
+ * exist in the <code>Node</code>.
+ *
+ * @param node The <code>Node</code> to add style attributes.
+ */
+ public void writeAttributes(Node node) {
+ }
+
+
+ /**
+ * Return true if <code>Style</code> is a subset of this one. Note
+ * that this will return true even if <code>Style</code> is less
+ * specific than this <code>Style</code>, so long as it does not
+ * contradict this <code>Style</code> in any way.
+ *
+ * This always returns true since only subclasses of
+ * <code>Style</code> contain any actual <code>Style</code>
+ * information.
+ *
+ * @param style The <code>Style</code> to check
+ *
+ * @return true if the <code>Style</code> is a subset, false otherwise.
+ */
+ public boolean isSubset(Style style) {
+ return true;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/StyleCatalog.java b/xmerge/java/org/openoffice/xmerge/converter/xml/StyleCatalog.java
new file mode 100644
index 000000000000..ace085389d96
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/StyleCatalog.java
@@ -0,0 +1,425 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Element;
+import org.openoffice.xmerge.util.*;
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.converter.xml.OfficeDocument;
+import java.io.IOException;
+import org.openoffice.xmerge.converter.xml.sxw.SxwDocument;
+import java.util.Vector;
+import java.lang.reflect.Constructor;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+
+/**
+ * A <code>StyleCatalog</code> holds a collection of <code>Style</code>
+ * objects. It is intended for use when parsing or building a DOM
+ * document.
+ *
+ * Each entry in the <code>StyleCatalog</code> represents a
+ * <code>Style</code>, and is an object which is a subclass of
+ * <code>Style</code>.
+ *
+ * @author David Proulx
+ * @see <a href="Style.html">Style</a>
+ */
+public class StyleCatalog {
+
+ private Vector styles; // The actual styles
+
+ /**
+ * Constructor
+ *
+ * @param initialEntries Expected number of entries to set
+ * for efficiency purposes.
+ */
+ public StyleCatalog(int initialEntries) {
+ styles = new Vector(initialEntries);
+ }
+
+
+ /**
+ * <p>Parse the <code>Document</code> starting from <code>node</code>
+ * and working downward, and add all styles found, so long as their
+ * family name is listed in <code>families</code>. For each
+ * family name in <code>families</code> there must be a corresponding
+ * element in <code>classes</code>, which specifies the class type
+ * to use for that family. All of these classes must be
+ * subclasses of <code>Style</code>. There can be multiple
+ * classes specified for a particular family.</p>
+ *
+ * <p>If <code>defaultClass</code> is non-null, then all styles that
+ * are found will be added. Any <code>Style</code> whose family is
+ * not listed in <code>families</code> will be added using defaultClass,
+ * which, of course, must be a subclass of <code>Style</code>.
+ * If <code>alwaysCreateDefault</code> is true, then a class
+ * of type <code>defaultClass</code> will always be created,
+ * regardless of whether there was also a match in
+ * <code>families</code>.</p>
+ *
+ * <p>DJP Todo: make it recursive so that <code>node</code> can be
+ * higher up in the <code>Document</code> tree.</p>
+ *
+ * @param node The node to be searched for
+ * <code>Style</code> objects.
+ * @param families An array of <code>Style</code> families
+ * to add.
+ * @param classes An array of class types corresponding
+ * to the families array.
+ * @param defaultClass All <code>Style</code> objects that are
+ * found are added to this class.
+ * @param alwaysCreateDefault A class of type <code>defaultClass</code>
+ * will always be created, regardless of
+ * whether there is a match in the
+ * families array.
+ */
+ public void add(Node node, String families[], Class classes[],
+ Class defaultClass, boolean alwaysCreateDefault) {
+
+ if (node == null)
+ return;
+
+ if (families == null)
+ families = new String[0];
+ if (classes == null)
+ classes = new Class[0];
+ if (node.hasChildNodes()) {
+ NodeList children = node.getChildNodes();
+ int len = children.getLength();
+
+ for (int i = 0; i < len; i++) {
+ boolean found = false;
+ Node child = children.item(i);
+ String name = child.getNodeName();
+ if (name.equals("style:default-style") || name.equals("style:style")) {
+ String familyName = getFamilyName(child);
+ if (familyName == null) {
+ Debug.log(Debug.ERROR, "familyName is null!");
+ continue;
+ }
+
+ for (int j = 0; j < families.length; j++) {
+ if (families[j].equals(familyName)) {
+ Class styleClass = classes[j];
+ callConstructor(classes[j], child);
+ found = true;
+ }
+ }
+ if ((!found || alwaysCreateDefault) && (defaultClass != null))
+ callConstructor(defaultClass, child);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Call the constructor of class <code>cls</code> with parameters
+ * <code>node</code>, and add the resulting <code>Style</code> to
+ * the catalog.
+ *
+ * @param cls The class whose constructor will be called.
+ * @param node The constructed class will be added to this node.
+ */
+ private void callConstructor(Class cls, Node node) {
+ Class params[] = new Class[2];
+ params[0] = Node.class;
+ params[1] = this.getClass();
+ try {
+ Constructor c = cls.getConstructor(params);
+ Object p[] = new Object[2];
+ p[0] = node;
+ p[1] = this;
+ styles.add(c.newInstance(p));
+ } catch (Exception e) {
+ Debug.log(Debug.ERROR, "Exception when calling constructor", e);
+ }
+ }
+
+
+ /**
+ * Add a <code>Style</code> to the catalog.
+ *
+ * @param s The <code>Style</code> to add.
+ */
+ public void add(Style s) {
+ styles.addElement(s);
+ }
+
+
+ /**
+ * Return the first <code>Style</code> matching the specified names.
+ *
+ * @param name Name to match, null is considered
+ * <i>always match</i>.
+ * @param family Family to match, null is considered
+ * <i>always match</i>.
+ * @param parent Parent to match, null is considered
+ * <i>always match</i>.
+ * @param styleClass styleClass to match, null is considered
+ * <i>always match</i>.
+ *
+ * @return <code>Style</code> value if all parameters match,
+ * null otherwise
+ */
+ public Style lookup(String name, String family, String parent,
+ Class styleClass) {
+ int nStyles = styles.size();
+ for (int i = 0; i < nStyles; i++) {
+ Style s = (Style)styles.elementAt(i);
+ if ((name != null) && (s.getName() != null)
+ && (!s.getName().equals(name)))
+ continue;
+ if ((family != null) && (s.getFamily() != null)
+ && (!s.getFamily().equals(family)))
+ continue;
+ if ((parent != null) && (s.getParent() != null)
+ && (!s.getParent().equals(parent)))
+ continue;
+ if ((styleClass != null) && (s.getClass() != styleClass))
+ continue;
+ if (s.getName() == null) continue; // DJP: workaround for "null name" problem
+ return s;
+ }
+ return null; // none found
+ }
+
+
+ /**
+ * Given a <code>Style</code> <code>s<code> return all
+ * <code>Style</code> objects that match.
+ *
+ * @param s <code>Style</code> to match.
+ *
+ * @return An array of <code>Style</code> objects that match, an
+ * empty array if none match.
+ */
+ public Style[] getMatching(Style s) {
+
+ // Run through and count the matching styles so we know how big of
+ // an array to allocate.
+ int matchCount = 0;
+ int nStyles = styles.size();
+ for (int j = 0; j < nStyles; j++) {
+ Style p = ((Style)styles.elementAt(j)).getResolved();
+ if (p.isSubset(s)) matchCount++;
+ }
+
+ // Now allocate the array, and run through again, populating it.
+ Style[] matchArray = new Style[matchCount];
+ matchCount = 0;
+ for (int j = 0; j < nStyles; j++) {
+ Style p = ((Style)styles.elementAt(j)).getResolved();
+ if (p.isSubset(s)) matchArray[matchCount++] = p;
+ }
+ return matchArray;
+ }
+
+
+ /**
+ * Given a <code>Style</code> <code>s</code>, return the
+ * <code>style</code> that is the closest match. Not currently
+ * implemented.
+ *
+ * @param s <code>Style</code> to match.
+ *
+ * @return The <code>Style</code> that most closely matches.
+ */
+ public Style getBestMatch(Style s) {
+ // DJP: is this needed?
+ // DJP ToDo: implement this
+ return null;
+ }
+
+
+ /**
+ * <p>Create a <code>Node</code> named <code>name</code> in
+ * <code>Document</code> <code>parentDoc</code>, and write the
+ * entire <code>StyleCatalog</code> to it.</p>
+ *
+ * <p>Note that the resulting node is returned, but is not connected
+ * into the document. Placing the output node in the document is
+ * left to the caller.</p>
+ *
+ * @param parentDoc The <code>Document</code> to add the
+ * <code>Node</code>.
+ * @param name The name of the <code>Node</code> to add.
+ *
+ * @return The <code>Element</code> that was created.
+ */
+ public Element writeNode(org.w3c.dom.Document parentDoc, String name) {
+ Element rootNode = parentDoc.createElement(name);
+
+ int len = styles.size();
+ for (int j = 0; j < len; j++) {
+ Style s = (Style)styles.get(j);
+
+ Element styleNode = parentDoc.createElement("style:style");
+
+ if (s.getName() != null)
+ styleNode.setAttribute("style:name", s.getName());
+ if (s.getParent() != null)
+ styleNode.setAttribute("style:parent-style-name", s.getParent());
+ if (s.getFamily() != null)
+ styleNode.setAttribute("style:family", s.getFamily());
+
+ Element propertiesNode = (Element) s.createNode(parentDoc, "style:properties");
+ // if (propertiesNode.getFirstChild() != null)
+ // DJP: only add node if has children OR attributes
+ if (propertiesNode != null)
+ styleNode.appendChild(propertiesNode);
+
+ rootNode.appendChild(styleNode);
+ }
+
+ return rootNode;
+ }
+
+
+ /**
+ * Dump the <code>Style</code> table in Comma Separated Value (CSV)
+ * format
+ *
+ * @param para If true, dump in paragraph <code>Style</code>,
+ * otherwise dump in text style.
+ */
+ public void dumpCSV(boolean para) {
+ if (!para) {
+ TextStyle.dumpHdr();
+ int nStyles = styles.size();
+ for (int i = 0; i < nStyles; i++) {
+ Style s = (Style)styles.get(i);
+ if (s.getClass().equals(TextStyle.class))
+ ((TextStyle)s).dumpCSV();
+ }
+ } else {
+ ParaStyle.dumpHdr();
+ int nStyles = styles.size();
+ for (int i = 0; i < nStyles; i++) {
+ Style s = (Style)styles.get(i);
+ if (s.getClass().equals(ParaStyle.class))
+ ((ParaStyle)s).dumpCSV();
+ }
+ }
+
+ }
+
+
+ /**
+ * Check whether a given node represents a <code>Style</code>
+ * that should be added to the catalog, and if so, return the
+ * class type for it. If <code>Style</code> should not be added,
+ * or if node is not a <code>Style</code>, return null.
+ *
+ * @param node The <code>Node</code> to be checked.
+ * @param families An array of <code>Style</code> families.
+ * @param classes An array of class types corresponding to the
+ * families array.
+ * @param defaultClass The default class.
+ *
+ * @return The class that is appropriate for this node.
+ */
+ private Class getClass(Node node, String[] families, Class[] classes,
+ Class defaultClass) {
+ NamedNodeMap attributes = node.getAttributes();
+ if (attributes != null) {
+ int len = attributes.getLength();
+ for (int i = 0; i < len; i++) {
+ Node attr = attributes.item(i);
+ if (attr.getNodeName().equals("style:family")) {
+ String familyName = attr.getNodeValue();
+ for (int j = 0; j < families.length; j++) {
+ if (families[j].equals(familyName))
+ return classes[j];
+ }
+ return defaultClass;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Find the family attribute of a <code>Style</code> <code>Node</code>.
+ *
+ * @param node The <code>Node</code> to check.
+ *
+ * @return The family attribute, or null if one does not
+ * exist.
+ */
+ private String getFamilyName(Node node) {
+ NamedNodeMap attributes = node.getAttributes();
+ if (attributes != null) {
+ int len = attributes.getLength();
+ for (int i = 0; i < len; i++) {
+ Node attr = attributes.item(i);
+ if (attr.getNodeName().equals("style:family")) {
+ return attr.getNodeValue();
+ }
+ }
+ }
+ return null;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/StyleTest01.xml b/xmerge/java/org/openoffice/xmerge/converter/xml/StyleTest01.xml
new file mode 100644
index 000000000000..ac2652c49ee6
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/StyleTest01.xml
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document office:class="text" office:version="0.9" xmlns:office="http://openoffice.org/2000/office" xmlns:style="http://openoffice.org/2000/style" xmlns:text="http://openoffice.org/2000/text" xmlns:table="http://openoffice.org/2000/table" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="http://openoffice.org/2000/meta" xmlns:number="http://openoffice.org/2000/datastyle" xmlns:svg="http://www.w3.org/2000/svg" xmlns:chart="http://openoffice.org/2000/chart" xmlns:dr3d="http://openoffice.org/2000/dr3d" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="http://openoffice.org/2000/form" xmlns:script="http://openoffice.org/2000/script" xmlns:zensync="haha">
+
+ <!-- styles01 is four styles, named "TX01" through "TX04". Each is a
+ child of its predecessor. They define properties as follows:
+ fo:margin-right fo:margin-top fo:margin-bottom
+ TX01 100 300
+ TX02
+ TX03 200
+ TX04 301
+ When inheritance is considered, the properties look like this:
+ fo:margin-right fo:margin-top fo:margin-bottom
+ TX01 100 300
+ TX02 100 300
+ TX03 100 200 300
+ TX04 100 200 301
+ DJP: change prop1, prop2, prop3 to paragraph or text properties so
+ the actual classes can be tested.
+ -->
+ <zensync:styles01>
+
+ <style:style style:name="TX01" style:family="text"
+ style:class="text">
+ <style:properties fo:margin-right="100" fo:margin-bottom="300"/>
+ </style:style>
+
+ <style:style style:name="TX02" style:family="text"
+ style:parent-style-name="TX01" style:class="text">
+ </style:style>
+
+ <style:style style:name="TX03" style:family="text"
+ style:parent-style-name="TX02" style:class="text">
+ <style:properties fo:margin-top="200" />
+ </style:style>
+
+ <style:style style:name="TX04" style:family="text"
+ style:parent-style-name="TX03" style:class="text">
+ <style:properties fo:margin-bottom="301" />
+ </style:style>
+
+ </zensync:styles01>
+
+
+
+ <office:styles>
+ <style:default-style style:family="paragraph">
+ <style:properties fo:color="#000000" style:font-name="Times New Roman" fo:font-size="12pt" fo:language="en" fo:country="US" style:font-name-asian="Andale WT UI" style:font-size-asian="12pt" style:language-asian="none" style:country-asian="none" style:font-name-complex="Simplified Arabic" style:font-size-complex="12pt" style:language-complex="none" style:country-complex="none" style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" style:line-break="strict">
+ <style:tab-stops>
+ <style:tab-stop style:position="22.05mm" style:type="default"/>
+ </style:tab-stops>
+ </style:properties>
+ </style:default-style>
+ <style:style style:name="Standard" style:family="paragraph" style:class="text"/>
+ <style:style style:name="Heading" style:family="paragraph" style:parent-style-name="Standard" style:next-style-name="Text body" style:class="text">
+ <style:properties style:font-name="Arial" fo:font-size="14pt" fo:margin-top="4.23mm" fo:margin-bottom="2.12mm" fo:keep-with-next="true"/>
+ </style:style>
+ <style:style style:name="Text body" style:family="paragraph" style:parent-style-name="Standard" style:class="text">
+ <style:properties fo:margin-top="0mm" fo:margin-bottom="2.12mm"/>
+ </style:style>
+ <style:style style:name="List" style:family="paragraph" style:parent-style-name="Text body" style:class="list">
+ <style:properties style:font-name="Times New Roman"/>
+ </style:style>
+ <style:style style:name="Caption" style:family="paragraph" style:parent-style-name="Standard" style:class="extra">
+ <style:properties style:font-name="Times New Roman" fo:font-size="10pt" fo:font-style="italic" fo:margin-top="2.12mm" fo:margin-bottom="2.12mm" text:number-lines="false" text:line-number="0"/>
+ </style:style>
+ <style:style style:name="Index" style:family="paragraph" style:parent-style-name="Standard" style:class="index">
+ <style:properties style:font-name="Times New Roman" text:number-lines="false" text:line-number="0"/>
+ </style:style>
+ <style:style style:name="Heading 1" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text body" style:class="text">
+ <style:properties fo:font-size="16pt" fo:font-weight="bold"/>
+ </style:style>
+ <style:style style:name="Heading 2" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text body" style:class="text">
+ <style:properties fo:font-size="14pt" fo:font-style="italic" fo:font-weight="bold"/>
+ </style:style>
+ <style:style style:name="Heading 3" style:family="paragraph" style:parent-style-name="Heading" style:next-style-name="Text body" style:class="text">
+ <style:properties fo:font-size="14pt" fo:font-weight="bold"/>
+ </style:style>
+ <style:style style:name="First line indent" style:family="paragraph" style:parent-style-name="Text body" style:class="text">
+ <style:properties fo:margin-left="0mm" fo:margin-right="0mm" fo:text-indent="4.99mm"/>
+ </style:style>
+ <style:style style:name="Hanging indent" style:family="paragraph" style:parent-style-name="Text body" style:class="text">
+ <style:properties fo:margin-left="10mm" fo:margin-right="0mm" fo:text-indent="-4.99mm">
+ <style:tab-stops>
+ <style:tab-stop style:position="0mm"/>
+ </style:tab-stops>
+ </style:properties>
+ </style:style>
+ <style:style style:name="Marginalia" style:family="paragraph" style:parent-style-name="Text body" style:class="text">
+ <style:properties fo:margin-left="40.01mm" fo:margin-right="0mm" fo:text-indent="0mm"/>
+ </style:style>
+ <style:style style:name="Salutation" style:family="paragraph" style:parent-style-name="Standard" style:class="text">
+ <style:properties text:number-lines="false" text:line-number="0"/>
+ </style:style>
+ <style:style style:name="Strong Emphasis" style:family="text">
+ <style:properties fo:font-weight="bold"/>
+ </style:style>
+ <style:style style:name="Example" style:family="text">
+ <style:properties style:font-name="Courier"/>
+ </style:style>
+ <style:style style:name="Definition" style:family="text"/>
+ <style:style style:name="Line numbering" style:family="text"/>
+ <style:default-style style:family="graphics">
+ <style:properties svg:width="0mm" svg:height="0mm" text:anchor-type="page" text:anchor-page-number="0" svg:x="0mm" svg:y="0mm" style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" style:vertical-pos="from-top" style:vertical-rel="page-content" style:horizontal-pos="from-left" style:horizontal-rel="paragraph-content" fo:background-color="transparent" fo:padding="0mm" style:editable="false"/>
+ </style:default-style>
+ <style:style style:name="Frame" style:family="graphics">
+ <style:properties text:anchor-type="paragraph" svg:x="0mm" svg:y="0mm" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" style:vertical-pos="top" style:vertical-rel="paragraph-content" style:horizontal-pos="center" style:horizontal-rel="paragraph-content" fo:padding="1.5mm" fo:border="0.02mm solid #000000"/>
+ </style:style>
+ <text:outline-style>
+ <text:outline-level-style text:level="1" style:num-format=""/>
+ <text:outline-level-style text:level="2" style:num-format=""/>
+ <text:outline-level-style text:level="3" style:num-format=""/>
+ <text:outline-level-style text:level="4" style:num-format=""/>
+ <text:outline-level-style text:level="5" style:num-format=""/>
+ <text:outline-level-style text:level="6" style:num-format=""/>
+ <text:outline-level-style text:level="7" style:num-format=""/>
+ <text:outline-level-style text:level="8" style:num-format=""/>
+ <text:outline-level-style text:level="9" style:num-format=""/>
+ <text:outline-level-style text:level="10" style:num-format=""/>
+ </text:outline-style>
+ <text:footnotes-configuration style:num-format="1" text:offset="0" text:footnotes-position="page" text:start-numbering-at="document"/>
+ <text:endnotes-configuration style:num-format="i" text:offset="0"/>
+ <text:bibliography-configuration text:prefix="[" text:suffix="]"/>
+ <text:linenumbering-configuration text:style-name="Line numbering" text:number-lines="false" text:offset="4.99mm" style:num-format="1" text:number-position="left" text:increment="5"/>
+ </office:styles>
+ <office:automatic-styles>
+ <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard">
+ <style:properties fo:font-style="normal" fo:font-weight="normal"/>
+ </style:style>
+ <style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard">
+ <style:properties fo:line-height="200%" fo:margin-top="6mm" fo:margin-bottom="20mm"/>
+ </style:style>
+ <style:style style:name="T1" style:family="text">
+ <style:properties fo:font-style="italic"/>
+ </style:style>
+ <style:style style:name="T2" style:family="text">
+ <style:properties fo:font-style="normal"/>
+ </style:style>
+ <style:style style:name="T3" style:family="text">
+ <style:properties fo:font-style="normal" fo:font-weight="bold"/>
+ </style:style>
+ <style:style style:name="T4" style:family="text">
+ <style:properties fo:font-style="normal" fo:font-weight="normal"/>
+ </style:style>
+ <style:style style:name="T5" style:family="text">
+ <style:properties style:text-underline="double" style:text-underline-color="#000000"/>
+ </style:style>
+ <style:style style:name="T6" style:family="text">
+ <style:properties style:text-underline="single" style:text-underline-color="#000000"/>
+ </style:style>
+ <style:style style:name="T7" style:family="text" style:parent-style-name="Example">
+ <style:properties fo:font-size="24pt"/>
+ </style:style>
+ <style:style style:name="T8" style:family="text" style:parent-style-name="Definition">
+ <style:properties fo:font-size="24pt"/>
+ </style:style>
+ <style:page-master style:name="pm1">
+ <style:properties fo:page-width="209.99mm" fo:page-height="296.99mm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="25.4mm" fo:margin-bottom="25.4mm" fo:margin-left="31.75mm" fo:margin-right="31.75mm"/>
+ <style:header-style/>
+ <style:footer-style/>
+ </style:page-master>
+ </office:automatic-styles>
+ <office:master-styles>
+ <style:master-page style:name="Standard" style:page-master-name="pm1"/>
+ </office:master-styles>
+</office:document>
+
+
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java b/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java
new file mode 100644
index 000000000000..a34060341192
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java
@@ -0,0 +1,712 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+// DJP ToDo: need way of specifying fg/bg colors on ws->DOM
+
+package org.openoffice.xmerge.converter.xml;
+
+import java.awt.Color;
+import java.io.IOException;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Element;
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.converter.xml.OfficeDocument;
+import org.openoffice.xmerge.converter.xml.sxw.SxwDocument;
+import org.openoffice.xmerge.util.Debug;
+
+/**
+ * Represents a text <code>Style</code> in an OpenOffice document.
+ *
+ * @author David Proulx
+ */
+public class TextStyle extends Style implements Cloneable {
+
+ final protected static int FIRST_ATTR = 0x01;
+ /** Indicates <i>bold</i> text. */
+ final public static int BOLD = 0x01;
+ /** Indicates <i>italic</i> text. */
+ final public static int ITALIC = 0x02;
+ /** Indicates <i>underlined</i> text. */
+ final public static int UNDERLINE = 0x04;
+ /** Indicates <i>strike-through</i> in the text. */
+ final public static int STRIKETHRU = 0x08;
+ /** Indicates <i>superscripted</i> text. */
+ final public static int SUPERSCRIPT = 0x10;
+ /** Indicates <i>subscripted</i> text. */
+ final public static int SUBSCRIPT = 0x20;
+ /** Indicates the last attribute. */
+ final protected static int LAST_ATTR = 0x20;
+
+ /** Values of text attributes. */
+ protected int values = 0;
+ /** Bitwise mask of text attributes. */
+ protected int mask = 0;
+
+ /** Font size in points. */
+ protected int sizeInPoints = 0;
+ /** Font name. */
+ protected String fontName = null;
+ /** Font <code>Color</code>. */
+ protected Color fontColor = null;
+ /** Background <code>Color</code>. */
+ protected Color bgColor = null;
+
+ /**
+ * Constructor for use when going from DOM to client device format.
+ *
+ * @param Node The <i>style:style</i> <code>Node</code> containing
+ * the <code>Style</code>. (This <code>Node</code> is
+ * assumed have a <i>family</i> attribute of <i>text</i>).
+ * @param sc The <code>StyleCatalog</code>, which is used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ public TextStyle(Node node, StyleCatalog sc) {
+ super(node, sc);
+
+ // Run through the attributes of this node, saving
+ // the ones we're interested in.
+ NamedNodeMap attrNodes = node.getAttributes();
+ if (attrNodes != null) {
+ int len = attrNodes.getLength();
+ for (int i = 0; i < len; i++) {
+ Node attr = attrNodes.item(i);
+ handleAttribute(attr.getNodeName(), attr.getNodeValue());
+ }
+ }
+
+ // Look for children. Only ones we care about are "style:properties"
+ // nodes. If any are found, recursively traverse them, passing
+ // along the style element to add properties to.
+ if (node.hasChildNodes()) {
+ NodeList children = node.getChildNodes();
+ int len = children.getLength();
+ for (int i = 0; i < len; i++) {
+ Node child = children.item(i);
+ String name = child.getNodeName();
+ if (name.equals("style:properties")) {
+ NamedNodeMap childAttrNodes = child.getAttributes();
+ if (childAttrNodes != null) {
+ int nChildAttrNodes = childAttrNodes.getLength();
+ for (int j = 0; j < nChildAttrNodes; j++) {
+ Node attr = childAttrNodes.item(j);
+ handleAttribute(attr.getNodeName(),
+ attr.getNodeValue());
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Constructor for use when going from client device format to DOM
+ *
+ * @param name Name of text <code>Style</code>. Can be null.
+ * @param family Family of text <code>Style</code> (usually
+ * <i>text</i>). Can be null.
+ * @param parent Name of parent text <code>Style</code>, or null
+ * for none.
+ * @param mask Bitwise mask of text attributes that this text
+ * <code>Style</code> will specify. Can be any
+ * combination of the following, or'ed together:
+ * {@link #BOLD}, {@link #ITALIC}, {@link #UNDERLINE},
+ * {@link #STRIKETHRU}, {@link #SUPERSCRIPT},
+ * {@link #SUBSCRIPT}. This parameter determines what
+ * attributes this <code>Style</code> will specify.
+ * When an attribute is specified in a
+ * <code>Style</code>, its value can be either
+ * <i>on</i> or <i>off</i>. The on/off value for
+ * each attribute is controlled by the
+ * <code>values</code> parameter.
+ * @param values Values of text attributes that this text
+ * <code>Style</code> will be setting. Any of the
+ * attributes ({@link #BOLD}, etc) listed for
+ * <code>mask</code> can be used for this.
+ * @param fontSize Font size in points.
+ * @param fontName Name of font.
+ * @param sc The <code>StyleCatalog</code>, which is used for
+ * looking up ancestor <code>Style</code> objects.
+ */
+ public TextStyle(String name, String family, String parent,
+ int mask, int values, int fontSize, String fontName, StyleCatalog sc) {
+ super(name, family, parent, sc);
+ this.mask = mask;
+ this.values = values;
+ this.sizeInPoints = fontSize;
+ this.fontName = fontName;
+ }
+
+
+ /**
+ * Parse a color specification of the form <i>#rrggbb</i>
+ *
+ * @param value <code>Color</code> specification to parse.
+ *
+ * @returns The <code>Color</code> associated the value.
+ */
+ private Color parseColorString(String value) {
+ // Assume color value is of form #rrggbb
+ String r = value.substring(1, 3);
+ String g = value.substring(3, 5);
+ String b = value.substring(5, 7);
+ int red = 0;
+ int green = 0;
+ int blue = 0;
+ try {
+ red = Integer.parseInt(r, 16);
+ green = Integer.parseInt(g, 16);
+ blue = Integer.parseInt(b, 16);
+ } catch (NumberFormatException e) {
+ Debug.log(Debug.ERROR, "Problem parsing a color string", e);
+ }
+ return new Color(red, green, blue);
+ }
+
+
+ /**
+ * Set an attribute.
+ *
+ * @param attr The attribute to set.
+ * @param value The attribute value to set.
+ */
+ private void handleAttribute(String attr, String value) {
+
+ if (attr.equals("fo:font-weight")) {
+ if (value.equals("bold")) turnAttributesOn(BOLD);
+ else if (value.equals("normal")) turnAttributesOff(BOLD);
+ }
+
+ else if (attr.equals("fo:font-style")) {
+ if (value.equals("italic")) turnAttributesOn(ITALIC);
+ else if (value.equals("oblique")) turnAttributesOn(ITALIC);
+ else if (value.equals("normal")) turnAttributesOff(ITALIC);
+ }
+
+ else if (attr.equals("style:text-underline")) {
+ if (value.equals("none"))
+ turnAttributesOff(UNDERLINE);
+ else
+ turnAttributesOn(UNDERLINE);
+ }
+
+ else if (attr.equals("style:text-crossing-out")) {
+ if (value.equals("none"))
+ turnAttributesOff(STRIKETHRU);
+ else
+ turnAttributesOn(STRIKETHRU);
+ }
+
+ else if (attr.equals("style:text-position")) {
+ if (value.startsWith("super "))
+ turnAttributesOn(SUPERSCRIPT);
+ else if (value.startsWith("sub "))
+ turnAttributesOn(SUBSCRIPT);
+ else if (value.startsWith("0% "))
+ turnAttributesOff(SUPERSCRIPT | SUBSCRIPT);
+ else {
+ String firstPart = value.substring(0, value.indexOf(" "));
+ if (firstPart.endsWith("%")) {
+ firstPart = firstPart.substring(0, value.indexOf("%"));
+ int amount;
+ try {
+ amount = Integer.parseInt(firstPart);
+ } catch (NumberFormatException e) {
+ amount = 0;
+ Debug.log(Debug.ERROR, "Problem with style:text-position tag", e);
+ }
+ if (amount < 0) turnAttributesOn(SUBSCRIPT);
+ else if (amount > 0) turnAttributesOn(SUPERSCRIPT);
+ }
+ }
+ }
+
+ else if (attr.equals("fo:font-size")) {
+ if (value.endsWith("pt")) {
+ String num = value.substring(0, value.length() - 2);
+ sizeInPoints = Integer.parseInt(num);
+ }
+ }
+
+ else if (attr.equals("style:font-name"))
+ fontName = value;
+
+ else if (attr.equals("fo:color"))
+ fontColor = parseColorString(value);
+
+ else if (attr.equals("style:text-background-color"))
+ bgColor = parseColorString(value);
+
+ else if (isIgnored(attr)) {}
+
+ else {
+ Debug.log(Debug.INFO, "TextStyle Unhandled: " + attr + "=" + value);
+ }
+ }
+
+
+ /**
+ * Return true if text <code>attribute</code> is set in this
+ * <code>Style</code>. An attribute that is set may have a
+ * value of <i>on</i> or <i>off</i>.
+ *
+ * @param attribute The attribute to check ({@link #BOLD},
+ * {@link #ITALIC}, etc.).
+ *
+ * @return true if text <code>attribute</code> is set in this
+ * <code>Style</code>, false otherwise.
+ */
+ public boolean isSet(int attribute) {
+ return (!((mask & attribute) == 0));
+ }
+
+
+ /**
+ * Return true if the <code>attribute</code> is set to <i>on</i>
+ *
+ * @param attribute Attribute to check ({@link #BOLD},
+ * {@link #ITALIC}, etc.)
+ *
+ * @return true if <code>attribute</code> is set to <i>on</i>,
+ * otherwise false.
+ */
+ public boolean getAttribute(int attribute) {
+ if ((mask & attribute) == 0)
+ return false;
+ return (!((values & attribute) == 0));
+ }
+
+
+ /**
+ * Return the font size for this <code>Style</code>.
+ *
+ * @return The font size in points
+ */
+ public int getFontSize() {
+ return sizeInPoints;
+ }
+
+
+ /**
+ * Return the name of the font for this <code>Style</code>.
+ *
+ * @return Name of font, or null if no font is specified by
+ * this <code>Style</code>.
+ */
+ public String getFontName() {
+ return fontName;
+ }
+
+
+ /**
+ * Return the font <code>Color</code> for this <code>Style</code>.
+ * Can be null if none was specified.
+ *
+ * @return <code>Color</code> value for this <code>Style</code>.
+ * Can be null.
+ */
+ public Color getFontColor() {
+ return fontColor;
+ }
+
+
+ /**
+ * Return the background <code>Color</code> for this
+ * <code>Style</code>. Can be null if none was specified.
+ *
+ * @return Background <code>Color</code> value for this
+ * <code>Style</code>. Can be null.
+ */
+ public Color getBackgroundColor() {
+ return bgColor;
+ }
+
+
+ /**
+ * Set the font and/or background <code>Color</code> for this
+ * <code>Style</code>.
+ *
+ * @param fontColor The font <code>Color</code> to set.
+ * @param backgroundColor The background <code>Color</code> to set.
+ */
+ public void setColors(Color fontColor, Color backgroundColor) {
+ if (fontColor != null)
+ this.fontColor = fontColor;
+ if (backgroundColor != null)
+ this.bgColor = backgroundColor;
+ }
+
+
+ /**
+ * Return a <code>Style</code> object corresponding to this one,
+ * but with all of the inherited information from parent
+ * <code>Style</code> objects filled in. The object returned will
+ * be a new object, not a reference to this object, even if it does
+ * not need any information added.
+ *
+ * @return The <code>StyleCatalog</code> in which to look up
+ * ancestors.
+ */
+ public Style getResolved() {
+ // Create a new object to return, which is a clone of this one.
+ TextStyle resolved = null;
+ try {
+ resolved = (TextStyle)this.clone();
+ } catch (Exception e) {
+ Debug.log(Debug.ERROR, "Can't clone", e);
+ }
+
+ // Look up the parentStyle. (If there is no style catalog
+ // specified, we can't do any lookups.)
+ TextStyle parentStyle = null;
+ if (sc != null) {
+ if (parent != null) {
+ parentStyle = (TextStyle)sc.lookup(parent, family, null,
+ this.getClass());
+ if (parentStyle == null)
+ Debug.log(Debug.ERROR, "parent style lookup of "
+ + parent + " failed!");
+ else
+ parentStyle = (TextStyle)parentStyle.getResolved();
+
+ } else if (!name.equals("DEFAULT_STYLE")) {
+ parentStyle = (TextStyle)sc.lookup("DEFAULT_STYLE", null,
+ null, this.getClass());
+ }
+ }
+
+ // If we found a parent, for any attributes which we don't have
+ // set, try to get the values from the parent.
+ if (parentStyle != null) {
+ parentStyle = (TextStyle)parentStyle.getResolved();
+
+ if ((sizeInPoints == 0) && (parentStyle.sizeInPoints != 0))
+ resolved.sizeInPoints = parentStyle.sizeInPoints;
+ if ((fontName == null) && (parentStyle.fontName != null))
+ resolved.fontName = parentStyle.fontName;
+ if ((fontColor == null) && (parentStyle.fontColor != null))
+ resolved.fontColor = parentStyle.fontColor;
+ if ((bgColor == null) && (parentStyle.bgColor != null))
+ resolved.bgColor = parentStyle.bgColor;
+ for (int m = BOLD; m <= SUBSCRIPT; m = m << 1) {
+ if (((mask & m) == 0) && ((parentStyle.mask & m) != 0)) {
+ resolved.mask |= m;
+ resolved.values |= (parentStyle.mask & m);
+ }
+ }
+
+ }
+ return resolved;
+ }
+
+
+ /**
+ * Set one or more text attributes to <i>on</i>.
+ *
+ * @param flags Flag values to set <i>on</i>.
+ */
+ private void turnAttributesOn(int flags) {
+ mask |= flags;
+ values |= flags;
+ }
+
+
+ /**
+ * Set one or more text attributes to <i>off</i>.
+ *
+ * @param flags The flag values to set <i>off</i>.
+ */
+ private void turnAttributesOff(int flags) {
+ mask |= flags;
+ values &= ~flags;
+ }
+
+
+ /**
+ * Private function to return the value as an element in
+ * a Comma Separated Value (CSV) format.
+ *
+ * @param The value to format.
+ *
+ * @return The formatted value.
+ */
+ private static String toCSV(String value) {
+ if (value != null)
+ return "\"" + value + "\",";
+ else
+ return "\"\",";
+ }
+
+
+ /**
+ * Private function to return the value as a last element in
+ * a Comma Separated Value (CSV) format.
+ *
+ * @param value The value to format.
+ *
+ * @return The formatted value.
+ */
+ private static String toLastCSV(String value) {
+ if (value != null)
+ return "\"" + value + "\"";
+ else
+ return "\"\"";
+ }
+
+
+ /**
+ * Print a Comma Separated Value (CSV) header line for the
+ * spreadsheet dump.
+ */
+ public static void dumpHdr() {
+ System.out.println(toCSV("Name") + toCSV("Family") + toCSV("parent")
+ + toCSV("Font") + toCSV("Size")
+ + toCSV("Bold") + toCSV("Italic") + toCSV("Underline")
+ + toCSV("Strikethru") + toCSV("Superscript") + toLastCSV("Subscript"));
+ }
+
+
+ /**
+ * Dump this <code>Style</code> as a Comma Separated Value (CSV) line.
+ */
+ public void dumpCSV() {
+ String attributes = "";
+ for (int bitVal = 0x01; bitVal <= 0x20; bitVal = bitVal << 1) {
+ if ((bitVal & mask) != 0) {
+ attributes += toCSV(((bitVal & values) != 0) ? "yes" : "no");
+ } else attributes += toCSV(null); // unspecified
+ }
+ System.out.println(toCSV(name) + toCSV(family) + toCSV(parent)
+ + toCSV(fontName) + toCSV("" + sizeInPoints) + attributes + toLastCSV(null));
+ }
+
+
+ /**
+ * Create a new <code>Node</code> in the <code>Document</code>, and
+ * write this <code>Style</code> to it.
+ *
+ * @param parentDoc Parent <code>Document</code> of the
+ * <code>Node</code> to create.
+ * @param name Name to use for the new <code>Node</code> (e.g.
+ * <i>style:style</i>)
+ *
+ * @return Created <code>Node</code>.
+ */
+ public Node createNode(org.w3c.dom.Document parentDoc, String name) {
+ Element node = parentDoc.createElement(name);
+ writeAttributes(node);
+ return node;
+ }
+
+
+ /**
+ * Return true if <code>style</code> specifies as much or less
+ * than this <code>Style</code>, and nothing it specifies
+ * contradicts this <code>Style</code>.
+ *
+ * @param style The <code>Style</code> to check.
+ *
+ * @return true if <code>style</code> is a subset, false
+ * otherwise.
+ */
+ public boolean isSubset(Style style) {
+ if (style.getClass() != this.getClass())
+ return false;
+ TextStyle tStyle = (TextStyle)style;
+
+ if (tStyle.values != values)
+ return false;
+
+ if (tStyle.sizeInPoints != 0) {
+ if (sizeInPoints != tStyle.sizeInPoints)
+ return false;
+ }
+
+ if (tStyle.fontName != null) {
+ if (fontName == null)
+ return false;
+ if (!fontName.equals(tStyle.fontName))
+ return false;
+ }
+
+ if (tStyle.fontColor != null) {
+ if (fontColor == null)
+ return false;
+ if (!fontColor.equals(tStyle.fontColor))
+ return false;
+ }
+
+ if (tStyle.bgColor != null) {
+ if (bgColor == null)
+ return false;
+ if (!bgColor.equals(tStyle.bgColor))
+ return false;
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Write this <code>Style</code> object's attributes to a
+ * <code>Node</code> in the <code>Document</code>.
+ *
+ * @param node The <code>Node</code> to add <code>Style</code>
+ * attributes.
+ */
+ public void writeAttributes(Element node) {
+
+ if ((mask & BOLD) != 0)
+ if ((values & BOLD) != 0)
+ node.setAttribute("fo:font-weight", "bold");
+
+ if ((mask & ITALIC) != 0)
+ if ((values & ITALIC) != 0)
+ node.setAttribute("fo:font-style", "italic");
+
+ if ((mask & UNDERLINE) != 0)
+ if ((values & UNDERLINE) != 0)
+ node.setAttribute("style:text-underline", "single");
+
+ if ((mask & STRIKETHRU) != 0)
+ if ((values & STRIKETHRU) != 0)
+ node.setAttribute("style:text-crossing-out", "single-line");
+
+ if ((mask & SUPERSCRIPT) != 0)
+ if ((values & SUPERSCRIPT) != 0)
+ node.setAttribute("style:text-position", "super 58%");
+
+ if ((mask & SUBSCRIPT) != 0)
+ if ((values & SUBSCRIPT) != 0)
+ node.setAttribute("style:text-position", "sub 58%");
+
+ if (sizeInPoints != 0) {
+ Integer fs = new Integer(sizeInPoints);
+ node.setAttribute("fo:font-size", fs.toString() + "pt");
+ }
+
+ if (fontName != null)
+ node.setAttribute("style:font-name", fontName);
+
+ if (fontColor != null)
+ node.setAttribute("fo:color", buildColorString(fontColor));
+
+ if (bgColor != null)
+ node.setAttribute("style:text-background-color",
+ buildColorString(bgColor));
+ }
+
+
+ /**
+ * Given a <code>Color</code>, return a string of the form
+ * <i>#rrggbb</i>.
+ *
+ * @param c The <code>Color</code> value.
+ *
+ * @return The <code>Color</code> value in the form <i>#rrggbb</i>.
+ */
+ private String buildColorString(Color c) {
+ int v[] = new int[3];
+ v[0] = c.getRed();
+ v[1] = c.getGreen();
+ v[2] = c.getBlue();
+ String colorString = new String("#");
+ for (int i = 0; i <= 2; i++) {
+ String xx = Integer.toHexString(v[i]);
+ if (xx.length() < 2)
+ xx = "0" + xx;
+ colorString += xx;
+ }
+ return colorString;
+ }
+
+
+ private static String[] ignored = {
+ "style:text-autospace", "style:text-underline-color",
+ "fo:margin-left", "fo:margin-right", "fo:text-indent",
+ "fo:margin-top", "fo:margin-bottom", "text:line-number",
+ "text:number-lines", "style:country-asian",
+ "style:font-size-asian", "style:font-name-complex",
+ "style:language-complex", "style:country-complex",
+ "style:font-size-complex", "style:punctuation-wrap",
+ "fo:language", "fo:country",
+ "style:font-name-asian", "style:language-asian",
+ "style:line-break", "fo:keep-with-next"
+ };
+
+
+ /*
+ * This code checks whether an attribute is one that we
+ * intentionally ignore.
+ *
+ * @param attribute The attribute to check.
+ *
+ * @return true if <code>attribute</code> can be ignored,
+ * otherwise false.
+ */
+ private boolean isIgnored(String attribute) {
+ for (int i = 0; i < ignored.length; i++) {
+ if (ignored[i].equals(attribute))
+ return true;
+ }
+ return false;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/build.xml b/xmerge/java/org/openoffice/xmerge/converter/xml/build.xml
new file mode 100644
index 000000000000..0ca9c305cbeb
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/build.xml
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_jooxc_xml" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_jooxc_xml"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package"
+ value="org/openoffice/xmerge/converter/xml"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/OfficeConstants.java"/>
+ <include name="${package}/OfficeZip.java"/>
+ <include name="${package}/OfficeDocument.java"/>
+ <include name="${package}/OfficeDocumentException.java"/>
+ <include name="${package}/ParaStyle.java"/>
+ <include name="${package}/StyleCatalog.java"/>
+ <include name="${package}/Style.java"/>
+ <include name="${package}/TextStyle.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/makefile.mk b/xmerge/java/org/openoffice/xmerge/converter/xml/makefile.mk
new file mode 100644
index 000000000000..40d3b41d675d
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_jooxc_xml
+PRJ=../../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/package.html b/xmerge/java/org/openoffice/xmerge/converter/xml/package.html
new file mode 100644
index 000000000000..6a609d8822be
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/package.html
@@ -0,0 +1,66 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge.util package</title>
+</head>
+
+<body bgcolor="white">
+
+<p><code>Document</code> and <code>PluginFactory</code> implementations
+for XML based formats.
+
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/DocumentMergerImpl.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/DocumentMergerImpl.java
new file mode 100644
index 000000000000..0e2530d58f24
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/DocumentMergerImpl.java
@@ -0,0 +1,227 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxc;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.DocumentMerger;
+import org.openoffice.xmerge.MergeException;
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+import org.openoffice.xmerge.merger.DiffAlgorithm;
+import org.openoffice.xmerge.merger.Difference;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.merger.DiffAlgorithm;
+import org.openoffice.xmerge.merger.NodeMergeAlgorithm;
+import org.openoffice.xmerge.merger.diff.IteratorRowCompare;
+import org.openoffice.xmerge.merger.diff.RowIterator;
+import org.openoffice.xmerge.merger.merge.SheetMerge;
+import org.openoffice.xmerge.merger.merge.PositionBaseRowMerge;
+import org.openoffice.xmerge.merger.MergeAlgorithm;
+import org.openoffice.xmerge.util.XmlUtil;
+import org.openoffice.xmerge.util.Debug;
+
+
+/**
+ * Generic small device implementation of <code>DocumentMerger</code> for
+ * the {@link
+ * org.openoffice.xmerge.converter.xml.sxc.SxcPluginFactory
+ * SxcPluginFactory}. Used with SXC <code>Document</code> objects.</p>
+ */
+public class DocumentMergerImpl implements DocumentMerger {
+
+ private ConverterCapabilities cc_;
+ private org.openoffice.xmerge.Document orig = null;
+
+ /**
+ * Constructor
+ *
+ * @param doc The original &quot;Office&quot; <code>Document</code>
+ * to merge.
+ * @param cc The <code>ConverterCapabilities</code>.
+ */
+ public DocumentMergerImpl(org.openoffice.xmerge.Document doc, ConverterCapabilities cc) {
+ cc_ = cc;
+ this.orig = doc;
+ }
+
+ public void merge(Document modifiedDoc) throws MergeException {
+
+ SxcDocument sdoc1 = (SxcDocument)orig;
+ SxcDocument sdoc2 = (SxcDocument)modifiedDoc;
+
+ org.w3c.dom.Document doc1 = sdoc1.getContentDOM();
+ org.w3c.dom.Document doc2 = sdoc2.getContentDOM();
+
+ Element elem1 = doc1.getDocumentElement();
+ Element elem2 = doc2.getDocumentElement();
+
+ // get table name
+ NodeList workSheetList1 =
+ elem1.getElementsByTagName(OfficeConstants.TAG_TABLE);
+ NodeList workSheetList2 =
+ elem2.getElementsByTagName(OfficeConstants.TAG_TABLE);
+
+ int numOfWorkSheet = workSheetList1.getLength();
+
+ for (int i=0; i < numOfWorkSheet; i++) {
+ Node workSheet = workSheetList1.item(i);
+
+ // try to match the workSheet
+ Node matchingWorkSheet = matchWorkSheet(workSheet, workSheetList2);
+
+ if (matchingWorkSheet != null) {
+
+ // need to put it into a row Iterator
+ // use a straight comparsion algorithm then do a merge on it
+ Iterator i1 = new RowIterator(cc_, workSheet);
+ Iterator i2 = new RowIterator(cc_, matchingWorkSheet);
+
+ // find out the diff
+ DiffAlgorithm diffAlgo = new IteratorRowCompare();
+
+ // find out the paragrah level diffs
+ Difference[] diffResult = diffAlgo.computeDiffs(i1, i2);
+
+ if (Debug.isFlagSet(Debug.INFO)) {
+ Debug.log(Debug.INFO, "Diff Result: ");
+
+ for (int j = 0; j < diffResult.length; j++) {
+ Debug.log(Debug.INFO, diffResult[j].debug());
+ }
+ }
+
+ // merge back the result
+ NodeMergeAlgorithm rowMerger = new PositionBaseRowMerge(cc_);
+ MergeAlgorithm merger = new SheetMerge(cc_, rowMerger);
+
+ Iterator result = null;
+
+ merger.applyDifference(i1, i2, diffResult);
+ }
+ }
+
+ numOfWorkSheet = workSheetList2.getLength();
+
+ // for those workSheet from target don't have a matching one
+ // in the original workSheet list, we add it
+
+ // find out the office body node first
+ NodeList officeBodyList =
+ elem1.getElementsByTagName(OfficeConstants.TAG_OFFICE_BODY);
+
+ Node officeBody = officeBodyList.item(0);
+
+ // for each WorkSheets, try to see whether we have it or not
+ for (int j=0; j < numOfWorkSheet; j++) {
+ Node workSheet= workSheetList2.item(j);
+
+ // try to match the workSheet
+ //
+ Node matchingWorkSheet = matchWorkSheet(workSheet, workSheetList1);
+
+ // add the new WorkSheet to the original document iff match not
+ // found
+ //
+ if (matchingWorkSheet == null) {
+ Node cloneNode = XmlUtil.deepClone(officeBody, workSheet);
+ officeBody.appendChild(cloneNode);
+ }
+ }
+ }
+
+ /**
+ * Try to find a WorkSheet from the modified WorkSheetList that
+ * has a matching table name from the original WorkSheet.
+ *
+ * @param orgSheet The original WorkSheet.
+ * @param modSheetList The modified WorkSheet.
+ *
+ * @return The Node in modSheetList that matches the orgSheet.
+ */
+ private Node matchWorkSheet(Node orgSheet, NodeList modSheetList) {
+
+ Node matchSheet = null;
+
+ String orgTableName = ((Element)orgSheet).getAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NAME);
+
+ if (orgTableName == null)
+ return null;
+
+ int numOfWorkSheet = modSheetList.getLength();
+
+ String modTableName;
+
+ for (int i=0; i < numOfWorkSheet; i++) {
+ modTableName = ((Element)modSheetList.item(i)).getAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NAME);
+ if (modTableName == null)
+ continue;
+
+ if (orgTableName.equals(modTableName)) {
+ matchSheet = modSheetList.item(i);
+ break;
+ }
+ }
+
+ return matchSheet;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/Format.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/Format.java
new file mode 100644
index 000000000000..5125b5c20c29
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/Format.java
@@ -0,0 +1,314 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxc;
+
+import java.awt.Color;
+
+/**
+ * This class specifies the format for a given spreadsheet cell.
+ *
+ * @author Mark Murnane
+ */
+public class Format implements Cloneable {
+
+ private String category;
+ private String formatSpecifier;
+ private int decimalPlaces;
+ private boolean bold;
+ private boolean italic;
+ private boolean underline;
+ private String font;
+ private Color foreground, background;
+
+
+ /**
+ * Constructor for creating a new <code>Format</code>.
+ */
+ public Format() {
+ category = "";
+ formatSpecifier = "";
+ font = "";
+ foreground = Color.black;
+ background = Color.white;
+ }
+
+
+ /**
+ * Constructor for creating a new <code>Format</code> object
+ * based on an existing one.
+ *
+ * @param fmt <code>Format</code> to copy.
+ */
+ public Format(Format fmt) {
+ category = fmt.getCategory();
+ formatSpecifier = fmt.getFormatSpecifier();
+ decimalPlaces = fmt.getDecimalPlaces();
+ bold = fmt.isBold();
+ italic = fmt.isItalic();
+ underline = fmt.isUnderline();
+ font = fmt.getFont();
+ foreground = fmt.getForeground();
+ background = fmt.getBackground();
+ }
+
+
+ /**
+ * Reset this <code>Format</code> description.
+ */
+ public void clearFormatting() {
+ category = "";
+ formatSpecifier = "";
+ decimalPlaces = 0;
+ bold = false;
+ italic = false;
+ underline = false;
+ font = "";
+ foreground = Color.black;
+ background = Color.white;
+ }
+
+
+ /**
+ * Set the formatting category of this object, i.e. number, date,
+ * currency. The <code>OfficeConstants</code> class contains string
+ * constants for the category types.
+ *
+ * @see org.openoffice.xmerge.converter.xml.OfficeConstants
+ *
+ * @param newCategory The name of the category to be set.
+ */
+ public void setCategory(String newCategory) {
+ category = newCategory;
+ }
+
+
+ /**
+ * Return the formatting category of the object.
+ *
+ * @see org.openoffice.xmerge.converter.xml.OfficeConstants
+ *
+ * @return The formatting category of the object.
+ */
+ public String getCategory() {
+ return category;
+ }
+
+
+ /**
+ * Set the <code>Format</code> specifier for this category.
+ *
+ * @param formatString The new <code>Format</code> specifier.
+ */
+ public void setFormatSpecifier(String formatString) {
+ formatSpecifier = formatString;
+ }
+
+
+ /**
+ * Get the <code>Format</code> specifier for this category.
+ *
+ * @return <code>Format</code> specifier for this category.
+ */
+ public String getFormatSpecifier() {
+ return formatSpecifier;
+ }
+
+
+ /**
+ * Set the precision of the number to be displayed.
+ *
+ * @param precision The number of decimal places to display.
+ */
+ public void setDecimalPlaces(int precision) {
+ decimalPlaces = precision;
+ }
+
+
+ /**
+ * Get the number of decimal places displayed.
+ *
+ * @return Number of decimal places.
+ */
+ public int getDecimalPlaces() {
+ return decimalPlaces;
+ }
+
+
+ /**
+ * Set the object's bold flag.
+ *
+ * @param value The value of the bold flag. true is bold,
+ * false is not bold.
+ */
+ public void setBold(boolean value) {
+ bold = value;
+ }
+
+
+ /**
+ * Get the object's bold flag.
+ *
+ * @return true if bold flag is on, false otherwise.
+ */
+ public boolean isBold() {
+ return bold;
+ }
+
+
+ /**
+ * Set the object's italic flag.
+ *
+ * @param value The value of the italic flag. true is italic,
+ * false is not italic.
+ */
+ public void setItalic(boolean value) {
+ italic = value;
+ }
+
+
+ /**
+ * Get the object's italic flag.
+ *
+ * @return True if italic flag is on, false otherwise.
+ */
+ public boolean isItalic() {
+ return italic;
+ }
+
+
+ /**
+ * Set the object's underline flag.
+ *
+ * @param value The value of the underline flag. true is underlined,
+ * false is not underlined.
+ */
+ public void setUnderline(boolean value) {
+ underline = value;
+ }
+
+
+ /**
+ * Get the object's underline flag.
+ *
+ * @return true if underline flag is on, false otherwise.
+ */
+ public boolean isUnderline() {
+ return underline;
+ }
+
+
+ /**
+ * Set the font used for this cell.
+ *
+ * @param fontName The name of the font.
+ */
+ public void setFont(String fontName) {
+ font = fontName;
+ }
+
+
+ /**
+ * Get the font used for this cell.
+ *
+ * @return The font name.
+ */
+ public String getFont() {
+ return font;
+ }
+
+
+ /**
+ * Set the Foreground <code>Color</code> for this cell.
+ *
+ * @param color A <code>Color</code> object representing the
+ * foreground color.
+ */
+ public void setForeground(Color color) {
+ foreground = new Color(color.getRGB());
+ }
+
+
+ /**
+ * Get the Foreground <code>Color</code> for this cell.
+ *
+ * @return Foreground <code>Color</code> value.
+ */
+ public Color getForeground() {
+ return new Color(foreground.getRGB());
+ }
+
+
+ /**
+ * Set the Background <code>Color</code> for this cell
+ *
+ * @param color A <code>Color</code> object representing
+ * the background color.
+ */
+ public void setBackground(Color color) {
+ background = new Color(color.getRGB());
+ }
+
+
+ /**
+ * Get the Foreground <code>Color</code> for this cell
+ *
+ * @return Background <code>Color</code> value
+ */
+ public Color getBackground() {
+ return new Color(background.getRGB());
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SpreadsheetDecoder.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SpreadsheetDecoder.java
new file mode 100644
index 000000000000..8cfc2c33908f
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SpreadsheetDecoder.java
@@ -0,0 +1,181 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxc;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.openoffice.xmerge.converter.xml.sxc.Format;
+import org.openoffice.xmerge.ConvertData;
+
+/**
+ * This class is a abstract class for encoding a &quot;Device&quot;
+ * <code>Document</code> format into an alternative spreadsheet format.
+ *
+ * @author Mark Murnane
+ */
+public abstract class SpreadsheetDecoder {
+
+ /**
+ * Constructor for creating new <code>SpreadsheetDecoder</code>.
+ */
+ public SpreadsheetDecoder(String name, String password) throws IOException {
+ }
+
+ /**
+ * Returns the total number of sheets in the WorkBook.
+ *
+ * @return The number of sheets in the WorkBook.
+ */
+ public abstract int getNumberOfSheets();
+
+
+ /**
+ * Returns the number of populated rows in the current WorkSheet.
+ *
+ * @return the number of populated rows in the current WorkSheet.
+ */
+ public abstract int getNumberOfRows();
+
+
+ /**
+ * Returns the number of populated columns in the current WorkSheet.
+ *
+ * @return The number of populated columns in the current WorkSheet.
+ */
+ public abstract int getNumberOfColumns();
+
+
+ /**
+ * Returns the name of the current WorkSheet.
+ *
+ * @return Name of the current WorkSheet.
+ */
+ public abstract String getSheetName();
+
+
+ /**
+ * Returns the number of the active column.
+ *
+ * @return The number of the active column.
+ */
+ public abstract int getColNumber();
+
+
+ /**
+ * Returns the number of the active row.
+ *
+ * @return The number of the active row.
+ */
+ public abstract int getRowNumber();
+
+
+ /**
+ * Sets the active WorkSheet.
+ *
+ * @param sheetIndex The index of the sheet to be made active.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public abstract void setWorksheet(int sheetIndex) throws IOException;
+
+
+ /**
+ * Move on the next populated cell in the current WorkSheet.
+ *
+ * @return true if successful, false otherwise.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public abstract boolean goToNextCell() throws IOException;
+
+
+ /**
+ * Return the contents of the active cell.
+ *
+ * @return The cell contents.
+ */
+ public abstract String getCellContents();
+
+
+ /**
+ * Return the data type of the active cell.
+ *
+ * @return The cell data type.
+ */
+ public abstract String getCellDataType();
+
+
+ /**
+ * Return a <code>Format</code> object describing the active cells
+ * formatting.
+ *
+ * @return <code>Format</code> object for the cell.
+ */
+ public abstract Format getCellFormat();
+
+
+ /**
+ * Add the contents of a <code>ConvertData</code> to the workbook.
+ *
+ * @param cd The <code>ConvertData</code> containing the
+ * content.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public abstract void addDeviceContent(ConvertData cd) throws IOException;
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SpreadsheetEncoder.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SpreadsheetEncoder.java
new file mode 100644
index 000000000000..33f37d5f3ecd
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SpreadsheetEncoder.java
@@ -0,0 +1,142 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxc;
+
+import java.io.IOException;
+
+import org.openoffice.xmerge.util.IntArrayList;
+
+/**
+ * <p>This class is a abstract class for encoding an SXC into an
+ * alternative spreadsheet format.</p>
+ *
+ * <p>TODO - Add appropriate exceptions to each of the methods.</p>
+ *
+ * @author Mark Murnane
+ */
+public abstract class SpreadsheetEncoder {
+
+
+ /**
+ * Creates new SpreadsheetEncoder.
+ *
+ * @param name The name of the WorkBook to be created.
+ * @param password An optional password for the WorkBook.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public SpreadsheetEncoder(String name, String password) throws IOException { };
+
+
+ /**
+ * Create a new WorkSheet within the WorkBook.
+ *
+ * @param sheetName The name of the WorkSheet.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public abstract void createWorksheet(String sheetName) throws IOException;
+
+
+ /**
+ * Set a cell's formatting options via a separately create
+ * <code>Format</code> object.
+ *
+ * @param row The row number of the cell to be changed
+ * @param column The column number of the cell to be changed
+ * @param fmt Object containing formatting settings for this cell.
+ */
+ public abstract void setCellFormat(int row, int column, Format fmt);
+
+
+ /**
+ * Add a cell to the current WorkSheet.
+ *
+ * @param row The row number of the cell
+ * @param column The column number of the cell
+ * @param fmt The <code>Format</code> object describing the
+ * appearance of this cell.
+ * @param cellContents The text or formula of the cell's contents.
+ */
+ public abstract void addCell(int row, int column,
+ Format fmt, String cellContents) throws IOException;
+
+
+ /**
+ * Get the number of sheets in the WorkBook.
+ *
+ * @return The number of sheets in the WorkBook.
+ */
+ public abstract int getNumberOfSheets();
+
+
+ /**
+ * Get the names of the sheets in the WorkBook.
+ *
+ * @param sheet The required sheet.
+ */
+ public abstract String getSheetName(int sheet);
+
+
+ /**
+ * Set the width of the columns in the WorkBook.
+ *
+ * @param columnWidths An <code>IntArrayList</code> of column
+ * widths.
+ */
+ public abstract void setColumnWidths(IntArrayList columnWidths) throws IOException;
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocument.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocument.java
new file mode 100644
index 000000000000..b775209a67c4
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocument.java
@@ -0,0 +1,111 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxc;
+
+import org.w3c.dom.Document;
+import org.openoffice.xmerge.converter.xml.OfficeDocument;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+
+/**
+ * This class is an implementation of <code>OfficeDocument</code> for
+ * the SXC format.
+ */
+public class SxcDocument extends OfficeDocument {
+
+ /**
+ * Constructor with arguments to set <code>name</code>.
+ *
+ * @param name The name of the <code>Document</code>
+ */
+ public SxcDocument(String name) {
+ super(name);
+ }
+
+
+ /**
+ * Constructor with arguments to set <code>name</code>, the
+ * <code>namespaceAware</code> flag, and the <code>validating</code>
+ * flag.
+ *
+ * @param name The name of the <code>Document</code>.
+ * @param namespaceAware The value of the <code>namespaceAware</code>
+ * flag.
+ * @param validating The value of the <code>validating</code> flag.
+ */
+ public SxcDocument(String name, boolean namespaceAware, boolean validating) {
+
+ super(name, namespaceAware, validating);
+ }
+
+ /**
+ * Returns the Office file extension for the SXC format.
+ *
+ * @return The Office file extension for the SXC format.
+ */
+ protected String getFileExtension() {
+ return OfficeConstants.SXC_FILE_EXTENSION;
+ }
+
+ /**
+ * Returns the Office attribute for the SXC format.
+ *
+ * @return The Office attribute for the SXC format.
+ */
+ protected String getOfficeClassAttribute() {
+ return OfficeConstants.SXC_TYPE;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentDeserializer.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentDeserializer.java
new file mode 100644
index 000000000000..c508b5867c5b
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentDeserializer.java
@@ -0,0 +1,622 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxc;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import java.io.IOException;
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.ConvertException;
+import org.openoffice.xmerge.DocumentDeserializer;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+import org.openoffice.xmerge.converter.xml.sxc.SxcDocument;
+import org.openoffice.xmerge.util.Debug;
+
+/**
+ * <p>General spreadsheet implementation of <code>DocumentDeserializer</code>
+ * for the {@link
+ * org.openoffice.xmerge.converter.xml.sxc.SxcPluginFactory
+ * SxcPluginFactory}. Used with SXC <code>Document</code> objects.</p>
+ *
+ * <p>The <code>deserialize</code> method uses a <code>DocDecoder</code>
+ * to read the device spreadsheet format into a <code>String</code>
+ * object, then it calls <code>buildDocument</code> to create a
+ * <code>SxcDocument</code> object from it.</p>
+ *
+ * @author Paul Rank
+ * @author Mark Murnane
+ */
+public abstract class SxcDocumentDeserializer implements OfficeConstants,
+ DocumentDeserializer {
+
+ /**
+ * A <code>SpreadsheetDecoder</code> object for decoding from
+ * device formats.
+ */
+ private SpreadsheetDecoder decoder = null;
+
+ /** A w3c <code>Document</code>. */
+ private org.w3c.dom.Document doc = null;
+
+ /** An <code>ConvertData</code> object assigned to this object. */
+ private ConvertData cd = null;
+
+
+ /**
+ * Constructor.
+ *
+ * @param cd <code>ConvertData</code> consisting of a
+ * device content object.
+ */
+ public SxcDocumentDeserializer(ConvertData cd) {
+ this.cd = cd;
+ }
+
+
+ /**
+ * This abstract method will be implemented by concrete subclasses
+ * and will return an application-specific Decoder.
+ *
+ * @param workbook The WorkBook to read.
+ * @param password The WorkBook password.
+ *
+ * @return The appropriate <code>SpreadSheetDecoder</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public abstract SpreadsheetDecoder createDecoder(String workbook, String[] worksheetNames, String password)
+ throws IOException;
+
+
+ /**
+ * <p>This method will return the name of the WorkBook from the
+ * <code>ConvertData</code>. Allows for situations where the
+ * WorkBook name differs from the Device Content name.</p>
+ *
+ * <p>Implemented in the Deserializer as the Decoder's constructor requires
+ * a name.</p>
+ *
+ * @param cd The <code>ConvertData</code> containing the Device
+ * content.
+ *
+ * @return The WorkBook name.
+ */
+ protected abstract String getWorkbookName(ConvertData cd) throws IOException;
+
+
+ /**
+ * This method will return the name of the WorkSheet from the
+ * <code>ConvertData</code>.
+ *
+ * @param cd The <code>ConvertData</code> containing the Device
+ * content.
+ *
+ * @return The WorkSheet names.
+ */
+ protected abstract String[] getWorksheetNames(ConvertData cd) throws IOException;
+
+
+ /**
+ * <p>Method to convert a set of &quot;Device&quot;
+ * <code>Document</code> objects into a <code>SxcDocument</code>
+ * object and returns it as a <code>Document</code>.</p>
+ *
+ * <p>This method is not thread safe for performance reasons.
+ * This method should not be called from within two threads.
+ * It would be best to call this method only once per object
+ * instance.</p>
+ *
+ * @return document An <code>SxcDocument</code> consisting
+ * of the data converted from the input
+ * stream.
+ *
+ * @throws ConvertException If any conversion error occurs.
+ * @throws IOException If any I/O error occurs.
+ */
+ public Document deserialize() throws ConvertException,
+ IOException {
+
+ // Get the name of the WorkBook from the ConvertData.
+ String[] worksheetNames = getWorksheetNames(cd);
+ String workbookName = getWorkbookName(cd);
+
+ // Create a document
+ SxcDocument sxcDoc = new SxcDocument(workbookName);
+ sxcDoc.initContentDOM();
+
+ doc = sxcDoc.getContentDOM();
+
+ // Little fact for the curious reader: workbookName should
+ // be the name of the StarCalc file minus the file extension suffix.
+
+ // Create a Decoder to decode the DeviceContent to a spreadsheet document
+ // TODO - we aren't using a password in StarCalc, so we can
+ // use any value for password here. If StarCalc XML supports
+ // passwords in the future, we should try to get the correct
+ // password value here.
+ //
+ decoder = createDecoder(workbookName, worksheetNames, "password");
+
+ Debug.log(Debug.TRACE, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ Debug.log(Debug.TRACE, "<DEBUGLOG>");
+
+ decoder.addDeviceContent(cd);
+ decode();
+
+ Debug.log(Debug.TRACE, "</DEBUGLOG>");
+
+ return sxcDoc;
+ }
+
+
+ /**
+ * Outer level method used to decode a WorkBook
+ * into a <code>Document</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void decode() throws IOException {
+
+ // Get number of worksheets
+ int numSheets = decoder.getNumberOfSheets();
+
+ for (int i = 0; i < numSheets; i++) {
+
+ // Set the decoder to the correct worksheet
+ decoder.setWorksheet(i);
+
+ // Traverse to the office:body element.
+ // There should only be one.
+ NodeList list = doc.getElementsByTagName(TAG_OFFICE_BODY);
+
+ int len = list.getLength();
+
+ if (len > 0) {
+
+ Node node = list.item(0);
+
+ // Process the spreadsheet
+ processTable(node);
+ }
+ }
+ }
+
+
+ /**
+ * This method process a WorkSheet and generates a portion
+ * of the <code>Document</code>. A spreadsheet is represented
+ * as a table Node in StarOffice XML format.
+ *
+ * @param root The root <code>Node</code> of the
+ * <code>Document</code> we are building. This
+ * <code>Node</code> should be a TAG_OFFICE_BODY
+ * tag.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void processTable(Node root) throws IOException {
+
+ Debug.log(Debug.TRACE, "<TABLE>");
+
+ // Create an element node for the table
+ Element tableElement = (Element) doc.createElement(TAG_TABLE);
+
+ // Get the sheet name
+ String sheetName = decoder.getSheetName();
+
+ // Set the table name attribute
+ tableElement.setAttribute(ATTRIBUTE_TABLE_NAME, sheetName);
+
+ // TODO - style currently hardcoded - get real value
+ // Set table style-name attribute
+ tableElement.setAttribute(ATTRIBUTE_TABLE_STYLE_NAME, "Default");
+
+ // Append the table element to the root node
+ root.appendChild(tableElement);
+
+ Debug.log(Debug.TRACE, "<SheetName>");
+ Debug.log(Debug.TRACE, sheetName);
+ Debug.log(Debug.TRACE, "</SheetName>");
+
+ // Get each cell and add to doc
+ processCells(tableElement);
+
+ Debug.log(Debug.TRACE, "</TABLE>");
+ }
+
+
+ /**
+ * <p>This method process the cells in a <code>Document</code>
+ * and generates a portion of the <code>Document</code>.</p>
+ *
+ * <p>This method assumes that records are sorted by
+ * row and then column.</p>
+ *
+ * @param root The <code>Node</code> of the <code>Document</code>
+ * we are building that we will append our cell
+ * <code>Node</code> objects. This <code>Node</code>
+ * should be a TAG_TABLE tag.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void processCells(Node root) throws IOException {
+
+ // The current row element
+ Element rowElement = null;
+
+ // The current cell element
+ Element cellElement = null;
+
+ // The row number - we may not have any rows (empty sheet)
+ // so set to zero.
+ int row = 0;
+
+ // The column number - This is the expected column number of
+ // the next cell we are reading.
+ int col = 1;
+
+ // The number of columns in the spreadsheet
+ int lastColumn = decoder.getNumberOfColumns();
+
+
+ // Loop over all cells in the spreadsheet
+ while (decoder.goToNextCell()) {
+
+ // Get the row number
+ int newRow = decoder.getRowNumber();
+
+ // Is the cell in a new row, or part of the current row?
+ if (newRow != row) {
+
+ // Make sure that all the cells in the previous row
+ // have been entered.
+ if (col <= lastColumn && rowElement != null) {
+ int numSkippedCells = lastColumn - col + 1;
+ addEmptyCells(numSkippedCells, rowElement);
+ }
+
+ // log an end row - if we already have a row
+ if (row != 0) {
+ Debug.log(Debug.TRACE, "</tr>");
+ }
+
+ // How far is the new row from the last row?
+ int deltaRows = newRow - row;
+
+ // Check if we have skipped any rows
+ if (deltaRows > 1) {
+ // Add in empty rows
+ addEmptyRows(deltaRows-1, root, lastColumn);
+ }
+
+ // Re-initialize column (since we are in a new row)
+ col = 1;
+
+ // Create an element node for the new row
+ rowElement = (Element) doc.createElement(TAG_TABLE_ROW);
+
+ // TODO - style currently hardcoded - get real value
+ // Set row style-name attribute
+ rowElement.setAttribute(ATTRIBUTE_TABLE_STYLE_NAME,
+ "Default");
+
+ // Append the row element to the root node
+ root.appendChild(rowElement);
+
+ // Update row number
+ row = newRow;
+
+ Debug.log(Debug.TRACE, "<tr>");
+ }
+
+ // Get the column number of the current cell
+ int newCol = decoder.getColNumber();
+
+ // Check to see if some columns were skipped
+ if (newCol != col) {
+
+ // How many columns have we skipped?
+ int numColsSkipped = newCol - col;
+
+ addEmptyCells(numColsSkipped, rowElement);
+
+ // Update the column number to account for the
+ // skipped cells
+ col = newCol;
+ }
+
+ // Lets start dealing with the cell data
+ Debug.log(Debug.TRACE, "<td>");
+
+ // Get the cell's contents
+ String cellContents = decoder.getCellContents();
+
+ // Get the type of the data in the cell
+ String cellType = decoder.getCellDataType();
+
+ // Create an element node for the cell
+ cellElement = (Element) doc.createElement(TAG_TABLE_CELL);
+
+ // TODO - style currently hardcoded - get real value
+ // Set cell style-name attribute
+ cellElement.setAttribute(ATTRIBUTE_TABLE_STYLE_NAME, "Default");
+
+ // Store the cell data into the appropriate attributes
+ processCellData(cellElement, cellType, cellContents);
+
+ // Append the cell element to the row node
+ rowElement.appendChild(cellElement);
+
+ // Append the cellContents as a text node
+ Element textElement = (Element) doc.createElement(TAG_PARAGRAPH);
+ cellElement.appendChild(textElement);
+ textElement.appendChild(doc.createTextNode(cellContents));
+
+ Debug.log(Debug.TRACE, cellContents);
+ Debug.log(Debug.TRACE, "</td>");
+
+ // Increment to the column number of the next expected cell
+ col++;
+ }
+
+ // Make sure that the last row is padded correctly
+ if (col <= lastColumn && rowElement != null) {
+ int numSkippedCells = lastColumn - col + 1;
+ addEmptyCells(numSkippedCells, rowElement);
+ }
+
+ if (row != 0) {
+
+ // The sheet does have rows, so write out a /tr
+ Debug.log(Debug.TRACE, "</tr>");
+ }
+ }
+
+
+ /**
+ * This method will add empty rows to the <code>Document</code>.
+ * It is called when the conversion process encounters
+ * a row (or rows) that do not contain any data in its cells.
+ *
+ * @param numEmptyRows The number of empty rows that we
+ * need to add to the <code>Document</code>.
+ * @param root The <code>Node</code> of the
+ * <code>Document</code> we are building
+ * that we will append our empty row
+ * <code>Node</code> objects. This
+ * <code>Node</code> should be a TAG_TABLE
+ * tag.
+ * @param numEmptyCells The number of empty cells in the
+ * empty row.
+ */
+ protected void addEmptyRows(int numEmptyRows, Node root, int numEmptyCells) {
+
+ // Create an element node for the row
+ Element rowElement = (Element) doc.createElement(TAG_TABLE_ROW);
+
+ // TODO - style currently hardcoded - get real value
+ // Set row style-name attribute
+ rowElement.setAttribute(ATTRIBUTE_TABLE_STYLE_NAME, "Default");
+
+ // Set cell number-rows-repeated attribute
+ rowElement.setAttribute(ATTRIBUTE_TABLE_NUM_ROWS_REPEATED,
+ Integer.toString(numEmptyRows));
+
+ // Append the row element to the root node
+ root.appendChild(rowElement);
+
+ // Open Office requires the empty row to have an empty cell (or cells)
+ addEmptyCells(numEmptyCells, rowElement);
+
+ // Write empty rows to the log
+ for (int i = 0; i < numEmptyRows; i++) {
+ Debug.log(Debug.TRACE, "<tr />");
+ }
+
+ }
+
+
+ /**
+ * This method will add empty cells to the <code>Document</code>.
+ * It is called when the conversion process encounters a row
+ * that contains some cells without data.
+ *
+ * @param numColsSkipped The number of empty cells
+ * that we need to add to the
+ * current row.
+ * @param row The <code>Node</code> of the
+ * <code>Document</code> we
+ * are building that we will
+ * append our empty cell
+ * <code>Node</code> objects.
+ * This <code>Node</code> should
+ * be a TAG_TABLE_ROW tag.
+ */
+ protected void addEmptyCells(int numColsSkipped, Node row) {
+
+ // Create an empty cellElement
+ Element cellElement = (Element) doc.createElement(TAG_TABLE_CELL);
+
+ // TODO - style currently hardcoded - get real value
+ // Set cell style-name attribute
+ cellElement.setAttribute(ATTRIBUTE_TABLE_STYLE_NAME, "Default");
+
+ // If we skipped more than 1 cell, we must set the
+ // appropriate attribute
+ if (numColsSkipped > 1) {
+
+ // Set cell number-columns-repeated attribute
+ cellElement.setAttribute(ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED,
+ Integer.toString(numColsSkipped));
+ }
+
+ // Append the empty cell element to the row node
+ row.appendChild(cellElement);
+
+ // Write empty cells to the log
+ for (int i = 0; i < numColsSkipped; i++) {
+ Debug.log(Debug.TRACE, "<td />");
+ }
+ }
+
+
+ /**
+ * This method process the data in a cell and sets
+ * the appropriate attributes on the cell <code>Element</code>.
+ *
+ * @param cellElement A TAG_TABLE_CELL <code>Element</code>
+ * that we will be adding attributes to
+ * based on the type of data in the cell.
+ * @param type The type of data contained in the cell.
+ * @param contents The contents of the data contained in
+ * the cell.
+ */
+ protected void processCellData(Element cellElement, String type,
+ String contents) {
+
+ // Set cell value-type attribute
+ cellElement.setAttribute(ATTRIBUTE_TABLE_VALUE_TYPE, type);
+
+ // Does the cell contain a formula?
+ if (contents.startsWith("=")) {
+
+ cellElement.setAttribute(ATTRIBUTE_TABLE_FORMULA,
+ parseFormula(contents));
+
+ // String data does not require any additional attributes
+ } else if (!type.equals(CELLTYPE_STRING)) {
+
+ if (type.equals(CELLTYPE_TIME)) {
+
+ // Data returned in StarOffice XML format, so store in
+ // attribute
+ cellElement.setAttribute(ATTRIBUTE_TABLE_TIME_VALUE,
+ contents);
+
+ } else if (type.equals(CELLTYPE_DATE)) {
+
+ // Data returned in StarOffice XML format, so store in
+ // attribute
+ cellElement.setAttribute(ATTRIBUTE_TABLE_DATE_VALUE,
+ contents);
+
+ } else if (type.equals(CELLTYPE_BOOLEAN)) {
+
+ // StarOffice XML format requires stored boolean value
+ // to be in lower case
+ cellElement.setAttribute(ATTRIBUTE_TABLE_BOOLEAN_VALUE,
+ contents.toLowerCase());
+
+ } else if (type.equals(CELLTYPE_CURRENCY)) {
+ // TODO - StarOffice XML format requires a correct style to
+ // display currencies correctly. Need to implement styles.
+ // TODO - USD is for US currencies. Need to pick up
+ // the correct currency location from the source file.
+ cellElement.setAttribute(ATTRIBUTE_TABLE_CURRENCY, "USD");
+
+ // Data comes stripped of currency symbols
+ cellElement.setAttribute(ATTRIBUTE_TABLE_VALUE, contents);
+
+ } else if (type.equals(CELLTYPE_PERCENT)) {
+ // Data comes stripped of percent signs
+ cellElement.setAttribute(ATTRIBUTE_TABLE_VALUE, contents);
+
+ } else {
+ // Remaining data types use table-value attribute
+
+ cellElement.setAttribute(ATTRIBUTE_TABLE_VALUE, contents);
+ }
+ }
+ }
+
+
+ /**
+ * <p>This method takes a formula and parses it into
+ * StarOffice XML formula format.</p>
+ *
+ * <p>Many spreadsheets use ',' as a separator.
+ * StarOffice XML format uses ';' as a separator instead.</p>
+ *
+ * <p>Many spreadsheets use '!' as a separator when refencing
+ * a cell in a different sheet.</p>
+ *
+ * <blockquote>
+ * Example: =sheet1!A1
+ * </blockquote>
+ *
+ * <p>StarOffice XML format uses '.' as a separator instead.</p>
+ *
+ * <blockquote>
+ * Example: =sheet1.A1
+ * </blockquote>
+ *
+ * @param formula A formula string.
+ *
+ * @return A StarOffice XML format formula string.
+ */
+ protected String parseFormula(String formula) {
+
+ formula = formula.replace(',', ';');
+ formula = formula.replace('!', '.');
+
+ return formula;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentSerializer.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentSerializer.java
new file mode 100644
index 000000000000..08fea746c647
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentSerializer.java
@@ -0,0 +1,809 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxc;
+
+import java.awt.Color;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Element;
+
+import java.io.IOException;
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.ConvertException;
+import org.openoffice.xmerge.DocumentSerializer;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+import org.openoffice.xmerge.converter.xml.sxc.SxcDocument;
+import org.openoffice.xmerge.util.Debug;
+import org.openoffice.xmerge.util.IntArrayList;
+import org.openoffice.xmerge.util.XmlUtil;
+
+import org.openoffice.xmerge.converter.xml.sxc.Format;
+
+
+/**
+ * <p>General spreadsheet implementation of <code>DocumentSerializer</code>
+ * for the {@link
+ * org.openoffice.xmerge.converter.xml.sxc.SxcPluginFactory
+ * SxcPluginFactory}. Used with SXC <code>Document</code> objects.</p>
+ *
+ * <p>The <code>serialize</code> method traverses the DOM
+ * <code>Document</code> from the given <code>Document</code> object.
+ * It uses a <code>DocEncoder</code> object for the actual conversion
+ * of contents to the device spreadsheet format.</p>
+ *
+ * @author Paul Rank
+ * @author Mark Murnane
+ */
+public abstract class SxcDocumentSerializer implements OfficeConstants,
+ DocumentSerializer {
+
+ /** The cell foreground <code>Color</code>. */
+ private Color foreground = Color.black;
+
+ /** The cell background <code>Color</code>. */
+ private Color background = Color.white;
+
+ /** The cell format. */
+ private long format = 0;
+
+ /** <code>Format</code> object describing the cell. */
+ private Format fmt = null;
+
+ /** The row number. */
+ private int rowID = 1;
+
+ /** The column number. */
+ private int colID = 1;
+
+ /** The number of times the current row is repeated. */
+ private int rowsRepeated = 1;
+
+ /** The number of times the current column is repeated. */
+ private int colsRepeated = 1;
+
+ /**
+ * An array of column widths of the current worksheet. Width is
+ * measured in number of characters.
+ */
+ private IntArrayList ColumnWidthList;
+
+ /** Width, in characters, of the current cell display data. */
+ private int displayWidth = 0;
+
+ /**
+ * A <code>SpreadsheetEncoder</code> object for encoding to
+ * appropriate format.
+ */
+ protected SpreadsheetEncoder encoder = null;
+
+ /** <code>SxcDocument</code> object that this converter processes. */
+ protected SxcDocument sxcDoc = null;
+
+
+ /**
+ * Constructor.
+ *
+ * @param document Input <code>SxcDocument</code>
+ * <code>Document</code>.
+ */
+ public SxcDocumentSerializer(Document document) {
+ fmt = new Format();
+ sxcDoc = (SxcDocument) document;
+ }
+
+
+ /**
+ * <p>Method to convert a DOM <code>Document</code> into
+ * &quot;Device&quot; <code>Document</code> objects.</p>
+ *
+ * <p>This method is not thread safe for performance reasons.
+ * This method should not be called from within two threads.
+ * It would be best to call this method only once per object
+ * instance.</p>
+ *
+ * @return <code>ConvertData</code> containing &quot;Device&quot;
+ * <code>Document</code> objects.
+ *
+ * @throws ConvertException If any conversion error occurs.
+ * @throws IOException If any I/O error occurs.
+ */
+ public abstract ConvertData serialize() throws ConvertException,
+ IOException;
+
+
+ /**
+ * This method traverses <i>office:body</i> <code>Element</code>.
+ *
+ * @param node <i>office:body</i> <code>Node</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void traverseBody(Node node) throws IOException {
+
+ Debug.log(Debug.TRACE, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ Debug.log(Debug.TRACE, "<DEBUGLOG>");
+
+ if (node.hasChildNodes()) {
+
+ NodeList nodeList = node.getChildNodes();
+ int len = nodeList.getLength();
+
+ for (int i = 0; i < len; i++) {
+ Node child = nodeList.item(i);
+
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ String nodeName = child.getNodeName();
+
+ if (nodeName.equals(TAG_TABLE)) {
+
+ traverseTable(child);
+
+ } else {
+
+ Debug.log(Debug.TRACE, "<OTHERS " + XmlUtil.getNodeInfo(child) + " />");
+ }
+ }
+ }
+ }
+
+ Debug.log(Debug.TRACE, "</DEBUGLOG>");
+ }
+
+
+ /**
+ * This method traverses the <i>table:table</i> element
+ * <code>Node</code>.
+ *
+ * @param node A <i>table:table</i> <code>Node</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void traverseTable(Node node) throws IOException {
+
+ Debug.log(Debug.TRACE, "<TABLE>");
+
+ ColumnWidthList = new IntArrayList();
+
+ // Get table attributes
+ // TODO - extract style from attribute
+
+ NamedNodeMap att = node.getAttributes();
+
+ String tableName =
+ att.getNamedItem(ATTRIBUTE_TABLE_NAME).getNodeValue();
+
+ rowID = 1;
+
+ encoder.createWorksheet(tableName);
+
+ if (node.hasChildNodes()) {
+
+ NodeList nodeList = node.getChildNodes();
+ int len = nodeList.getLength();
+
+ for (int i = 0; i < len; i++) {
+ Node child = nodeList.item(i);
+
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ String nodeName = child.getNodeName();
+
+ if (nodeName.equals(TAG_TABLE_ROW)) {
+ // TODO - handle all the possible rows
+ // spelled out in the entities
+
+ traverseTableRow(child);
+
+ } else if (nodeName.equals(TAG_TABLE_COLUMN)) {
+
+ traverseTableColumn(child);
+
+ } else if (nodeName.equals(TAG_TABLE_SCENARIO)) {
+
+ // TODO
+
+ } else {
+
+ Debug.log(Debug.TRACE, "<OTHERS " + XmlUtil.getNodeInfo(child) + " />");
+ }
+ }
+ }
+
+ }
+
+ // Add column width info to the current sheet
+ encoder.setColumnWidths(ColumnWidthList);
+
+ Debug.log(Debug.TRACE, "</TABLE>");
+ }
+
+
+ /**
+ * This method traverses the <i>table:table-row</i> element
+ * <code>Node</code>.
+ *
+ * @param node A <i>table:table-row</i> <code>Node</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void traverseTableRow(Node node) throws IOException {
+
+ // Get the attributes of the row
+ NamedNodeMap cellAtt = node.getAttributes();
+
+ if (cellAtt != null) {
+
+ // Get the attribute representing the number of rows repeated
+ Node rowsRepeatedNode =
+ cellAtt.getNamedItem(ATTRIBUTE_TABLE_NUM_ROWS_REPEATED);
+
+ // There is a number of rows repeated attribute:
+ if (rowsRepeatedNode != null) {
+
+ // Get the number of times the row is repeated
+ String rowsRepeatedString = rowsRepeatedNode.getNodeValue();
+
+ Integer rowsRepeatedInt = new Integer(rowsRepeatedString);
+
+ rowsRepeated = rowsRepeatedInt.intValue();
+
+ } else {
+
+ // The row is not repeated
+ rowsRepeated = 1;
+ }
+ }
+
+ Debug.log(Debug.TRACE, "<TR>");
+
+ if (node.hasChildNodes()) {
+
+ NodeList nodeList = node.getChildNodes();
+ int len = nodeList.getLength();
+
+ for (int i = 0; i < len; i++) {
+ Node child = nodeList.item(i);
+
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ String nodeName = child.getNodeName();
+
+ if (nodeName.equals(TAG_TABLE_CELL)) {
+
+ traverseCell(child);
+
+ } else {
+
+ Debug.log(Debug.TRACE, "<OTHERS " + XmlUtil.getNodeInfo(child) + " />");
+ }
+ }
+ }
+ }
+
+ // Increase the row counter by the number of rows which are repeated
+ rowID += rowsRepeated;
+
+ // Re-initialize number of rows repeated before processing the next
+ // row data.
+ rowsRepeated = 1;
+
+ // When starting a new row, set the column counter back to the
+ // first column.
+ colID = 1;
+
+ // Re-initialize number of columns repeated before processing
+ // the next row data.
+ colsRepeated = 1;
+
+ Debug.log(Debug.TRACE, "</TR>");
+ }
+
+
+ /**
+ * This method traverses the <i>table:table-column</i>
+ * <code>Node</code>. Not yet implemented.
+ *
+ * @param node A <i>table:table-column</i> <code>Node</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void traverseTableColumn(Node node) throws IOException {
+
+ // TODO
+ }
+
+
+ /**
+ * This method traverses a <i>table:table-cell</i> element
+ * <code>Node</code>.
+ *
+ * @param node a <i>table:table-cell</i> <code>Node</code>.
+ *
+ * @throws IOException if any I/O error occurs.
+ */
+ protected void traverseCell(Node node) throws IOException {
+
+ NamedNodeMap cellAtt = node.getAttributes();
+
+ int debug_i=0;
+ Node debug_attrib = null;
+ if (cellAtt == null || cellAtt.item(0) == null)
+ {
+ Debug.log(Debug.INFO, "No Cell Attributes\n");
+ }
+ else
+ {
+ while ((debug_attrib = cellAtt.item(debug_i++)) != null)
+ {
+ Debug.log(Debug.INFO, "Cell Attribute " + debug_i +
+ ": " + debug_attrib.getNodeName() + " : " +
+ debug_attrib.getNodeValue() + "\n");
+ }
+ }
+
+ // Get the type of data in the cell
+ Node tableValueTypeNode =
+ cellAtt.getNamedItem(ATTRIBUTE_TABLE_VALUE_TYPE);
+
+ // Get the number of columns this cell is repeated
+ Node colsRepeatedNode =
+ cellAtt.getNamedItem(ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED);
+
+ // There is a number of cols repeated attribute
+ if (colsRepeatedNode != null) {
+
+ // Get the number of times the cell is repeated
+ String colsRepeatedString = colsRepeatedNode.getNodeValue();
+
+ Integer colsRepeatedInt = new Integer(colsRepeatedString);
+
+ colsRepeated = colsRepeatedInt.intValue();
+
+ } else {
+
+ // The cell is not repeated
+ colsRepeated = 1;
+ }
+
+ if (tableValueTypeNode != null) {
+
+ // Make sure we initialize to 0 the width of the current cell
+ displayWidth = 0;
+
+ String cellType =
+ tableValueTypeNode.getNodeValue();
+
+ if (cellType.equalsIgnoreCase(CELLTYPE_STRING)) {
+
+ // has text:p tag
+ fmt.setCategory(CELLTYPE_STRING);
+ } else if (cellType.equalsIgnoreCase(CELLTYPE_FLOAT)) {
+
+ // has table:value attribute
+ // has text:p tag
+
+ // Determine the number of decimal places StarCalc
+ // is displaying for this floating point output.
+ fmt.setCategory(CELLTYPE_FLOAT);
+ fmt.setDecimalPlaces(getDecimalPlaces(node));
+
+
+ } else if (cellType.equalsIgnoreCase(CELLTYPE_TIME)) {
+
+ // has table:time-value attribute
+ // has text:p tag - which is the value we convert
+
+ fmt.setCategory(CELLTYPE_TIME);
+
+ } else if (cellType.equalsIgnoreCase(CELLTYPE_DATE)) {
+
+ // has table:date-value attribute
+ // has text:p tag - which is the value we convert
+
+ fmt.setCategory(CELLTYPE_DATE);
+
+ } else if (cellType.equalsIgnoreCase(CELLTYPE_CURRENCY)) {
+
+ // has table:currency
+ // has table:value attribute
+ // has text:p tag
+
+ fmt.setCategory(CELLTYPE_CURRENCY);
+ fmt.setDecimalPlaces(getDecimalPlaces(node));
+
+ } else if (cellType.equalsIgnoreCase(CELLTYPE_BOOLEAN)) {
+
+ // has table:boolean-value attribute
+ // has text:p tag - which is the value we convert
+
+ fmt.setCategory(CELLTYPE_BOOLEAN);
+
+ } else if (cellType.equalsIgnoreCase(CELLTYPE_PERCENT)) {
+
+ // has table:value attribute
+ // has text:p tag
+
+ fmt.setCategory(CELLTYPE_PERCENT);
+ fmt.setDecimalPlaces(getDecimalPlaces(node));
+
+ } else {
+
+ // Should never get here
+
+ }
+ }
+
+ Node tableFormulaNode =
+ cellAtt.getNamedItem(ATTRIBUTE_TABLE_FORMULA);
+
+ Node tableValueNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_VALUE);
+
+ Node tableBooleanNode =
+ cellAtt.getNamedItem(ATTRIBUTE_TABLE_BOOLEAN_VALUE);
+
+ if (tableFormulaNode != null) {
+
+ Debug.log(Debug.INFO, "TableFormulaNode\n");
+ String cellFormula = tableFormulaNode.getNodeValue();
+ String parsedCellFormula = parseFormula(cellFormula);
+ addCell(parsedCellFormula);
+
+ } else if (tableValueNode != null) {
+
+ // Float node, currency node, percent node
+ //
+ Debug.log(Debug.INFO, "TableValueNode\n");
+ String cellValue = tableValueNode.getNodeValue();
+ addCell(cellValue);
+
+ } else if (tableBooleanNode != null) {
+
+ // Boolean Node
+ //
+ String cellValue = tableBooleanNode.getNodeValue();
+
+ if (cellValue.equalsIgnoreCase("true"))
+ {
+ Debug.log(Debug.INFO, "TableBooleanNode - TRUE\n");
+ addCell("TRUE");
+ }
+ else
+ {
+ Debug.log(Debug.INFO, "TableBooleanNode - FALSE\n");
+ addCell("FALSE");
+ }
+
+ } else {
+
+ // Text node, Date node, or Time node
+ //
+ Debug.log(Debug.INFO,
+ "TextNode, DateNode, TimeNode or BooleanNode\n");
+
+ if (node.hasChildNodes()) {
+
+ NodeList childList = node.getChildNodes();
+ int len = childList.getLength();
+
+ for (int i = 0; i < len; i++) {
+
+ Node child = childList.item(i);
+
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+
+ String childName = child.getNodeName();
+
+ if (childName.equals(TAG_PARAGRAPH)) {
+
+ traverseParagraph(child);
+ }
+ }
+ }
+ }
+ }
+
+ // Clear out format for current cell after it is written
+ format = 0;
+
+ // Increase the column counter by the number of times the
+ // last cell was repeated.
+ colID += colsRepeated;
+
+ // Re-initialize the number of columns repeated before processing
+ // the next cell data.
+ colsRepeated = 1;
+
+ }
+
+
+ /**
+ * This method traverses the <i>text:p</i> element <code>Node</code>.
+ *
+ * @param node A <i>text:p</i> <code>Node</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void traverseParagraph(Node node) throws IOException {
+
+ NamedNodeMap cellAtt = node.getAttributes();
+
+ int debug_i=0;
+ Node debug_attrib = null;
+ if (cellAtt == null || cellAtt.item(0) == null)
+ {
+ Debug.log(Debug.INFO, "No Paragraph Attributes\n");
+ }
+ else
+ {
+ while ((debug_attrib = cellAtt.item(debug_i++)) != null)
+ {
+ Debug.log(Debug.INFO, "Paragraph Attribute " + debug_i +
+ ": " + debug_attrib.getNodeName() + " : " +
+ debug_attrib.getNodeValue() + "\n");
+ }
+ }
+
+ if (node.hasChildNodes()) {
+
+ NodeList nodeList = node.getChildNodes();
+
+ int len = nodeList.getLength();
+
+ StringBuffer buffer = new StringBuffer();
+
+ for (int i = 0; i < len; i++) {
+
+ Node child = nodeList.item(i);
+
+ // TODO: need to handle space/tabs/newline nodes later
+ short nodeType = child.getNodeType();
+
+ switch (nodeType) {
+
+ case Node.TEXT_NODE:
+ buffer.append(child.getNodeValue());
+ break;
+
+ case Node.ENTITY_REFERENCE_NODE:
+
+ NodeList nodeList2 = child.getChildNodes();
+ int len2 = nodeList2.getLength();
+
+ for (int j = 0; j < len2; j++) {
+ Node child2 = nodeList2.item(j);
+
+ if (child2.getNodeType() == Node.TEXT_NODE) {
+ buffer.append(child2.getNodeValue());
+ }
+ }
+
+ break;
+ }
+ }
+
+ String s = buffer.toString();
+ displayWidth = calculateContentWidth(s);
+ addCell(s);
+
+ }
+ }
+
+
+ /**
+ * This method will take the input cell value and add
+ * it to the spreadsheet <code>Document</code> we are currently
+ * encoding. This method correctly handles cells that are
+ * repeated in either the row, cell, or both directions.
+ *
+ * @param cellValue The contents of the cell we want to add
+ * to the spreadsheet <code>Document</code>.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ protected void addCell(String cellValue) throws IOException {
+
+ int col = colID;
+ int row = rowID;
+
+ for (int i = 0; i < rowsRepeated; i++) {
+
+ // Log the columns when there are rowsRepeated.
+ if (i > 0) {
+ Debug.log(Debug.TRACE, "</TR>");
+ Debug.log(Debug.TRACE, "<TR>");
+ }
+
+ col = colID;
+
+ for (int j = 0; j < colsRepeated; j++) {
+
+ Debug.log(Debug.TRACE, "<TD>");
+
+ // Add the cell data to the encoded spreadsheet document
+ encoder.addCell(row, col, fmt, cellValue);
+
+ // Check the column width to see if it affects the limits
+ // of the column
+ processColumnWidth(col);
+
+ Debug.log(Debug.TRACE, cellValue);
+ Debug.log(Debug.TRACE, "</TD>");
+
+ col++;
+ }
+
+ row++;
+
+ }
+
+ }
+
+
+ /**
+ * This method calculates the width of the input
+ * <code>String</code>. This value is used in the calculation
+ * of column widths.
+ *
+ * @param content The contents from which to calculate
+ * the width.
+ */
+ protected int calculateContentWidth(String content) {
+
+ // We currently use number of characters as our measure
+ // of width, so width is simply String.length().
+ return content.length();
+ }
+
+
+ /**
+ * This method maintains an array of integers that
+ * contains the desired widths (in number of chars)
+ * for each column.
+ *
+ * @param column The current column number.
+ */
+ protected void processColumnWidth(int column) {
+
+ // Make sure the list has the current column
+ ColumnWidthList.ensureCapacityAndFill(column, 0);
+
+ int index = column - 1;
+
+ int currentWidth = ColumnWidthList.get(index);
+
+ // displayWidth is the size (in characters) of the expected
+ // content of the cell.
+ if (displayWidth > currentWidth) {
+ ColumnWidthList.set(index, displayWidth);
+ }
+ }
+
+
+ /**
+ * This method takes a <i>table:table-cell</i> <code>Node</code>
+ * and traverses down to the <i>text:p</i> tag. The value is
+ * extracted from the <i>text:p</i> tag and the number of decimal
+ * places is calculated.
+ *
+ * @param node A <i>table:table-cell</i> <code>Node</code>.
+ *
+ * @return The number of decimal places in the display
+ * string of the data in the input <code>Node</code>.
+ */
+ protected int getDecimalPlaces(Node node) {
+
+ int decimals = 0;
+
+ Element element = null;
+
+ // cast org.w3c.dom.Node to org.w3c.dom.Element
+ if (node instanceof Element) {
+ element = (Element) node;
+ } else {
+ return decimals;
+ }
+
+ // Traverse to the text:p element, there should only be one.
+ NodeList list = element.getElementsByTagName(TAG_PARAGRAPH);
+
+ if (list.getLength() != 1) {
+ return decimals;
+ }
+
+ Node paragraph = list.item(0);
+
+ if (paragraph.hasChildNodes()) {
+
+ NodeList nodeList = paragraph.getChildNodes();
+
+ int len = nodeList.getLength();
+
+ for (int j = 0; j < len; j++) {
+
+ Node child = nodeList.item(j);
+
+ if (child.getNodeType() == Node.TEXT_NODE) {
+
+ String s = child.getNodeValue();
+
+ displayWidth = calculateContentWidth(s);
+
+ int k = s.lastIndexOf(".");
+ if (k > 0) {
+ s = s.substring(k+1);
+ decimals = s.length();
+ }
+ }
+ }
+ }
+
+ return decimals;
+ }
+
+
+ /**
+ * This abstract method takes a StarOffice formula and parses
+ * into the spreadsheet formula format.
+ *
+ * @param formula The formula to be parsed
+ *
+ * @return The parsed formula.
+ */
+ protected abstract String parseFormula(String formula);
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcPluginFactory.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcPluginFactory.java
new file mode 100644
index 000000000000..5fbd64ad3247
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcPluginFactory.java
@@ -0,0 +1,101 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxc;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.PluginFactory;
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.DocumentMergerFactory;
+
+
+/**
+ * General implementation of the <code>PluginFactory</code> interface
+ * for SXC <code>Document</code> objects.
+ *
+ * @see org.openoffice.xmerge.DocumentDeserializer
+ * @see org.openoffice.xmerge.DocumentMerger
+ * @see org.openoffice.xmerge.DocumentSerializer
+ */
+public abstract class SxcPluginFactory
+ extends PluginFactory implements DocumentMergerFactory {
+
+
+ /**
+ * Constructor that caches the <code>ConvertInfo</code> that
+ * corresponds to the registry information for this plug-in.
+ *
+ * @param ci <code>ConvertInfo</code> object.
+ */
+ public SxcPluginFactory(ConverterInfo ci) {
+ super(ci);
+ }
+
+
+ public Document createOfficeDocument(String name, InputStream is)
+ throws IOException {
+
+ // read zipped XML stream
+ //
+ SxcDocument doc = new SxcDocument(name);
+ doc.read(is);
+ return doc;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/build.xml b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/build.xml
new file mode 100644
index 000000000000..e1c99c9facdc
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/build.xml
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_jooxcx_sxc" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_jooxcx_sxc"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package"
+ value="org/openoffice/xmerge/converter/xml/sxc"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/SxcDocument.java"/>
+ <include name="${package}/Format.java"/>
+ <include name="${package}/SpreadsheetDecoder.java"/>
+ <include name="${package}/SpreadsheetEncoder.java"/>
+ <include name="${package}/SxcDocumentDeserializer.java"/>
+ <include name="${package}/SxcDocumentSerializer.java"/>
+ <include name="${package}/DocumentMergerImpl.java"/>
+ <include name="${package}/SxcPluginFactory.java"/>
+
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/makefile.mk b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/makefile.mk
new file mode 100644
index 000000000000..617f9b262f77
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_jooxcx_sxc
+PRJ=../../../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/package.html b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/package.html
new file mode 100644
index 000000000000..295ea09326df
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/package.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge.converter.xml.sxc package</title>
+</head>
+
+<body bgcolor="white">
+<p>Provides base implementation of StarCalc XML conversion to and from
+different &quot;Device&quot; <code>Document</code> formats.</p>
+
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/SxwDocument.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/SxwDocument.java
new file mode 100644
index 000000000000..1b7e3f577c22
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/SxwDocument.java
@@ -0,0 +1,113 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxw;
+
+import org.w3c.dom.Document;
+import org.openoffice.xmerge.converter.xml.OfficeDocument;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+
+/**
+ * This class is an implementation of <code>OfficeDocument</code> for
+ * the SXW format.
+ */
+public class SxwDocument extends OfficeDocument {
+
+
+ /**
+ * Constructor with arguments to set <code>name</code>.
+ *
+ * @param name The name of the <code>Document</code>
+ */
+ public SxwDocument(String name) {
+ super(name);
+ }
+
+
+ /**
+ * Constructor with arguments to set <code>name</code>, the
+ * <code>namespaceAware</code> flag, and the <code>validating</code>
+ * flag.
+ *
+ * @param name The name of the <code>Document</code>.
+ * @param namespaceAware The value of the namespaceAware flag.
+ * @param validating The value of the validating flag.
+ */
+ public SxwDocument(String name, boolean namespaceAware, boolean validating) {
+
+ super(name, namespaceAware, validating);
+ }
+
+
+ /**
+ * Returns the Office file extension for the SXW format.
+ *
+ * @return The Office file extension for the SXW format.
+ */
+ protected String getFileExtension() {
+ return OfficeConstants.SXW_FILE_EXTENSION;
+ }
+
+
+ /**
+ * Returns the Office attribute for the SXW format.
+ *
+ * @return The Office attribute for the SXW format.
+ */
+ protected String getOfficeClassAttribute() {
+ return OfficeConstants.SXW_TYPE;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/SxwPluginFactory.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/SxwPluginFactory.java
new file mode 100644
index 000000000000..8faabd245228
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/SxwPluginFactory.java
@@ -0,0 +1,97 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.sxw;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.PluginFactory;
+import org.openoffice.xmerge.PluginFactory;
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+
+/**
+ * General implementation of the <code>PluginFactory</code> interface
+ * for SXW documents.
+ *
+ * @see org.openoffice.xmerge.DocumentDeserializer
+ * @see org.openoffice.xmerge.DocumentMerger
+ * @see org.openoffice.xmerge.DocumentSerializer
+ */
+public abstract class SxwPluginFactory extends PluginFactory {
+
+ /**
+ * Constructor that caches the <code>ConvertInfo</code> that
+ * corresponds to the registry information for this plug-in.
+ *
+ * @param ci <code>ConvertInfo</code> object.
+ */
+ public SxwPluginFactory (ConverterInfo ci) {
+ super(ci);
+ }
+
+
+ public Document createOfficeDocument(String name, InputStream is)
+ throws IOException {
+
+ // read zipped XML stream
+ SxwDocument doc = new SxwDocument(name);
+ doc.read(is);
+ return doc;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/build.xml b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/build.xml
new file mode 100644
index 000000000000..b6376496b13f
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/build.xml
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_jooxcx_sxw" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_jooxcx_sxw"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package"
+ value="org/openoffice/xmerge/converter/xml/sxw"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/SxwDocument.java"/>
+ <include name="${package}/SxwPluginFactory.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/makefile.mk b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/makefile.mk
new file mode 100644
index 000000000000..eeaaad905622
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_jooxcx_sxw
+PRJ=../../../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/package.html b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/package.html
new file mode 100644
index 000000000000..cbf3cabb0956
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxw/package.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge.converter.xml.sxw package</title>
+</head>
+
+<body bgcolor="white">
+<p>Provides base implementation of StarWriter XML conversion to and from
+different &quot;Device&quot; <code>Document</code> formats.</p>
+
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentDeserializerImpl.java b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentDeserializerImpl.java
new file mode 100644
index 000000000000..bf21f0ac33f2
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentDeserializerImpl.java
@@ -0,0 +1,238 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.xslt;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+
+
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.ConvertException;
+import org.openoffice.xmerge.DocumentDeserializer;
+import org.openoffice.xmerge.converter.dom.DOMDocument;
+import org.openoffice.xmerge.converter.xml.sxw.SxwDocument;
+import org.openoffice.xmerge.util.Debug;
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+
+// Imported TraX classes
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerConfigurationException;
+
+//
+//import org.apache.xalan.serialize.Serializer;
+//import org.apache.xalan.serialize.SerializerFactory;
+//import org.apache.xalan.templates.OutputProperties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+// Imported java classes
+import java.io.FileNotFoundException;
+
+
+/**
+ * <p>Xslt implementation of
+ * org.openoffice.xmerge.DocumentSerializer
+ * for the {@link
+ * org.openoffice.xmerge.converter.xml.xslt.PluginFactoryImpl
+ * PluginFactoryImpl}.</p>
+ *
+ * <p>The <code>serialize</code> method transforms the DOM
+ * document from the given <code>Document</code> object by
+ * means of a supplied Xsl Stylesheet.</p>
+ *
+ * @author Aidan Butler
+ */
+public final class DocumentDeserializerImpl
+ implements DocumentDeserializer {
+
+ /** A <code>ConvertData</code> object assigned to this object. */
+ private InputStream is = null;
+ private ConvertData cd = null;
+ private PluginFactoryImpl pluginFactory = null;
+
+ /**
+ * Constructor that assigns the given <code>ConvertData</code>
+ * to this object.
+ *
+ * @param pf A <code>PluginFactoryImpl</code> object.
+ *
+ * @param cd A <code>ConvertData</code> object to read data for
+ * the conversion process by the <code>deserialize</code>
+ * method.
+ */
+ public DocumentDeserializerImpl(PluginFactoryImpl pf,ConvertData cd) {
+ this.cd = cd;
+ pluginFactory = pf;
+ }
+
+
+ /**
+ * Convert the given <code>DOMDocument</code> format object
+ * into a <code>SxwDocument</code> object.
+ *
+ * @return Resulting <code>SxwDocument</code> object.
+ *
+ * @throws ConvertException If any conversion error occurs.
+ * @throws IOException If any I/O error occurs.
+ */
+ public Document deserialize() throws ConvertException, IOException {
+
+ Enumeration enum = cd.getDocumentEnumeration();
+ org.w3c.dom.Document domDoc=null;
+ DOMDocument docOut=null;
+ DOMResult domTree=null;
+ SxwDocument doc = null;
+
+ while (enum.hasMoreElements()) {
+ docOut = (DOMDocument) enum.nextElement();
+ }
+ domDoc = docOut.getContentDOM();
+
+
+ try{
+ domTree=transform(domDoc);
+
+ }
+ catch(Exception e){
+ System.out.println("The following error occurred:"+e);
+ }
+ SxwDocument sxwDoc = new SxwDocument("output");
+ sxwDoc.initContentDOM();
+ sxwDoc.setContentDOM(domTree.getNode());
+
+ return sxwDoc;
+
+ }
+
+ /*
+ * This method performs the sxl transformation on the supplied Dom Tree.
+ *
+ * Xslt transformation code
+ *
+ * @throws TransformerException,TransformerConfigurationException
+ * , FileNotFoundException,IOException
+ *
+ */
+
+
+ private DOMResult transform(org.w3c.dom.Document xmlDoc)
+ throws TransformerException,TransformerConfigurationException
+ , FileNotFoundException,IOException{
+
+ //System.out.println("\nTransforming...");
+ DOMResult xmlDomResult = new DOMResult();
+ ConverterInfo ci = pluginFactory.getConverterInfo();
+
+ try{
+ DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
+ dFactory.setNamespaceAware(true);
+ DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
+
+ String teststr = ci.getXsltDeserial();
+ teststr= teststr.substring(0,6);
+ org.w3c.dom.Document xslDoc=null;
+ if ((teststr.equals("http:/"))||(teststr.equals("file:/"))
+ ||(teststr.equals("jar://"))){
+ //System.out.println(ci.getXsltDeserial());
+ xslDoc= dBuilder.parse(ci.getXsltDeserial());
+
+ }
+ else{
+ //System.out.println(ci.getJarName()+"!/"+ci.getXsltDeserial());
+ xslDoc = dBuilder.parse(
+ "jar:"+ci.getJarName()+"!/"+ci.getXsltDeserial());
+ }
+
+
+ DOMSource xslDomSource = new DOMSource(xslDoc);
+ DOMSource xmlDomSource = new DOMSource(xmlDoc);
+
+ //call the tranformer using the XSL, Source and Result dom.
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+
+ Transformer transformer = tFactory.newTransformer(xslDomSource);
+ transformer.transform(xmlDomSource, xmlDomResult);
+ /*
+ // Serialize for output to standard out
+ Serializer serializer = SerializerFactory.getSerializer
+ (OutputProperties.getDefaultMethodProperties("xml"));
+ serializer.setOutputStream(System.out);
+ serializer.asDOMSerializer().serialize(xmlDomResult.getNode());
+ */
+
+ //System.out.println("\n** Transform Complete ***");
+
+ }
+ catch(Exception e){
+ System.out.println("An error occured in the transformation : "+e);
+ }
+ return xmlDomResult;
+ }
+
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java
new file mode 100644
index 000000000000..e6bd90b4755d
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/DocumentSerializerImpl.java
@@ -0,0 +1,235 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.xslt;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.ConvertException;
+import org.openoffice.xmerge.DocumentSerializer;
+import org.openoffice.xmerge.converter.xml.sxw.SxwDocument;
+import org.openoffice.xmerge.converter.dom.DOMDocument;
+import org.openoffice.xmerge.util.Debug;
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+
+// Imported TraX classes
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerConfigurationException;
+
+//
+import org.apache.xalan.serialize.Serializer;
+import org.apache.xalan.serialize.SerializerFactory;
+import org.apache.xalan.templates.OutputProperties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+// Imported java classes
+import java.io.FileNotFoundException;
+
+/**
+ * <p>Xslt implementation of
+ * org.openoffice.xmerge.DocumentSerializer
+ * for the {@link
+ * org.openoffice.xmerge.converter.xml.xslt.PluginFactoryImpl
+ * PluginFactoryImpl}.</p>
+ *
+ * <p>The <code>serialize</code> method transforms the DOM
+ * document from the given <code>Document</code> object by
+ * means of a supplied Xsl Stylesheet.</p>
+ *
+ * @author Aidan Butler
+ */
+
+
+public final class DocumentSerializerImpl
+ implements DocumentSerializer {
+
+
+ /** SXW <code>Document</code> object that this converter processes. */
+ private SxwDocument sxwDoc = null;
+
+ private PluginFactoryImpl pluginFactory = null;
+
+ /**
+ * Constructor.
+ *
+ * @param pf A <code>PluginFactoryImpl</code>
+ * @param doc A SXW <code>Document</code> to be converted.
+ */
+ public DocumentSerializerImpl(PluginFactoryImpl pf,Document doc) {
+ pluginFactory=pf;
+ sxwDoc = (SxwDocument) doc;
+ }
+
+
+ /**
+ * Method to convert a <code>Document</code> with an xsl stylesheet.
+ * It creates a <code>Document</code> object, which is then transformed
+ * with the Xslt processer. A <code>ConvertData </code> object is
+ * constructed and returned.
+ *
+ * @returns cd A <code>ConvertData</code> object.
+ * @throws ConvertException If any I/O error occurs.
+ * @throws IOException If any I/O error occurs.
+ */
+ public ConvertData serialize() throws ConvertException, IOException {
+ String docName = sxwDoc.getName();
+ org.w3c.dom.Document domDoc = sxwDoc.getContentDOM();
+ ByteArrayOutputStream baos= new ByteArrayOutputStream();
+ ConvertData cd = new ConvertData();
+ try{
+ baos=transform(domDoc);
+ }
+ catch (Exception e){
+ System.out.println("\n Error with Xslt\n");
+ }
+
+ String ext = pluginFactory.getDeviceFileExtension();
+ DOMDocument resultDomDoc=(DOMDocument)pluginFactory.createDeviceDocument(docName,new ByteArrayInputStream(baos.toByteArray()));
+ cd.addDocument (resultDomDoc);
+ return cd;
+ }
+
+
+
+ /*
+ * This method performs the sxl transformation on the supplied <code>
+ * Document</code> and returns a <code>DOMResult</code> object.
+ *
+ * Xslt transformation code
+ *
+ * @returns baos A <code>ByteArrayOutputStream</code> object containing
+ * the result of the Xslt transformation.
+ * @throws TransformerException,TransformerConfigurationException
+ * , FileNotFoundException,IOException
+ *
+ */
+
+
+ private ByteArrayOutputStream transform(org.w3c.dom.Document domDoc)
+ throws TransformerException,TransformerConfigurationException
+ , FileNotFoundException,IOException{
+
+
+ //System.out.println("\nTransforming...");
+ ConverterInfo ci = pluginFactory.getConverterInfo();
+ DOMResult xmlDomResult = new DOMResult();
+ ByteArrayOutputStream baos= new ByteArrayOutputStream();
+ try{
+
+ DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
+ dFactory.setNamespaceAware(true);
+
+ DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
+ String teststr = ci.getXsltSerial();
+ teststr= teststr.substring(0,6);
+ org.w3c.dom.Document xslDoc=null;
+ if ((teststr.equals("http:/"))||(teststr.equals("file:/"))
+ ||(teststr.equals("jar://"))){
+ //System.out.println(ci.getXsltSerial());
+ xslDoc= dBuilder.parse(ci.getXsltSerial());
+
+ }
+ else{
+ //System.out.println(ci.getJarName()+"!/"+ci.getXsltSerial());
+ xslDoc = dBuilder.parse(
+ "jar:"+ci.getJarName()+"!/"+ci.getXsltSerial());
+ }
+ DOMSource xslDomSource = new DOMSource(xslDoc);
+ DOMSource xmlDomSource = new DOMSource(domDoc);
+
+ //xmlDomSource.setSystemId("content.xml");
+ //xslDomSource.setSystemId("staroff.xsl");
+
+ //call the tranformer using the XSL, Source and Result dom.
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ Transformer transformer = tFactory.newTransformer(xslDomSource);
+ transformer.transform(xmlDomSource, xmlDomResult);
+ // Serialize for output to standard out
+
+ Serializer serializer = SerializerFactory.getSerializer
+ (OutputProperties.getDefaultMethodProperties("xml"));
+ //serializer.setOutputStream(System.out);
+ serializer.setOutputStream(baos);
+ serializer.asDOMSerializer().serialize(xmlDomResult.getNode());
+ //System.out.println(baos.toString());
+ //System.out.println("\n** Transform Complete ***");
+ }
+ catch(Exception e){
+ System.out.println("An error occured in the transformation : "+e);
+ }
+ return baos;
+ }
+
+
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/PluginFactoryImpl.java b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/PluginFactoryImpl.java
new file mode 100644
index 000000000000..69ae3c0e885a
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/PluginFactoryImpl.java
@@ -0,0 +1,200 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.converter.xml.xslt;
+
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.DocumentSerializer;
+import org.openoffice.xmerge.DocumentSerializerFactory;
+import org.openoffice.xmerge.DocumentDeserializer;
+import org.openoffice.xmerge.DocumentDeserializerFactory;
+import org.openoffice.xmerge.PluginFactory;
+import org.openoffice.xmerge.converter.dom.DOMDocument;
+import org.openoffice.xmerge.converter.xml.sxw.SxwDocument;
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * <p>Xslt implementation of the <code>PluginFactory</code>.
+ * This encapsulates conversion of StarWriter XML format to and from
+ * a supported format.</p>
+ *
+ * <p>The superclass produces a particular
+ * {@link org.openoffice.xmerge.Document Document}
+ * object, i.e. {@link
+ * org.openoffice.xmerge.converter.xml.sxw.SxwDocument
+ * SxwDocument} that the converters in this class work with. Thus,
+ * this class only implements the methods that produces the converters,
+ * i.e. {@link
+ * org.openoffice.xmerge.DocumentSerializer
+ * DocumentSerializer} and {@link
+ * org.openoffice.xmerge.DocumentDeserializer
+ * DocumentDeserializer}</p>
+ *
+ * @author Aidan Butler
+ */
+public final class PluginFactoryImpl extends PluginFactory
+ implements DocumentDeserializerFactory, DocumentSerializerFactory {
+
+ public PluginFactoryImpl (ConverterInfo ci) {
+ super(ci);
+ }
+
+
+
+ /**
+ * Returns an instance of <code>DocumentSerializerImpl</code>,
+ * which is an implementation of the <code>DocumentSerializer</code>
+ * interface.
+ *
+ * @param doc <code>Document</code> object to be
+ * converted/serialized.
+ *
+ * @return A <code>DocumentSerializerImpl</code> object.
+ */
+ public DocumentSerializer createDocumentSerializer(Document doc) {
+ return new DocumentSerializerImpl(this,doc);
+ }
+
+
+ /**
+ * Returns an instance of <code>DocumentDeserializerImpl</code>,
+ * which is an implementation of the <code>DocumentDeserializer</code>
+ * interface.
+ *
+ * @param is <code>ConvertData</code> object.
+ *
+ * @return A DocumentDeserializerImpl object.
+ */
+ public DocumentDeserializer createDocumentDeserializer(ConvertData cd) {
+
+ return new DocumentDeserializerImpl(this,cd);
+ }
+
+
+
+ public org.openoffice.xmerge.Document createDeviceDocument(java.lang.String str, java.io.InputStream inputStream) throws java.io.IOException {
+ String ext = this.getDeviceFileExtension();
+ DOMDocument domDoc = new DOMDocument(str,ext);
+ domDoc.read(inputStream);
+ return domDoc;
+ }
+
+
+ public Document createOfficeDocument(String name, InputStream is)
+ throws IOException {
+
+ // read zipped XML stream
+ SxwDocument doc = new SxwDocument(name);
+ doc.read(is);
+ return doc;
+ }
+
+ /**
+ * Returns a <code>String</code> containing the file extension of a
+ * <code>Document</code>. This method uses a properties file to determine
+ * a mapping from the device mime in the <code>ConverterInfo</code> to a
+ * particular file extension. If a mapping is not specified, the default
+ * is ".txt".
+ *
+ * @return <code>String</code>.
+ */
+
+
+ public String getDeviceFileExtension(){
+ Class c = this.getClass();
+ InputStream is = c.getResourceAsStream("XsltPlugin.properties");
+ Properties props = new Properties();
+ String ext= ".txt";
+ String mimeType = null;
+ ConverterInfo ci = this.getConverterInfo();
+ Enumeration enum = ci.getDeviceMime();
+ while (enum.hasMoreElements()) {
+ mimeType= (String) enum.nextElement();
+ }
+ try {
+ props.load(is);
+
+ String info = props.getProperty(mimeType);
+ if (info != null) {
+ ext = info;
+ }
+ } catch (Exception e) {
+
+ // It is okay for the property file to not exist.
+ //
+ }
+ return ext;
+ }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/XsltPlugin.properties b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/XsltPlugin.properties
new file mode 100644
index 000000000000..23a2d8c4c477
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/XsltPlugin.properties
@@ -0,0 +1,63 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+
+#
+# XsltPlugin.properties
+#
+
+#This file allows users to specify the mime-type to file extension mappings
+
+# e.g text/html=.html
+text/html=.html
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/build.xml b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/build.xml
new file mode 100644
index 000000000000..8be6fb008c5d
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/build.xml
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_jooxcx_xslt" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_jooxcx_xslt"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../../../../"/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package"
+ value="org/openoffice/xmerge/converter/xml/xslt/"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/xalan.jar"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/DocumentDeserializerImpl.java"/>
+ <include name="${package}/DocumentSerializerImpl.java"/>
+ <include name="${package}/PluginFactoryImpl.java"/>
+ </javac>
+ <copy todir="${build.class}/${package}">
+ <fileset dir=".">
+ <include name="*.properties"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/converter.xml b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/converter.xml
new file mode 100644
index 000000000000..d3c76cbf3373
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/converter.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<!--<!DOCTYPE converters SYSTEM "converter.dtd">-->
+<converters>
+ <converter type="staroffice/sxw" version="1.0">
+ <converter-display-name>
+ XSLT Transformation
+ </converter-display-name>
+ <converter-description>
+ Converter which performs xslt transformations
+ </converter-description>
+ <converter-vendor>OpenOffice.org</converter-vendor>
+ <converter-class-impl>
+ org.openoffice.xmerge.converter.xml.xslt.PluginFactoryImpl
+ </converter-class-impl>
+ <converter-xslt-serialize>
+ sofftohtml.xsl
+ </converter-xslt-serialize>
+ <converter-xslt-deserialize>
+ htmltosoff.xsl
+ </converter-xslt-deserialize>
+ <converter-target type="text/html" />
+ </converter>
+</converters>
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/htmltosoff.xsl b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/htmltosoff.xsl
new file mode 100644
index 000000000000..2f4381e73ee0
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/htmltosoff.xsl
@@ -0,0 +1,201 @@
+<?xml version='1.0' encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:office="http://openoffice.org/2000/office"
+ xmlns:style="http://openoffice.org/2000/style"
+ xmlns:text="http://openoffice.org/2000/text"
+ xmlns:table="http://openoffice.org/2000/table"
+ xmlns:draw="http://openoffice.org/2000/drawing"
+ xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:number="http://openoffice.org/2000/datastyle"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:chart="http://openoffice.org/2000/chart"
+ xmlns:dr3d="http://openoffice.org/2000/dr3d"
+ xmlns:math="http://www.w3.org/1998/Math/MathML"
+ xmlns:form="http://openoffice.org/2000/form"
+ xmlns:script="http://openoffice.org/2000/script"
+ >
+<xsl:output method="html" />
+
+
+<xsl:template match="/">
+ <xsl:apply-templates />
+</xsl:template>
+
+<xsl:template match="html">
+
+ <office:document-content xmlns:office="http://openoffice.org/2000/office"
+ xmlns:style="http://openoffice.org/2000/style"
+ xmlns:text="http://openoffice.org/2000/text"
+ xmlns:table="http://openoffice.org/2000/table"
+ xmlns:draw="http://openoffice.org/2000/drawing"
+ xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:number="http://openoffice.org/2000/datastyle"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:chart="http://openoffice.org/2000/chart"
+ xmlns:dr3d="http://openoffice.org/2000/dr3d"
+ xmlns:math="http://www.w3.org/1998/Math/MathML"
+ xmlns:form="http://openoffice.org/2000/form"
+ xmlns:script="http://openoffice.org/2000/script"
+ office:class="text" office:version="1.0">
+
+<office:script/>
+ <office:font-decls>
+ <style:font-decl style:name="Letter Gothic" fo:font-family="&apos;Letter Gothic&apos;" style:font-family-generic="modern" style:font-pitch="fixed"/>
+ <style:font-decl style:name="Arial Unicode MS" fo:font-family="&apos;Arial Unicode MS&apos;" style:font-pitch="variable"/>
+ <style:font-decl style:name="HG Mincho Light J" fo:font-family="&apos;HG Mincho Light J&apos;" style:font-pitch="variable"/>
+ <style:font-decl style:name="CG Times" fo:font-family="&apos;CG Times&apos;" style:font-family-generic="roman" style:font-pitch="variable"/>
+ <style:font-decl style:name="Thorndale" fo:font-family="Thorndale" style:font-family-generic="roman" style:font-pitch="variable"/>
+ <style:font-decl style:name="Antique Olive" fo:font-family="&apos;Antique Olive&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/>
+ <style:font-decl style:name="Arial Black" fo:font-family="&apos;Arial Black&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/>
+ </office:font-decls>
+ <office:automatic-styles>
+ <style:style style:name="Table1" style:family="table">
+ <style:properties style:width="16.999cm" table:align="margins"/>
+ </style:style>
+ <style:style style:name="Table1.A" style:family="table-column">
+ <style:properties style:column-width="3.399cm" style:rel-column-width="13107*"/>
+ </style:style>
+ <style:style style:name="Table1.A1" style:family="table-cell">
+ <style:properties fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000"/>
+ </style:style>
+ <style:style style:name="Table1.E1" style:family="table-cell">
+ <style:properties fo:padding="0.097cm" fo:border="0.002cm solid #000000"/>
+ </style:style>
+ <style:style style:name="Table1.A2" style:family="table-cell">
+ <style:properties fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.002cm solid #000000"/>
+ </style:style>
+ <style:style style:name="Table1.E2" style:family="table-cell">
+ <style:properties fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="0.002cm solid #000000" fo:border-top="none" fo:border-bottom="0.002cm solid #000000"/>
+ </style:style>
+ <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard">
+ <style:properties fo:margin-left="0cm" fo:margin-right="0cm" fo:text-indent="0cm" style:auto-text-indent="false"/>
+ </style:style>
+ <style:style style:name="P2" style:family="paragraph" style:parent-style-name="Table Contents">
+ <style:properties style:font-name="Arial Black" fo:font-size="20pt"/>
+ </style:style>
+ </office:automatic-styles>
+
+
+
+
+
+ <office:body>
+ <text:sequence-decls>
+ <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>
+ <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
+ <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
+ <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
+ </text:sequence-decls>
+
+ <xsl:apply-templates/>
+ </office:body>
+ </office:document-content>
+
+</xsl:template>
+
+<xsl:template match="body">
+ <xsl:apply-templates />
+</xsl:template>
+
+
+
+<xsl:template match="p">
+ <xsl:for-each select=".">
+ <text:p text:style-name="P1">
+ <!--<xsl:value-of select="."/>-->
+ <xsl:apply-templates />
+ </text:p>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="br">
+ <xsl:if test="ancestor::p">
+ <xsl:text disable-output-escaping="yes">&lt;/text:p&gt; &lt;text:p text:style-name="P1"&gt;</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="table">
+ <xsl:for-each select=".">
+ <table:table table:name="Table1" table:style-name="Table1">
+ <table:table-column table:style-name="Table1.A" table:number-columns-repeated="5"/>
+ <xsl:apply-templates/>
+ </table:table>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="tr">
+ <xsl:for-each select=".">
+ <table:table-row>
+ <xsl:apply-templates/>
+ </table:table-row>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="td">
+ <xsl:for-each select=".">
+ <table:table-cell table:style-name="Table1.A1" table:value-type="string">
+ <text:p text:style-name="P1">
+ <xsl:value-of select="."/>
+ </text:p>
+ </table:table-cell>
+ </xsl:for-each>
+</xsl:template>
+
+
+
+</xsl:stylesheet>
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/makefile.mk b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/makefile.mk
new file mode 100644
index 000000000000..58dac2d2c643
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_jooxcx_xslt
+PRJ=../../../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/package.html b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/package.html
new file mode 100644
index 000000000000..6cb78f7ee80a
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/package.html
@@ -0,0 +1,92 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<HTML>
+<HEAD>
+ <TITLE>org.openoffice.xmerge.converter.xml.xslt package</TITLE>
+</HEAD>
+<BODY>
+<P>Provides the tools for doing the conversion of StarWriter XML to
+and from supported formats, through the use of an XSLT
+transformation.</P>
+<P>It follows the {@link org.openoffice.xmerge}
+framework for the conversion process.</P>
+<P>This converter does not currently support merge.</P>
+<P><FONT FACE="Times New Roman, serif"><FONT SIZE=5><B>XSLT
+Transformation</B></FONT></FONT></P>
+<p>The converter makes use
+of one or more XSLT style sheets, which are used in the
+DocumentSerializer and DocumentDeserializer, to perform the actual
+translations. The location of these stylesheets is extracted from the {@link org.openoffice.xmerge.util.registry.ConverterInfo ConverterInfo} data structure, and are specified using the optional converter-xslt-serialize and converter-xsltdeserialize tags in a plugins converter.xml file. Please refer to the SDK document for more information about how to implement a Plugin Configuration XML File for a specific plugin.
+A sample OpenOffice to Html stylesheet and Html to
+Openffice stylesheet, has been provided as a sample implementation.
+The converter also makes use of an XsltPlugin.properties file, which may be edited by the user to provide MIME-TYPE to file extension mappings. This file is used by the {@link org.openoffice.xmerge.converter.xml.xslt.PluginFactoryImpl getDeviceFileExtension} method.
+</p>
+
+<H2>TODO list</H2>
+
+<p><ol>
+<li>Expand XSLT style sheets to support more office/html
+ capabilities</li>
+<li>Add support for certain character codes, such as &amp;nbsp
+ which currently causes the transformer to break.</li>
+<li>Change the DocumentDeserializer transformer, so that the DOMResult is serialized using the xalan serializer and create an SxwDocument from the result</li>
+</ol></p>
+
+@see org.openoffice.xmerge.util.registry
+
+</BODY>
+</HTML>
+
+
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/sofftohtml.xsl b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/sofftohtml.xsl
new file mode 100644
index 000000000000..0ce80aa71383
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/xslt/sofftohtml.xsl
@@ -0,0 +1,193 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:style="http://openoffice.org/2000/style" xmlns:table="http://openoffice.org/2000/table" xmlns:text="http://openoffice.org/2000/text" xmlns:office="http://openoffice.org/2000/office" xmlns:fo="http://www.w3.org/1999/XSL/Format">
+<xsl:output method="html" indent="yes" encoding="ISO-8859-1"/>
+<!--doctype-system=[<!ENTITY acirc "">] -->
+
+<xsl:strip-space elements="tokens"/>
+
+<xsl:template match="office:document-content">
+ <html>
+ <xsl:apply-templates />
+ </html>
+</xsl:template>
+
+<xsl:template match="office:automatic-styles">
+ <style type="text/css">
+ p.Table-Heading{font-weight :bold;}
+ <xsl:apply-templates />
+ </style>
+</xsl:template>
+
+
+<xsl:template match="style:style">
+ <xsl:if test="@style:family ='paragraph'">
+ p.<xsl:value-of select="@style:name"/>{
+ <xsl:apply-templates />}
+ </xsl:if>
+ <xsl:if test="@style:family ='paragraph'">
+ p.<xsl:value-of select="@style:name"/>{
+ <xsl:if test="@style:parent-style-name='Table Heading'">
+ font-weight :bold;font-style:italic;
+ </xsl:if>
+ <xsl:apply-templates />}
+ </xsl:if>
+ <xsl:if test="@style:family ='table-cell'">
+ td.<xsl:value-of select="@style:name"/>{
+ <xsl:if test="@style:parent-style-name='Table Heading'">
+ font-weight :bold;font-style:italic;
+ </xsl:if>
+ <xsl:apply-templates />}
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="style:properties">
+ <!--<xsl:param name="style" select="@fo:font-weight"/>-->
+ <xsl:if test="@fo:font-weight">
+ font-weight :<xsl:value-of select="@fo:font-weight"/>;
+ </xsl:if>
+ <xsl:if test="@fo:font-style">
+ font-style :<xsl:value-of select="@fo:font-style"/>;
+ </xsl:if>
+ <xsl:if test="@style:font-name">
+ font-family :<xsl:value-of select="@style:font-name"/>;
+ </xsl:if>
+ <xsl:if test="@fo:font-size">
+ font-size : <xsl:value-of select="@fo:font-size"/>;
+ </xsl:if>
+ <xsl:if test="@style:text-underline='single'">
+ text-decoration :underline;
+ </xsl:if>
+ <xsl:if test="@style:text-crossing-out='single-line'">
+ text-decoration:line-through;
+ </xsl:if>
+ <xsl:if test="@fo:text-align='start'">
+ text-align :left
+ </xsl:if>
+ <xsl:if test="@fo:text-align='center'">
+ text-align :center
+ </xsl:if>
+ <xsl:if test="@fo:text-align='end'">
+ text-align :right
+ </xsl:if>
+ <!--<xsl:value-of select="$style"/>-->
+</xsl:template>
+
+<xsl:template match="office:body">
+ <xsl:apply-templates />
+</xsl:template>
+
+<xsl:template match="table:table">
+ <table border="1" cellpadding="2" width="100%">
+ <xsl:apply-templates />
+ </table>
+
+</xsl:template>
+
+
+<xsl:template match="table:table-header-rows">
+ <th>
+ <xsl:apply-templates />
+ </th>
+</xsl:template>
+
+<xsl:template match="table:table-row">
+ <tr>
+ <xsl:apply-templates />
+ </tr>
+</xsl:template>
+
+<xsl:template match="table:table-cell">
+ <xsl:text disable-output-escaping="yes">&lt;td class="</xsl:text>
+ <xsl:value-of select="@table:style-name"/>
+ <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
+ <!--<xsl:value-of select="."/>-->
+ <xsl:apply-templates />
+ <xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
+
+
+ <!--<td width="20%">
+ <xsl:apply-templates />
+ </td>-->
+</xsl:template>
+
+
+<xsl:template match="text:p">
+ <xsl:if test="ancestor-or-self::table:table-cell">
+ <xsl:if test=".=''">
+ <br/>
+ </xsl:if>
+ </xsl:if>
+ <xsl:text disable-output-escaping="yes">&lt;p class="</xsl:text>
+ <xsl:choose>
+ <xsl:when test="@text:style-name ='Table Heading'">
+ Table-Heading
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="@text:style-name"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
+ <xsl:value-of select="."/>
+ <xsl:text disable-output-escaping="yes">&lt;/p&gt;</xsl:text>
+ <!--<xsl:value-of select="."/>-->
+ <!--<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>-->
+ <!--<br/>-->
+
+
+</xsl:template>
+
+
+</xsl:stylesheet>
diff --git a/xmerge/java/org/openoffice/xmerge/makefile.mk b/xmerge/java/org/openoffice/xmerge/makefile.mk
new file mode 100644
index 000000000000..e9eb2509a04c
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_joo_xmerge
+PRJ=../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/merger/DiffAlgorithm.java b/xmerge/java/org/openoffice/xmerge/merger/DiffAlgorithm.java
new file mode 100644
index 000000000000..98c27b0b17dd
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/DiffAlgorithm.java
@@ -0,0 +1,79 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger;
+
+/**
+ * This is the difference algorithm interface. It is an interface so
+ * that different algorithms may be plugged-in to actually compute
+ * the differences.
+ *
+ * NOTE: this code may not be thread safe.
+ */
+public interface DiffAlgorithm {
+
+ /**
+ * Returns a <code>Difference</code> array. This method finds out
+ * the difference between two sequences.
+ *
+ * @param orgSeq The original sequence of object.
+ * @param modSeq The modified (or changed) sequence to
+ * compare against with the origial.
+ *
+ * @return A <code>Difference</code> array.
+ */
+ public Difference[] computeDiffs(Iterator orgSeq, Iterator modSeq);
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/Difference.java b/xmerge/java/org/openoffice/xmerge/merger/Difference.java
new file mode 100644
index 000000000000..9f173f251ce9
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/Difference.java
@@ -0,0 +1,270 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger;
+
+
+/**
+ * This is the <code>Difference</code> basic unit. Used by the
+ * <code>DiffAlgorithm</code> as a set of difference between two
+ * <code>Iterators</code> (the original and modified
+ * <code>Iterators</code>).
+ *
+ * @author smak
+ */
+public final class Difference {
+
+ /**
+ * Add operation.
+ */
+ public static final int ADD = 1;
+
+ /**
+ * Delete operation.
+ */
+ public static final int DELETE = 2;
+
+ /**
+ * Change operation.
+ */
+ public static final int CHANGE = 3;
+
+ /**
+ * Unchange operation (i.e. no change).
+ */
+ public static final int UNCHANGE = 4;
+
+ /**
+ * The action of the diff - either {@link #ADD} or {@link #DELETE}.
+ */
+ private int operation;
+
+ /**
+ * <p>The position of the content that should be operated on (original
+ * iterator).</p>
+ *
+ * <p>For ADD, the orgPosition is the position of the original sequence
+ * where the diff will insert (the element count is starting from 0, and
+ * always insert before the element). The modPosition is the position
+ * of the diff in the modified sequence (also starting from 0).</p>
+ *
+ * <blockquote><pre>
+ * example:
+ *
+ * diff - &lt;B D&gt;and &lt;A B C D E F&gt;
+ * note: &lt;B D&gt;is original sequence and &lt;A B C D E F&gt;
+ * is the modified one.
+ *
+ * and here is the position of those sequence:
+ * &lt;B D&gt; &lt;A B C D E F&gt;
+ * 0 1 0 1 2 3 4 5
+ *
+ * result:
+ * &lt;diff orgPos=0 modPos=0 operation=ADD&gt; &lt;-- element A
+ * &lt;diff orgPos=1 modPos=2 operation=ADD&gt; &lt;-- element C
+ * &lt;diff orgPos=2 modPos=4 operation=ADD&gt; &lt;-- element E
+ * &lt;diff orgPos=2 modPos=5 operation=ADD&gt; &lt;-- element F
+ *
+ * </pre> </blockquote>
+ * <p>One can notice the add operation is inserted before the position.
+ * Hence, in order to append an element, we will have a position of
+ * original sequence length + 1 to denote an append.</p>
+ *
+ * <p>For DELETE, orgPosition is the position that the element
+ * will be deleted (starting from 0) and modPosition is the position
+ * where the deleted element should be (consider as an ADD).</p>
+ *
+ * <p>The modPosition is less useful and it is difficult to understand
+ * how the position is calculated. One can just skip this piece of
+ * information. It is useful if one wants to reverse the role
+ * of original sequence and modified sequence and find out the diff
+ * easily (just change add to delete and delete to add for operation
+ * and swap the orgPosition and modPosition).</p>
+ *
+ * <blockquote><pre>
+ * example:
+ *
+ * diff - &lt;A B C D E F&gt; and &lt; B D&gt;
+ * note: &lt;A B C D E F&gt; is original sequence and &lt;B D&gt;
+ * is the modified one.
+ *
+ * and here is the position of those sequence:
+ * &lt;A B C D E F&gt; &lt;B D&gt;
+ * 0 1 2 3 4 5 0 1
+ *
+ * result:
+ * &lt;diff orgPos=0 modPos=0 operation=DELETE&gt; &lt;-- element A
+ * &lt;diff orgPos=2 modPos=1 operation=DELETE&gt; &lt;-- element C
+ * &lt;diff orgPos=4 modPos=2 operation=DELETE&gt; &lt;-- element E
+ * &lt;diff orgPos=5 modPos=2 operation=DELETE&gt; &lt;-- element F
+ * </pre></blockquote>
+ */
+ private int orgPosition;
+
+ /**
+ * The position of the content that should be operated (modified iterator).
+ * For explanation and examples, see {@link #orgPosition}.
+ */
+ private int modPosition;
+
+
+ /**
+ * Constructor. This is the standard way to create a
+ * <code>Difference</code> object.
+ *
+ * @param operation Either {@link #ADD} or {@link #DELETE}.
+ * @param orgPosition The position in the original (first)
+ * <code>Iterator</code>.
+ * @param modPosition The position in the modified (second)
+ * <code>Iterator</code>.
+ */
+ public Difference(int operation, int orgPosition,
+ int modPosition) {
+ this.operation = operation;
+ this.orgPosition = orgPosition;
+ this.modPosition = modPosition;
+ }
+
+
+ /**
+ * Get the operation of the <code>Difference</code>.
+ *
+ * @return the operation of the <code>Difference</code>,
+ * either {@link #ADD} or {@link #DELETE}
+ */
+ public int getOperation() {
+ return operation;
+ }
+
+ /**
+ * Get the original <code>Iterator</code> position.
+ *
+ * @return The position in the original (first) <code>Iterator</code>
+ */
+ public int getOrgPosition() {
+ return orgPosition;
+ }
+
+ /**
+ * Get the modified <code>Iterator</code> position.
+ *
+ * @return The position in the modified (second) <code>Iterator</code>
+ */
+ public int getModPosition() {
+ return modPosition;
+ }
+
+
+ /**
+ * Two <code>Difference</code> objects will equal if and only if
+ * all operation, orgPosition, modPosition and content are equal.
+ *
+ * @param obj Object to compare.
+ *
+ * @return true if equal, false otherwise.
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof Difference) {
+ Difference diff = (Difference) obj;
+ if ((operation == diff.operation) &&
+ (orgPosition == diff.orgPosition) &&
+ (modPosition == diff.modPosition)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Display debug information.
+ *
+ * @return Debug string.
+ */
+ public String debug() {
+
+ String opStr = "";
+
+ switch (operation) {
+ case ADD:
+ opStr = "add";
+ break;
+ case DELETE:
+ opStr = "del";
+ break;
+ case CHANGE:
+ opStr = "chg";
+ break;
+ case UNCHANGE:
+ opStr = "uch";
+ break;
+ default:
+ break;
+ }
+ return "<diff orgPos=" + orgPosition + " modPos=" + modPosition +
+ " op=" + opStr + ">";
+ }
+
+ /**
+ * Returns position and operation values as a single string.
+ *
+ * @return orgPosition, modPosition and operation as a single string.
+ */
+ public String toString() {
+
+ return orgPosition + " " + modPosition + " " + operation;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/Iterator.java b/xmerge/java/org/openoffice/xmerge/merger/Iterator.java
new file mode 100644
index 000000000000..7b1f64ba8a55
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/Iterator.java
@@ -0,0 +1,151 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger;
+
+/**
+ * This is an interface used by the {@link
+ * org.openoffice.xmerge.merger.DiffAlgorithm
+ * DiffAlgorithm} and {@link
+ * org.openoffice.xmerge.merger.MergeAlgorithm
+ * MergeAlgorithm} to access a <code>Document</code>.
+ *
+ * @author smak
+ */
+public interface Iterator {
+
+
+ /**
+ * Move to next element in the sequence.
+ *
+ * @return The <code>Object</code> of the next element in the sequence.
+ * If there is no next element, then return null.
+ */
+ public Object next();
+
+
+ /**
+ * Move to previous element in the sequence.
+ *
+ * @return The <code>Object</code> of the previous element in the sequence.
+ * If there is no previous element, then return null.
+ */
+ public Object previous();
+
+
+ /**
+ * Move to the beginning of the sequence.
+ *
+ * @return The <code>Object</code> of the first element in the sequence.
+ * If it is empty, then return null.
+ */
+ public Object start();
+
+
+ /**
+ * Move to the end of the sequence.
+ *
+ * @return The <code>Object</code> of the last element in the sequence.
+ * If it is empty, then return null.
+ */
+ public Object end();
+
+
+ /**
+ * Return the current element <code>Object</code> content.
+ *
+ * @return The <code>Object</code> at current position.
+ */
+ public Object currentElement();
+
+
+ /**
+ * Return the total element count in the sequence.
+ *
+ * @return The total element count.
+ */
+ public int elementCount();
+
+
+ /**
+ * A method to allow the difference algorithm to test whether the
+ * <code>obj1</code> and <code>obj2</code> in the
+ * <code>Iterator</code> are considered equal. As not every
+ * <code>Object</code> in the <code>Iterator</code> can implement its
+ * own equal method, with this equivalent method, we can allow
+ * flexibility for the <code>Iterator</code> to choose a custom way
+ * to compare two objects. Two objects can even be compared based on
+ * the position in the <code>Iterator</code> rather than by
+ * the content via this option.
+ *
+ * @param obj1 The first <code>Object</code>.
+ * @param obj2 The second <code>Object</code>.
+ *
+ * @return true if equal, false otherwise.
+ */
+ public boolean equivalent(Object obj1, Object obj2);
+
+
+ /**
+ * <p>A method to force the <code>Iterator</code> to transverse the tree
+ * again to refresh the content.</p>
+ *
+ * <p>It is used mainly for <code>Iterator</code> objects which take a snap
+ * shot instead of dynamically transversing the tree. The current
+ * position will be set to the beginning.</p>
+ */
+ public void refresh();
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/MergeAlgorithm.java b/xmerge/java/org/openoffice/xmerge/merger/MergeAlgorithm.java
new file mode 100644
index 000000000000..0e9c3392400c
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/MergeAlgorithm.java
@@ -0,0 +1,89 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger;
+
+import org.openoffice.xmerge.MergeException;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.merger.Difference;
+
+/**
+ * This is the <code>MergeAlgorithm</code> interface. It is an
+ * interface so that different merge algorithms may be plugged-in
+ * to actually merge the diffs back to an original document.
+ *
+ * @author smak
+ */
+public interface MergeAlgorithm {
+
+ /**
+ * This method is to merge the difference to an <code>Iterator</code>.
+ * The original <code>Iterator</code> will be modified after the call.
+ *
+ * @param objSeq The original sequence which the difference
+ * will be applied. It will be modified.
+ * @param modSeq The modified sequence where the difference
+ * content will be extracted.
+ * @param differences The <code>Difference</code> array.
+ *
+ * @return An <code>Iterator</code> which is the modified original
+ * <code>Iterator</code> Sequence. Same as the first parameter.
+ *
+ * @throws MergeException If an error occurs during the merge.
+ */
+ public void applyDifference(Iterator orgSeq, Iterator modSeq,
+ Difference[] differences) throws MergeException;
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/NodeMergeAlgorithm.java b/xmerge/java/org/openoffice/xmerge/merger/NodeMergeAlgorithm.java
new file mode 100644
index 000000000000..90320368bfb1
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/NodeMergeAlgorithm.java
@@ -0,0 +1,83 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger;
+
+import org.w3c.dom.Node;
+
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.merger.Difference;
+
+/**
+ * This is an interface for a {@link
+ * org.openoffice.xmerge.merger.MergeAlgorithm
+ * MergeAlgorithm} to merge two <code>Node</code> objects. It is an
+ * interface so that different merge algorithms may be plugged-in.
+ *
+ * @author smak
+ */
+public interface NodeMergeAlgorithm {
+
+ /**
+ * This method is used to merge two given <code>Node</code>
+ * objects. Note: the original <code>Node</code> may be modified.
+ *
+ * @param originalNode The original <code>Node</code>.
+ * @param modifyNode The <code>Node</code> to be merged. It may
+ * be modified.
+ */
+ public void merge(Node orginialNode, Node modifyNode);
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/build.xml b/xmerge/java/org/openoffice/xmerge/merger/build.xml
new file mode 100644
index 000000000000..82939c6673e4
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/build.xml
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_joox_merger" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_joox_merger"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package"
+ value="org/openoffice/xmerge/merger"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/DiffAlgorithm.java"/>
+ <include name="${package}/Difference.java"/>
+ <include name="${package}/Iterator.java"/>
+ <include name="${package}/MergeAlgorithm.java"/>
+ <include name="${package}/NodeMergeAlgorithm.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/CellNodeIterator.java b/xmerge/java/org/openoffice/xmerge/merger/diff/CellNodeIterator.java
new file mode 100644
index 000000000000..71ed0d504948
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/CellNodeIterator.java
@@ -0,0 +1,144 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+import org.openoffice.xmerge.util.Debug;
+import org.openoffice.xmerge.util.Resources;
+
+
+/**
+ * <p>This is an implementations of the <code>Iterator</code> interface.
+ * It will traverse the tree and find cell <code>Node</code> sequences.</p>
+ *
+ * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code>
+ * will be a snap shot of that tree. That means even the tree is
+ * modified later, than the cached paragraph <code>Node</code> list will
+ * not be updated accordingly. For this reason and for performance reasons
+ * this <code>Iterator</code> does not support any operation methods such
+ * as insert, remove or replace. The main purpose of this
+ * <code>Iterator</code> is to be used with difference, not with merge.</p>
+ *
+ * @author smak
+ */
+public final class CellNodeIterator extends NodeIterator {
+
+ private Resources res = Resources.getInstance();
+
+ // can be expanded to an array in the future, not necessary right now
+ private static final String SUPPORTED_TAG1 = OfficeConstants.TAG_TABLE_CELL;
+
+ /**
+ * The standard constructor.
+ *
+ * @param cc The <code>ConverterCapabilities</code>.
+ * @param node The initial root <code>Node</code>.
+ */
+ public CellNodeIterator(ConverterCapabilities cc, Node node) {
+ super(cc, node);
+ }
+
+
+ /**
+ * Overwrite the parent <code>nodeSupported</code> method. Only cell
+ * <code>Node</code> objects are supported.
+ *
+ * @param node The <code>Node</code> to check.
+ *
+ * @return true if the <code>Node</code> is supported, false otherwise.
+ */
+ protected boolean nodeSupported(Node node) {
+
+ // can use an array later to check all possible tags for
+ // future expansion
+ if (node.getNodeType() == Node.ELEMENT_NODE &&
+ node.getNodeName().equals(SUPPORTED_TAG1)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ protected boolean childrenEqual(Node node1, Node node2) {
+
+ boolean equal = false;
+
+ if (node1.hasChildNodes() && node2.hasChildNodes()) {
+ Element cell1 = (Element)node1;
+ Element cell2 = (Element)node2;
+
+ // only need compare the first <text:p> children node, don't want
+ // to compare any non-supported features
+ // TODO: need to confirm whether all the text string is the
+ // first <text:p>, though I checked with the openoffice 619 build
+ Node paraNode1 = cell1.getElementsByTagName(
+ OfficeConstants.TAG_PARAGRAPH).item(0);
+ Node paraNode2 = cell2.getElementsByTagName(
+ OfficeConstants.TAG_PARAGRAPH).item(0);
+
+ equal = super.compareNode(paraNode1, paraNode2);
+ }
+
+ return equal;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/CharArrayLCSAlgorithm.java b/xmerge/java/org/openoffice/xmerge/merger/diff/CharArrayLCSAlgorithm.java
new file mode 100644
index 000000000000..8e5e31329f19
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/CharArrayLCSAlgorithm.java
@@ -0,0 +1,263 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import java.util.Vector;
+import org.openoffice.xmerge.merger.DiffAlgorithm;
+import org.openoffice.xmerge.merger.Difference;
+
+/**
+ * <p>This is an implementations of <code>DiffAlgorithm</code> interface
+ * which will difference char arrays.</p>
+ *
+ * <p>It also use Longest Common Subsequence (LCS). The algorithm is based
+ * on the book "Introduction to Algorithms" by Thomas H.Cormen,
+ * Charles E.Leiserson, and Ronald L.Riverst (MIT Press 1990) page 314.</p>
+ *
+ * @author smak
+ */
+public class CharArrayLCSAlgorithm {
+
+ /**
+ * Return an <code>Difference</code> array. This method finds out
+ * the difference between two sequences.
+ *
+ * @param orgSeq The original sequence.
+ * @param modSeq The modified (or changed) sequence to
+ * compare against the origial.
+ *
+ * @return A <code>Difference</code> array.
+ */
+ public Difference[] computeDiffs(char[] orgSeq, char[] modSeq) {
+
+ int orgSeqlen = orgSeq.length;
+ int modSeqlen = modSeq.length;
+
+ int[][] diffTable;
+
+ // Diff table is used to keep track which element is the same or not
+ // in those 2 sequences
+ diffTable = createDiffTable(orgSeq, modSeq);
+
+ // debug purpose...
+ // printDiffTable(diffTable);
+
+ Vector diffResult = new Vector();
+
+ generateResult(diffTable, orgSeqlen, modSeqlen, diffResult);
+
+ // don't need anymore if Difference do not contain content information
+ /* fillInDiffContent(diffResult, orgSeq, modSeq); */
+
+ Difference[] diffArray = new Difference[0];
+
+ // convert the vector to array, it has to do in here as
+ // generateResult is called recursively
+ if (diffResult.size() > 0) {
+ diffArray = new Difference[diffResult.size()];
+ diffResult.copyInto(diffArray);
+ }
+
+ diffTable = null;
+ diffResult = null;
+
+ return diffArray;
+ }
+
+
+ /**
+ * Debug function Used to print out the nicely formatted
+ * difference table.
+ *
+ * @param diffTable The difference table to display.
+ */
+ private void printDiffTable(int[][] diffTable) {
+
+ for (int i = 0; i < diffTable.length; i++) {
+ for (int j = 0; j < diffTable[i].length; j++) {
+ System.out.print(" " + diffTable[i][j] + " ");
+ }
+ System.out.println();
+ }
+ }
+
+
+ /**
+ * Create the difference table.
+ * The difference table is used internal to keep track what
+ * elements are common or different in the two sequences.
+ *
+ * @param orgSeq The original sequence to be used as a base.
+ * @param modSeq The modified sequence to compare.
+ *
+ * @return A difference table as a two-dimensional array of
+ * integers.
+ */
+ private int[][] createDiffTable(char[] orgSeq, char[] modSeq) {
+ int orgSeqlen = orgSeq.length + 1;
+ int modSeqlen = modSeq.length + 1;
+ int[][] diffTable;
+
+ // initialize the diffTable (it need to be 1 row/col bigger
+ // than the original str)
+ diffTable = new int[orgSeqlen][];
+ for (int i = 0; i < orgSeqlen; i++) {
+ diffTable[i] = new int[modSeqlen];
+ }
+
+ // compute the diff Table using LCS algorithm, refer to the book
+ // mentioned at the top of the program
+ for (int i = 1; i < orgSeqlen; i++) {
+ for (int j = 1; j < modSeqlen; j++) {
+
+ if (orgSeq[i-1] == modSeq[j-1]) {
+ diffTable[i][j] = diffTable[i-1][j-1]+1;
+ } else {
+ if (diffTable[i-1][j] >= diffTable[i][j-1]) {
+ diffTable[i][j] = diffTable[i-1][j];
+ } else {
+ diffTable[i][j] = diffTable[i][j-1];
+ }
+ }
+ }
+ }
+
+ return diffTable;
+ }
+
+
+ /**
+ * Generate the <code>Difference</code> result vector.
+ * This method will be called recursively to backtrack the difference
+ * table to get the difference result (and also the LCS).
+ *
+ * @param diffTable The difference table containing the
+ * <code>Difference</code> result.
+ * @param i The nth element in original sequence to
+ * compare. This method is called recursively
+ * with i and j decreased until 0.
+ * @param j The nth element in modified sequence to
+ * compare.
+ * @param diffVector A vector to output the <code>Difference</code>
+ * result. Can not use a return variable as it
+ * is a recursive method. The vector will contain
+ * <code>Difference</code> objects with operation
+ * and positions filled in.
+ */
+ private void generateResult(int[][] diffTable,
+ int i, int j, Vector diffVector) {
+
+ // handle the first element
+ if (i == 0 || j == 0) {
+ if (i == 0 && j == 0) {
+ // return
+ } else if (j == 0) {
+ for (int cnt = 0; cnt < i; cnt++) {
+ Difference diff =
+ new Difference(Difference.DELETE, cnt, j);
+ diffVector.add(diff);
+ }
+ } else {
+ for (int cnt = 0; cnt < j; cnt++) {
+ Difference diff =
+ new Difference(Difference.ADD, i, cnt);
+ diffVector.add(diff);
+ }
+ }
+ return;
+ }
+
+ // for the detail of this algorithm, refer to the book mentioned on
+ // the top and page 317 and 318.
+ if ((diffTable[i-1][j-1] == diffTable[i][j] -1) &&
+ (diffTable[i-1][j-1] == diffTable[i-1][j]) &&
+ (diffTable[i-1][j-1] == diffTable[i][j-1])) {
+
+ // the element of ith and jth in org and mod sequence is the same
+ generateResult(diffTable, i-1, j-1, diffVector);
+ } else {
+ if (diffTable[i-1][j] > diffTable[i][j-1]) {
+
+ // recursively call first, then add the result so that
+ // the beginning of the diffs will be stored first
+ generateResult(diffTable, i-1, j, diffVector);
+
+ Difference diff =
+ new Difference(Difference.DELETE, i-1, j);
+ diffVector.add(diff);
+ } else if (diffTable[i-1][j] < diffTable[i][j-1]) {
+
+ // recursively call first, then add the result so that
+ // the beginning of the diffs will be stored first
+ generateResult(diffTable, i, j-1, diffVector);
+
+ Difference diff =
+ new Difference(Difference.ADD, i, j-1);
+ diffVector.add(diff);
+ } else { // diffTable[i-1][j] == diffTable[i][j-1]
+ // recursively call first, then add the result so that
+ // the beginning of the diffs will be stored first
+ generateResult(diffTable, i-1, j-1, diffVector);
+
+ Difference diff =
+ new Difference(Difference.CHANGE, i-1, j-1);
+ diffVector.add(diff);
+
+ }
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/CharacterParser.java b/xmerge/java/org/openoffice/xmerge/merger/diff/CharacterParser.java
new file mode 100644
index 000000000000..1cf1bd2db8cc
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/CharacterParser.java
@@ -0,0 +1,171 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+
+import java.util.Vector;
+import java.util.List;
+
+
+/**
+ * <p>This is a parser to return a character array for difference purpose.
+ * It will use depth first search to traverse all the characters inside the
+ * text <code>Node</code> under a given <code>Node</code> (most likely to be
+ * a paragraph <code>Node</code>).</p>
+ *
+ * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> will be
+ * a snap shot of that tree. That means even the tree is modified later, than
+ * the cached paragraph <code>Node</code> list will not be updated accordingly.
+ * For this reason and for performance reasons this <code>Iterator</code> does
+ * not support any operation methods such as insert, remove or replace. The
+ * main purpose of this <code>Iterator</code> is to be used with difference,
+ * not with merge.</p>
+ *
+ * @author smak
+ */
+public class CharacterParser {
+
+ private TextNodeIterator textNodes;
+ private int currentPosition = 0;
+ private List nodeList_ = null;
+ private char[] charArray;
+
+
+ /**
+ * Standard constructor.
+ *
+ * @param node The initial root <code>Node</code>.
+ */
+ public CharacterParser(Node node) {
+ textNodes = new TextNodeIterator(node);
+ nodeList_ = new Vector();
+
+ parseNodes();
+ }
+
+
+ /**
+ * Returns the <code>Node</code> pointer with the given character position.
+ *
+ * @return The <code>Node</code> pointer with the given character position.
+ */
+ public List getNodeList() {
+ // will go through the nodeList to find the corresponding node
+ return nodeList_;
+ }
+
+ /**
+ * Returns the character array representation of the text.
+ *
+ * @return The character array representation of the text.
+ */
+ public char[] getCharArray() {
+ return charArray;
+ }
+
+ private void parseNodes() {
+
+ StringBuffer strBuf = new StringBuffer();
+
+ /* create the character array by iterate the textnode iterator */
+ Node currentNode = (Node)(textNodes.start());
+ for (;
+ currentNode != null;
+ currentNode = (Node)(textNodes.next())) {
+
+ // add the text value into the array
+ String textValue = null;
+ String nodeName = currentNode.getNodeName();
+
+ // TODO: Space node have a count attribute which is not handled!
+ if (currentNode.getNodeType() == Node.TEXT_NODE) {
+ textValue = currentNode.getNodeValue();
+ } else if (nodeName.equals(OfficeConstants.TAG_SPACE)) {
+ textValue = " ";
+ } else if (nodeName.equals(OfficeConstants.TAG_TAB_STOP)) {
+ textValue = "\t";
+ }
+
+ if (textValue != null) {
+ strBuf.append(textValue);
+ addNewNodeEntry(textValue.length(), currentNode);
+ }
+ }
+
+ charArray = strBuf.toString().toCharArray();
+ }
+
+
+ /**
+ * Adds a new <code>Node</code> entry.
+ *
+ * @param textLen The text length.
+ * @param node The <code>Node</code>.
+ */
+ private void addNewNodeEntry(int textLen, Node node) {
+
+ TextNodeEntry nodeEntry = new TextNodeEntry(currentPosition,
+ currentPosition + textLen - 1, node);
+ currentPosition = currentPosition + textLen;
+
+ nodeList_.add(nodeEntry);
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorLCSAlgorithm.java b/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorLCSAlgorithm.java
new file mode 100644
index 000000000000..10e6df5eb1ba
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorLCSAlgorithm.java
@@ -0,0 +1,264 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import java.util.Vector;
+import org.openoffice.xmerge.merger.DiffAlgorithm;
+import org.openoffice.xmerge.merger.Difference;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.util.Debug;
+
+/**
+ * This is one of the implementations of <code>DiffAlgorithm</code> interface.
+ * Using Longest Common Subsequence (LCS). The algorithm here is based
+ * on the book "Introduction to Algorithms" by Thomas H.Cormen,
+ * Charles E.Leiserson and Ronald L.Riverst (MIT Press 1990) page 314.
+ *
+ * @author smak
+ */
+public class IteratorLCSAlgorithm implements DiffAlgorithm {
+
+ public Difference[] computeDiffs(Iterator orgSeq, Iterator modSeq) {
+
+ int orgSeqlen = orgSeq.elementCount();
+ int modSeqlen = modSeq.elementCount();
+
+ int[][] diffTable;
+
+ // Diff table is used to keep track which element is the same or not
+ // in those 2 sequences
+ diffTable = createDiffTable(orgSeq, modSeq);
+
+ // debug purpose...
+ if (Debug.isFlagSet(Debug.INFO)) {
+ printDiffTable(diffTable);
+ }
+
+ Vector diffResult = new Vector();
+
+ generateResult(diffTable, orgSeqlen, modSeqlen, diffResult);
+
+ Difference[] diffArray = new Difference[0];
+
+ // convert the vector to array, it has to do in here as
+ // generateResult is called recursively
+ if (diffResult.size() > 0) {
+ diffArray = new Difference[diffResult.size()];
+ diffResult.copyInto(diffArray);
+ }
+
+ diffTable = null;
+ diffResult = null;
+
+ return diffArray;
+ }
+
+
+ /**
+ * Debug function used to print out the nicely formatted
+ * difference table.
+ *
+ * @param diffTable The difference table to display.
+ */
+ private void printDiffTable(int[][] diffTable) {
+
+ String tmpString = "";
+
+ for (int i = 0; i < diffTable.length; i++) {
+ for (int j = 0; j < diffTable[i].length; j++) {
+ tmpString = tmpString + " " + diffTable[i][j] + " ";
+ }
+ Debug.log(Debug.INFO, tmpString);
+ tmpString = "";
+ }
+ }
+
+ /**
+ * Create the difference table.
+ * The difference table is used internal to keep track what
+ * elements are common or different in the two sequences.
+ *
+ * @param orgSeq The original sequence to be used as a base.
+ * @param modSeq The modified sequence to compare.
+ *
+ * @return A difference table as a two-dimensional array of
+ * integers.
+ */
+ private int[][] createDiffTable(Iterator orgSeq, Iterator modSeq) {
+ int orgSeqlen = orgSeq.elementCount() + 1;
+ int modSeqlen = modSeq.elementCount() + 1;
+ int[][] diffTable;
+
+ // initialize the diffTable
+ diffTable = new int[orgSeqlen][];
+ for (int i = 0; i < orgSeqlen; i++) {
+ diffTable[i] = new int[modSeqlen];
+ }
+
+ // compute the diff Table using LCS algorithm, refer to the book
+ // mentioned at the top of the program
+
+ int i, j;
+
+ Object orgSeqObject, modSeqObject;
+
+ for (orgSeqObject = orgSeq.start(), i = 1;
+ orgSeqObject != null;
+ orgSeqObject = orgSeq.next(), i++) {
+
+ for (modSeqObject = modSeq.start(), j = 1;
+ modSeqObject != null;
+ modSeqObject = modSeq.next(), j++) {
+
+ if (orgSeq.equivalent(orgSeqObject, modSeqObject)) {
+ diffTable[i][j] = diffTable[i-1][j-1]+1;
+ } else {
+ if (diffTable[i-1][j] >= diffTable[i][j-1]) {
+ diffTable[i][j] = diffTable[i-1][j];
+ } else {
+ diffTable[i][j] = diffTable[i][j-1];
+ }
+ }
+ }
+ }
+
+ return diffTable;
+ }
+
+
+ /**
+ * Generate the <code>Difference</code> object result vector.
+ * This method will be called recursively to backtrack the difference
+ * table to get the difference result (and also the LCS).
+ *
+ * @param diffTable The difference table containing the
+ * <code>Difference</code> result.
+ * @param i The nth element in original sequence to
+ * compare. This method is called recursively
+ * with i and j decreased until 0.
+ * @param j The nth element in modified sequence to
+ * compare.
+ * @param diffVector A vector to output the <code>Difference</code>
+ * result. Can not use a return variable as it
+ * is a recursive method. The vector will contain
+ * <code>Difference</code> objects with operation
+ * and positions fill in.
+ */
+ private void generateResult(int[][] diffTable,
+ int i, int j, Vector diffVector) {
+
+ // handle the first element
+ if (i == 0 && j == 0) {
+ return;
+
+ } else if (j == 0) {
+ for (int cnt = 0; cnt < i; cnt++) {
+ Difference diff =
+ new Difference(Difference.DELETE, cnt, j);
+ diffVector.add(diff);
+ }
+ return;
+
+ } else if (i == 0) {
+ for (int cnt = 0; cnt < j; cnt++) {
+ Difference diff =
+ new Difference(Difference.ADD, i, cnt);
+ diffVector.add(diff);
+ }
+ return;
+ }
+
+ // for the detail of this algorithm, refer to the book mentioned on
+ // the top and page 317 and 318.
+ if ((diffTable[i-1][j-1] == diffTable[i][j] -1) &&
+ (diffTable[i-1][j-1] == diffTable[i-1][j]) &&
+ (diffTable[i-1][j-1] == diffTable[i][j-1])) {
+
+ // the element of ith and jth in org and mod sequence is the same
+ generateResult(diffTable, i-1, j-1, diffVector);
+ } else {
+ if (diffTable[i-1][j] > diffTable[i][j-1]) {
+
+ // recursively call first, then add the result so that
+ // the beginning of the diffs will be stored first
+ generateResult(diffTable, i-1, j, diffVector);
+
+ Difference diff =
+ new Difference(Difference.DELETE, i-1, j);
+ diffVector.add(diff);
+ } else if (diffTable[i-1][j] < diffTable[i][j-1]) {
+
+ // recursively call first, then add the result so that
+ // the beginning of the diffs will be stored first
+ generateResult(diffTable, i, j-1, diffVector);
+
+ Difference diff =
+ new Difference(Difference.ADD, i, j-1);
+ diffVector.add(diff);
+ } else { // diffTable[i-1][j] == diffTable[i][j-1]
+ // recursively call first, then add the result so that
+ // the beginning of the diffs will be stored first
+ generateResult(diffTable, i-1, j-1, diffVector);
+
+ Difference diff =
+ new Difference(Difference.CHANGE, i-1, j-1);
+ diffVector.add(diff);
+
+ }
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorRowCompare.java b/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorRowCompare.java
new file mode 100644
index 000000000000..f227d1a7cab3
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/IteratorRowCompare.java
@@ -0,0 +1,271 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import java.util.Vector;
+import org.openoffice.xmerge.merger.DiffAlgorithm;
+import org.openoffice.xmerge.merger.Difference;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+
+/**
+ * <p>A very simple and direct difference algorithm for row
+ * <code>Node</code> objects in a spreadsheet. Basically, it will
+ * compare objects in sequence and does not look ahead (unlike LCS).</p>
+ *
+ * <p><ol><li>
+ * If two objects are the same, skip to next one.
+ * </li><li>
+ * Otherwise check whether the row repeated attribute is the same.
+ * </li><li>
+ * If the row repeated attribute is the same, then compare two rows
+ * and mark it as <i>change</i> if those rows are different.
+ * </li><li>
+ * If the row repeated attribute is different, then split the rows and
+ * continue to compare.
+ * </li><li>
+ * If there are more objects in the modseq than the original sequence,
+ * then all of the extra ones in the modified sequence are marked as add.
+ * </li><li>
+ * If there are more objects in the original sequence than the modified
+ * sequence, then all the extra one in the modified sequence are marked
+ * as delete.
+ * </li></ol></p>
+ *
+ * <p>NOTE: The algorithm will have potential side effect to split rows.</p>
+ *
+ * @author smak
+ */
+
+public class IteratorRowCompare implements DiffAlgorithm {
+
+ /**
+ * Compute the differences of the given two sequences.
+ * Refer to the class description.
+ *
+ * Return an array of <code>Difference</code> objects. This method finds
+ * out the difference between two sequences.
+ *
+ * @param orgSeq The original sequence.
+ * @param modSeq The modified (or changed) sequence to
+ * compare against with the origial.
+ *
+ * @return An array of Difference objects.
+ */
+ public Difference[] computeDiffs(Iterator orgSeq, Iterator modSeq) {
+
+ int orgSeqlen = orgSeq.elementCount();
+ int modSeqlen = modSeq.elementCount();
+
+ Vector diffVector = new Vector();
+
+ // i and j are counters to keep track the current position in the
+ // iterator
+ int i = 0;
+ int j = 0;
+ Object orgSeqObject = orgSeq.start();
+ Object modSeqObject = modSeq.start();
+ Element orgRow, modRow;
+ boolean different = false;
+ boolean orgSplited = false;
+ boolean modSplited = false;
+
+ while (orgSeqObject != null) {
+
+ different = true;
+
+ if (modSeqObject == null) {
+ // no more modsequence, all the remaining org sequence objs
+ // should consider as a delete.
+ Difference diff = new Difference(Difference.DELETE, i, j);
+ diffVector.add(diff);
+ orgSeqObject = orgSeq.next();
+
+ } else {
+ if (!orgSeq.equivalent(orgSeqObject, modSeqObject)) {
+
+ orgRow = (Element)orgSeqObject;
+ modRow = (Element)modSeqObject;
+
+ // check whether the original Row with multiple row
+ // if so, need to split one out for merge
+ String orgRowRepeated = orgRow.getAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_ROWS_REPEATED);
+ String modRowRepeated = modRow.getAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_ROWS_REPEATED);
+
+
+ int orgRowNum = 1;
+ int modRowNum = 1;
+
+ if (orgRowRepeated.length() > 0) {
+ orgRowNum =
+ Integer.valueOf(orgRowRepeated).intValue();
+ }
+ if (modRowRepeated.length() > 0) {
+ modRowNum =
+ Integer.valueOf(modRowRepeated).intValue();
+ }
+
+ // try to find out the common number of repeated Rows
+ if (orgRowNum == modRowNum) {
+ orgSeqObject = orgSeq.next();
+ modSeqObject = modSeq.next();
+
+ // cut the original row into two halves, first half
+ // have the repeated attribute = modify row attr
+ } else if (orgRowNum > modRowNum) {
+ Element orgSplitRow = splitRepeatedRow(
+ orgRow, modRowNum,
+ orgRowNum - modRowNum);
+ // it may equal after the split!
+ if (orgSeq.equivalent(orgSplitRow, modRow)) {
+ different = false;
+ }
+ orgSplited = true;
+ modSeqObject = modSeq.next();
+
+ // cut the modified Row into two halves, first half
+ // have the repeated attribute = original Row attr
+ } else {
+ Element modSplitRow = splitRepeatedRow(
+ modRow, orgRowNum,
+ modRowNum - orgRowNum);
+
+ // check whether rows are equal after the split
+ if (modSeq.equivalent(orgRow, modSplitRow)) {
+ different = false;
+ }
+ modSplited = true;
+ orgSeqObject = orgSeq.next();
+ }
+
+ if (different) {
+ Difference diff = new Difference(Difference.CHANGE,
+ i, j);
+ diffVector.add(diff);
+ }
+
+ } else {
+ // Rows are equivalent, move on to next one.
+ orgSeqObject = orgSeq.next();
+ modSeqObject = modSeq.next();
+ } // end if-else
+ j++;
+ } // end if-else
+ i++;
+ } // end while loop
+
+ // any extra objects in modify sequence should consider as an add
+ // to the original sequence
+ for (; modSeqObject != null; modSeqObject = modSeq.next(), j++) {
+ Difference diff = new Difference(Difference.ADD, i, j);
+ diffVector.add(diff);
+ }
+
+ // need to refresh the iterator if we split the rows
+ if (orgSplited) {
+ orgSeq.refresh();
+ }
+
+ if (modSplited) {
+ modSeq.refresh();
+ }
+
+
+ // convert the vector to array
+ Difference[] diffArray = new Difference[diffVector.size()];
+ diffVector.copyInto(diffArray);
+
+ return diffArray;
+ }
+
+
+ private Element splitRepeatedRow(Element orgRow, int splitNum, int orgNum) {
+ // NOTE: should we really want to do deep clone?
+ // in most the case, it is an empty Row, but the
+ // specification didn't forbid any node to use multiple
+ // column attributes. i.e. the node can contain text
+ // nodes or other things under it.
+ Element splitRow = (Element)(orgRow.cloneNode(true));
+
+ if (splitNum > 1) {
+ splitRow.setAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_ROWS_REPEATED,
+ String.valueOf(splitNum));
+ } else if (splitNum == 1) {
+ splitRow.removeAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_ROWS_REPEATED);
+ }
+ if (orgNum > 1) {
+ orgRow.setAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_ROWS_REPEATED,
+ String.valueOf(orgNum));
+ } else if (orgNum == 1) {
+ orgRow.removeAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_ROWS_REPEATED);
+ }
+
+ Node parentNode = orgRow.getParentNode();
+ parentNode.insertBefore(splitRow, orgRow);
+
+ return splitRow;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/NodeIterator.java b/xmerge/java/org/openoffice/xmerge/merger/diff/NodeIterator.java
new file mode 100644
index 000000000000..060a179f58fe
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/NodeIterator.java
@@ -0,0 +1,414 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Element;
+
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+import org.openoffice.xmerge.util.Debug;
+import org.openoffice.xmerge.util.Resources;
+
+import java.util.Vector;
+import java.util.List;
+
+
+/**
+ * <p>This is an implementation of the <code>Iterator</code> interface.
+ * It will traverse the tree and find <code>Node</code> sequences.</p>
+ *
+ * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> will
+ * be a snap shot of that tree. That means even the tree is modified later,
+ * than the cached paragraph <code>Node</code> list will not be updated
+ * accordingly. For this reason and for performance reasons this
+ * <code>Iterator</code> does not support any operation methods such as
+ * insert, remove or replace. The main purpose of this
+ * <code>Iterator</code> is to be used with difference, not with merge.</p>
+ *
+ * @author smak
+ */
+public abstract class NodeIterator implements Iterator {
+
+ private List nodeList = null;
+ private int currentPosition = 0;
+ private Node root;
+ private ConverterCapabilities cc_ = null;
+
+
+ /**
+ * Standard constructor.
+ *
+ * @param cc The <code>ConverterCapabilities</code>.
+ * @param node The initial root <code>Node</code>.
+ */
+ public NodeIterator(ConverterCapabilities cc, Node node) {
+ cc_ = cc;
+ nodeList = new Vector();
+ root = node;
+ markTree(node);
+ }
+
+
+ public Object next() {
+ if (currentPosition < nodeList.size() - 1) {
+ currentPosition++;
+ return currentElement();
+ } else {
+ return null;
+ }
+ }
+
+
+ public Object previous() {
+ if (currentPosition > 0) {
+ currentPosition--;
+ return currentElement();
+ } else {
+ return null;
+ }
+ }
+
+
+ public Object start() {
+ currentPosition = 0;
+ return currentElement();
+ }
+
+
+ public Object end() {
+ int size = nodeList.size();
+
+ if (size > 0) {
+ currentPosition = size - 1;
+ return currentElement();
+ } else {
+ return null;
+ }
+ }
+
+
+ public Object currentElement() {
+
+ if (currentPosition < 0 || currentPosition >= nodeList.size()) {
+ return null;
+ }
+
+ return nodeList.get(currentPosition);
+ }
+
+
+ public int elementCount() {
+ return nodeList.size();
+ }
+
+
+ public boolean equivalent(Object obj1, Object obj2) {
+ boolean equal = false;
+ String errMsg = null;
+ if (!(obj1 instanceof Node && obj2 instanceof Node)) {
+ errMsg = Resources.getInstance().getString("NOT_NODE_ERROR");
+ Debug.log(Debug.ERROR, errMsg);
+ } else {
+ Node node1 = (Node)obj1;
+ Node node2 = (Node)obj2;
+
+ equal = compareNode(node1, node2);
+ }
+ return equal;
+ }
+
+
+ public void refresh() {
+ nodeList = new Vector();
+ markTree(root);
+ currentPosition = 0;
+ }
+
+
+ /**
+ * Used to compare two <code>Node</code> objects (type/name/value)
+ * and all their children <code>Node</code> objects.
+ *
+ * @param node1 The first <code>Node</code> to compare.
+ * @param node2 The second <code>Node</code> to compare.
+ *
+ * @return true if <code>Node</code> is equal, false otherwise.
+ */
+ protected boolean compareNode(Node node1, Node node2) {
+ boolean equal = false;
+
+ nodeCheck: {
+
+ if (node1 == null || node2 == null) {
+ break nodeCheck;
+ }
+
+ // nodevalue is short
+ if (node1.getNodeType() != node2.getNodeType()) {
+ break nodeCheck;
+ }
+
+ // nodeName will not be null
+ if (!node1.getNodeName().equals(node2.getNodeName())) {
+ break nodeCheck;
+ }
+
+ // nodeValue can be null for a lot of type of cells
+ if (node1.getNodeValue() == null && node2.getNodeValue() == null) {
+ // empty
+ } else if (node1.getNodeValue() == null ||
+ node2.getNodeValue() == null) {
+ break nodeCheck;
+ } else if (!node1.getNodeValue().equals(node2.getNodeValue())) {
+ break nodeCheck;
+ }
+
+ // try to compare attributes
+ if (!attributesEqual(node1, node2)) {
+ break nodeCheck;
+ }
+
+ // don't need to compare if both node do not have children
+ if (!node1.hasChildNodes() && !node2.hasChildNodes()) {
+ equal = true;
+ break nodeCheck;
+ // don't need to compare if one node has children but not the other
+ } else if (!node1.hasChildNodes() || !node2.hasChildNodes()) {
+ equal = false;
+ break nodeCheck;
+ // need to compare if both node has children
+ } else if (!childrenEqual(node1, node2)) {
+ break nodeCheck;
+ }
+
+ equal = true;
+ }
+
+ return equal;
+ }
+
+
+ /**
+ * Compare the children of two <code>Node</code> objects. This
+ * method can be intentionally overridden by any class that
+ * extend from <code>NodeIterator</code> so that it can have
+ * its own children comparison if necessary.
+ *
+ * @param node1 The first <code>Node</code> to compare.
+ * @param node2 The second <code>Node</code> to compare.
+ *
+ * @return true if children are equal, false otherwise.
+ */
+ protected boolean childrenEqual(Node node1, Node node2) {
+
+ boolean equal = false;
+
+ childrenCheck: {
+ NodeList node1Children = node1.getChildNodes();
+ NodeList node2Children = node2.getChildNodes();
+
+ if (node1Children == null || node2Children == null) {
+ break childrenCheck;
+ }
+
+ if (node1Children.getLength() != node2Children.getLength()) {
+ break childrenCheck;
+ }
+
+ // compare all the childrens
+ equal = true;
+
+ for (int i = 0; i < node1Children.getLength(); i++) {
+ if (!compareNode(node1Children.item(i),
+ node2Children.item(i))) {
+ equal = false;
+ break childrenCheck;
+ }
+ }
+ }
+
+ return equal;
+ }
+
+
+ /**
+ * Compare attributes of two <code>Node</code> objects. This
+ * method can be intentionally overridden by any class that
+ * extends from <code>NodeIterator</code> so that it can have
+ * its own attribute comparison.
+ *
+ * @param node1 The first <code>Node</code> to compare.
+ * @param node2 The second <code>Node</code> to compare.
+ *
+ * @return true if attributes are equal, false otherwise.
+ */
+ protected boolean attributesEqual(Node node1, Node node2) {
+
+ boolean equal = false;
+ String nodeName = node1.getNodeName();
+ NamedNodeMap attrNode[] = new NamedNodeMap[2];
+ attrNode[0] = node1.getAttributes();
+ attrNode[1] = node2.getAttributes();
+
+ // attribute node will be null if node is not an element node
+ // and attribute nodes are equal if both are not element node
+ if (attrNode[0] == null || attrNode[1] == null) {
+ if (attrNode[0] == null && attrNode[1] == null) {
+ equal = true;
+ }
+ return equal;
+ }
+
+ // compare the attributes from node1 vs node2 and node2 vs node1
+ // though it's a little inefficient for the duplication of comparison
+ // as the number of attributes is not so many, it should not be
+ // a big problem.
+ int len [] = new int[2];
+ int src, dst;
+
+ attrCheck: {
+ for (int i = 0; i < 2; i++) {
+
+ if (i == 0) {
+ src = 0;
+ dst = 1;
+ } else {
+ src = 1;
+ dst = 0;
+ }
+
+ len[src] = attrNode[src].getLength();
+
+ for (int j = 0; j < len[src]; j++) {
+ Node srcAttr = attrNode[src].item(j);
+ String srcAttrName = srcAttr.getNodeName();
+
+ // copy the supported attrs
+ if (cc_ == null ||
+ cc_.canConvertAttribute(nodeName, srcAttrName)) {
+
+ // check whether the attribute exist in dst node
+ Node dstAttr = attrNode[dst].getNamedItem(srcAttrName);
+
+ if (dstAttr == null) {
+ Debug.log(Debug.INFO,
+ "[NodeIterator] Attr not exist in dst - "
+ + srcAttrName);
+ break attrCheck;
+ }
+
+ // then compare the attribute values
+ if (!srcAttr.getNodeValue().equals(
+ dstAttr.getNodeValue())) {
+ Debug.log(Debug.INFO,
+ "[NodeIterator] Attr diff src: " +
+ srcAttr.getNodeValue() + " dst: "+
+ dstAttr.getNodeValue());
+ break attrCheck;
+ }
+ } // end if cc_ loop
+ } // end for j loop
+ } // end for i loop
+
+ // the whole checking is done smoothly and all attributes are equal
+ equal = true;
+ }
+
+ return equal;
+ }
+
+
+ /**
+ * Check whether a <code>Node</code> is supported. This method
+ * can be intentionally overridden by any class that extends from
+ * <code>NodeIterator</code> so that it can specify which
+ * <code>Node</code> to support.
+ *
+ * @param node <code>Node</code> to check.
+ *
+ * @return true if <code>Node</code> is supported, false otherwise.
+ */
+ protected abstract boolean nodeSupported(Node node);
+
+ // doing a depth first search for the tree and mark all supported nodes
+ private void markTree(Node node) {
+
+ // if this is a supported node, then we add it to our cache table
+ if (nodeSupported(node)) {
+ nodeList.add(node);
+ } else {
+ // or we go through all children nodes recursively
+ // (can be optimized in future)
+ String nodeName = node.getNodeName();
+ if ( cc_ == null || cc_.canConvertTag(nodeName)) {
+ NodeList nodeList = node.getChildNodes();
+ int nodeListLength = nodeList.getLength();
+ for (int i = 0; i < nodeListLength; i++) {
+ markTree(nodeList.item(i));
+ }
+ }
+ else {
+ Debug.log(Debug.INFO, " [NodeIterator::markTree] Skipping node "
+ + nodeName);
+ }
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/ObjectArrayIterator.java b/xmerge/java/org/openoffice/xmerge/merger/diff/ObjectArrayIterator.java
new file mode 100644
index 000000000000..2f90f78100ab
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/ObjectArrayIterator.java
@@ -0,0 +1,238 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.openoffice.xmerge.merger.Iterator;
+
+/**
+ * <p>This is an implementation of the <code>Iterator</code> interface.
+ * It is based upon a simple <code>Object</code> array.</p>
+ *
+ * <p>Note: this class is not thread safe for performance reasons.</p>
+ *
+ * @author smak
+ */
+public final class ObjectArrayIterator implements Iterator {
+
+
+ /**
+ * The <code>Object</code> array.
+ */
+ private Object [] objArray;
+ private int currentPosition;
+
+
+ /**
+ * Private default constructor.
+ */
+ private ObjectArrayIterator() {
+ // do not allow user new a ObjectArrayIterator without argument
+ }
+
+
+ /**
+ * Standard constructor.
+ *
+ * @param objArray The <code>Object</code> array.
+ */
+ public ObjectArrayIterator(Object [] objArray) {
+ if (objArray != null) {
+ this.objArray = new Object[objArray.length];
+ System.arraycopy(objArray, 0, this.objArray, 0, objArray.length);
+ currentPosition = 0;
+ } else {
+ this.objArray = new Object[0];
+ }
+ }
+
+
+ public Object next() {
+ if (currentPosition < objArray.length - 1) {
+ currentPosition++;
+ return currentElement();
+ } else {
+ return null;
+ }
+
+ }
+
+
+ public Object previous() {
+ if (currentPosition > 0) {
+ currentPosition--;
+ return currentElement();
+ } else {
+ return null;
+ }
+ }
+
+
+ public Object start() {
+ currentPosition = 0;
+ return currentElement();
+ }
+
+
+ public Object end() {
+ if (objArray.length > 0) {
+ currentPosition = objArray.length - 1;
+ }
+ return currentElement();
+ }
+
+
+ public Object currentElement() {
+ if (objArray.length > 0) {
+ return objArray[currentPosition];
+ } else {
+ return null;
+ }
+ }
+
+
+ /**
+ * Replace current <code>Object</code>.
+ *
+ * @param object <code>Object</code> to replace.
+ */
+ public void replace(Object object) {
+ objArray[currentPosition] = object;
+ }
+
+
+ /**
+ * Insert <code>Object</code> after current <code>Object</code>.
+ *
+ * @param object <code>Object</code> to insert.
+ */
+ public void insert(Object object) {
+ Object [] objArray2 = new Object[objArray.length+1];
+
+ // copy the array content up before the currentposition
+ if (currentPosition > 0) {
+ System.arraycopy(objArray, 0, objArray2, 0, currentPosition);
+ }
+
+ objArray2[currentPosition] = object;
+
+ // copy the array content up after the currentposition
+ System.arraycopy(objArray, currentPosition, objArray2,
+ currentPosition + 1, objArray.length - currentPosition);
+
+ objArray = objArray2;
+ currentPosition++;
+ }
+
+ /**
+ * Append <code>Object</code> after current <code>Object</code>.
+ *
+ * @param object <code>Object</code> to append.
+ */
+ public void append(Object object) {
+ Object [] objArray2 = new Object[objArray.length + 1];
+
+ int newPosition = currentPosition + 1;
+
+ // copy the array content up to the currentposition
+ System.arraycopy(objArray, 0, objArray2, 0, newPosition);
+
+ objArray2[newPosition] = object;
+
+ // copy the array content up after the currentposition
+ if (currentPosition < objArray.length - 1) {
+ System.arraycopy(objArray, newPosition, objArray2,
+ newPosition + 1, objArray.length - newPosition);
+ }
+
+ objArray = objArray2;
+ }
+
+ /**
+ * Remove current <code>Object</code>.
+ */
+ public void remove() {
+ Object [] objArray2 = new Object[objArray.length - 1];
+
+ // copy the array content up before the currentposition
+ if (currentPosition > 0) {
+ System.arraycopy(objArray, 0, objArray2, 0, currentPosition);
+ }
+
+ // copy the array content up after the currentposition
+ if (currentPosition < objArray.length - 1) {
+ System.arraycopy(objArray, currentPosition + 1, objArray2,
+ currentPosition, objArray.length - currentPosition - 1);
+ }
+
+ objArray = objArray2;
+
+ if (currentPosition == objArray.length)
+ currentPosition--;
+ }
+
+ public int elementCount() {
+ return objArray.length;
+ }
+
+ public boolean equivalent(Object obj1, Object obj2) {
+ return obj1.equals(obj2);
+ }
+
+ public void refresh() {
+ // do nothing
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/ParaNodeIterator.java b/xmerge/java/org/openoffice/xmerge/merger/diff/ParaNodeIterator.java
new file mode 100644
index 000000000000..5504e533199a
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/ParaNodeIterator.java
@@ -0,0 +1,123 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+
+import java.util.Vector;
+import java.util.List;
+
+
+/**
+ * <p>This is an implementation of the <code>Iterator</code> interface.
+ * It will traverse the tree and find the Paragraph/Heading <code>Node</code>
+ * sequences.</p>
+ *
+ * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code> will
+ * be a snap shot of that tree. That means even the tree is modified later,
+ * than the cached paragraph <code>Node</code> list will not be updated
+ * accordingly. For this reason and for performance reasons this
+ * <code>Iterator</code> does not support any operation methods such as
+ * insert, remove or replace. The main purpose of this
+ * <code>Iterator</code> is to be used with difference, not with merge.</p>
+ *
+ * @author smak
+ */
+public final class ParaNodeIterator extends NodeIterator {
+
+ // can be expanded to an array in the future, not necessary right now
+ private static final String SUPPORTED_TAG1 = OfficeConstants.TAG_PARAGRAPH;
+ private static final String SUPPORTED_TAG2 = OfficeConstants.TAG_HEADING;
+
+ /**
+ * Standard constructor.
+ *
+ * @param cc The <code>ConverterCapabilities</code>.
+ * @param node The initial root <code>Node</code>.
+ */
+ public ParaNodeIterator(ConverterCapabilities cc, Node node) {
+ // not using convertercapabilities unless it's needed in future.
+ super(cc, node);
+ }
+
+
+ /**
+ * Overwrite the parent <code>nodeSupported</code> method.
+ *
+ * @param node <code>Node</code> to check.
+ *
+ * @return true if the <code>Node</code> is supported, false
+ * otherwise.
+ */
+ protected boolean nodeSupported(Node node) {
+
+ // can use an array later to check all possible tags for
+ // future expansion
+ if (node.getNodeType() == Node.ELEMENT_NODE &&
+ (node.getNodeName().equals(SUPPORTED_TAG1) ||
+ node.getNodeName().equals(SUPPORTED_TAG2))) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/RowIterator.java b/xmerge/java/org/openoffice/xmerge/merger/diff/RowIterator.java
new file mode 100644
index 000000000000..18274d9b2ace
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/RowIterator.java
@@ -0,0 +1,112 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+import org.openoffice.xmerge.util.Debug;
+import org.openoffice.xmerge.util.Resources;
+
+
+/**
+ * This is an implementation of the <code>Iterator</code> interface and extends
+ * <code>NodeIterator</code>. It will traverse the tree and find row sequences.
+ *
+ * @author smak
+ */
+public final class RowIterator extends NodeIterator {
+
+ private Resources res = Resources.getInstance();
+
+ // TODO: should compare the ConverterCapabilities supported feature only!
+ // otherwise even though one with a chart, one without, will still be
+ // considered to be not equivalent.
+
+ /**
+ * Standard constructor.
+ *
+ * @param cc The <code>ConverterCapabilities</code>.
+ * @param node The initial root <code>Node</code>.
+ */
+ public RowIterator(ConverterCapabilities cc, Node node) {
+ super(cc, node);
+ }
+
+ /**
+ * Overwrite the parent <code>nodeSupported</code> method. Only
+ * row <code>Node</code> objects are supported.
+ *
+ * @param node <code>Node</code> to check.
+ *
+ * @return true if the <code>Node</code> is supported, false otherwise.
+ */
+ protected boolean nodeSupported(Node node) {
+
+ // can use an array later to check all possible tags for
+ // future expansion
+ if (node.getNodeType() == Node.ELEMENT_NODE &&
+ node.getNodeName().equals(OfficeConstants.TAG_TABLE_ROW)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeEntry.java b/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeEntry.java
new file mode 100644
index 000000000000..cf7905f6b91f
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeEntry.java
@@ -0,0 +1,116 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.w3c.dom.Node;
+
+/**
+ * A small class to hold the start/end character position and the
+ * <code>Node</code> pointer in a text <code>Node</code>. It is
+ * mainly used for character parser to make a list of text
+ * <code>Node</code> cache entries.
+ *
+ * @author smak
+ */
+public class TextNodeEntry {
+
+ private int startChar_;
+ private int endChar_;
+ private Node node_;
+
+ /**
+ * Constructor
+ *
+ * @param startChar The start character position.
+ * @param endChar The end character position.
+ * @param node The text <code>Node</code>.
+ */
+ public TextNodeEntry(int startChar, int endChar, Node node) {
+ startChar_ = startChar;
+ endChar_ = endChar;
+ node_ = node;
+ }
+
+ /**
+ * Returns the start character.
+ *
+ * @return The start character.
+ */
+ public int startChar() {
+ return startChar_;
+ }
+
+
+ /**
+ * Returns the end character.
+ *
+ * @return The end character.
+ */
+ public int endChar() {
+ return endChar_;
+ }
+
+
+ /**
+ * Returns the <code>Node</code>.
+ *
+ * @return The <code>Node</code>.
+ */
+ public Node node() {
+ return node_;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeIterator.java b/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeIterator.java
new file mode 100644
index 000000000000..e9881fab1e59
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/TextNodeIterator.java
@@ -0,0 +1,118 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.diff;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+
+import java.util.Vector;
+import java.util.List;
+
+
+/**
+ * <p>This is an implementation of the <code>Iterator</code> interface.
+ * It will traverse the tree and find text/space/tab <code>Node</code>
+ * sequences.</p>
+ *
+ * <p>Note: Once the XML Tree is parsed, then the <code>Iterator</code>
+ * will be a snap shot of that tree. That means even the tree is modified
+ * later, than the cached paragraph <code>Node</code> list will not be
+ * updated accordingly. For this reason and for performance reasons
+ * this <code>Iterator</code> does not support any operation methods
+ * such as insert, remove or replace. The main purpose of this
+ * <code>Iterator</code> is to be used with difference, not with merge.</p>
+ *
+ * @author smak
+ */
+public final class TextNodeIterator extends NodeIterator {
+
+ /**
+ * Standard constructor.
+ *
+ * @param initial The initial root <code>Node</code>.
+ */
+ public TextNodeIterator(Node node) {
+ super(null, node);
+ }
+
+ /**
+ * Overwrite the parent <code>nodeSupported</code> method. Only text
+ * <code>Node</code> objects are supported.
+ *
+ * @param node <code>Node</code> to check.
+ *
+ * @return true if the <code>Node</code> is supported, false
+ * otherwise.
+ */
+ protected boolean nodeSupported(Node node) {
+
+ // can use an array later to check all possible tags for
+ // future expansion
+ if (node.getNodeType() == Node.TEXT_NODE ||
+ node.getNodeName().equals(OfficeConstants.TAG_SPACE) ||
+ node.getNodeName().equals(OfficeConstants.TAG_TAB_STOP) ||
+ node.getNodeName().equals(OfficeConstants.TAG_LINE_BREAK)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/build.xml b/xmerge/java/org/openoffice/xmerge/merger/diff/build.xml
new file mode 100644
index 000000000000..cf982977fc26
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/build.xml
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_jooxm_diff" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_jooxm_diff"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package"
+ value="org/openoffice/xmerge/merger/diff"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/CharacterParser.java"/>
+ <include name="${package}/CharArrayLCSAlgorithm.java"/>
+ <include name="${package}/IteratorLCSAlgorithm.java"/>
+ <include name="${package}/IteratorRowCompare.java"/>
+ <include name="${package}/NodeIterator.java"/>
+ <include name="${package}/ObjectArrayIterator.java"/>
+ <include name="${package}/ParaNodeIterator.java"/>
+ <include name="${package}/CellNodeIterator.java"/>
+ <include name="${package}/TextNodeEntry.java"/>
+ <include name="${package}/TextNodeIterator.java"/>
+ <include name="${package}/RowIterator.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/makefile.mk b/xmerge/java/org/openoffice/xmerge/merger/diff/makefile.mk
new file mode 100644
index 000000000000..b25ccd3be663
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_jooxm_diff
+PRJ=../../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/merger/diff/package.html b/xmerge/java/org/openoffice/xmerge/merger/diff/package.html
new file mode 100644
index 000000000000..e5d424776748
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/diff/package.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge.merger.diff package</title>
+</head>
+
+<body bgcolor="white">
+<p>Provides implementations for the {@link
+org.openoffice.xmerge.merger.Iterator Iterator}
+interface and related support classes. These are used by the {@link
+org.openoffice.xmerge.merger.DiffAlgorithm
+DiffAlgorithm} interface.</p>
+
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/merger/makefile.mk b/xmerge/java/org/openoffice/xmerge/merger/makefile.mk
new file mode 100644
index 000000000000..6b14946ee886
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_joox_merger
+PRJ=../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/merger/merge/CharacterBaseParagraphMerge.java b/xmerge/java/org/openoffice/xmerge/merger/merge/CharacterBaseParagraphMerge.java
new file mode 100644
index 000000000000..1ffc2feda0aa
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/merge/CharacterBaseParagraphMerge.java
@@ -0,0 +1,338 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.merge;
+
+import java.util.List;
+import org.w3c.dom.Node;
+import org.openoffice.xmerge.merger.Difference;
+import org.openoffice.xmerge.merger.NodeMergeAlgorithm;
+import org.openoffice.xmerge.merger.diff.CharacterParser;
+import org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm;
+import org.openoffice.xmerge.merger.diff.TextNodeEntry;
+import org.openoffice.xmerge.util.Debug;
+
+/**
+ * This is an implementation of the <code>NodeMergeAlgorithm</code>
+ * interface. It is used to merge two paragraph <code>Node</code>
+ * objects based on character comparisons.
+ *
+ * @author smak
+ */
+public final class CharacterBaseParagraphMerge
+ implements NodeMergeAlgorithm {
+
+
+ private class cacheCharArray {
+ public cacheCharArray(int cacheSize) {
+ }
+ }
+
+
+ /**
+ * Merge two paragraph <code>Node</code> by using Longest Common
+ * Subsequence (LCS) character algorithm defined in {@link
+ * org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm
+ * CharArrayLCSAlgorithm}
+ *
+ * @param orgPara The original paragraph <code>Node</code>.
+ * @param modPara The modified paragraph <code>Node</code>.
+ */
+ public void merge(Node orgPara, Node modPara) {
+ CharacterParser orgParser = new CharacterParser(orgPara);
+ CharacterParser modParser = new CharacterParser(modPara);
+
+ char[] orgCharArray = orgParser.getCharArray();
+ char[] modCharArray = modParser.getCharArray();
+
+ CharArrayLCSAlgorithm diffAlgo = new CharArrayLCSAlgorithm();
+
+ Difference[] diffResult = diffAlgo.computeDiffs(orgCharArray,
+ modCharArray);
+ // debug use
+ System.out.println("Diff Result: ");
+ for (int i = 0; i < diffResult.length; i++) {
+ Debug.log(Debug.INFO, diffResult[i].debug());
+ }
+
+ applyDifference(orgParser, modParser, diffResult);
+ }
+
+
+ private void applyDifference(CharacterParser orgParser,
+ CharacterParser modParser,
+ Difference[] diffs) {
+
+ List orgNodeList = orgParser.getNodeList();
+ List modNodeList = modParser.getNodeList();
+ int diffCount = 0;
+ int modNodeListCnt = 0;
+ int numNode = orgNodeList.size();
+
+ for (int i = 0; i < numNode; i++) {
+
+ int extraChar = 0;
+ int orgDiffCount = diffCount;
+ TextNodeEntry orgTextNode = (TextNodeEntry)(orgNodeList.get(i));
+
+ Debug.log(Debug.INFO, "checking node " + (i + 1) + " of " + numNode);
+
+ // check any difference in this node and estimate the new char num
+ for (; diffCount < diffs.length; diffCount++) {
+
+ Debug.log(Debug.INFO, " checking diff " + (diffCount + 1) +
+ " of " + diffs.length);
+ Debug.log(Debug.INFO, " OrgPosision <" +
+ diffs[diffCount].getOrgPosition() + "> diffCount <" +
+ diffCount + "> orgDiffCount <" + orgDiffCount + ">");
+
+ // don't need to check and diffs beyond the current node text
+ // range except the last node
+ if (diffs[diffCount].getOrgPosition() > orgTextNode.endChar() &&
+ i < numNode - 1) {
+ Debug.log(Debug.INFO, " breaking!");
+ break;
+ }
+
+ if (diffs[diffCount].getOrgPosition()
+ >= orgTextNode.startChar()) {
+ if (diffs[diffCount].getOperation() == Difference.DELETE) {
+ extraChar--;
+ } else if (diffs[diffCount].getOperation()
+ == Difference.ADD) {
+ extraChar++;
+ }
+
+ }
+ }
+
+ Debug.log(Debug.INFO, " final diffCount <" + diffCount +
+ "> final orgDiffCount <" + orgDiffCount + ">");
+
+ // will only try to merge if there is a difference in this node
+ if (diffCount > orgDiffCount) {
+
+ Debug.log(Debug.INFO, " There is a difference, doing merge");
+ Debug.log(Debug.INFO, " TextNode name <" +
+ orgTextNode.node().getNodeName() + ">");
+ Debug.log(Debug.INFO, " TextNode value <" +
+ orgTextNode.node().getNodeValue() + ">");
+ Debug.log(Debug.INFO, " TextNode start char <" +
+ orgTextNode.startChar() + "> TextNode end char <" +
+ orgTextNode.endChar() + ">");
+ Debug.log(Debug.INFO, " extraChar value <" + extraChar + ">");
+
+ coreMerge(orgDiffCount, diffCount, diffs, orgParser,
+ modParser, orgTextNode, extraChar);
+ }
+ }
+ }
+
+ private void coreMerge(int startDiffNum, int endDiffNum, Difference[] diffs,
+ CharacterParser orgParser, CharacterParser modParser,
+ TextNodeEntry orgTextNode, int extraChar) {
+
+ Node orgNode = orgTextNode.node();
+ char[] modTextArray = modParser.getCharArray();
+ String tmpString;
+
+ // Handle situation where getNodeValue returns null
+ //
+ if (orgNode.getNodeValue() != null)
+ tmpString = orgNode.getNodeValue();
+ else
+ tmpString = "";
+
+ char[] orgNodeText = tmpString.toCharArray();
+ char[] newNodeText;
+
+ if (orgNodeText.length + extraChar > 0)
+ newNodeText = new char[orgNodeText.length + extraChar];
+ else
+ newNodeText = new char[0];
+
+ int orgTextPosition = orgTextNode.startChar(); // used for block copy
+ int newTextPosition = 0; // used for block copy
+ int unChangedTextLength = 0;
+
+ char[] cacheCharArray = new char[endDiffNum - startDiffNum];
+ int cacheLength = 0;
+ int lastDiffOperation = Difference.UNCHANGE;
+ int lastDiffPosition = -1;
+
+ // starting to diff
+ //
+ for (int j = startDiffNum; j < endDiffNum; j++) {
+
+ // copy any contents before the diff
+ //
+ if (diffs[j].getOrgPosition() > orgTextPosition) {
+ // need to flush first
+ if (cacheLength > 0) {
+ System.arraycopy(cacheCharArray, 0,
+ newNodeText, newTextPosition, cacheLength);
+ newTextPosition += cacheLength;
+
+ // reset the markers
+ lastDiffPosition = -1;
+ lastDiffOperation = Difference.UNCHANGE;
+ cacheLength = 0;
+ }
+
+ // find out the length how many characters are
+ // untouched by the diff
+ unChangedTextLength = diffs[j].getOrgPosition() -
+ orgTextPosition;
+ System.arraycopy(orgNodeText,
+ orgTextPosition - orgTextNode.startChar(),
+ newNodeText, newTextPosition,
+ unChangedTextLength);
+ orgTextPosition += unChangedTextLength;
+ newTextPosition += unChangedTextLength;
+ }
+
+ // for any deleted characters, just skip without copy
+ // but still need to take care the cached characters
+ //
+ if (diffs[j].getOperation() == Difference.DELETE) {
+ orgTextPosition++;
+
+ // flush out the cache and copy the content to new Text
+ if (cacheLength > 0) {
+ System.arraycopy(cacheCharArray, 0,
+ newNodeText, newTextPosition, cacheLength);
+ newTextPosition += cacheLength;
+
+ // reset the markers
+ lastDiffPosition = -1;
+ lastDiffOperation = Difference.UNCHANGE;
+ cacheLength = 0;
+ }
+
+ continue;
+
+
+ // check whether we should flush the cache.
+ // For changed diffs, only continuous changes can be cached
+ // For Add diffs, only same insertion point can be cached
+ // and for both changed/add diffs, need to have same operation
+ // as last cached diffs.
+
+ } else {
+ if (lastDiffOperation != diffs[j].getOperation() ||
+ (diffs[j].getOperation() == Difference.CHANGE &&
+ diffs[j].getOrgPosition() != lastDiffPosition + 1) ||
+ (diffs[j].getOperation() == Difference.ADD &&
+ diffs[j].getOrgPosition() != lastDiffPosition)) {
+
+ // flush the cache
+ if (cacheLength > 0) {
+ System.arraycopy(cacheCharArray, 0, newNodeText,
+ newTextPosition, cacheLength);
+ newTextPosition += cacheLength;
+
+ // reset the markers
+ lastDiffPosition = -1;
+ lastDiffOperation = Difference.UNCHANGE;
+ cacheLength = 0;
+ }
+ }
+
+ // add the diffs to the cache, now the diffs will be either
+ // a new 'changed' char or is an adjacent following change of
+ // last difference
+ cacheCharArray[cacheLength] =
+ modTextArray[diffs[j].getModPosition()];
+ cacheLength++;
+ lastDiffOperation = diffs[j].getOperation();
+ lastDiffPosition = diffs[j].getOrgPosition();
+
+ // need to increment the original text position
+ // after we cached it
+ if (lastDiffOperation == Difference.CHANGE) {
+ orgTextPosition++;
+ }
+ }
+ }
+
+ // flush any contents remaining in the cache
+ if (cacheLength > 0) {
+ System.arraycopy(cacheCharArray, 0, newNodeText,
+ newTextPosition, cacheLength);
+ newTextPosition += cacheLength;
+ // no need to reset any cache-related info as this is a last flush
+ }
+
+ // copy any contents after all the diffs
+ int orgStartPosition = orgTextNode.startChar();
+ if (orgNodeText.length + orgStartPosition > orgTextPosition) {
+ unChangedTextLength = orgNodeText.length + orgStartPosition
+ - orgTextPosition;
+ System.arraycopy(orgNodeText, orgTextPosition - orgStartPosition,
+ newNodeText, newTextPosition,
+ unChangedTextLength);
+ }
+
+ // set the text to the original node if there are any diffs processed.
+ // can't use newNodeText.length to check as even it is empty, we may
+ // process a whole bunch of deletion already (i.e. the whole
+ // orgNodeText deleted).
+ if (endDiffNum > startDiffNum) {
+ String newString = new String(newNodeText);
+ orgNode.setNodeValue(newString);
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/merge/DocumentMerge.java b/xmerge/java/org/openoffice/xmerge/merger/merge/DocumentMerge.java
new file mode 100644
index 000000000000..f2cf97b4ee48
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/merge/DocumentMerge.java
@@ -0,0 +1,278 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.merge;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.NamedNodeMap;
+
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.MergeException;
+import org.openoffice.xmerge.merger.MergeAlgorithm;
+import org.openoffice.xmerge.merger.NodeMergeAlgorithm;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.merger.Difference;
+import org.openoffice.xmerge.util.XmlUtil;
+
+/**
+ * This is an implementation of the <code>MergeAlgorithm</code> interface.
+ * This class will merge two <code>Document</code> classes. It utilizes the
+ * appropriate class which implements {@link
+ * org.openoffice.xmerge.merger.NodeMergeAlgorithm
+ * NodeMergeAlgorithm} to perform the merge.
+ *
+ * @author smak
+ */
+public class DocumentMerge implements MergeAlgorithm {
+
+ private NodeMergeAlgorithm subDocumentMerge = null;
+
+ /** The capabilities of this converter. */
+ protected ConverterCapabilities cc_;
+
+
+ /**
+ * Constructor
+ *
+ * @param cc The <code>ConverterCapabilities</code>.
+ * @param merge The <code>NodeMergeAlgorithm</code>.
+ */
+ public DocumentMerge(ConverterCapabilities cc, NodeMergeAlgorithm merge) {
+ cc_ = cc;
+ subDocumentMerge = merge;
+ }
+
+
+ public void applyDifference(Iterator orgSeq, Iterator modSeq,
+ Difference[] differences) throws MergeException {
+
+
+ // a quick test whether the differences array is in ascending order
+ int currentPosition = -1;
+ boolean haveDeleteOperation = false;
+
+ for (int i = 0; i < differences.length; i++) {
+ if (differences[i].getOrgPosition() > currentPosition) {
+ currentPosition = differences[i].getOrgPosition();
+ if (differences[i].getOperation() == Difference.DELETE) {
+ haveDeleteOperation = true;
+ } else {
+ haveDeleteOperation = false;
+ }
+ } else if (differences[i].getOrgPosition() == currentPosition) {
+ if (differences[i].getOperation() == Difference.DELETE) {
+ haveDeleteOperation = true;
+ } else if (differences[i].getOperation() == Difference.ADD &&
+ haveDeleteOperation == true) {
+ throw new MergeException(
+ "Differences array is not sorted. Delete before Add");
+ }
+ } else {
+ throw new MergeException("Differences array need to be sorted.");
+ }
+ }
+
+ // reset sequence counters
+ orgSeq.start();
+ int orgSeqCounter = 0;
+
+ modSeq.start();
+ int modSeqCounter = 0;
+
+ // check for each diff unit in the diff array to apply the diff
+ for (int i = 0; i < differences.length; i++) {
+
+ Difference currentDiff = differences[i];
+
+ int operation = currentDiff.getOperation();
+
+ Object currentElement;
+
+ switch (operation) {
+
+ case Difference.DELETE:
+ // loop through the original sequence up to the expected
+ // position. note that we use delta (see above comment)
+ // also. we will just continue the counter without reset it.
+ for (;
+ orgSeqCounter < currentDiff.getOrgPosition();
+ orgSeqCounter++, orgSeq.next()) {
+ // empty
+ }
+
+ // remove the Node. note that it will NOT affect the
+ // iterator sequence as ParaNodeIterator is a static one.
+ removeNode((Node)(orgSeq.currentElement()));
+
+ break;
+
+ // if it's an add operation, then get content from original seq
+ case Difference.ADD:
+ // loop through the modified sequence up to the expected
+ // position to get the content. As we don't need to modify
+ // the sequence. we don't need to use delta to do adjustment.
+ for (;
+ modSeqCounter < currentDiff.getModPosition();
+ modSeqCounter++, modSeq.next()) {
+ // empty
+ }
+
+ currentElement = orgSeq.currentElement();
+
+ for (;
+ orgSeqCounter < currentDiff.getOrgPosition();
+ orgSeqCounter++, currentElement = orgSeq.next()) {
+ // empty
+ }
+
+ if (orgSeqCounter > orgSeq.elementCount() - 1) {
+ // append the element to the end of the original sequence
+ appendNode((Node)(orgSeq.currentElement()),
+ (Node)(modSeq.currentElement()));
+ } else {
+ // insert the element BEFORE the current element
+ insertNode((Node)(orgSeq.currentElement()),
+ (Node)(modSeq.currentElement()));
+ }
+
+ break;
+
+ case Difference.CHANGE:
+ for (;
+ modSeqCounter < currentDiff.getModPosition();
+ modSeqCounter++, modSeq.next()) {
+ // empty
+ }
+
+ currentElement = orgSeq.currentElement();
+
+ for (;
+ orgSeqCounter < currentDiff.getOrgPosition();
+ orgSeqCounter++, currentElement = orgSeq.next()) {
+ // empty
+ }
+
+ if (subDocumentMerge == null) {
+ // use a simple replace if no row merge algorithm supply
+ replaceElement((Element)orgSeq.currentElement(),
+ (Element)modSeq.currentElement());
+ } else {
+ subDocumentMerge.merge((Element)orgSeq.currentElement(),
+ (Element)modSeq.currentElement());
+
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+
+ /**
+ * Removes the specified <code>Node</code>.
+ *
+ * @param node <code>Node</code> to remove.
+ */
+ protected void removeNode(Node node) {
+
+ Node parent = node.getParentNode();
+ parent.removeChild(node);
+ }
+
+ /**
+ * Appends <code>Node</code> after the specified <code>Node</code>.
+ *
+ * @param oldNode <code>Node</code> to append after.
+ * @param newNode <code>Node</code> to append.
+ */
+ protected void appendNode(Node oldNode, Node newNode) {
+ Node clonedNode = XmlUtil.deepClone(oldNode, newNode);
+ Node parent = oldNode.getParentNode();
+ parent.appendChild(clonedNode);
+ }
+
+
+ /**
+ * Insert <code>Node</code> before the specified <code>Node</code>.
+ *
+ * @param oldNode <code>Node</code> to insert before.
+ * @param newNode <code>Node</code> to insert.
+ */
+ protected void insertNode(Node oldNode, Node newNode) {
+ Node clonedNode = XmlUtil.deepClone(oldNode, newNode);
+ Node parent = oldNode.getParentNode();
+ parent.insertBefore(clonedNode, oldNode);
+ }
+
+
+ /**
+ * Replace <code>Element</code>.
+ *
+ * @param currElem <code>Element</code> to be replaced.
+ * @param newElem <code>Element</code> to replace.
+ */
+ protected void replaceElement(Element currElem, Element newElem) {
+
+ Node clonedNode = XmlUtil.deepClone(currElem, newElem);
+ Node parent = currElem.getParentNode();
+ parent.replaceChild(clonedNode, currElem);
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/merge/PositionBaseRowMerge.java b/xmerge/java/org/openoffice/xmerge/merger/merge/PositionBaseRowMerge.java
new file mode 100644
index 000000000000..40e7e16d77b8
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/merge/PositionBaseRowMerge.java
@@ -0,0 +1,295 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.merge;
+
+import java.util.List;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.NamedNodeMap;
+
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.merger.Difference;
+import org.openoffice.xmerge.merger.Iterator;
+import org.openoffice.xmerge.merger.DiffAlgorithm;
+import org.openoffice.xmerge.merger.NodeMergeAlgorithm;
+import org.openoffice.xmerge.merger.diff.CellNodeIterator;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+import org.openoffice.xmerge.util.XmlUtil;
+import org.openoffice.xmerge.util.Debug;
+
+
+/**
+ * This is an implementation of the <code>NodeMergeAlgorithm</code>
+ * interface. It is used to merge two rows using a positional
+ * comparison base method.
+ */
+public final class PositionBaseRowMerge implements NodeMergeAlgorithm {
+
+ /** The capabilities of this converter. */
+ private ConverterCapabilities cc_;
+
+
+ /**
+ * Constructor.
+ *
+ * @param cc The <code>ConverterCapabilities</code>.
+ */
+ public PositionBaseRowMerge(ConverterCapabilities cc) {
+ cc_ = cc;
+ }
+
+
+ public void merge(Node orgRow, Node modRow) {
+
+ Iterator orgCells = new CellNodeIterator(cc_, orgRow);
+ Iterator modCells = new CellNodeIterator(cc_, modRow);
+
+ mergeCellSequences(orgCells, modCells);
+ }
+
+
+ // used to compare the cell 1 by 1
+ private void mergeCellSequences(Iterator orgSeq, Iterator modSeq) {
+
+ int i, j;
+ boolean needMerge = true;
+ Element orgCell, modCell;
+
+ Object orgSeqObject = orgSeq.start();
+ Object modSeqObject = modSeq.start();
+
+ while (orgSeqObject != null) {
+
+
+ needMerge = true;
+
+ if (modSeqObject == null) {
+ // no corresponding cell in the target, empty out the cell
+ SheetUtil.emptyCell(cc_, (Node)orgSeqObject);
+ orgSeqObject = orgSeq.next();
+
+ } else {
+
+ // compare the cell directly
+ if (!orgSeq.equivalent(orgSeqObject, modSeqObject)) {
+
+ orgCell = (Element)orgSeqObject;
+ modCell = (Element)modSeqObject;
+
+ // check whether the original cell with multiple column
+ // if so, need to split one out for merge
+ String orgColRepeated = orgCell.getAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED);
+ String modColRepeated = modCell.getAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED);
+
+ int orgColNum = 1;
+ int modColNum = 1;
+
+ if (orgColRepeated.length() > 0) {
+ orgColNum =
+ Integer.valueOf(orgColRepeated).intValue();
+ }
+ if (modColRepeated.length() > 0) {
+ modColNum =
+ Integer.valueOf(modColRepeated).intValue();
+ }
+
+ // try to find out the common number of repeated cols
+ if (orgColNum == modColNum) {
+ orgSeqObject = orgSeq.next();
+ modSeqObject = modSeq.next();
+
+ // cut the original cell into 2 half, first half
+ // have the repeated attribute = modify cell attr
+ } else if (orgColNum > modColNum) {
+ Element orgSplitCell = splitColRepeatedCell(
+ orgCell, modColNum,
+ orgColNum - modColNum);
+ // it may equal after the split!
+ if (orgSeq.equivalent(orgSplitCell, modCell)) {
+ needMerge = false;
+ }
+ orgCell = orgSplitCell;
+ modSeqObject = modSeq.next();
+
+ // cut the modified cell into 2 half, first half
+ // have the repeated attribute = original cell attr
+ } else {
+ Element modSplitCell = splitColRepeatedCell(
+ modCell, orgColNum,
+ modColNum - orgColNum);
+ // it may equal after the split!
+ if (modSeq.equivalent(orgCell, modSplitCell)) {
+ needMerge = false;
+ }
+ modCell = modSplitCell;
+ orgSeqObject = orgSeq.next();
+ }
+
+ if (needMerge) {
+ mergeCells(orgCell, modCell);
+ }
+
+ } else {
+ // cells are equivalent, move on to next one.
+ orgSeqObject = orgSeq.next();
+ modSeqObject = modSeq.next();
+ } // end if-else
+ } // end if-else
+ } // end while loop
+
+ // get the one of the original cell, so that the cloned node
+ // can base it to find the document node
+ orgCell = (Element)orgSeq.start();
+
+ // add any extra cells to the original cell sequence.
+ for (; modSeqObject != null; modSeqObject = modSeq.next()) {
+ Node clonedNode = XmlUtil.deepClone(orgCell, (Node)modSeqObject);
+ Node parent = orgCell.getParentNode();
+ parent.appendChild(clonedNode);
+ }
+ }
+
+
+ private Element splitColRepeatedCell(Element orgCell,
+ int splitNum, int orgNum) {
+ // NOTE: should we really want to do deep clone?
+ // in most the case, it is an empty cell, but the
+ // specification didn't forbid any node to use multiple
+ // column attributes. i.e. the node can contain text
+ // nodes or other things under it.
+ Element splitCell = (Element)(orgCell.cloneNode(true));
+
+ if (splitNum > 1) {
+ splitCell.setAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED,
+ String.valueOf(splitNum));
+ } else if (splitNum == 1) {
+ splitCell.removeAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED);
+ }
+ if (orgNum > 1) {
+ orgCell.setAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED,
+ String.valueOf(orgNum));
+ } else if (orgNum == 1) {
+ orgCell.removeAttribute(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED);
+ }
+
+ Node parentNode = orgCell.getParentNode();
+ parentNode.insertBefore(splitCell, orgCell);
+
+ return splitCell;
+ }
+
+
+ private void mergeCells(Element orgCell, Element modCell) {
+
+ // remove all the supported attributes and possible text child for
+ // string cells
+ SheetUtil.emptyCell(cc_, orgCell);
+
+ // copy all the supported attributes and possible text child from
+ // the modified cell
+ NamedNodeMap attrNodes = modCell.getAttributes();
+
+ if (attrNodes != null) {
+
+ // copy the first text:p node. As it's not necessary only string
+ // type cell can have a text:p section.
+ NodeList paraNodes =
+ modCell.getElementsByTagName(OfficeConstants.TAG_PARAGRAPH);
+
+ Node firstParaNode = paraNodes.item(0);
+
+ // try to clone the node
+ if (firstParaNode != null) {
+
+ Node clonedNode = XmlUtil.deepClone(orgCell, firstParaNode);
+
+ // insert as the first child of the original cell
+ Node firstChild = orgCell.getFirstChild();
+ if (firstChild != null) {
+ orgCell.insertBefore(clonedNode, firstChild);
+ } else {
+ orgCell.appendChild(clonedNode);
+ }
+ }
+
+ // check all the attributes and copy those we supported in
+ // converter
+ // NOTE: for attribute list, refer to section 4.7.2 in specification
+ int len = attrNodes.getLength();
+
+ for (int i = 0; i < len; i++) {
+ Node attr = attrNodes.item(i);
+
+ // copy the supported attrs
+ if (cc_.canConvertAttribute(OfficeConstants.TAG_TABLE_CELL,
+ attr.getNodeName())) {
+ orgCell.setAttribute(attr.getNodeName(),
+ attr.getNodeValue());
+ }
+ }
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/merge/SheetMerge.java b/xmerge/java/org/openoffice/xmerge/merger/merge/SheetMerge.java
new file mode 100644
index 000000000000..94d5b2226563
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/merge/SheetMerge.java
@@ -0,0 +1,120 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.merge;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.merger.NodeMergeAlgorithm;
+import org.openoffice.xmerge.util.Debug;
+
+/**
+ * This class extends the <code>DocumentMerge</code> class.
+ * This class will merge two spreadsheet documents.
+ * The main difference between this implementation and
+ * <code>DocumentMerge</code>
+ * is that this merge will try to maintain unsupported features by
+ * examing the cell <code>node</code> objects one by one when it
+ * removes a node from the original <code>Iterator</code>.
+ *
+ * @author smak
+ */
+public final class SheetMerge extends DocumentMerge {
+
+ /**
+ * Constructor.
+ *
+ * @param cc The <code>ConverterCapabilities</code>.
+ * @param merge The <code>NodeMergeAlgorithm</code>.
+ */
+ public SheetMerge(ConverterCapabilities cc, NodeMergeAlgorithm merge) {
+ super(cc, merge);
+ }
+
+
+ /**
+ * Remove specified <code>Node</code>.
+ *
+ * @param node <code>Node</code> to remove.
+ */
+ protected void removeNode(Node node) {
+
+ clearRow(node);
+ }
+
+
+ /**
+ * Clear the row corresponding to the <code>Node</code>
+ *
+ * @param node <code>Node</code> containing the row to clear.
+ */
+ private void clearRow(Node node) {
+ NodeList children = node.getChildNodes();
+ int numOfChildren = children.getLength();
+
+ Node child;
+
+ // clear all the cells under the row node but maintain any unsupported
+ // features
+ // TODO: we can actually check anything left after the clear up.
+ // if there is nothing left, then we can even delete the cell nodes
+ for (int i = 0; i < numOfChildren; i++) {
+ SheetUtil.emptyCell(cc_, children.item(i));
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/merge/SheetUtil.java b/xmerge/java/org/openoffice/xmerge/merger/merge/SheetUtil.java
new file mode 100644
index 000000000000..5b3115c286e6
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/merge/SheetUtil.java
@@ -0,0 +1,136 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.merger.merge;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.NamedNodeMap;
+
+import org.openoffice.xmerge.ConverterCapabilities;
+import org.openoffice.xmerge.merger.diff.CellNodeIterator;
+import org.openoffice.xmerge.converter.xml.OfficeConstants;
+
+
+/**
+ * Utility methods to handle sheet XML tree.
+ */
+public class SheetUtil {
+
+ /**
+ * <p>Empty the content of a cell value. This includes the following:
+ * </p>
+ *
+ * <p><ul><li>
+ * Remove all of the supported attributes.
+ * </li><li>
+ * Remove the first <i>text:p</i> <code>Node</code> for most of the cells.
+ * </li></ul></p>
+ *
+ * @param cc The <code>ConverterCapabilities</code>.
+ * @param node The <code>Node</code>.
+ */
+ public static void emptyCell(ConverterCapabilities cc, Node node) {
+
+ NamedNodeMap attrNodes = node.getAttributes();
+
+ if (attrNodes != null) {
+
+ // empty the first text:p node.
+ // Note: it's not necessary only string type cell contain text:p
+ // basically, all different type of cell will contain one
+ Element cell = (Element)node;
+
+ // get the paragraph node list
+ NodeList paraNodes =
+ cell.getElementsByTagName(OfficeConstants.TAG_PARAGRAPH);
+
+ Node firstParaNode = paraNodes.item(0);
+
+ // remove the first paragraph element node
+ if (firstParaNode != null) {
+ Node parent = firstParaNode.getParentNode();
+ parent.removeChild(firstParaNode);
+ }
+
+ // check all the attributes and remove those we supported in
+ // converter
+ // NOTE: for attribute list, refer to section 4.7.2 in specification
+ int len = attrNodes.getLength();
+
+ for (int i = 0; i < len; ) {
+ Node attr = attrNodes.item(i);
+
+ // when we hit the end of the attribute nodes, return
+ // it may happen sooner as we keep on removing nodes
+ if (attr == null) {
+ break;
+ }
+ // remove the supported attr except columns repeated attribute
+ if (cc.canConvertAttribute(OfficeConstants.TAG_TABLE_CELL,
+ attr.getNodeName()) &&
+ !attr.getNodeName().equals(
+ OfficeConstants.ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED)) {
+
+ attrNodes.removeNamedItem(attr.getNodeName());
+ } else {
+ i++;
+ }
+ }
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/merge/build.xml b/xmerge/java/org/openoffice/xmerge/merger/merge/build.xml
new file mode 100644
index 000000000000..f87cc99575c1
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/merge/build.xml
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_jooxm_merge" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_jooxm_merge"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package"
+ value="org/openoffice/xmerge/merger/merge"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/CharacterBaseParagraphMerge.java"/>
+ <include name="${package}/PositionBaseRowMerge.java"/>
+ <include name="${package}/DocumentMerge.java"/>
+ <include name="${package}/SheetMerge.java"/>
+ <include name="${package}/SheetUtil.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/merger/merge/makefile.mk b/xmerge/java/org/openoffice/xmerge/merger/merge/makefile.mk
new file mode 100644
index 000000000000..b1c33f1ad449
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/merge/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_jooxm_merge
+PRJ=../../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/merger/merge/package.html b/xmerge/java/org/openoffice/xmerge/merger/merge/package.html
new file mode 100644
index 000000000000..2d885970dcbb
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/merge/package.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge.merger.diff package</title>
+</head>
+
+<body bgcolor="white">
+<p>Provides implementations for the {@link
+org.openoffice.xmerge.merger.MergeAlgorithm
+MergeAlgorithm} interface, the {@link
+org.openoffice.xmerge.merger.NodeMergeAlgorithm
+NodeMergeAlgorithm} interface, and related support classes.</p>
+
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/merger/package.html b/xmerge/java/org/openoffice/xmerge/merger/package.html
new file mode 100644
index 000000000000..192afe554245
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/merger/package.html
@@ -0,0 +1,100 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge.merger package</title>
+</head>
+
+<body bgcolor="white">
+<p>The <code>DiffAlgorithm</code> and <code>MergeAlgorithm</code>
+are used to provide the merge capabilities of this project.</p>
+
+<p>Merge is useful when an <code>OfficeDocument</code>
+is converted to a &quot;Device&quot; <code>Document</code> format,
+and the &quot;Device&quot; <code>Document</code> version is modified.
+Those changes can be merged back into the original
+<code>OfficeDocument</code> with the merger. The merger is capable
+of doing this even if the &quot;Device&quot; format is lossy in
+comparison to the <code>OfficeDocument</code> format.</p>
+
+<p>The <code>DiffAlgorithm</code> generates a list of
+<code>Difference</code> objects that represent the
+differences between two <code>OfficeDocument</code> objects.
+It is assumed that one is the original <code>OfficeDocument</code>
+object and the other is a &quot;lossy&quot; version of the same
+<code>Document</code> with edits to be merged. Typically the
+&quot;lossy&quot; version is created by converting a &quot;Device&quot
+<code>Document</code> back into an <code>OfficeDocument</code>.
+
+<p>The <code>MergeAlgorithm</code> takes the <code>Difference</code>
+objects as input, and creates a merged <code>OfficeDocument</code>.
+A merged <code>OfficeDocument</code> has the following features:</p>
+
+<p><ul>
+<li>Tags in the <code>OfficeDocument</code> that are not
+ supported in the device format are not altered or removed.
+<li>Changes made to the device format are merged back into
+ the <code>OfficeDocument</code> in the location determined by
+ the <code>DiffAlgorithm</code>.
+</ul></p>
+
+<p>Each converter provides an implementation of the
+{@link org.openoffice.xmerge.ConverterCapabilities
+ConverterCapabilities} which specifies which
+<code>OfficeDocument</code> tags are supported for the
+device format.</p>
+
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/package.html b/xmerge/java/org/openoffice/xmerge/package.html
new file mode 100644
index 000000000000..14c726f18e76
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/package.html
@@ -0,0 +1,138 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge package</title>
+</head>
+
+<body bgcolor="white">
+
+<p>Provides interfaces for converting between two <code>Document</code>
+formats, and supports a &quot;merge&quot; interface for merging back
+changes from a &quot;lossy&quot; format back into a rich format.</p>
+
+<p>The {@link org.openoffice.xmerge.Convert
+Convert} object encapsulates the conversion of one format to/from another
+format. The user requests a <code>Convert</code> object via the
+<code>ConverterFactory</code>.</p>
+
+<p>The <code>Convert</code> class encapsulates a specific plug-in.
+A plug-in can support deserialization (convert from &quot;Device&quot;
+to &quot;Office&quot;) and/or serialization (convert from
+&quot;Office&quot; to &quot;Device&quot;). If a plug-in supports
+both deserialization and serialization, then it can also support
+&quot;merge&quot;.</p>
+
+<p>To support conversions where a single input <code>Document</code> can
+create multiple output <code>Document</code> objects, data is passed in
+and out of the conversion functions via a <code>ConvertData</code> object.
+This <code>ConvertData</code> can contain one or more <code>Document</code>
+objects. It is assumed that the client will know when to pass multiple
+files into a specific plug-in, and that the plug-in will know how to
+handle the multiple files.</p>
+
+<p>Merging is useful when converting from a rich <code>Document</code>
+format to a more lossy format. Then the user may modify the
+<code>Document</code> in the lossy format, and &quot;merge&quot; those
+changes back into the original &quot;rich&quot; <code>Document</code>.
+Each merge implementation provides a <code>ConverterCapabilities</code>
+implementation so that the merge logic knows what changes from the
+&quot;lossy&quot; format to merge into the original &quot;rich&quot;
+<code>Document</code>.</p>
+
+<p>Each plug-in must be registed via the singleton ConverterInfoMgr
+object via its {@link
+org.openoffice.xmerge.util.registry.ConverterInfoMgr#addPlugIn
+addPlugIn} method.</p>
+
+<h2>Providing implementations</h2>
+
+<p>The plug-in implementation must include the <code>getDeviceDocument</code>
+and <code>getOfficeDocument</code> methods. These functions need to return
+the appropriate type of <code>Document</code> for the plug-in. It may be
+necessary to create a new implementation of the <code>Document</code>
+interface if one does not exist that meets the needs of the plug-in.</p>
+
+<p>Currently, base implementations for working with StarWriter XML
+<code>Document</code> objects are available via the
+<a href="converter/xml/sxc/package-summary.html#package_description">
+org.openoffice.xmerge.xml.sxw</a>
+package, and StarCalc XML <code>Document</code> objects via the
+<a href="converter/xml/sxw/package-summary.html#package_description">
+org.openoffice.xmerge.xml.sxc</a>
+package.</p>
+
+<h2>TODO/IDEAS list</h2>
+
+<p><ol>
+<li>An idea is to combine the <code>ConvertData</code> and the
+ <code>Convert</code> classes, so that a <code>ConvertData</code>
+ knows what it can convert into and whether or not it can merge.
+ Then a user would call convert/merge methods on the
+ <code>ConvertData</code> class, which returns a
+ <code>ConvertData</code> object that likewise knows what it can
+ convert/merge into.</li>
+<li><code>DocumentSerialize</code> constructors and the
+ <code>DocumentDeserializer.deserializer</code> method could pass
+ in a <code>ConvertData</code> object rather than assuming
+ a single <code>Document</code> will represent a &quot;rich&quot;
+ <code>Document</code>.</li>
+<li>May need to add a <code>PluginFactory.setProperties</code>
+ method for adding properties specific to each converter.</li>
+</ol></p>
+
+</body>
+</html>
+
diff --git a/xmerge/java/org/openoffice/xmerge/test/ConverterInfoList.java b/xmerge/java/org/openoffice/xmerge/test/ConverterInfoList.java
new file mode 100644
index 000000000000..c1f2185d1b07
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/test/ConverterInfoList.java
@@ -0,0 +1,136 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.test;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.io.BufferedInputStream;
+import java.util.Properties;
+import java.util.Vector;
+import java.util.Enumeration;
+
+/**
+ * Loads a properties file so that registry knows which plug-ins
+ * it needs to load.
+ *
+ * @author: Martin Maher
+ */
+public class ConverterInfoList {
+
+ private static String defaultPropsFile = "ConverterInfoList.properties";
+
+ private Vector jars;
+ private Properties props = null;
+
+
+ /**
+ * This constructor loads and reads the default properties file.
+ * The default property file name is:
+ * &quot;ConverterInfoList.properties&quot;.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public ConverterInfoList() throws IOException {
+ this(defaultPropsFile);
+ }
+
+ /**
+ * This constructor loads and reads the properties file.
+ *
+ * @param propsFile The properties file to load.
+ *
+ * @throws IOException If any I/O error occurs.
+ */
+ public ConverterInfoList(String propsFile) throws IOException {
+
+ Class c = this.getClass();
+ InputStream is = c.getResourceAsStream(propsFile);
+ BufferedInputStream bis = new BufferedInputStream(is);
+ props = new Properties();
+ props.load(bis);
+ bis.close();
+
+ int i = 1;
+ String jarFileName = new String();
+ jars = new Vector();
+
+ while ((jarFileName = props.getProperty("jarname" + i)) != null) {
+ jars.add(jarFileName);
+ i++;
+ }
+ }
+
+
+ /**
+ * Returns a <code>Vector</code> containing a list of
+ * <code>String</code> objects. Each <code>String</code>
+ * describes a plug-in to be loaded into the registry.
+ *
+ *
+ * @return A <code>Vector</code> containing a list of
+ * <code>String</code> objects. Each
+ * <code>String</code> describes a plug-in to be
+ * loaded into the registry.
+ */
+ public Enumeration getJarFileEnum() {
+
+ return jars.elements();
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/test/ConverterInfoList.properties b/xmerge/java/org/openoffice/xmerge/test/ConverterInfoList.properties
new file mode 100644
index 000000000000..909587fa9b09
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/test/ConverterInfoList.properties
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+#
+# Jarfiles to be loaded
+#
+jarname1=file:///jarDirectory/htmlsoff.jar
+
diff --git a/xmerge/java/org/openoffice/xmerge/test/Driver.java b/xmerge/java/org/openoffice/xmerge/test/Driver.java
new file mode 100644
index 000000000000..50216678536b
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/test/Driver.java
@@ -0,0 +1,349 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.test;
+
+import java.util.Vector;
+import java.util.Enumeration;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.File;
+
+import org.openoffice.xmerge.Convert;
+import org.openoffice.xmerge.Document;
+import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.ConverterFactory;
+import org.openoffice.xmerge.test.ConverterInfoList;
+import org.openoffice.xmerge.util.registry.ConverterInfo;
+import org.openoffice.xmerge.util.registry.ConverterInfoMgr;
+import org.openoffice.xmerge.util.registry.ConverterInfoReader;
+import org.openoffice.xmerge.DocumentMerger;
+
+/**
+ * This class is a command-line driver for the converter framework.
+ * It is expected that this code will be later called by the device
+ * server. It does some basic validation of the command-line
+ * parameters.
+ */
+public final class Driver {
+
+ /** Command-line parameter. */
+ private String fromMime = null;
+
+ /** Command-line parameter. */
+ private String toMime = null;
+
+ /** mergeFile name. */
+ private String mergeFile = null;
+
+ /** Command-line parmeter. */
+ private Vector deviceFiles = new Vector();
+
+ /** Command-line parmeter shortcuts. */
+ private String mimeTypes[] = {
+ "sxc", "staroffice/sxc",
+ "sxw","staroffice/sxw"
+ };
+
+
+ /**
+ * Main.
+ *
+ * @param args The argument passed on the command line.
+ */
+ public static void main(String args[]) {
+
+ // Register jarfiles
+ //
+ String propFile = "ConverterInfoList.properties";
+ ConverterInfoList cil = null;
+ try {
+ cil = new ConverterInfoList(propFile);
+ } catch (Exception e) {
+ System.out.println("\nCannot not load " + propFile +
+ " property file");
+ }
+
+ Enumeration jarInfoEnumeration;
+ ConverterInfoReader cir;
+
+ Enumeration jarFileEnum = cil.getJarFileEnum();
+ while (jarFileEnum.hasMoreElements()) {
+ String jarName = (String) jarFileEnum.nextElement();
+ try {
+ cir = new ConverterInfoReader(jarName, false);
+ jarInfoEnumeration = cir.getConverterInfoEnumeration();
+ ConverterInfoMgr.addPlugIn(jarInfoEnumeration);
+ } catch (Exception e) {
+ System.out.println("\nCannot not load <" + jarName +
+ "> from the <" + propFile + "> property file");
+ }
+ }
+
+ try {
+
+ Driver app = new Driver();
+ app.parseCommandLine(args);
+ app.doConversion();
+ } catch (IllegalArgumentException ex) {
+
+ String msg = ex.getMessage();
+ if (msg != null) System.out.println("\n" + msg);
+ showUsage();
+
+ } catch (Exception ex) {
+
+ String msg = ex.getMessage();
+ if (msg != null) System.out.println("\n" + msg);
+ ex.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Gets a <code>Convert</code> object using the
+ * <code>ConverterFactory</code> and does the conversion using
+ * this object.
+ *
+ * @throws IllegalArgumentException If an argument is invalid.
+ */
+ private void doConversion() throws IllegalArgumentException {
+
+ ConverterFactory cf = new ConverterFactory();
+ Convert myConvert = cf.getConverter(fromMime, toMime);
+ String processFile = null;
+
+ if (myConvert == null) {
+ System.out.println("\nNo plug-in exists to convert from <" +
+ fromMime + "> to <" + toMime + ">");
+ throw new IllegalArgumentException();
+ }
+
+ try {
+ Enumeration dfEnum = deviceFiles.elements();
+ while (dfEnum.hasMoreElements()) {
+ processFile = (String)dfEnum.nextElement();
+ File f = new File(processFile);
+
+ // Make sure the input file actually exists before using it
+ if (!f.exists()) {
+ System.out.println(processFile + " does not exist!");
+ System.exit(0);
+ }
+ FileInputStream fis = new FileInputStream(f);
+ myConvert.addInputStream(f.getName(), fis);
+ }
+ } catch (Exception addExcept) {
+ System.out.println("\nFile <" + processFile + "> is not in <" +
+ fromMime + "> format");
+ throw new IllegalArgumentException();
+ }
+
+ ConvertData dataOut = null;
+
+ try {
+ dataOut = myConvert.convert();
+ } catch (Exception convertExcept) {
+ System.out.println("\nThere was an error in the conversion");
+ convertExcept.printStackTrace();
+ }
+
+ if (dataOut != null ) {
+
+ if (mergeFile == null) {
+ Enumeration docEnum = dataOut.getDocumentEnumeration();
+ while (docEnum.hasMoreElements()) {
+ Document docOut = (Document)docEnum.nextElement();
+ String fileName = docOut.getFileName();
+ try {
+ FileOutputStream fos = new FileOutputStream(fileName);
+ docOut.write(fos);
+ fos.flush();
+ fos.close();
+ } catch (Exception writeExcept) {
+ System.out.println("\nThere was an writing out file <" +
+ fileName + ">");
+ writeExcept.printStackTrace();
+ }
+ }
+ } else {
+ try {
+ FileInputStream mergeIS = new FileInputStream(mergeFile);
+ Document mergeDoc = myConvert.getOfficeDocument(mergeFile, mergeIS);
+ DocumentMerger merger = myConvert.getDocumentMerger(mergeDoc);
+ Enumeration mergeDocEnum = dataOut.getDocumentEnumeration();
+ Document convertedFile = (Document)mergeDocEnum.nextElement();
+
+ merger.merge(convertedFile);
+ mergeIS.close();
+
+ FileOutputStream fos = new FileOutputStream(mergeFile);
+ mergeDoc.write(fos);
+ fos.flush();
+ fos.close();
+ } catch (Exception mergeExcept) {
+ System.out.println("\nThere was an error in the merge");
+ mergeExcept.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Display usage.
+ */
+ private static void showUsage() {
+
+ System.out.println("\nUsage:");
+ System.out.println("\n java org.openoffice.xmerge.test.Driver <args>");
+ System.out.println("\n where <args> is as follows:");
+ System.out.println(" -from <MIMETYPE> -to <MIMETYPE> [ -merge <OrigDoc ] <document>\n");
+ }
+
+
+ /**
+ * Parse command-line arguments.
+ *
+ * @param args Array of command line arguments.
+ *
+ * @throws IllegalArgumentException If an argument is invalid.
+ */
+ private void parseCommandLine(String args[])
+ throws IllegalArgumentException {
+
+ if (args.length == 0) {
+ throw new IllegalArgumentException();
+ }
+
+ for (int i = 0; i < args.length; i++) {
+ String arg = args[i];
+
+ if ("-to".equals(arg)) {
+ toMime = extractArg(i, args);
+ for (int j = 0; j < mimeTypes.length; j+=2) {
+ if(mimeTypes[j].equals(extractArg(i, args)))
+ toMime = mimeTypes[j+1];
+ }
+ i++;
+ } else if ("-from".equals(arg)) {
+ fromMime = extractArg(i, args);
+ for (int j = 0; j < mimeTypes.length; j+=2) {
+ if(mimeTypes[j].equals(extractArg(i, args)))
+ fromMime = mimeTypes[j+1];
+ }
+ i++;
+ } else if ("-merge".equals(arg)) {
+ mergeFile = extractArg(i, args);
+ if (!isZip(mergeFile)) {
+ throw new
+ IllegalArgumentException("Arg " + i +
+ ": expected zip, got " +
+ mergeFile);
+ }
+ i++;
+ } else {
+ deviceFiles.add(arg);
+ }
+ }
+
+ System.out.println("\nConverting from " + fromMime + " to " + toMime +
+ ((mergeFile != null) ? " with merge " : " "));
+ }
+
+
+ /**
+ * Extract the next argument from the array, while checking to see
+ * that the array size is not exceeded. Throw a friendly error
+ * message in case the arg is missing.
+ *
+ * @param i Argument index.
+ * @param args Array of command line arguments.
+ *
+ * @return The argument with the specified index.
+ *
+ * @throws IllegalArgumentException If an argument is invalid.
+ */
+ private String extractArg(int i, String args[])
+ throws IllegalArgumentException {
+
+ if (i+1 < args.length)
+ return args[i+1];
+ else throw new
+ IllegalArgumentException("Arg " + i +
+ ": expected arg for " + args[i]);
+ }
+
+
+ /**
+ * Simple validation for Office ZIP files.
+ *
+ * @param zipName The name of the ZIP file.
+ *
+ * @return true if zipName is valid, false otherwise.
+ */
+ private boolean isZip(String zipName) {
+
+ String str = zipName.toLowerCase();
+ if (str.endsWith("sxw") || zipName.endsWith("sxc")) {
+ return true;
+ }
+
+ return false;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/test/build.xml b/xmerge/java/org/openoffice/xmerge/test/build.xml
new file mode 100644
index 000000000000..1ac5c6360e98
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/test/build.xml
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_joox_test" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_joox_test"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package" value="org/openoffice/xmerge/test"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/ConverterInfoList.java"/>
+ <include name="${package}/Driver.java"/>
+ </javac>
+ <copy todir="${build.class}/${package}">
+ <fileset dir=".">
+ <include name="*.properties"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
diff --git a/xmerge/java/org/openoffice/xmerge/test/makefile.mk b/xmerge/java/org/openoffice/xmerge/test/makefile.mk
new file mode 100644
index 000000000000..09a9ca7f5e8b
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/test/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_joox_test
+PRJ=../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/util/Debug.java b/xmerge/java/org/openoffice/xmerge/util/Debug.java
new file mode 100644
index 000000000000..65bf1b9b6238
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/Debug.java
@@ -0,0 +1,369 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.util;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Calendar;
+import java.util.Properties;
+import org.w3c.dom.Node;
+
+
+/**
+ * This class is used for logging debug messages.
+ * Currently, there are three types of logging: {@link #INFO},
+ * {@link #TRACE} & {@link #ERROR}. Use the Debug.properties
+ * file to set or unset each type. Also use Debug.properties
+ * to set the writer to either <code>System.out</code>,
+ * <code>System.err</code>, or to a file.
+ *
+ * @author Herbie Ong
+ */
+public final class Debug {
+
+ /** Informational messages. */
+ public final static int INFO = 0x0001;
+ /** Error messages. */
+ public final static int ERROR = 0x0002;
+ /** Trace messages. */
+ public final static int TRACE = 0x0004;
+
+ /** To set a flag. */
+ public final static boolean SET = true;
+ /** To unset a flag. */
+ public final static boolean UNSET = false;
+
+ private static int flags = 0;
+ private static PrintWriter writer = null;
+
+ static {
+
+ try {
+
+ Class c = new Debug().getClass();
+ InputStream is = c.getResourceAsStream("Debug.properties");
+ Properties props = new Properties();
+ props.load(is);
+
+ String info = props.getProperty("debug.info", "false");
+ info = info.toLowerCase();
+
+ if (info.equals("true")) {
+ setFlags(Debug.INFO, Debug.SET);
+ }
+
+ String trace = props.getProperty("debug.trace", "false");
+ trace = trace.toLowerCase();
+
+ if (trace.equals("true")) {
+ setFlags(Debug.TRACE, Debug.SET);
+ }
+
+ String error = props.getProperty("debug.error", "false");
+ error = error.toLowerCase();
+
+ if (error.equals("true")) {
+ setFlags(Debug.ERROR, Debug.SET);
+ }
+
+ String w = props.getProperty("debug.output", "System.out");
+ setOutput(w);
+
+ } catch (Throwable ex) {
+
+ ex.printStackTrace(System.err);
+ }
+ }
+
+
+ /**
+ * Private constructor so as not to allow any instances
+ * of this class. This serves as a singleton class.
+ */
+ private Debug() {
+ }
+
+
+ /**
+ * Set the output to the specified argument.
+ * This method is only used internally to prevent
+ * invalid string parameters.
+ *
+ * @param str Output specifier.
+ */
+ private static void setOutput(String str) {
+
+ if (writer == null) {
+
+ if (str.equals("System.out")) {
+
+ setOutput(System.out);
+
+ } else if (str.equals("System.err")) {
+
+ setOutput(System.err);
+
+ } else {
+
+ try {
+
+ setOutput(new FileWriter(str));
+
+ } catch (IOException e) {
+
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Set the output to an <code>OutputStream</code> object.
+ *
+ * @param stream OutputStream object.
+ */
+ private static void setOutput(OutputStream stream) {
+
+ setOutput(new OutputStreamWriter(stream));
+ }
+
+
+ /**
+ * Set the <code>Writer</code> object to manage the output.
+ *
+ * @param w <code>Writer</code> object to write out.
+ */
+ private static void setOutput(Writer w) {
+
+ if (writer != null) {
+
+ writer.close();
+ }
+
+ writer = new PrintWriter(new BufferedWriter(w), true);
+ }
+
+
+ /**
+ * <p>
+ * This method sets the levels for debugging logs.
+ * Example calls:
+ * </p>
+ *
+ * <blockquote><pre><code>
+ * Debug.setFlags( Debug.INFO, Debug.SET )
+ * Debug.setFlags( Debug.TRACE, Debug.SET )
+ * Debug.setFlags( Debug.INFO | Debug.TRACE, Debug.SET )
+ * Debug.setFlags( Debug.ERROR, Debug.UNSET )
+ * </code></pre></blockquote>
+ *
+ * @param f Debug flag
+ * @param set Use Debug.SET to set, and Debug.UNSET to unset
+ * the given flag.
+ */
+ private static void setFlags(int f, boolean set) {
+
+ if (set) {
+ flags |= f;
+ } else {
+ flags &= ~f;
+ }
+ }
+
+
+ /**
+ * Prints out information regarding platform.
+ */
+ public static void logSystemInfo() {
+
+ if (writer != null) {
+
+ writer.println();
+ writer.println("Platform Information:");
+ writer.println("OS : " + System.getProperty("os.name"));
+ writer.println("Version : " + System.getProperty("os.version"));
+ writer.println("Platform : " + System.getProperty("os.arch"));
+ writer.println("JDK Version : " + System.getProperty("java.version"));
+ writer.println("JDK Vendor : " + System.getProperty("java.vendor"));
+ writer.println();
+ }
+ }
+
+
+ /**
+ * Prints out timestamp.
+ */
+ public static void logTime() {
+
+ if (writer != null) {
+
+ Date time = Calendar.getInstance().getTime();
+ DateFormat dt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
+ writer.println(dt.format(time));
+ }
+ }
+
+
+ /**
+ * Checks if flag is set.
+ *
+ * @return true if info logging is on, otherwise false
+ */
+ public static boolean isFlagSet(int f) {
+
+ return ((flags & f) != 0);
+ }
+
+
+ /**
+ * <p>Log message based on the flag type.</p>
+ *
+ * <p>Example 1:</p>
+ *
+ * <blockquote><pre><code>
+ * Debug.log(Debug.INFO, "info string here");
+ * </code></pre></blockquote>
+ *
+ * <p>This logs the message during runtime if
+ * <code>debug.info</code> in the properties file is
+ * set to true.</p>
+ *
+ * <p>Example 2:</p>
+ *
+ * <blockquote><pre><code>
+ * Debug.log(Debug.INFO | Debug.TRACE, "info string here");
+ * </code></pre></blockquote>
+ *
+ * <p>This logs the message during runtime if debug.info or debug.trace
+ * in the properties file is set to true.</p>
+ *
+ * @param int Log type, one of the Debug constants
+ * {@link #INFO}, {@link #TRACE}, {@link #ERROR}
+ * or a combination of which or'ed together.
+ * @param msg The message.
+ */
+ public static void log(int flag, String msg) {
+
+ if (isFlagSet(flag)) {
+
+ if (writer != null) {
+
+ writer.println(msg);
+ }
+ }
+ }
+
+
+ /**
+ * Log message based on flag type plus print out stack trace
+ * of the exception passed in. Refer to the other log method
+ * for description.
+ *
+ * @param int Log type, one of the Debug constants
+ * {@link #INFO}, {@link #TRACE}, {@link #ERROR}
+ * or a combination of which or'ed together.
+ * @param msg The message.
+ * @param e Throwable object.
+ */
+ public static void log(int flag, String msg, Throwable e) {
+
+ if (isFlagSet(flag)) {
+
+ if (writer != null) {
+
+ writer.println(msg);
+ if (e != null)
+ e.printStackTrace(writer);
+ }
+ }
+ }
+
+
+ /**
+ * Converts the given bytes to a <code>String</code> of
+ * Hex digits.
+ *
+ * @param bytes <code>byte</code> array.
+ *
+ * @return Hex representation in a <code>String</code>.
+ */
+ public static String byteArrayToHexString(byte bytes[]) {
+
+ StringBuffer buff = new StringBuffer();
+
+ for (int i = 0; i < bytes.length; i++) {
+
+ int ch = ((int) bytes[i] & 0xff);
+ String str = Integer.toHexString(ch);
+ if (str.length() < 2)
+ buff.append('0');
+ buff.append(str);
+ buff.append(' ');
+ }
+
+ return buff.toString();
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/Debug.properties b/xmerge/java/org/openoffice/xmerge/util/Debug.properties
new file mode 100644
index 000000000000..e08f38f8f601
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/Debug.properties
@@ -0,0 +1,65 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+
+#
+# debug logging information and settings.
+#
+
+debug.info=false
+debug.trace=false
+debug.error=false
+debug.output=System.err
+
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/IntArrayList.java b/xmerge/java/org/openoffice/xmerge/util/IntArrayList.java
new file mode 100644
index 000000000000..c8d78a6b3409
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/IntArrayList.java
@@ -0,0 +1,175 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.util;
+
+import java.util.ArrayList;
+import java.lang.Integer;
+
+/**
+ * This is a convenience class used to create an
+ * <code>ArrayList</code> of integers.
+ */
+public class IntArrayList {
+
+ /** The list to hold our integers. */
+ private ArrayList list;
+
+ /**
+ * Constructor.
+ * Creates the list with 0 length.
+ */
+ public IntArrayList() {
+ list = new ArrayList();
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param initialCapacity Initial capacity of the list.
+ */
+ public IntArrayList(int initialCapacity) {
+ list = new ArrayList(initialCapacity);
+ }
+
+
+ /**
+ * This method ensures that the list is large enough for
+ * <code>minCapacity</code> elements.
+ *
+ * @param minCapacity The minimum capacity of the list.
+ */
+ public void ensureCapacity(int minCapacity) {
+
+ list.ensureCapacity(minCapacity);
+ }
+
+
+ /**
+ * This method ensures that the list is large enough for
+ * <code>minCapacity</code> elements. It also fills in the
+ * new slots in the list with the integer value input as
+ * <code>fillValue</code>.
+ *
+ * @param minCapacity The minimum capacity of the list.
+ * @param fillValue This method adds in a integer for each
+ * slot that was added to ensure that the
+ * list meets the minimum capacity.
+ * <code>fillValue</code> is the value
+ * used as the initial value of these
+ * added elements.
+ */
+ public void ensureCapacityAndFill(int minCapacity, int fillValue) {
+
+ list.ensureCapacity(minCapacity);
+
+ int needToAdd = minCapacity - list.size();
+ if (needToAdd > 0) {
+ for (int i = 0; i < needToAdd; i++) {
+ list.add(new Integer(fillValue));
+ }
+ }
+ }
+
+
+ /**
+ * This method sets an element of the list to the input
+ * integer value.
+ *
+ * @param index The index in the list of the element
+ * we wish to set.
+ * @param value The integer value that we assign to the
+ * selected element of the list.
+ */
+ public void set(int index, int value) {
+ list.set(index, new Integer(value));
+ }
+
+
+ /**
+ * This method appends an element to the list.
+ *
+ * @param value The integer value that we assign to the
+ * element that we are appending to the list.
+ */
+ public void add(int value) {
+ list.add(new Integer(value));
+ }
+
+
+ /**
+ * This method gets the integer value stored in element index.
+ *
+ * @param index The index in the list of the element
+ * we wish to get the value from.
+ *
+ * @return The value of the data stored in element index.
+ */
+ public int get(int index) {
+ return ((Integer)list.get(index)).intValue();
+ }
+
+
+ /**
+ * This method gets the size of the list.
+ *
+ * @return The size of the list.
+ */
+ public int size() {
+ return list.size();
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/Resources.java b/xmerge/java/org/openoffice/xmerge/util/Resources.java
new file mode 100644
index 000000000000..f78667a92813
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/Resources.java
@@ -0,0 +1,128 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.util;
+
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
+
+/**
+ * <p>Provides a singleton resource class for converter messages.</p>
+ *
+ * <p>By default, this class will search for a
+ * <code>ResourceBundle</code> class file or properties file based
+ * on the default locale.</p>
+ *
+ * <p>A properties file resources.properties will be provided.</p>
+ *
+ * <p>Note that if the resource bundle object is not loaded, the
+ * construction of the singleton object will throw a
+ * <code>MissingResourceException</code>, which is a
+ * <code>RuntimeException</code>, thus I opted to not explicitly
+ * declare it. If it does throw <code>MissingResourceException</code>,
+ * it may be due to a packaging problem.</p>
+ *
+ * @author Herbie Ong
+ */
+public final class Resources
+{
+ private ResourceBundle rb = null;
+
+ private static Resources instance = null;
+
+
+ /**
+ * This method returns the singleton instance
+ * of this class.
+ *
+ * @return The singleton <code>Resources</code>
+ * instance.
+ */
+ public synchronized static Resources getInstance()
+ {
+ if (instance == null)
+ {
+ instance = new Resources();
+ }
+
+ return instance;
+ }
+
+
+ /**
+ * Default constructor is only accessible within this class.
+ * Load the resource bundle that contains the resource
+ * <code>String</code> values.
+ */
+ private Resources()
+ {
+ rb = ResourceBundle.getBundle("org.openoffice.xmerge.util.resources");
+ }
+
+
+ /**
+ * This method returns the corresponding <code>String</code> given
+ * the key.
+ *
+ * @param key Key string for getting the message
+ * <code>String</code>.
+ * @return Message <code>String</code> corresponding to the key.
+ */
+ public String getString(String key)
+ {
+ return rb.getString(key);
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/XmlUtil.java b/xmerge/java/org/openoffice/xmerge/util/XmlUtil.java
new file mode 100644
index 000000000000..fe2993eb4480
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/XmlUtil.java
@@ -0,0 +1,217 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.util;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+/**
+ * Class containing static util methods for handling XML trees.
+ *
+ * @author smak
+ */
+public final class XmlUtil {
+
+
+ /**
+ * Perform a deep clone of certain <code>Node</code> which
+ * will base on the document <code>Node</code> of the old
+ * <code>Node</code>.
+ *
+ * @param oldNode The <code>Document</code> of this
+ * <code>Node</code> is used to clone
+ * the <code>Node</code>
+ * @param newNode The <code>Node</code> to clone.
+ *
+ * @return The cloned <code>Node</code>.
+ */
+ public static Node deepClone(Node oldNode, Node newNode) {
+ Document docNode = oldNode.getOwnerDocument();
+
+ // clone the starting node
+ Node clonedNode = cloneNode(docNode, newNode);
+
+ // then clone the sub-tree recursively
+ cloneTree(docNode, clonedNode, newNode);
+
+ return clonedNode;
+ }
+
+
+ /**
+ * Clone the sub-tree under certain given <code>Node</code>
+ *
+ * @param docNode The <code>Document</code> used to clone
+ * the <code>Node</code>.
+ * @param oldNode The <code>Node</code> to clone.
+ * @param newNode The destination <code>Node</code>.
+ */
+ private static void cloneTree(Document docNode, Node oldNode, Node newNode) {
+
+ NodeList nodeList = newNode.getChildNodes();
+ int nodeListLen = nodeList.getLength();
+
+ for (int i = 0; i < nodeListLen; i++) {
+ Node newClonedChild = cloneNode(docNode, nodeList.item(i));
+ if (newClonedChild != null) {
+ oldNode.appendChild(newClonedChild);
+ cloneTree(docNode, newClonedChild, nodeList.item(i));
+ }
+ }
+ }
+
+
+ /**
+ * Clone a <code>Node</code> (either text or element).
+ *
+ * @param docNode The <code>Document</code> used to
+ * clone the <code>Node</code>.
+ * @param newNode The <code>Node</code> to clone.
+ *
+ * @return The cloned <code>Node</code>.
+ */
+ private static Node cloneNode(Document docNode, Node newNode) {
+
+ Node clonedNode = null;
+
+ // only support text node and element node (will copy the attributes)
+ switch (newNode.getNodeType()) {
+ case Node.TEXT_NODE:
+ String textStr = newNode.getNodeValue();
+ clonedNode = docNode.createTextNode(textStr);
+ break;
+ case Node.ELEMENT_NODE:
+ Element oldElem = (Element)newNode;
+ String tagName = newNode.getNodeName();
+ Element newElem = (docNode.createElement(tagName));
+
+ // copy the attributes
+ NamedNodeMap attrs = oldElem.getAttributes();
+
+ for (int i = 0; i < attrs.getLength(); i++) {
+ newElem.setAttribute(attrs.item(i).getNodeName(),
+ attrs.item(i).getNodeValue());
+ }
+ clonedNode = newElem;
+ break;
+ }
+ return clonedNode;
+ }
+
+
+ /**
+ * Returns the name and type of an XML DOM <code>Node</code>.
+ *
+ * @param node <code>Node</code> to query.
+ *
+ * @return Name and type of XML DOM <code>Node</code>.
+ */
+ public static String getNodeInfo(Node node) {
+
+ String str = null;
+ switch (node.getNodeType()) {
+
+ case Node.ELEMENT_NODE:
+ str = "ELEMENT";
+ break;
+ case Node.ATTRIBUTE_NODE:
+ str = "ATTRIBUTE";
+ break;
+ case Node.TEXT_NODE:
+ str = "TEXT";
+ break;
+ case Node.CDATA_SECTION_NODE:
+ str = "CDATA_SECTION";
+ break;
+ case Node.ENTITY_REFERENCE_NODE:
+ str = "ENTITY_REFERENCE";
+ break;
+ case Node.ENTITY_NODE:
+ str = "ENTITY";
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ str = "PROCESSING_INSTRUCTION";
+ break;
+ case Node.COMMENT_NODE:
+ str = "COMMENT";
+ break;
+ case Node.DOCUMENT_NODE:
+ str = "DOCUMENT";
+ break;
+ case Node.DOCUMENT_TYPE_NODE:
+ str = "DOCUMENT_TYPE";
+ break;
+ case Node.DOCUMENT_FRAGMENT_NODE:
+ str = "DOCUMENT_FRAGMENT";
+ break;
+ case Node.NOTATION_NODE:
+ str = "NOTATION";
+ break;
+ }
+
+ StringBuffer buffer = new StringBuffer("name=\"");
+ buffer.append(node.getNodeName());
+ buffer.append("\" type=\"");
+ buffer.append(str);
+ buffer.append("\"");
+
+ return buffer.toString();
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/build.xml b/xmerge/java/org/openoffice/xmerge/util/build.xml
new file mode 100644
index 000000000000..031ef4a72c17
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/build.xml
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_joox_util" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_joox_util"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package" value="org/openoffice/xmerge/util"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set whether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/IntArrayList.java"/>
+ <include name="${package}/Resources.java"/>
+ <include name="${package}/XmlUtil.java"/>
+ <include name="${package}/Debug.java"/>
+ </javac>
+ <copy todir="${build.class}/${package}">
+ <fileset dir=".">
+ <include name="*.properties"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ <include name="${package}/*.properties"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/makefile.mk b/xmerge/java/org/openoffice/xmerge/util/makefile.mk
new file mode 100644
index 000000000000..0c034bd3f539
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_joox_util
+PRJ=../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/util/package.html b/xmerge/java/org/openoffice/xmerge/util/package.html
new file mode 100644
index 000000000000..f3a5112a4a0d
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/package.html
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge.util package</title>
+</head>
+
+<body bgcolor="white">
+<p>Provides general purpose utilities.</p>
+
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfo.java b/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfo.java
new file mode 100644
index 000000000000..a792179ee1f2
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfo.java
@@ -0,0 +1,464 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.util.registry;
+
+import java.util.Vector;
+import java.util.Enumeration;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.lang.reflect.Constructor;
+import org.openoffice.xmerge.PluginFactory;
+import org.openoffice.xmerge.DocumentSerializerFactory;
+import org.openoffice.xmerge.DocumentDeserializerFactory;
+import org.openoffice.xmerge.DocumentMergerFactory;
+
+/**
+ * Class for storing the information about a converter plugin.
+ *
+ * @author Brian Cameron
+ */
+public class ConverterInfo {
+
+ /**
+ * Keep track of the valid Office mime types
+ */
+ private static String[] validOfficeTypes;
+ public static String SxwType = "staroffice/sxw";
+ public static String SxcType = "staroffice/sxc";
+
+
+ static {
+ // This needs to be updated to reflect all valid office types.
+ //
+ validOfficeTypes = new String[2];
+ validOfficeTypes[0] = SxwType;
+ validOfficeTypes[1] = SxcType;
+ }
+
+ private String piJarName;
+ private String piOfficeMime;
+ private Vector piDeviceMime;
+ private String piDisplayName;
+ private String piDescription;
+ private String piVersion;
+ private String piVendor;
+ private String piClassImpl;
+ private String piXsltSerial;
+ private String piXsltDeserial;
+ private boolean piCanSerialize = false;
+ private boolean piCanDeserialize = false;
+ private boolean piCanMerge = false;
+ private ClassLoader piClassLoader = null;
+ private PluginFactory piPluginFactory;
+
+
+ /**
+ * The constructor builds a ConverterInfo structure.
+ *
+ * @param jarName The URL of the jarfile.
+ * @param officeMime The office mime-type.
+ * @param deviceMime The device mime-type.
+ * @param displayName The display name.
+ * @param description The description.
+ * @param version The version.
+ * @param vendor The vendor name.
+ * @param impl The implementation class name of
+ * PluginFactory.
+ * @param xsltSerial The url of the serializer xsl stylesheet
+ * @param xsltDeserial The url of the deserializer xsl stylesheet
+ *
+ * @throws RegistryException If <code>ci</code> cannot
+ * be loaded.
+ */
+ public ConverterInfo(String jarName, String officeMime,
+ Vector deviceMime, String displayName, String description,
+ String version, String vendor, String impl,String xsltSerial,
+ String xsltDeserial)
+ throws RegistryException {
+
+ if (isValidOfficeType(officeMime.trim()) == false) {
+ RegistryException re = new RegistryException(
+ "Invalid office type");
+ throw re;
+ }
+
+ piJarName = jarName.trim();
+ piOfficeMime = officeMime.trim();
+ piDeviceMime = deviceMime;
+ piDisplayName = displayName.trim();
+ piDescription = description.trim();
+ piVersion = version.trim();
+ piVendor = vendor.trim();
+ piXsltSerial = xsltSerial.trim();
+ piXsltDeserial= xsltDeserial.trim();
+ piClassImpl = impl.trim();
+ piClassLoader = this.getClass().getClassLoader();
+
+ // Get instance of the PluginFactory.
+ //
+ try {
+ URL jarURL = new URL(jarName);
+ URLClassLoader loader = new URLClassLoader(new URL[] { jarURL },
+ piClassLoader);
+ Class clas = loader.loadClass(piClassImpl);
+ Class[] argumentTypes = { org.openoffice.xmerge.util.registry.ConverterInfo.class };
+ Constructor construct = clas.getConstructor(argumentTypes);
+
+ Object[] arguments = { this };
+ piPluginFactory = ( PluginFactory ) construct.newInstance(arguments);
+
+ // See which interfaces the plug-in PluginFactory supports.
+ //
+ Class[] cl = piPluginFactory.getClass().getInterfaces();
+ for (int i=0; i < cl.length; i++) {
+
+ if (cl[i].getName().equals("org.openoffice.xmerge.DocumentSerializerFactory")) {
+ piCanSerialize = true;
+ }
+ if (cl[i].getName().equals("org.openoffice.xmerge.DocumentDeserializerFactory")) {
+ piCanDeserialize = true;
+ }
+ if (cl[i].getName().equals("org.openoffice.xmerge.DocumentMergerFactory")) {
+ piCanMerge = true;
+ }
+ }
+
+ } catch (Exception e) {
+ RegistryException re = new RegistryException(
+ "Class implementation of the plug-in cannot be loaded.");
+ throw re;
+ }
+ }
+
+ /**
+ * The constructor builds a ConverterInfo structure.
+ *
+ * @param jarName The URL of the jarfile.
+ * @param officeMime The office mime-type.
+ * @param deviceMime The device mime-type.
+ * @param displayName The display name.
+ * @param description The description.
+ * @param version The version.
+ * @param vendor The vendor name.
+ * @param impl The implementation class name of
+ * PluginFactory.
+ *
+ * @throws RegistryException If <code>ci</code> cannot
+ * be loaded.
+ */
+
+
+ public ConverterInfo(String jarName, String officeMime,
+ Vector deviceMime, String displayName, String description,
+ String version, String vendor, String impl)
+ throws RegistryException {
+
+ if (isValidOfficeType(officeMime.trim()) == false) {
+ RegistryException re = new RegistryException(
+ "Invalid office type");
+ throw re;
+ }
+
+ piJarName = jarName.trim();
+ piOfficeMime = officeMime.trim();
+ piDeviceMime = deviceMime;
+ piDisplayName = displayName.trim();
+ piDescription = description.trim();
+ piVersion = version.trim();
+ piVendor = vendor.trim();
+ piClassImpl = impl.trim();
+ piClassLoader = this.getClass().getClassLoader();
+
+ // Get instance of the PluginFactory.
+ //
+ try {
+ URL jarURL = new URL(jarName);
+ URLClassLoader loader = new URLClassLoader(new URL[] { jarURL },
+ piClassLoader);
+ Class clas = loader.loadClass(piClassImpl);
+ Class[] argumentTypes = { org.openoffice.xmerge.util.registry.ConverterInfo.class };
+ Constructor construct = clas.getConstructor(argumentTypes);
+
+ Object[] arguments = { this };
+ piPluginFactory = ( PluginFactory ) construct.newInstance(arguments);
+
+ // See which interfaces the plug-in PluginFactory supports.
+ //
+ Class[] cl = piPluginFactory.getClass().getInterfaces();
+ for (int i=0; i < cl.length; i++) {
+
+ if (cl[i].getName().equals("org.openoffice.xmerge.DocumentSerializerFactory")) {
+ piCanSerialize = true;
+ }
+ if (cl[i].getName().equals("org.openoffice.xmerge.DocumentDeserializerFactory")) {
+ piCanDeserialize = true;
+ }
+ if (cl[i].getName().equals("org.openoffice.xmerge.DocumentMergerFactory")) {
+ piCanMerge = true;
+ }
+ }
+
+ } catch (Exception e) {
+ RegistryException re = new RegistryException(
+ "Class implementation of the plug-in cannot be loaded.");
+ throw re;
+ }
+ }
+
+
+
+
+ /**
+ * Create a default constructor so we can use isValidOfficeType
+ * without having to actually have a valid ConverterInfo.
+ */
+ private ConverterInfo() {
+ }
+
+
+ /**
+ * Returns an instance of the DocumentDeserializerFactory interface.
+ *
+ * @return instance of the DocumentDeserializer for this ConverterInfo.
+ */
+ public DocumentSerializerFactory getDocSerializerFactory() {
+ return (DocumentSerializerFactory)piPluginFactory;
+ }
+
+
+ /**
+ * Returns an instance of the DocumentSerializerFactory interface.
+ *
+ * @return instance of the DocumentSerializer for this ConverterInfo.
+ */
+ public DocumentDeserializerFactory getDocDeserializerFactory() {
+ return (DocumentDeserializerFactory)piPluginFactory;
+ }
+
+
+ /**
+ * Returns an instance of the DocumentMergerFactory interface.
+ *
+ * @return instance of the DocumentMergerFactory for this ConverterInfo.
+ */
+ public DocumentMergerFactory getDocMergerFactory() {
+ return (DocumentMergerFactory)piPluginFactory;
+ }
+
+
+ /**
+ * Returns the jar file name.
+ *
+ * @return The jar file name, null if none exists.
+ */
+ public String getJarName() {
+ return piJarName;
+ }
+
+
+ /**
+ * Returns the office mime-type.
+ *
+ * @return The office mime-type, null if none exists.
+ */
+ public String getOfficeMime() {
+ return piOfficeMime;
+ }
+
+
+ /**
+ * Returns an <code>Enumeration</code> of <code>String</code>
+ * objects indicating the device mime-type.
+ *
+ * @return An <code>Enumeration</code> of <code>String</code>
+ * objects indicating the device mime-type.
+ */
+ public Enumeration getDeviceMime() {
+ return(piDeviceMime.elements());
+ }
+
+
+ /**
+ * Returns the display name.
+ *
+ * @return The display name, null if none exists.
+ */
+ public String getDisplayName() {
+ return piDisplayName;
+ }
+
+
+ /**
+ * Returns the description.
+ *
+ * @return The description, null if none exists.
+ */
+ public String getDescription() {
+ return piDescription;
+ }
+
+
+ /**
+ * Returns the version.
+ *
+ * @return The version, null if none exists.
+ */
+ public String getVersion() {
+ return piVersion;
+ }
+
+
+ /**
+ * Returns the vendor name.
+ *
+ * @return The vendor name, null if none exists.
+ */
+ public String getVendor() {
+ return piVendor;
+ }
+
+
+ /**
+ * Returns the implementation class name of PluginFactory.
+ *
+ * @return The implementation class name of PluginFactory,
+ * null if none exists.
+ */
+ public String getClassImpl() {
+ return piClassImpl;
+ }
+
+
+ /**
+ * Returns the PluginFactory instance for this plug-in.
+ *
+ * @return The PluginFactory instance for this plug-in.
+ */
+ public PluginFactory getPluginFactory() {
+ return piPluginFactory;
+ }
+
+
+ /**
+ * Returns true if this plug-in has a serializier, false otherwise.
+ *
+ * @return true if this plug-in has a serializier, false otherwise.
+ */
+ public boolean canSerialize() {
+ return piCanSerialize;
+ }
+
+
+ /**
+ * Returns true if this plug-in has a deserializier, false otherwise.
+ *
+ * @return true if this plug-in has a deserializier, false otherwise.
+ */
+ public boolean canDeserialize() {
+ return piCanDeserialize;
+ }
+
+
+ /**
+ * Returns true if this plug-in has a merger, false otherwise.
+ *
+ * @return true if this plug-in has a merger, false otherwise.
+ */
+ public boolean canMerge() {
+ return piCanMerge;
+ }
+
+
+ /**
+ * Returns true if the officeMime is a valid Office mime type.
+ *
+ * @return true if the officeMime is a valid Office mime type.
+ */
+ public static boolean isValidOfficeType(String officeMime) {
+
+ boolean rc = false;
+ for (int i=0; i < validOfficeTypes.length; i++) {
+ if (officeMime.equals(validOfficeTypes[i])) {
+ rc = true;
+ }
+ }
+
+ return rc;
+ }
+
+ /**
+ * Returns a <code>String</code> containing the Xslt stylesheet url that
+ * is to be used by the Xslt Plugin Serializer.
+ *
+ * @return <code>String</code>
+ */
+
+ public String getXsltSerial() {
+ return piXsltSerial;
+ }
+
+ /**
+ * Returns a <code>String</code> containing the xslt stylesheet url that
+ * is to be used by the Xslt Plugin Deserializer.
+ *
+ * @return <code>String</code>
+ */
+
+ public String getXsltDeserial() {
+ return piXsltDeserial;
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfoMgr.java b/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfoMgr.java
new file mode 100644
index 000000000000..8b0a2c9e4d00
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfoMgr.java
@@ -0,0 +1,554 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.util.registry;
+
+import java.util.*;
+import java.io.*;
+import javax.xml.parsers.*;
+
+/**
+ * Manages the converter plug-ins that are currently active.
+ * This class allows plug-ins to be added or removed dynamically.
+ * This class is a singleton (static) class, so that only one
+ * manager can exist at a time. It is final, so it may not be
+ * subclassed.
+ *
+ * @author: Brian Cameron
+ */
+public final class ConverterInfoMgr {
+
+ private static Vector converterInfoList;
+
+ /**
+ * Constructor
+ */
+ static {
+ converterInfoList = new Vector();
+ }
+
+
+ /**
+ * Adds a converter plug-in to the registry. The
+ * <code>ConverterInfo</code> must have a unique DisplayName
+ * and must have non-null values for DisplayName, ClassImpl,
+ * OfficeMime, and DeviceMime.
+ *
+ * @param ConverterInfo A <code>ConverterInfo</code> object
+ * describing a plug-in.
+ *
+ * @throws RegistryException If the <code>ConverterInfo</code>
+ * is not valid.
+ */
+ public static void addPlugIn(ConverterInfo ci) throws RegistryException {
+
+ ConverterInfo converterInfo;
+
+ // Validate
+ //
+ if (ci.getDisplayName() == null) {
+ RegistryException re = new RegistryException(
+ "Converter must have valid name.");
+ throw re;
+ }
+ if (ci.getClassImpl() == null) {
+ RegistryException re = new RegistryException(
+ "Converter must have valid class implementation specified.");
+ throw re;
+ }
+ if (ci.getOfficeMime() == null) {
+ RegistryException re = new RegistryException(
+ "Converter must have valid office mime specified.");
+ throw re;
+ }
+ if (! ci.getDeviceMime().hasMoreElements()) {
+ RegistryException re = new RegistryException(
+ "Converter must have valid device mime specified.");
+ throw re;
+ }
+
+ // Verify there is no converter with the same Display Name in
+ // the registry.
+ //
+ Enumeration ciEnum = converterInfoList.elements();
+ while (ciEnum.hasMoreElements()) {
+ converterInfo = (ConverterInfo)ciEnum.nextElement();
+ if (ci.getDisplayName().equals(converterInfo.getDisplayName())) {
+ RegistryException re = new RegistryException(
+ "Converter with specified display name already exists.");
+ throw re;
+ }
+ }
+
+ // Since this is a adding to a static Vector, make sure this
+ // add method call is synchronized.
+ //
+ synchronized (converterInfoList) {
+ converterInfoList.add(ci);
+ }
+ }
+
+
+ /**
+ * Adds a <code>Vector</code> of converter plug-ins to the registry.
+ * Each <code>ConverterInfo</code> in the <code>Vector</code> must have
+ * a unique DisplayName and must have non-null values for DisplayName,
+ * ClassImpl, OfficeMime, and DeviceMime.
+ *
+ * @param ciVectory A <code>Vector</code> of <code>ConverterInfo</code>
+ * objects describing one or more plug-in(s).
+ *
+ * @throws RegistryException If a <code>ConverterInfo</code> in the
+ * <code>Vector</code> is not valid.
+ */
+ public static void addPlugIn(Enumeration jarEnum) throws RegistryException {
+
+ while (jarEnum.hasMoreElements()) {
+ ConverterInfo converterInfo = (ConverterInfo)jarEnum.nextElement();
+ addPlugIn(converterInfo);
+ }
+ }
+
+
+ /**
+ * Returns an <code>Enumeration</code> of registered
+ * <code>ConverterInfo</code> objects.
+ *
+ * @return An <code>Enumeration</code> containing the currently registered
+ * <code>ConverterInfo</code> objects, an empty
+ * <code>Vector</code> if none exist.
+ */
+ public static Enumeration getConverterInfoEnumeration() {
+ return (converterInfoList.elements());
+ }
+
+
+ /**
+ * Removes any <code>ConverterInfo</code> object from the registry
+ * that have the specified jar name value.
+ *
+ * @param jar The name of the jarfile.
+ *
+ * @return True if a <code>ConverterInfo</code> object was
+ * removed, false otherwise.
+ */
+ public static boolean removeByJar(String jar) {
+
+ ConverterInfo converterInfo;
+ boolean rc = false;
+
+ Enumeration ciEnum = converterInfoList.elements();
+ while (ciEnum.hasMoreElements())
+ {
+ converterInfo = (ConverterInfo)ciEnum.nextElement();
+ if (jar.equals(converterInfo.getJarName())) {
+ converterInfoList.remove(converterInfo);
+ rc = true;
+ }
+ }
+ return rc;
+ }
+
+
+ /**
+ * Removes any <code>ConverterInfo</code> object from the registry
+ * that have the specified display name value.
+ *
+ * @param name The display name.
+ *
+ * @return True if a <code>ConverterInfo</code> object was
+ * removed, false otherwise.
+ */
+ public static boolean removeByName(String name) {
+
+ ConverterInfo converterInfo;
+ boolean rc = false;
+
+ Enumeration ciEnum = converterInfoList.elements();
+ while (ciEnum.hasMoreElements())
+ {
+ converterInfo = (ConverterInfo)ciEnum.nextElement();
+ if (name.equals(converterInfo.getDisplayName())) {
+ converterInfoList.remove(converterInfo);
+ rc = true;
+ }
+ }
+ return rc;
+ }
+
+
+ /**
+ * Returns the <code>ConverterInfo</code> object that supports
+ * the specified device/office mime type conversion. If there
+ * are multiple <code>ConverterInfo</code> objects registered
+ * that support this conversion, only the first is returned.
+ *
+ * @param deviceMime The device mime.
+ * @param officeMime The office mime.
+ *
+ * @return The first plug-in that supports the specified
+ * conversion.
+ */
+ public static ConverterInfo findConverterInfo(String deviceMime, String officeMime) {
+
+ ConverterInfo converterInfo;
+
+ if (deviceMime == null ||
+ ConverterInfo.isValidOfficeType(officeMime) == false) {
+ return null;
+ }
+
+ // Loop over elements comparing with deviceFromMime
+ //
+ Enumeration ciEnum = converterInfoList.elements();
+ while (ciEnum.hasMoreElements()) {
+
+ converterInfo = (ConverterInfo)ciEnum.nextElement();
+ String toDeviceInfo = (String)converterInfo.getOfficeMime();
+ Enumeration fromEnum = converterInfo.getDeviceMime();
+
+ // Loop over the deviceMime types.
+ //
+ while (fromEnum.hasMoreElements()) {
+ String fromDeviceInfo = (String)fromEnum.nextElement();
+ if (deviceMime.trim().equals(fromDeviceInfo) &&
+ officeMime.trim().equals(toDeviceInfo)) {
+ return (converterInfo);
+ }
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Returns an array of two <code>ConverterInfo</code> objects that
+ * can be chained to perform the specified mime type conversion.
+ * If there are multiple <code>ConverterInfo</code> objects that
+ * support this conversion, only the first is returned.
+ *
+ * @param deviceMimeFrom The device from mime.
+ * @param deviceMimeTo The device to mime.
+ *
+ * @return An array of two <code>ConverterInfo</code> objects
+ * that can be chained to perform the specified
+ * conversion.
+ */
+ public static ConverterInfo[] findConverterInfoChain(String deviceFromMime, String deviceToMime) {
+
+ if (deviceFromMime == null || deviceToMime == null) {
+ return null;
+ }
+
+ ConverterInfo[] converterInfo = new ConverterInfo[2];
+
+ // Loop over elements comparing with deviceFromMime
+ //
+ Enumeration cifEnum = converterInfoList.elements();
+ while (cifEnum.hasMoreElements()) {
+
+ converterInfo[0] = (ConverterInfo)cifEnum.nextElement();
+ String fromOfficeInfo = converterInfo[0].getOfficeMime();
+ Enumeration fromEnum = converterInfo[0].getDeviceMime();
+
+ // Loop over the deviceMime types looking for a deviceFromMime
+ // match.
+ //
+ while (fromEnum.hasMoreElements()) {
+ String fromDeviceInfo = (String)fromEnum.nextElement();
+
+ if (deviceFromMime.trim().equals(fromDeviceInfo)) {
+
+ // Found a a match for deviceFrom. Now loop over the
+ // elements comparing with deviceToMime
+ //
+ Enumeration citEnum = converterInfoList.elements();
+ while (citEnum.hasMoreElements()) {
+
+ converterInfo[1] = (ConverterInfo)citEnum.nextElement();
+ String toOfficeInfo = converterInfo[1].getOfficeMime();
+ Enumeration toEnum = converterInfo[1].getDeviceMime();
+
+ // Loop over deviceMime types looking for a
+ // deviceToMime match.
+ //
+ while (toEnum.hasMoreElements()) {
+ String toDeviceInfo = (String)toEnum.nextElement();
+ if (deviceToMime.trim().equals(toDeviceInfo) &&
+ fromOfficeInfo.equals(toOfficeInfo)) {
+
+ // Found a match
+ //
+ return (converterInfo);
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * main to let the user specify what plug-ins to register from
+ * jarfiles and to display the currently registered plug-ins.
+ *
+ * @param args Not used.
+ */
+ public static void main(String args[]) {
+
+ ConverterInfoReader cir = null;
+ boolean validate = false;
+ InputStreamReader isr = new InputStreamReader(System.in);
+ BufferedReader br = new BufferedReader(isr);
+ char c = ' ';
+
+ boolean exitFlag = false;
+ while (exitFlag == false) {
+
+ System.out.println("\nMenu:");
+ System.out.println("(L)oad plug-ins from a jar file");
+ System.out.println("(D)isplay name unload");
+ System.out.println("(J)ar name unload");
+ System.out.println("(F)ind ConverterInfo");
+ System.out.println("(C)ind ConverterInfo chain");
+ System.out.println("(V)iew plug-ins");
+ System.out.println("(T)oggle Validation");
+ System.out.println("(Q)uit\n");
+
+ try {
+ c = br.readLine().toUpperCase().trim().charAt(0);
+ } catch(Exception e) {
+ System.out.println("Invalid entry");
+ System.out.println("Error msg: " + e.getMessage());
+ continue;
+ }
+
+ System.out.println("");
+
+ // Quit
+ //
+ if (c == 'Q') {
+ exitFlag = true;
+
+ // Load by Jarfile
+ //
+ } else if (c == 'L') {
+
+ System.out.println("Enter path to jarfile: ");
+ try {
+ String jarname = br.readLine().trim();
+ cir = new ConverterInfoReader(jarname,validate);
+ } catch (RegistryException e) {
+ System.out.println("Cannot load plug-in ConverterFactory implementation.");
+ System.out.println("Error msg: " + e.getMessage());
+ } catch (Exception e) {
+ System.out.println("Error adding data to registry");
+ System.out.println("Error msg: " + e.getMessage());
+ }
+
+ if (cir != null) {
+ Enumeration jarInfoEnum = cir.getConverterInfoEnumeration();
+ try {
+ ConverterInfoMgr.addPlugIn(jarInfoEnum);
+ } catch (Exception e) {
+ System.out.println("Error adding data to registry");
+ System.out.println("Error msg: " + e.getMessage());
+ }
+ }
+
+ // Unload by Display Name or Jarfile
+ //
+ } else if (c == 'T') {
+ if (validate== true){
+ System.out.println("Validation switched off");
+ validate=false;
+ }else{
+ System.out.println("Validation switched on");
+ validate=true;
+ }
+ } else if (c == 'D' || c == 'J') {
+
+ if (c == 'D') {
+ System.out.println("Enter display name: ");
+ } else {
+ System.out.println("Enter path to jarfile: ");
+ }
+
+ try
+ {
+ String name = br.readLine().trim();
+ boolean rc = false;
+
+ if (c == 'D') {
+ rc = ConverterInfoMgr.removeByName(name);
+ } else {
+ rc = ConverterInfoMgr.removeByJar(name);
+ }
+
+ if (rc == true) {
+ System.out.println("Remove successful.");
+ } else {
+ System.out.println("Remove failed.");
+ }
+
+ } catch (Exception e) {
+ System.out.println("Error removing value from registry");
+ System.out.println("Error msg: " + e.getMessage());
+ }
+
+ // Find Office Mime
+ //
+ } else if (c == 'F' || c == 'C') {
+
+ String findMimeOne = null;
+ String findMimeTwo = null;
+
+ if (c == 'F') {
+ System.out.println("Enter device mime: ");
+ } else {
+ System.out.println("Enter device from mime: ");
+ }
+
+ try {
+ findMimeOne = br.readLine().trim();
+ } catch (Exception e) {
+ System.out.println("Error adding data to registry");
+ System.out.println("Error msg: " + e.getMessage());
+ }
+
+ if (c == 'F') {
+ System.out.println("Enter office mime: ");
+ } else {
+ System.out.println("Enter device to mime: ");
+ }
+
+ try {
+ findMimeTwo = br.readLine().trim();
+ } catch (Exception e) {
+ System.out.println("Error adding data to registry");
+ System.out.println("Error msg: " + e.getMessage());
+ }
+
+ if (c == 'F') {
+ ConverterInfo foundInfo = ConverterInfoMgr.findConverterInfo(findMimeOne, findMimeTwo);
+ if (foundInfo != null) {
+ System.out.println(" Found ConverterInfo");
+ System.out.println(" DisplayName : " + foundInfo.getDisplayName());
+ } else {
+ System.out.println(" Did not find ConverterInfo");
+ }
+ } else {
+ ConverterInfo[] foundInfo = ConverterInfoMgr.findConverterInfoChain(findMimeOne,
+ findMimeTwo);
+ if (foundInfo[0] != null && foundInfo[1] != null ) {
+ System.out.println(" Found ConverterInfo Chain");
+ System.out.println(" DisplayName : " + foundInfo[0].getDisplayName());
+ System.out.println(" DisplayName : " + foundInfo[1].getDisplayName());
+ } else {
+ System.out.println(" Did not find ConverterInfo");
+ }
+ }
+
+ // View
+ //
+ } else if (c == 'V') {
+
+ Enumeration ciEnum = ConverterInfoMgr.getConverterInfoEnumeration();
+
+ int ciCnt = 0;
+ while (ciEnum.hasMoreElements())
+ {
+ System.out.println("");
+ System.out.println(" Displaying converter number " + ciCnt);
+ ConverterInfo converterInfo = (ConverterInfo)ciEnum.nextElement();
+ System.out.println(" DisplayName : " + converterInfo.getDisplayName());
+ System.out.println(" JarFile : " + converterInfo.getJarName());
+ System.out.println(" Description : " + converterInfo.getDescription());
+ System.out.println(" Version : " + converterInfo.getVersion());
+ System.out.println(" OfficeMime : " + converterInfo.getOfficeMime());
+ Enumeration fromEnum = converterInfo.getDeviceMime();
+ int feCnt = 1;
+ while (fromEnum.hasMoreElements())
+ {
+ System.out.println(" DeviceMime : (#" + feCnt + ") : " +
+ (String)fromEnum.nextElement());
+ feCnt++;
+ }
+ if (feCnt == 1) {
+ System.out.println(" DeviceMime : None specified");
+ }
+
+ System.out.println(" Vendor : " + converterInfo.getVendor());
+ System.out.println(" ClassImpl : " + converterInfo.getClassImpl());
+ System.out.println(" XsltSerial : " + converterInfo.getXsltSerial());
+ System.out.println(" XsltDeserial : " + converterInfo.getXsltDeserial());
+ System.out.println(" Serialize : " + converterInfo.canSerialize());
+ System.out.println(" Deserialize : " + converterInfo.canDeserialize());
+ System.out.println(" Merge : " + converterInfo.canMerge());
+ ciCnt++;
+ }
+
+ if (ciCnt == 0) {
+ System.out.println("No converters registered");
+ }
+ } else {
+ System.out.println("Invalid input");
+ }
+ }
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfoReader.java b/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfoReader.java
new file mode 100644
index 000000000000..10e7edacc79d
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/registry/ConverterInfoReader.java
@@ -0,0 +1,307 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.util.registry;
+
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+import org.xml.sax.*;
+import org.w3c.dom.*;
+import javax.xml.parsers.*;
+import java.net.URL;
+import java.net.JarURLConnection;
+
+/**
+ * The <code>ConverterInfoReader</code> pulls a META-INF/converter.xml
+ * file out of a jar file and parses it, providing access to this
+ * information in a <code>Vector</code> of <code>ConverterInfo</code>
+ * objects.
+ *
+ * @author Brian Cameron
+ */
+public class ConverterInfoReader {
+
+ private final static String TAG_CONVERTER = "converter";
+ private final static String ATTRIB_OFFICE_TYPE = "type";
+ private final static String ATTRIB_VERSION = "version";
+ private final static String TAG_NAME = "converter-display-name";
+ private final static String TAG_DESC = "converter-description";
+ private final static String TAG_VENDOR = "converter-vendor";
+ private final static String TAG_CLASS_IMPL = "converter-class-impl";
+ private final static String TAG_TARGET = "converter-target";
+ private final static String ATTRIB_DEVICE_TYPE = "type";
+ private final static String TAG_XSLT_DESERIAL = "converter-xslt-deserialize";
+ private final static String TAG_XSLT_SERIAL = "converter-xslt-serialize";
+ private String jarfilename;
+ private Document document;
+ private Vector converterInfoList;
+
+
+ /**
+ * Constructor. A jar file is passed in. The jar file is
+ * parsed and the <code>Vector</code> of <code>ConverterInfo</code>
+ * objects is built.
+ *
+ * @param jar The URL of the jar file to process.
+ * @param shouldvalidate Boolean to enable or disable xml validation.
+ *
+ * @throws IOException If the jar file cannot
+ * be read or if the
+ * META-INF/converter.xml
+ * can not be read in the
+ * jar file.
+ * @throws ParserConfigurationException If the DocumentBuilder
+ * can not be built.
+ * @throws org.xml.sax.SAXException If the converter.xml
+ * file can not be parsed.
+ * @throws RegistryException If the ConverterFactory
+ * implementation of a
+ * plug-in cannot be loaded.
+ */
+ public ConverterInfoReader(String jar,boolean shouldvalidate) throws IOException,
+ ParserConfigurationException, org.xml.sax.SAXException,
+ RegistryException {
+
+ InputStream istream;
+ InputSource isource;
+ DocumentBuilderFactory builderFactory;
+ DocumentBuilder builder;
+ JarURLConnection jarConnection;
+ JarEntry jarentry;
+ JarFile jarfile;
+ URL url;
+
+ converterInfoList = new Vector();
+ jarfilename = jar;
+
+ // Get Jar via URL
+ //
+ url = new URL("jar:" + jar + "!/META-INF/converter.xml");
+ jarConnection = (JarURLConnection)url.openConnection();
+ jarentry = jarConnection.getJarEntry();
+ jarfile = jarConnection.getJarFile();
+
+ // Build the InputSource
+ //
+ istream = jarfile.getInputStream(jarentry);
+ isource = new InputSource(istream);
+
+ // Get the DOM builder and build the document.
+ //
+ builderFactory = DocumentBuilderFactory.newInstance();
+
+ //DTD validation
+ if (shouldvalidate){
+ System.out.println("Validating xml...");
+ builderFactory.setValidating(true);
+ }
+ //
+ builder = builderFactory.newDocumentBuilder();
+ document = builder.parse(isource);
+
+ // Parse the document.
+ //
+ parseDocument();
+ }
+
+
+ /**
+ * Loops over the <i>converter</i> <code>Node</code> in the converter.xml
+ * file and processes them.
+ *
+ * @throws RegistryException If the plug-in associated with a
+ * specific <i>converter</i> <code>Node</code>
+ * cannot be loaded.
+ */
+ private void parseDocument() throws RegistryException {
+
+ Node converterNode;
+ NodeList converterNodes = document.getElementsByTagName(TAG_CONVERTER);
+
+ for (int i=0; i < converterNodes.getLength(); i++) {
+ converterNode = converterNodes.item(i);
+ if (converterNode.getNodeType() == Node.ELEMENT_NODE) {
+ parseConverterNode((Element)converterNode);
+ }
+ }
+ }
+
+
+ /**
+ * Parses a <i>converter</i> node, pulling the information out of
+ * the <code>Node</code> and placing it in a <code>ConverterInfo</code>
+ * object, and adds that object to a <code>Vector</code> of
+ * <code>ConverterInfo</code> objects.
+ *
+ * @param e The <code>Element</code> corresponding to the
+ * <i>converter</i> XML tag.
+ *
+ *
+ * @throws RegistryException If the plug-in cannot be loaded.
+ */
+ private void parseConverterNode(Element e) throws RegistryException {
+
+ Element detailElement;
+ Node detailNode;
+ String elementTagName;
+ String officeMime = null;
+ Vector deviceMime = new Vector();
+ String name = null;
+ String desc = null;
+ String version = null;
+ String vendor = null;
+ String classImpl = null;
+ String xsltSerial = null;
+ String xsltDeserial= null;
+ String temp;
+
+ temp = e.getAttribute(ATTRIB_OFFICE_TYPE);
+ if (temp.length() != 0) {
+ officeMime = temp;
+ }
+
+ temp = e.getAttribute(ATTRIB_VERSION);
+ if (temp.length() != 0) {
+ version = temp;
+ }
+
+ NodeList detailNodes = e.getChildNodes();
+ for (int i=0; i < detailNodes.getLength(); i++) {
+
+ detailNode = detailNodes.item(i);
+ if (detailNode.getNodeType() == Node.ELEMENT_NODE) {
+
+ detailElement = (Element)detailNode;
+ elementTagName = detailElement.getTagName();
+
+ if (TAG_NAME.equalsIgnoreCase(elementTagName)) {
+ name = getTextValue(detailElement);
+ } else if (TAG_DESC.equalsIgnoreCase(elementTagName)) {
+ desc = getTextValue(detailElement);
+ } else if (TAG_VENDOR.equalsIgnoreCase(elementTagName)) {
+ vendor = getTextValue(detailElement);
+ } else if (TAG_XSLT_SERIAL.equalsIgnoreCase(elementTagName)) {
+ xsltSerial = getTextValue(detailElement);
+ } else if (TAG_XSLT_DESERIAL.equalsIgnoreCase(elementTagName)) {
+ xsltDeserial = getTextValue(detailElement);
+ } else if (TAG_CLASS_IMPL.equalsIgnoreCase(elementTagName)) {
+ classImpl = getTextValue(detailElement);
+ } else if (TAG_TARGET.equalsIgnoreCase(elementTagName)) {
+
+ temp = detailElement.getAttribute(ATTRIB_DEVICE_TYPE);
+ if (temp.length() != 0) {
+ deviceMime.add(temp);
+ }
+ }
+ }
+ }
+ ConverterInfo converterInfo;
+ if ((xsltSerial==null) || (xsltDeserial==null)){
+ converterInfo = new ConverterInfo(jarfilename,
+ officeMime, deviceMime, name,
+ desc, version, vendor,classImpl);
+ }
+ else{
+ converterInfo = new ConverterInfo(jarfilename,
+ officeMime, deviceMime, name,
+ desc, version, vendor,classImpl,
+ xsltSerial,xsltDeserial);
+ }
+ /*ConverterInfo converterInfo = new ConverterInfo(jarfilename,
+ officeMime, deviceMime, name, desc, version, vendor,
+ classImpl);*/
+ converterInfoList.add(converterInfo);
+ }
+
+
+ /**
+ * Helper function to get the text value of an
+ * <code>Element</code>.
+ *
+ * @param e The <code>Element</code> to process.
+ *
+ * @return The text value of the <code>Element</code>.
+ */
+ private String getTextValue(Element e) {
+
+ NodeList tempNodes = e.getChildNodes();
+ String text = null;
+ Node tempNode;
+
+ for (int j=0; j < tempNodes.getLength(); j++) {
+ tempNode = tempNodes.item(j);
+ if (tempNode.getNodeType() == Node.TEXT_NODE) {
+ text = tempNode.getNodeValue().trim();
+ break;
+ }
+ }
+
+ return text;
+ }
+
+
+ /**
+ * Returns an <code>Enumeration</code> of <code>ConverterInfo</code>
+ * objects.
+ *
+ * @return An <code>Enumeration</code> of <code>ConverterInfo</code>
+ * objects.
+ */
+ public Enumeration getConverterInfoEnumeration() {
+ return (converterInfoList.elements());
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/registry/RegistryException.java b/xmerge/java/org/openoffice/xmerge/util/registry/RegistryException.java
new file mode 100644
index 000000000000..0dbba18a48a2
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/registry/RegistryException.java
@@ -0,0 +1,75 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+package org.openoffice.xmerge.util.registry;
+
+/**
+ * This <code>Exception</code> is thrown by converter registry
+ * algorithms.
+ */
+public class RegistryException extends Exception {
+
+
+ /**
+ * Exception thrown by merge algorithms.
+ *
+ * @param message Message to be included in the
+ * <code>Exception</code>.
+ */
+ public RegistryException(String message) {
+ super(message);
+ }
+}
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/registry/build.xml b/xmerge/java/org/openoffice/xmerge/util/registry/build.xml
new file mode 100644
index 000000000000..0ec83df0e597
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/registry/build.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_jooxu_registry" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_jooxu_registry"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value="../../../../../.."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/java"/>
+
+ <!-- path component for current java package -->
+ <property name="package" value="org/openoffice/xmerge/util/registry"/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set whether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="${package}/ConverterInfo.java"/>
+ <include name="${package}/ConverterInfoMgr.java"/>
+ <include name="${package}/ConverterInfoReader.java"/>
+ <include name="${package}/RegistryException.java"/>
+ <include name="${package}/UnoBridgeConverterInfo.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/registry/converter.dtd b/xmerge/java/org/openoffice/xmerge/util/registry/converter.dtd
new file mode 100644
index 000000000000..7983a21a285b
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/registry/converter.dtd
@@ -0,0 +1,121 @@
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+
+<!-- converter.dtd
+
+ Author: Brian Cameron
+
+ This DTD file is provided for documentation and development
+ purposes, the converter does not actually validate the
+ converter.xml files that it processes. Plug-ins will not
+ work properly, though, if the converter.xml does not
+ conform to this DTD specification. -->
+
+<!-- The root node, converters, must contain one or more
+ converter nodes, each corresponds to a converter plug-in. -->
+
+<!ELEMENT converters (converter)+>
+
+<!-- The converter node must contain two elements:
+ type - The convert-from mime-type.
+ version - The version of the plug-in.
+
+ Each converter node must contain these child nodes:
+ converter-display-name - Name of the converter
+ converter-class-impl - The PluginFactory implementation for
+ the plugin
+ converter-targets - Can be one or more of these nodes. Each
+ contains only a "type" element. This
+ "type" element specifies the convert-to
+ mime-type.
+
+ Each converter node may contain these child nodes:
+ converter-description - Descriptive description of the plug-in.
+ converter-vendor - Plug-in vendor name
+ converter-xslt-serialize - The URL of the xsl stylesheet for
+ serialization. This stylesheet must
+ exist if the xslt plugin implementation
+ is to be used. It is assumed that the
+ plug-in specified via converter-class-impl
+ will make use of this value.
+ converter-xslt-deserialize - The URL of the xsl stylesheet for
+ deserialization. This stylesheet must
+ exist if the xslt plugin implementation
+ is to be used. It is assumed that the
+ plug-in specified via converter-class-impl
+ will make use of this value.
+ -->
+
+<!ELEMENT converter (converter-display-name,
+ converter-description?,
+ converter-vendor?,
+ converter-class-impl,
+ converter-xslt-serialize?,
+ converter-xslt-deserialize?,
+ converter-target+)>
+
+<!ATTLIST converter type CDATA #REQUIRED>
+<!ATTLIST converter version CDATA #REQUIRED>
+
+<!ELEMENT converter-display-name (#PCDATA)>
+<!ELEMENT converter-description (#PCDATA)>
+<!ELEMENT converter-vendor (#PCDATA)>
+<!ELEMENT converter-class-impl (#PCDATA)>
+<!ELEMENT converter-xslt-serialize (#PCDATA)>
+<!ELEMENT converter-xslt-deserialize (#PCDATA)>
+
+<!ELEMENT converter-target EMPTY>
+
+<!ATTLIST converter-target type CDATA #REQUIRED>
+
diff --git a/xmerge/java/org/openoffice/xmerge/util/registry/makefile.mk b/xmerge/java/org/openoffice/xmerge/util/registry/makefile.mk
new file mode 100644
index 000000000000..8a758756cee2
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/registry/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_jooxu_registry
+PRJ=../../../../../..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/java/org/openoffice/xmerge/util/registry/package.html b/xmerge/java/org/openoffice/xmerge/util/registry/package.html
new file mode 100644
index 000000000000..0e32cc1e7d88
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/registry/package.html
@@ -0,0 +1,107 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<html>
+<head>
+<title>org.openoffice.xmerge.util.registry package</title>
+</head>
+
+<body bgcolor="white">
+
+<p>Provides an interface for plug-in registration. Each plug-in must
+have a corresponding Plugin Configuration XML File which is named
+converter.xml. If the plug-in is stored in a jarfile, this
+converter.xml file is typically stored in the following location in
+the jarfile:</p>
+
+<blockquote>
+ META-INF/converter.xml
+</blockquote>
+
+<p>The Plugin Configuration XML File must validate against the
+converter.dtd file provided with this package. Since a jarfile
+can contain multiple plug-ins, this DTD supports specifying multiple
+plug-ins per jarfile. Please refer to the SDK document for more
+information about how to implement a Plugin Configuration XML File
+for a specific plugin.</p>
+
+<p>All information in the Plugin Configuratino XML File is bundled
+into one or more <code>ConverterInfo</code> object. The
+<code>ConverterInfoReader</code> object is used to build a
+<code>Vector</code> of <code>ConverterInfo</code> objects from a
+jarfile.</p>
+
+<p>The <code>ConverterInfoMgr</code> manages the registry of
+<code>ConverterInfo</code>. It is a singleton class, so that only one
+registry manager will ever exist. It is the client program's
+responsibility to register <code>ConverterInfo</code> objects that
+correspond to the plug-ins that are to be used.</p>
+
+<h2>TODO/IDEAS list</h2>
+
+<p><ol>
+<li>The <code>ConverterInfo</code> object could contain
+ <code>org.w3c.dom.Document</code> fragments that are accessed in a
+ generic fashion rather than get/set methods for each item in the DTD.
+ This would provide a more flexible approach, especially for adding
+ custom tags to a specific Plugin Configuration XML file (tags that
+ are only used by its associated plug-in).
+<li><code>ConverterInfo</code> should allow the merge/serialize/deserialize
+ logic to be included in separate plug-ins, if desired.</li>
+<li><code>ConverterInfoMgr</code> could use the Java Activation
+ Framework (JAF) to manage registration.</li>
+</ol></p>
+
+</body>
+</html>
diff --git a/xmerge/java/org/openoffice/xmerge/util/resources.properties b/xmerge/java/org/openoffice/xmerge/util/resources.properties
new file mode 100644
index 000000000000..fa8bb7eb02ed
--- /dev/null
+++ b/xmerge/java/org/openoffice/xmerge/util/resources.properties
@@ -0,0 +1,95 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+
+#
+# resources.properties
+#
+# resources for org.openoffice.xmerge.converter package.
+#
+NULL_MIME_EXCEPTION=Cannot specify null MIME types
+EMPTY_MIME_EXCEPTION=Cannot specify empty MIME types
+CANNOT_LOAD_CLASS=Unable to load class
+CANNOT_INST_CLASS=Unable to instantiate class
+NOT_AN_INSTANCE= is not an instance of
+CANNOT_FIND_REGISTERED=Cannot find registered class
+PARSE_ERROR=Parse Error
+LINE=Line
+COLUMN=Column
+PUBLIC_ID=PublicId
+SYSTEM_ID=SystemId
+INVALID_LOG_LEVEL=Invalid log level specified
+OPERATION_NOT_SUPPORTED=Operation not supported
+TEMPLATE_FILE_LOAD_ERROR=Error in loading template file -
+
+#
+# diff/merge algorithm erro messages
+#
+EMPTY_NODE_EXCEPTION=Current Node is empty
+NOT_LEAFNODE_EXCEPTION=Current Node is not a leaf node
+ROOTNODE_EXCEPTION=Cannot perform insert/append/remove on root node
+NOT_TEXTNODE_EXCEPTION=The target Node is not a TEXT_NODE, it is -
+NULL_NODE_EXCEPTION=The initial Xmldocument node is null
+CELL_NODE_EXCEPTION1=Cell node do not have only 1 child <text:p> nodes, will skip the merge of this node.Num of PARA child nodes:
+CELL_NODE_EXCEPTION2=Cell node have a non Element child nodes -
+CELL_NODE_EXCEPTION2=There is a child node under an expected empty cell node.
+NOT_ELEM_NODE_ERROR=The compared nodes are not a Element Node
+NOT_PARA_NODE_ERROR=The compared nodes are not a Paragraph or Heading node -
+NOT_NODE_ERROR=The compared nodes are not a Node
+#
+# SXW to/from DOC conversion error messages.
+#
+UNKNOWN_DOC_VERSION=Unknown DOC version.
+DOC_TEXT_LENGTH_EXCEEDED=DOC text length exceeds maximum value.
+DOC_TEXT_RECORD_SIZE_EXCEEDED=DOC text record exceeds size limit.
diff --git a/xmerge/prj/build.lst b/xmerge/prj/build.lst
new file mode 100644
index 000000000000..0ece8eefeb5d
--- /dev/null
+++ b/xmerge/prj/build.lst
@@ -0,0 +1,2 @@
+xmrg xmerge : NULL
+xmrg xmerge nmake - all xmrg_mkout NULL
diff --git a/xmerge/prj/d.lst b/xmerge/prj/d.lst
new file mode 100644
index 000000000000..a40df8efdcc1
--- /dev/null
+++ b/xmerge/prj/d.lst
@@ -0,0 +1,5 @@
+..\%__SRC%\class\xmerge.jar %_DEST%\bin%_EXT%\xmerge.jar
+.\%__SRC%\class\htmlsoff.jar %_DEST%\bin%_EXT%\htmlsoff.jar
+..\%__SRC%\doc\xmerge_javadoc.zip %_DEST%\doc\xmerge_javadoc.zip
+mkdir: %_DEST%\doc\xmerge
+..\%__SRC%\doc\javadoc\package-list %_DEST%\doc\xmerge\package-list
diff --git a/xmerge/util/build.xml b/xmerge/util/build.xml
new file mode 100644
index 000000000000..364fc91e73af
--- /dev/null
+++ b/xmerge/util/build.xml
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_util" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_util"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value=".."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="../java"/>
+
+ <!-- path component for java package -->
+ <property name="package" value="org/openoffice/xmerge"/>
+
+ <!-- path component for java package -->
+ <property name="htmlsoff" value="org/openoffice/xmerge/converter/xml/xslt"/>
+
+ <!-- name of jar file created, without .jar extension -->
+ <property name="jarname1" value="xmerge"/>
+
+ <!-- name of jar file created, without .jar extension -->
+ <property name="jarname2" value="htmlsoff"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,xmerge,htmlsoff"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- create xmerge jar file -->
+ <target name="xmerge" depends="prepare" if="build.class">
+ <jar jarfile="${build.class}/${jarname1}.jar"
+ basedir="${build.class}"
+ manifest="${jarname1}.mf">
+ <include name="${package}/**"/>
+ </jar>
+ </target>
+
+ <!-- create htmlsoff jar file -->
+ <target name="htmlsoff" depends="prepare,xmerge" if="build.class">
+ <jar jarfile="${build.class}/${jarname2}.jar"
+ basedir="${java.dir}/${htmlsoff}">
+ <include name="htmltosoff.xsl"/>
+ <include name="sofftohtml.xsl"/>
+ <metainf dir="${java.dir}/${htmlsoff}" includes="converter.xml"/>
+ </jar>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete file="${build.class}/${jarname1}.jar"/>
+ <delete file="${build.class}/${jarname2}.jar"/>
+ </target>
+
+</project>
+
diff --git a/xmerge/util/makefile.mk b/xmerge/util/makefile.mk
new file mode 100644
index 000000000000..ae6d57595440
--- /dev/null
+++ b/xmerge/util/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_util
+PRJ=..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD
diff --git a/xmerge/util/minicalc.mf b/xmerge/util/minicalc.mf
new file mode 100644
index 000000000000..1f0a0e35e276
--- /dev/null
+++ b/xmerge/util/minicalc.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: jmc.jar
+
diff --git a/xmerge/util/xmerge.mf b/xmerge/util/xmerge.mf
new file mode 100644
index 000000000000..4c58b71b672e
--- /dev/null
+++ b/xmerge/util/xmerge.mf
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Main-Class: org.openoffice.xmerge.test.Driver
+Class-Path: jaxp.jar parser.jar
+Specification-Title: OpenOffice XMerge Framework
+Specification-Vendor: OpenOffice.org
+Specification-Version: 0.6.0
+Implementation-Version: #IMPL-VERSION#
+
diff --git a/xmerge/workben/XmlDiff.java b/xmerge/workben/XmlDiff.java
new file mode 100644
index 000000000000..4cf3aa77a587
--- /dev/null
+++ b/xmerge/workben/XmlDiff.java
@@ -0,0 +1,486 @@
+/************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.io.PrintWriter;
+import java.util.Vector;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+/**
+ * This class will diff 2 Xml files.
+ *
+ * @author Stephen Mak
+ */
+
+public final class XmlDiff {
+
+ private static final String PROPSFILE = "XmlDiff.properties";
+ private static final String FILE1 = "XmlDiff.file1";
+ private static final String FILE2 = "XmlDiff.file2";
+ private static final String OUTPUT= "XmlDiff.output";
+ private static final String IGNORE_TAGS= "XmlDiff.tags";
+
+ private Properties props_ = null;
+ private static PrintWriter writer_ = null;
+ private String[] tags_ = null;
+ private String file1_ = null;
+ private String file2_ = null;
+
+ /**
+ * Constructor. Load the properties file.
+ */
+
+ public XmlDiff() throws IOException {
+
+ Class c = this.getClass();
+ InputStream is = c.getResourceAsStream(PROPSFILE);
+ BufferedInputStream bis = new BufferedInputStream(is);
+ props_ = new Properties();
+ props_.load(bis);
+ bis.close();
+
+ String file1 = props_.getProperty(FILE1, "");
+ String file2 = props_.getProperty(FILE2, "");
+ String tagsString = props_.getProperty(IGNORE_TAGS, "");
+ String output = props_.getProperty("debug.output", "System.out");
+ setOutput(output);
+ tags_ = parseTags(tagsString);
+ }
+
+ /**
+ * diff 2 xml, but overwrite the property file's file1/2 setting with
+ * the input argument
+ */
+ public boolean diff(String file1, String file2) throws IOException {
+ file1_ = file1;
+ file2_ = file2;
+ return diff();
+ }
+
+ public boolean diff() throws IOException {
+
+ boolean result = false;
+
+ writer_.println("parsing "+ file1_ + "...");
+ // parse the Xml file
+ Document doc1 = parseXml(file1_);
+
+ writer_.println("parsing "+ file1_ + "...");
+ Document doc2 = parseXml(file2_);
+
+ if (doc1 != null && doc2 != null) {
+ writer_.println("diffing "+ file1_ + " & " + file2_ + "...");
+ result = compareNode(doc1, doc2);
+ }
+ return result;
+ }
+
+ private void diffLog(String errMsg, Node node1, Node node2) {
+
+ String node1Str = "";
+ String node2Str = "";
+
+ if (node1 != null) {
+ node1Str = "[Type]:" + nodeInfo(node1) +
+ " [Name]:" + node1.getNodeName();
+ if (node1.getNodeValue() != null)
+ node1Str += " [Value]:" + node1.getNodeValue();
+ }
+
+ if (node2 != null) {
+ node2Str = "[Type]:" + nodeInfo(node2) +
+ " [Name]:" + node2.getNodeName();
+ if (node2.getNodeValue() != null)
+ node2Str += " [Value]:" + node2.getNodeValue();
+ }
+
+ writer_.println(errMsg);
+ writer_.println(" Node1 - " + node1Str);
+ writer_.println(" Node2 - " + node2Str);
+ }
+
+ private String nodeInfo(Node node) {
+
+ String str = null;
+ switch (node.getNodeType()) {
+
+ case Node.ELEMENT_NODE:
+ str = "ELEMENT";
+ break;
+ case Node.ATTRIBUTE_NODE:
+ str = "ATTRIBUTE";
+ break;
+ case Node.TEXT_NODE:
+ str = "TEXT";
+ break;
+ case Node.CDATA_SECTION_NODE:
+ str = "CDATA_SECTION";
+ break;
+ case Node.ENTITY_REFERENCE_NODE:
+ str = "ENTITY_REFERENCE";
+ break;
+ case Node.ENTITY_NODE:
+ str = "ENTITY";
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ str = "PROCESSING_INSTRUCTION";
+ break;
+ case Node.COMMENT_NODE:
+ str = "COMMENT";
+ break;
+ case Node.DOCUMENT_NODE:
+ str = "DOCUMENT";
+ break;
+ case Node.DOCUMENT_TYPE_NODE:
+ str = "DOCUMENT_TYPE";
+ break;
+ case Node.DOCUMENT_FRAGMENT_NODE:
+ str = "DOCUMENT_FRAGMENT";
+ break;
+ case Node.NOTATION_NODE:
+ str = "NOTATION";
+ break;
+ }
+ return str;
+ }
+
+ private boolean ignoreTag(String nodeName) {
+
+
+ if (tags_ != null) {
+ for (int i = 0; i < tags_.length; i++) {
+ if (tags_[i].equals(nodeName))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // for future use if we want to compare attributes
+ private boolean attributesEqual(Node node1, Node node2) {
+ return true;
+ }
+
+ private boolean compareNode(Node node1, Node node2) {
+ boolean equal = false;
+
+ while (true) {
+
+ if (node1 == null && node2 == null) {
+ equal = true;
+ break;
+ } else if (node1 == null || node2 == null) {
+ diffLog("DIFF: one of the node is null", node1, node2);
+ break;
+ }
+
+ if (node1.getNodeType() != node2.getNodeType()) {
+ diffLog("DIFF: nodetype is different", node1, node2);
+ break;
+ }
+
+ if (node1.getNodeName() == null && node2.getNodeName() == null) {
+ // empty
+ } else if (node1.getNodeName() == null ||
+ node2.getNodeName() == null) {
+ diffLog("DIFF: one of the nodeName is null", node1, node2);
+ break;
+ } else if (!node1.getNodeName().equals(node2.getNodeName())) {
+ diffLog("DIFF: nodeName is different", node1, node2);
+ break;
+ }
+
+ if (ignoreTag(node1.getNodeName())) {
+ diffLog("DIFF: Some tag(s) is ignored", node1, node2);
+ equal = true;
+ break;
+ }
+
+ if (node1.getNodeValue() == null && node2.getNodeValue() == null) {
+ // empty
+ } else if (node1.getNodeValue() == null ||
+ node2.getNodeValue() == null) {
+ diffLog("DIFF: one of the nodevalue is null", node1, node2);
+ break;
+ } else if (!node1.getNodeValue().equals(node2.getNodeValue())) {
+ diffLog("DIFF: nodeValue is different", node1, node2);
+ break;
+ }
+
+ // try to compare attributes if necessary
+ if (!attributesEqual(node1, node2))
+ break;
+
+ NodeList node1Children = node1.getChildNodes();
+ NodeList node2Children = node2.getChildNodes();
+
+ // number of children have to be the same
+ if (node1Children == null && node2Children == null) {
+ equal = true;
+ break;
+ }
+
+ if (node1Children == null || node2Children == null) {
+ diffLog("DIFF: one node's children is null", node1, node2);
+ break;
+ }
+
+ if (node1Children.getLength() != node2Children.getLength()) {
+ diffLog("DIFF: num of children is different", node1, node2);
+ break;
+ }
+
+ // compare all the childrens
+ equal = true;
+
+ for (int i = 0; i < node1Children.getLength(); i++) {
+ if (!compareNode(node1Children.item(i),
+ node2Children.item(i))) {
+ equal = false;
+ break;
+ }
+ }
+ break;
+ }
+
+ return equal;
+ }
+
+ private Document parseXml (String filename) throws IOException {
+
+ Document w3cDocument = null;
+
+ FileInputStream fis;
+
+ try {
+ fis = new FileInputStream(filename);
+ } catch (FileNotFoundException ex) {
+ ex.printStackTrace(writer_);
+ writer_.println(ex.getMessage());
+ return w3cDocument;
+ }
+
+ /** factory for DocumentBuilder objects */
+ DocumentBuilderFactory factory = null;
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setValidating(false);
+
+ /** DocumentBuilder object */
+ DocumentBuilder builder = null;
+
+ try {
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException ex) {
+ ex.printStackTrace(writer_);
+ writer_.println(ex.getMessage());
+ return null;
+ }
+
+
+ builder.setErrorHandler(
+ new org.xml.sax.ErrorHandler() {
+ // ignore fatal errors (an exception is guaranteed)
+ public void fatalError(SAXParseException e)
+ throws SAXException {
+ throw e;
+ }
+
+ public void error(SAXParseException e)
+ throws SAXParseException {
+ // make sure validation error is thrown.
+ throw e;
+ }
+
+ public void warning(SAXParseException e)
+ throws SAXParseException {
+ }
+ }
+ );
+
+ try {
+ w3cDocument = builder.parse(fis);
+ w3cDocument.getDocumentElement().normalize();
+ } catch (SAXException ex) {
+ ex.printStackTrace(writer_);
+ writer_.println(ex.getMessage());
+ return w3cDocument;
+ }
+
+ return w3cDocument;
+ }
+
+ private String [] parseTags(String tagsString) {
+ Vector tagsVector = new Vector();
+ if (tagsString.length() == 0)
+ return null;
+
+ int start = 0;
+ int end = 0;
+ // break the tag string into a vector of strings by words
+ for (end = tagsString.indexOf(" ", start);
+ end != -1 ;
+ start = end + 1, end = tagsString.indexOf(" ", start)) {
+ tagsVector.add(tagsString.substring(start,end));
+ }
+
+ tagsVector.add(tagsString.substring(start,tagsString.length()));
+
+ // convert the vector to array
+ String[] tags= new String[tagsVector.size()];
+ tagsVector.copyInto(tags);
+
+ return tags;
+ }
+
+
+ /**
+ * Set the output to the specified argument.
+ * This method is only used internally to prevent
+ * invalid string parameter.
+ *
+ * @param str output specifier
+ */
+ private static void setOutput(String str) {
+
+ if (writer_ == null) {
+
+ if (str.equals("System.out")) {
+
+ setOutput(System.out);
+
+ } else if (str.equals("System.err")) {
+
+ setOutput(System.err);
+
+ } else {
+
+ try {
+
+ setOutput(new FileWriter(str));
+
+ } catch (IOException e) {
+
+ e.printStackTrace(System.err);
+ }
+ }
+ }
+ }
+
+ /**
+ * Set the output to an OutputStream object.
+ *
+ * @param stream OutputStream object
+ */
+
+ private static void setOutput(OutputStream stream) {
+
+ setOutput(new OutputStreamWriter(stream));
+ }
+
+ /**
+ * Set the Writer object to manage the output.
+ *
+ * @param w Writer object to write out
+ */
+
+ private static void setOutput(Writer w) {
+
+ if (writer_ != null) {
+
+ writer_.close();
+ }
+
+ writer_ = new PrintWriter(new BufferedWriter(w), true);
+ }
+
+ public static void main(String args[]) throws IOException {
+
+ if (args.length != 0 && args.length != 2) {
+ System.out.println("Usage: XmlDiff [<file1> <file2>].");
+ return;
+ }
+
+ XmlDiff xmldiff = new XmlDiff();
+
+ boolean same = false;
+ if (args.length == 2) {
+ same = xmldiff.diff(args[0], args[1]);
+ } else {
+ same = xmldiff.diff();
+ }
+
+ System.out.println("Diff result: " + same);
+ }
+}
+
diff --git a/xmerge/workben/XmlDiff.properties b/xmerge/workben/XmlDiff.properties
new file mode 100644
index 000000000000..f98473aee1df
--- /dev/null
+++ b/xmerge/workben/XmlDiff.properties
@@ -0,0 +1,66 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+
+#
+# This properties file provides info for XmlDiff program
+# XmlDiff.file1 is the first input XML file
+# XmlDiff.file2 is the second input XML file
+# XmlDiff.output is where the output (err/message) go
+# XmlDiff.tags are what tagname should ignore (and the subtree under it)
+#
+XmlDiff.file1=test1.xml
+XmlDiff.file2=test2.xml
+XmlDiff.output=System.err
+XmlDiff.tags=
diff --git a/xmerge/workben/build.xml b/xmerge/workben/build.xml
new file mode 100644
index 000000000000..3dddd8d97282
--- /dev/null
+++ b/xmerge/workben/build.xml
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ # The Contents of this file are made available subject to the terms of
+ # either of the following licenses
+ #
+ # - GNU Lesser General Public License Version 2.1
+ # - Sun Industry Standards Source License Version 1.1
+ #
+ # Sun Microsystems Inc., October, 2000
+ #
+ # GNU Lesser General Public License Version 2.1
+ # =============================================
+ # Copyright 2000 by Sun Microsystems, Inc.
+ # 901 San Antonio Road, Palo Alto, CA 94303, USA
+ #
+ # This library is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License version 2.1, as published by the Free Software Foundation.
+ #
+ # This library is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with this library; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ # MA 02111-1307 USA
+ #
+ #
+ # Sun Industry Standards Source License Version 1.1
+ # =================================================
+ # The contents of this file are subject to the Sun Industry Standards
+ # Source License Version 1.1 (the "License"); You may not use this file
+ # except in compliance with the License. You may obtain a copy of the
+ # License at http://www.openoffice.org/license.html.
+ #
+ # Software provided under this License is provided on an "AS IS" basis,
+ # WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ # WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ # MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ # See the License for the specific provisions governing your rights and
+ # obligations concerning the Software.
+ #
+ # The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ #
+ # Copyright: 2000 by Sun Microsystems, Inc.
+ #
+ # All Rights Reserved.
+ #
+ # Contributor(s): _______________________________________
+ #
+ #
+ -->
+<project name="xmrg_workben" default="main" basedir=".">
+
+ <!-- ================================================================= -->
+ <!-- settings -->
+ <!-- ================================================================= -->
+
+ <!-- project prefix, used for targets and build.lst -->
+ <property name="prj.prefix" value="xmrg"/>
+
+ <!-- name of this sub target used in recursive builds -->
+ <property name="target" value="xmrg_workben"/>
+
+ <!-- relative path to project directory -->
+ <property name="prj" value=".."/>
+
+ <!-- start of java source code package structure -->
+ <property name="java.dir" value="${prj}/workben"/>
+
+ <!-- path component for current java package -->
+ <property name="package" value="."/>
+
+ <!-- define how to handle CLASSPATH environment -->
+ <property name="build.sysclasspath" value="ignore"/>
+
+ <!-- classpath settings for javac tasks -->
+ <path id="classpath">
+ <pathelement location="${build.class}"/>
+ <pathelement location="${solar.jar}/parser.jar"/>
+ <pathelement location="${solar.jar}/jaxp.jar"/>
+ </path>
+
+ <!-- set wether we want to compile with or without deprecation -->
+ <property name="deprecation" value="on"/>
+
+ <!-- ================================================================= -->
+ <!-- solar build environment targets -->
+ <!-- ================================================================= -->
+
+ <target name="build_dir" unless="build.dir">
+ <property name="build.dir" value="${out}"/>
+ </target>
+
+ <target name="solar" depends="build_dir" if="solar.update">
+ <property name="solar.properties"
+ value="${solar.bin}/solar.properties"/>
+ </target>
+
+ <target name="init" depends="solar">
+ <property name="build.compiler" value="classic"/>
+ <property file="${solar.properties}"/>
+ <property file="${build.dir}/class/solar.properties"/>
+ </target>
+
+ <target name="info">
+ <echo message="--------------------"/>
+ <echo message="${target}"/>
+ <echo message="--------------------"/>
+ </target>
+
+
+ <!-- ================================================================= -->
+ <!-- custom targets -->
+ <!-- ================================================================= -->
+
+ <!-- the main target, called in recursive builds -->
+ <target name="main" depends="info,prepare,compile"/>
+
+ <!-- prepare output directories -->
+ <target name="prepare" depends="init" if="build.class">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.class}"/>
+ </target>
+
+ <!-- compile java sources in ${package} and sub packages -->
+ <target name="compile" depends="prepare" if="build.class">
+ <javac srcdir="${java.dir}"
+ destdir="${build.class}"
+ debug="${debug}"
+ deprecation="${deprecation}"
+ optimize="${optimize}">
+ <classpath refid="classpath"/>
+ <include name="XmlDiff.java"/>
+ </javac>
+ </target>
+
+ <!-- clean up -->
+ <target name="clean" depends="prepare">
+ <delete includeEmptyDirs="true">
+ <fileset dir="${build.class}">
+ <patternset>
+ <include name="${package}/**/*.class"/>
+ </patternset>
+ </fileset>
+ </delete>
+ </target>
+
+</project>
diff --git a/xmerge/workben/jstyle.pl b/xmerge/workben/jstyle.pl
new file mode 100644
index 000000000000..1f9368507a78
--- /dev/null
+++ b/xmerge/workben/jstyle.pl
@@ -0,0 +1,568 @@
+#!/bin/sh -- # This comment tells perl not to loop!
+#
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+
+eval 'exec perl -S $0 "$@"'
+if 0;
+#
+# @(#)jstyle 1.2 98/01/08
+#
+# jstyle - check for some common stylistic errors.
+#
+# jstyle is a sort of "lint" for Java coding style.
+#
+# There's a lot this can't check for, like proper
+# indentation of continuation lines. There's also
+# a lot more this could check for.
+#
+# A note to the non perl literate:
+#
+# perl regular expressions are pretty much like egrep
+# regular expressions, with the following special symbols
+#
+# \s any space character
+# \S any non-space character
+# \w any "word" character [a-zA-Z0-9_]
+# \W any non-word character
+# \d a digit [0-9]
+# \D a non-digit
+# \b word boundary (between \w and \W)
+# \B non-word boundary
+#
+#require "getopts.pl";
+# XXX - because some versions of perl can not find the lib directory,
+# we just include this here.
+;# getopts.pl - a better getopt.pl
+
+;# Usage:
+;# do Getopts("a:bc"); # -a takes arg. -b & -c not. Sets opt_* as a
+;# # side effect.
+
+sub Getopts {
+ local($argumentative) = @_;
+ local(@args,$_,$first,$rest);
+ local($[) = 0;
+ local($errs) = 0;
+
+ @args = split( / */, $argumentative );
+ while(($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
+ ($first,$rest) = ($1,$2);
+ $pos = index($argumentative,$first);
+ if($pos >= $[) {
+ if($args[$pos+1] eq ":") {
+ shift(@ARGV);
+ if($rest eq "") {
+ $rest = shift(@ARGV);
+ }
+ eval "\$opt_$first = \$rest;";
+ }
+ else {
+ eval "\$opt_$first = 1";
+ if($rest eq "") {
+ shift(@ARGV);
+ }
+ else {
+ $ARGV[0] = "-$rest";
+ }
+ }
+ }
+ else {
+ print STDERR "Unknown option: $first\n";
+ ++$errs;
+ if($rest ne "") {
+ $ARGV[0] = "-$rest";
+ }
+ else {
+ shift(@ARGV);
+ }
+ }
+ }
+ $errs == 0;
+}
+
+1;
+# end of getopts.pl
+
+$usage =
+"usage: jstyle [-c] [-h] [-p] [-s] [-t] [-v] [-C] file ...
+ -c check continuation line indenting
+ -h perform heuristic checks that are sometimes wrong
+ -p perform some of the more picky checks
+ -s check for spaces vs. tabs
+ -t insist on indenting by tabs
+ -v verbose
+ -C don't check anything in header block comments
+ -S print out overall statistics
+";
+
+if (!&Getopts("chpstvCS")) {
+ print $usage;
+ exit 1;
+}
+
+$check_continuation = $opt_c;
+$heuristic = $opt_h;
+$picky = $opt_p;
+$spaces = $opt_s;
+$tabs = $opt_t;
+$verbose = $opt_v;
+$ignore_hdr_comment = $opt_C;
+$statistics = $opt_S;
+
+if ($verbose) {
+ $fmt = "%s: %d: %s\n%s\n";
+} else {
+ $fmt = "%s: %d: %s\n";
+}
+
+# Note, following must be in single quotes so that \s and \w work right.
+$typename = '(int|char|boolean|byte|short|long|float|double)';
+
+if ($#ARGV >= 0) {
+ foreach $arg (@ARGV) {
+ if (!open(STDIN, $arg)) {
+ printf "%s: can not open\n", $arg;
+ } else {
+ &jstyle($arg);
+ close STDIN;
+ }
+ }
+} else {
+ &jstyle("<stdin>");
+}
+
+if ($statistics != 0) {
+ foreach $key (sort(keys %errcount)) {
+ printf "%6d %s\n", $errcount{$key}, $key;
+ }
+ printf " -----\n";
+ printf "%6d Total warnings\n", $tot_errcount;
+ printf "%6d Lines of code\n", $totlines;
+}
+
+sub err {
+ if ($statistics == 0) {
+ printf $fmt, $filename, $., $_[0], $line;
+ } else {
+ $msg = $_[0];
+ $msg =~ s/ \([0-9][0-9]*\)$//;
+ $errcount{$msg} += 1;
+ $tot_errcount += 1;
+ }
+}
+
+sub jstyle {
+
+$in_comment = 0;
+$in_header_comment = 0;
+$in_continuation = 0;
+$in_class = 0;
+$in_declaration = 0;
+$note_level = 0;
+$nextok = 0;
+$nocheck = 0;
+$expect_continuation = 0;
+$prev = '';
+
+$filename = $_[0];
+
+line: while (<STDIN>) {
+ ++$totlines;
+ s/\r?\n$//; # strip return and newline
+
+ # save the original line, then remove all text from within
+ # double or single quotes, we do not want to check such text.
+
+ $line = $_;
+ s/"[^"]*"/\"\"/g;
+ s/'.'/''/g;
+
+ # an /* END JSTYLED */ comment ends a no-check block.
+ if ($nocheck) {
+ if (/\/\* *END *JSTYLED *\*\//) {
+ $nocheck = 0;
+ } else {
+ next line;
+ }
+ }
+
+ # a /*JSTYLED*/ comment indicates that the next line is ok.
+ if ($nextok) {
+ if ($okmsg) {
+ do err($okmsg);
+ }
+ $nextok = 0;
+ $okmsg = 0;
+ if (/\/\* *JSTYLED.*\*\//) {
+ /^.*\/\* *JSTYLED *(.*) *\*\/.*$/;
+ $okmsg = $1;
+ $nextok = 1;
+ }
+ $prev = $line;
+ next line;
+ }
+
+ # check length of line.
+ # first, a quick check to see if there is any chance of being too long.
+ if ($line =~ tr/\t/\t/ * 7 + length($line) > 100) {
+ # yes, there is a chance.
+ # replace tabs with spaces and check again.
+ $eline = $line;
+ 1 while $eline =~
+ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
+ $l = length($eline);
+ if (length($eline) > 100) {
+ do err("line > 100 characters ($l)");
+ }
+ }
+# this is the fastest way to check line length,
+# but it doesnt work with perl 3.0.
+# if ($line =~ tr/\t/\t/ * 7 + length($line) > 80) {
+# $pos = $oldp = $p = 0;
+# while (($p = index($line, "\t", $p)) >= 0) {
+# $pos = ($pos + $p - $oldp + 8) & ~7;
+# $oldp = ++$p;
+# }
+# $pos += length($line) - $oldp;
+# if ($pos > 80) {
+# do err("line > 80 characters");
+# }
+# }
+
+ # remember whether we expect to be inside a continuation line.
+ $in_continuation = $expect_continuation;
+
+ # check for proper continuation line. blank lines
+ # in the middle of the
+ # continuation do not count.
+ # XXX - only check within functions.
+ if ($check_continuation && $expect_continuation && $in_class &&
+ !/^\s*$/) {
+ # continuation line must start with whitespace of
+ # previous line, plus either 4 spaces or a tab, but
+ # do not check lines that start with a string constant
+ # since they are often shifted to the left to make them
+ # fit on the line.
+ if (!/^$continuation_indent \S/ &&
+ !/^$continuation_indent\t\S/ && !/^\s*"/) {
+ do err("continuation line improperly indented");
+ }
+ $expect_continuation = 0;
+ }
+
+ # a /* BEGIN JSTYLED */ comment starts a no-check block.
+ if (/\/\* *BEGIN *JSTYLED *\*\//) {
+ $nocheck = 1;
+ }
+
+ # a /*JSTYLED*/ comment indicates that the next line is ok.
+ if (/\/\* *JSTYLED.*\*\//) {
+ /^.*\/\* *JSTYLED *(.*) *\*\/.*$/;
+ $okmsg = $1;
+ $nextok = 1;
+ }
+ if (/\/\/ *JSTYLED/) {
+ /^.*\/\/ *JSTYLED *(.*)$/;
+ $okmsg = $1;
+ $nextok = 1;
+ }
+
+ # is this the beginning or ending of a class?
+ if (/^(public\s+)*\w(class|interface)\s/) {
+ $in_class = 1;
+ $in_declaration = 1;
+ $prev = $line;
+ next line;
+ }
+ if (/^}\s*(\/\*.*\*\/\s*)*$/) {
+ $in_class = 0;
+ $prev = $line;
+ next line;
+ }
+
+ if (!$spaces) {
+ # strip trailing spaces
+ s/\s*$//;
+ }
+
+ # does this looks like the start of a block comment?
+ if (/^\s*\/\*(\*|)$/) {
+ if (!/^(\t| )*\/\*(\*|)$/) {
+ do err("block comment not indented properly");
+ }
+ $in_comment = 1;
+ s/\/\*(\*|)/ /;
+ $comment_prefix = $_;
+ if ($comment_prefix eq " ") {
+ $in_header_comment = 1;
+ }
+ $prev = $line;
+ next line;
+ }
+ if (/^\s*\/\*./ && !/^\s*\/\*\*$/ && !/^\s*\/\*.*\*\//) {
+ do err("improper first line of block comment");
+ # it's a bad one, but it still is one.
+ # avoid ripple effect of not recognizing this.
+ if (!/^(\t| )*\/\*(\*|)/) {
+ do err("block comment not indented properly");
+ }
+ $in_comment = 1;
+ s/\/\*.*/ /;
+ $comment_prefix = $_;
+ if ($comment_prefix eq " ") {
+ $in_header_comment = 1;
+ }
+ $prev = $line;
+ next line;
+ }
+ # are we still in the block comment?
+ if ($in_comment && !/^$comment_prefix\*/) {
+ # assume out of comment
+ $in_comment = 0;
+ $in_header_comment = 0;
+ }
+
+ if ($in_header_comment && $ignore_hdr_comment) {
+ $prev = $line;
+ next line;
+ }
+
+ # check for errors that might occur in comments and in code.
+
+ # allow spaces to be used to draw pictures in header comments.
+ if ($spaces && /[^ ] / && !/".* .*"/ && !$in_header_comment) {
+ do err("spaces instead of tabs");
+ }
+ if ($tabs && /^ / && !/^ \*[ \t\/]/ && !/^ \*$/ &&
+ (!/^ \w/ || $in_class != 0)) {
+ do err("indent by spaces instead of tabs");
+ }
+ if (!$in_comment && (/^(\t )* {1,3}\S/ || /^(\t )* {5,7}\S/) &&
+ !(/^\s*[-+|&\/?:=]/ || ($prev =~ /,\s*$/))) {
+ do err("indent not a multiple of 4");
+ }
+ if ($spaces && /\s$/) {
+ do err("space or tab at end of line");
+ }
+if (0) {
+ if (/^[\t]+ [^ \t\*]/ || /^[\t]+ \S/ || /^[\t]+ \S/) {
+ do err("continuation line not indented by 4 spaces");
+ }
+}
+ if (/[^ \t(]\/\*/ && !/\w\(\/\*.*\*\/\);/) {
+ do err("comment preceded by non-blank");
+ }
+ if ($spaces && /\t[ ]+\t/) {
+ do err("spaces between tabs");
+ }
+ if ($spaces && / [\t]+ /) {
+ do err("tabs between spaces");
+ }
+
+ if ($in_comment) { # still in comment
+ $prev = $line;
+ next line;
+ }
+
+ if ((/\/\*\S/ && !/\/\*\*/) || /\/\*\*\S/) {
+ do err("missing blank after open comment");
+ }
+ if (/\S\*\//) {
+ do err("missing blank before close comment");
+ }
+ # allow // at beginnging of line, often used to comment out code
+ if (/.\/\/\S/) { # C++ comments
+ do err("missing blank after start comment");
+ }
+ # check for unterminated single line comments.
+ if (/\S.*\/\*/ && !/\S.*\/\*.*\*\//) {
+ do err("unterminated single line comment");
+ }
+
+ # delete any comments and check everything else.
+ s/\/\*.*\*\///g;
+ s/\/\/.*$//; # C++ comments
+
+ # delete any trailing whitespace; we have already checked for that.
+ s/\s*$//;
+
+ # following checks do not apply to text in comments.
+
+ # if it looks like an operator at the end of the line, and it is
+ # not really the end of a comment (...*/), and it is not really
+ # a label (done:), and it is not a case label (case FOO:),
+ # or we are not in a function definition (ANSI C style) and the
+ # operator is a "," (to avoid hitting "int\nfoo(\n\tint i,\n\tint j)"),
+ # or we are in a function and the operator is a
+ # "*" (to avoid hitting on "char*\nfunc()").
+ if ((/[-+|&\/?:=]$/ && !/\*\/$/ && !/^\s*\w*:$/ &&
+ !/^\s\s*case\s\s*\w*:$/) ||
+ /,$/ ||
+ ($in_class && /\*$/)) {
+ $expect_continuation = 1;
+ if (!$in_continuation) {
+ /^(\s*)\S/;
+ $continuation_indent = $1;
+ }
+ }
+ if (/[^<>\s][!<>=]=/ || /[^<>][!<>=]=\S/ ||
+ (/[^->]>[^=>\s]/ && !/[^->]>$/) || (/[^<]<[^=<\s]/ && !/[^<]<$/) ||
+ /[^<\s]<[^<]/ || /[^->\s]>[^>]/) {
+ do err("missing space around relational operator");
+ }
+ if (/\S>>=/ || /\S<<=/ || />>=\S/ || /<<=\S/ || /\S[-+*\/&|^%]=/ ||
+ (/[^-+*\/&|^%!<>=\s]=[^=]/ && !/[^-+*\/&|^%!<>=\s]=$/) ||
+ (/[^!<>=]=[^=\s]/ && !/[^!<>=]=$/)) {
+ do err("missing space around assignment operator");
+ }
+ if (/[,;]\S/ && !/\bfor \(;;\)/) {
+ do err("comma or semicolon followed by non-blank");
+ }
+ # allow "for" statements to have empty "while" clauses
+ if (/\s[,;]/ && !/^[\t]+;$/ && !/^\s*for \([^;]*; ;[^;]*\)/) {
+ do err("comma or semicolon preceded by blank");
+ }
+if (0) {
+ if (/^\s*(&&|\|\|)/) {
+ do err("improper boolean continuation");
+ }
+}
+ if ($picky && /\S *(&&|\|\|)/ || /(&&|\|\|) *\S/) {
+ do err("more than one space around boolean operator");
+ }
+ if (/\b(for|if|while|switch|return|case|catch|synchronized)\(/) {
+ do err("missing space between keyword and paren");
+ }
+ if (/(\b(for|if|while|switch|return|catch|synchronized)\b.*){2,}/) {
+ # multiple "case" allowed
+ do err("more than one keyword on line");
+ }
+ if (/\b(for|if|while|switch|return|case|catch|synchronized)\s\s+\(/ &&
+ !/^#if\s+\(/) {
+ do err("extra space between keyword and paren");
+ }
+ # try to detect "func (x)" but not "if (x)" or
+ # "int (*func)();"
+ if (/\w\s\(/) {
+ $s = $_;
+ # strip off all keywords on the line
+ s/\b(for|if|while|switch|return|case|catch|synchronized)\s\(/XXX(/g;
+ #s/\b($typename|void)\s+\(+/XXX(/og;
+ if (/\w\s\(/) {
+ do err("extra space between function name and left paren");
+ }
+ $_ = $s;
+ }
+ if (/\(\s/) {
+ do err("whitespace after left paren");
+ }
+ # allow "for" statements to have empty "continue" clauses
+ if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/) {
+ do err("whitespace before right paren");
+ }
+ if (/^\s*\(void\)[^ ]/) {
+ do err("missing space after (void) cast");
+ }
+ if (/\S{/ && !/{{/) {
+ do err("missing space before left brace");
+ }
+ if ($in_class && /^\s+{/ && ($prev =~ /\)\s*$/)) {
+ do err("left brace starting a line");
+ }
+ if (/}(else|while)/) {
+ do err("missing space after right brace");
+ }
+ if (/}\s\s+(else|while)/) {
+ do err("extra space after right brace");
+ }
+ if (/\b$typename\*/o) {
+ do err("missing space between type name and *");
+ }
+ if ($heuristic) {
+ # cannot check this everywhere due to "struct {\n...\n} foo;"
+ if ($in_class && !$in_declaration &&
+ /}./ && !/}\s+=/ && !/{.*}[;,]$/ && !/}(\s|)*$/ &&
+ !/} (else|while)/ && !/}}/) {
+ do err("possible bad text following right brace");
+ }
+ # cannot check this because sub-blocks in
+ # the middle of code are ok
+ if ($in_class && /^\s+{/) {
+ do err("possible left brace starting a line");
+ }
+ }
+ if (/^\s*else\W/) {
+ if ($prev =~ /^\s*}$/) {
+ $str = "else and right brace should be on same line";
+ if ($statistics == 0) {
+ printf $fmt, $filename, $., $str, $prev;
+ if ($verbose) {
+ printf "%s\n", $line;
+ }
+ } else {
+ $errcount{$str} += 1;
+ $tot_errcount += 1;
+ }
+ }
+ }
+ $prev = $line;
+}
+
+if ($picky && $prev eq "") {
+ do err("last line in file is blank");
+}
+
+}
diff --git a/xmerge/workben/makefile.mk b/xmerge/workben/makefile.mk
new file mode 100644
index 000000000000..bb7d01c06e5e
--- /dev/null
+++ b/xmerge/workben/makefile.mk
@@ -0,0 +1,59 @@
+#***************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#***************************************************************************
+
+TARGET=xmrg_workben
+PRJ=..
+
+.INCLUDE : ant.mk
+ALLTAR: ANTBUILD