diff --git a/build.xml b/build.xml index 6757c99..7d893c7 100644 --- a/build.xml +++ b/build.xml @@ -2,7 +2,7 @@ ############################################################################ # This is the Ant build file for writer2latex # Original: Sep 2004 (mgn) - # version 1.4 (2012-03-13) + # version 1.4 (2012-03-16) ############################################################################ --> @@ -76,6 +76,7 @@ + @@ -91,6 +92,7 @@ + @@ -166,6 +168,7 @@ + diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index b7a3409..09b8930 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -2,3 +2,6 @@ Changelog for Writer2LaTeX version 1.2 -> 1.4 ---------- version 1.3.1 alpha ---------- +[all] Removed unused code in writer2latex.xmerge + +[w2x] Moved localized strings to .properties files \ No newline at end of file diff --git a/source/distro/doc/user-manual.odt b/source/distro/doc/user-manual.odt index fc4000e..4c00250 100644 Binary files a/source/distro/doc/user-manual.odt and b/source/distro/doc/user-manual.odt differ diff --git a/source/java/writer2latex/api/ConverterFactory.java b/source/java/writer2latex/api/ConverterFactory.java index 9a4593e..e68183f 100644 --- a/source/java/writer2latex/api/ConverterFactory.java +++ b/source/java/writer2latex/api/ConverterFactory.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.4 (2012-03-13) + * Version 1.4 (2012-03-19) * */ @@ -33,7 +33,7 @@ public class ConverterFactory { // Version information private static final String VERSION = "1.3.1"; - private static final String DATE = "2012-03-13"; + private static final String DATE = "2012-03-19"; /** Return the Writer2LaTeX version in the form * (major version).(minor version).(patch level)
diff --git a/source/java/writer2latex/base/ConfigBase.java b/source/java/writer2latex/base/ConfigBase.java index 66d8d7b..eeab8d0 100644 --- a/source/java/writer2latex/base/ConfigBase.java +++ b/source/java/writer2latex/base/ConfigBase.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2009 by Henrik Just + * Copyright: 2002-2012 by Henrik Just * * All Rights Reserved. * - * Version 1.2 (2009-09-24) + * Version 1.4 (2012-03-19) * */ @@ -46,7 +46,7 @@ import org.w3c.dom.Element; import org.w3c.dom.DOMImplementation; import writer2latex.api.ComplexOption; -import writer2latex.xmerge.NewDOMDocument; +import writer2latex.xmerge.DOMDocument; public abstract class ConfigBase implements writer2latex.api.Config { @@ -112,7 +112,7 @@ public abstract class ConfigBase implements writer2latex.api.Config { * @param is the input stream to read the configuration from */ public void read(InputStream is) throws IOException { - NewDOMDocument doc = new NewDOMDocument("config",".xml"); + DOMDocument doc = new DOMDocument("config",".xml"); doc.read(is); // may throw an IOException Document dom = doc.getContentDOM(); if (dom==null) { @@ -147,7 +147,7 @@ public abstract class ConfigBase implements writer2latex.api.Config { protected abstract void readInner(Element elm); public void write(OutputStream os) throws IOException { - NewDOMDocument doc = new NewDOMDocument("config",".xml"); + DOMDocument doc = new DOMDocument("config",".xml"); Document dom = null; try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); diff --git a/source/java/writer2latex/epub/ContainerWriter.java b/source/java/writer2latex/epub/ContainerWriter.java index 7ef3682..a817db2 100644 --- a/source/java/writer2latex/epub/ContainerWriter.java +++ b/source/java/writer2latex/epub/ContainerWriter.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2001-2010 by Henrik Just + * Copyright: 2001-2012 by Henrik Just * * All Rights Reserved. * - * version 1.2 (2010-03-29) + * version 1.4 (2012-03-19) * */ @@ -35,12 +35,12 @@ import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; -import writer2latex.xmerge.NewDOMDocument; +import writer2latex.xmerge.DOMDocument; /** This class creates the required META-INF/container.xml file for an EPUB package * (see http://www.idpf.org/ocf/ocf1.0/download/ocf10.htm). */ -public class ContainerWriter extends NewDOMDocument { +public class ContainerWriter extends DOMDocument { public ContainerWriter() { super("container", "xml"); diff --git a/source/java/writer2latex/epub/NCXWriter.java b/source/java/writer2latex/epub/NCXWriter.java index 4e49844..7e14697 100644 --- a/source/java/writer2latex/epub/NCXWriter.java +++ b/source/java/writer2latex/epub/NCXWriter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * version 1.2 (2012-02-22) + * version 1.4 (2012-03-19) * */ @@ -40,12 +40,12 @@ import org.w3c.dom.Element; import writer2latex.api.ContentEntry; import writer2latex.api.ConverterResult; import writer2latex.util.Misc; -import writer2latex.xmerge.NewDOMDocument; +import writer2latex.xmerge.DOMDocument; /** This class creates the required NXC file for an EPUB document * (see http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html#Section2.4). */ -public class NCXWriter extends NewDOMDocument { +public class NCXWriter extends DOMDocument { public NCXWriter(ConverterResult cr, String sUUID) { super("book", "ncx"); diff --git a/source/java/writer2latex/epub/OPFWriter.java b/source/java/writer2latex/epub/OPFWriter.java index c2e93ec..3ecc045 100644 --- a/source/java/writer2latex/epub/OPFWriter.java +++ b/source/java/writer2latex/epub/OPFWriter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * version 1.2 (2012-02-26) + * version 1.4 (2012-03-19) * */ @@ -44,11 +44,11 @@ import writer2latex.api.ContentEntry; import writer2latex.api.ConverterResult; import writer2latex.api.OutputFile; import writer2latex.util.Misc; -import writer2latex.xmerge.NewDOMDocument; +import writer2latex.xmerge.DOMDocument; /** This class writes an OPF-file for an EPUB document (see http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html). */ -public class OPFWriter extends NewDOMDocument { +public class OPFWriter extends DOMDocument { private String sUID=null; public OPFWriter(ConverterResult cr) { diff --git a/source/java/writer2latex/xhtml/BatchConverterImpl.java b/source/java/writer2latex/xhtml/BatchConverterImpl.java index 37bb9c8..db3e7b3 100644 --- a/source/java/writer2latex/xhtml/BatchConverterImpl.java +++ b/source/java/writer2latex/xhtml/BatchConverterImpl.java @@ -37,6 +37,7 @@ import org.w3c.dom.Element; import writer2latex.api.IndexPageEntry; import writer2latex.api.OutputFile; import writer2latex.base.BatchConverterBase; +import writer2latex.xhtml.l10n.L10n; /** * Implementation of writer2latex.api.BatchConverter for diff --git a/source/java/writer2latex/xhtml/Converter.java b/source/java/writer2latex/xhtml/Converter.java index 7267ef6..f0bc129 100644 --- a/source/java/writer2latex/xhtml/Converter.java +++ b/source/java/writer2latex/xhtml/Converter.java @@ -60,6 +60,7 @@ import writer2latex.office.StyleWithProperties; import writer2latex.office.XMLString; import writer2latex.util.ExportNameCollection; import writer2latex.util.Misc; +import writer2latex.xhtml.l10n.L10n; /** *

This class converts an OpenDocument file to an XHTML(+MathML) or EPUB document.

diff --git a/source/java/writer2latex/xhtml/L10n.java b/source/java/writer2latex/xhtml/L10n.java deleted file mode 100644 index d965c76..0000000 --- a/source/java/writer2latex/xhtml/L10n.java +++ /dev/null @@ -1,325 +0,0 @@ -/************************************************************************ - * - * L10n.java - * - * 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 - * - * Copyright: 2002-2011 by Henrik Just - * - * All Rights Reserved. - * - * Version 1.2 (2011-07-25) - * - */ - -package writer2latex.xhtml; - -import java.util.Locale; - -// This class handles localized strings (used for navigation) -public class L10n { - public final static int UP = 0; - public final static int FIRST = 1; - public final static int PREVIOUS = 2; - public final static int NEXT = 3; - public final static int LAST = 4; - public final static int CONTENTS = 5; - public final static int INDEX = 6; - public final static int HOME = 7; - public final static int DIRECTORY = 8; - public final static int DOCUMENT = 9; - - private Locale locale = null; - private String sLocale="en-US"; - - public void setLocale(String sLanguage, String sCountry) { - if (sLanguage!=null) { - if (sCountry!=null) { - locale = new Locale(sLanguage,sCountry); - } - else { - locale = new Locale(sLanguage); - } - } - else { - locale = Locale.getDefault(); - } - - if (locale.getCountry().length()>0) { - sLocale = locale.getLanguage()+"-"+locale.getCountry(); - } - else { - sLocale = locale.getLanguage(); - } - } - - public Locale getLocale() { - return locale; - } - - public String get(int nString) { - if (sLocale.startsWith("de")) { // German - switch (nString) { - case UP: return "Nach oben"; - case FIRST : return "Anfang"; - case PREVIOUS : return "Vorheriges"; - case NEXT : return "N\u00e4chstes"; - case LAST : return "Ende"; - case CONTENTS : return "Inhalte"; - case INDEX : return "Index"; - case HOME : return "Home"; - case DIRECTORY: return "Verzeichnis"; - case DOCUMENT: return "Dokument"; - } - } - if (sLocale.startsWith("fr")) { // French - switch (nString) { - case UP: return "Haut"; - case FIRST : return "D\u00e9but"; - case PREVIOUS : return "Pr\u00e9c\u00e9dent"; - case NEXT : return "Suivant"; - case LAST : return "Dernier"; - case CONTENTS : return "Contenus"; - case INDEX : return "Index"; - case HOME : return "Documents Personnels"; - case DIRECTORY: return "R\u00e9pertoire"; - case DOCUMENT: return "Document"; - } - } - if (sLocale.startsWith("es")) { // Spanish - switch (nString) { - case UP: return "Arriba"; - case FIRST : return "Primero"; - case PREVIOUS : return "Previo"; - case NEXT : return "Siguiente"; - case LAST : return "\u00daltimo"; - case CONTENTS : return "Contenido"; - case INDEX : return "\u00cdndice"; - case HOME : return "Inicio"; - case DIRECTORY: return "Directorio"; - case DOCUMENT: return "Documento"; - } - } - if (sLocale.startsWith("it")) { // Italian - switch (nString) { - case UP: return "Su"; - case FIRST : return "Inizio"; - case PREVIOUS : return "Precedente"; - case NEXT : return "Successivo"; - case LAST : return "Fine"; - case CONTENTS : return "Sommario"; - case INDEX : return "Indice"; - case HOME : return "Home"; - case DIRECTORY: return "Cartella"; - case DOCUMENT: return "Documento"; - } - } - if (sLocale.startsWith("pt")) { // (Brazilian) Portuguese - switch (nString) { - case UP: return "Acima"; - case FIRST : return "Primeiro"; - case PREVIOUS : return "Anterior"; - case NEXT : return "Pr\u00f3ximo"; - case LAST : return "\u00daltimo"; - case CONTENTS : return "Conte\u00fado"; - case INDEX : return "\u00cdndice"; - case HOME : return "Home"; - case DIRECTORY: return "Diret\u00f3rio"; - case DOCUMENT: return "Documento"; - } - } - if (sLocale.startsWith("cs")) { // Czech - switch (nString) { - case UP: return "Nahoru"; - case FIRST : return "Prvn\u00ed"; - case PREVIOUS : return "P\u0159edchoz\u00ed"; - case NEXT : return "Dal\u0161\u00ed"; - case LAST : return "Posledn\u00ed"; - case CONTENTS : return "Obsah"; - case INDEX : return "Rejst\u0159\u00edk"; - case HOME : return "Dom\u016f"; - case DIRECTORY: return "Adres\u00e1\u0159 (slo\u017eka)"; - case DOCUMENT: return "Dokument"; - } - } - if (sLocale.startsWith("nl")) { // Dutch - switch (nString) { - case UP: return "Omhoog"; - case FIRST : return "Eerste"; - case PREVIOUS : return "Vorige"; - case NEXT : return "Volgende"; - case LAST : return "Laatste"; - case CONTENTS : return "Inhoud"; - case INDEX : return "Index"; - case HOME : return "Hoofdpagina"; - case DIRECTORY: return "Directory"; - case DOCUMENT: return "Document"; - } - } - if (sLocale.startsWith("da")) { // Danish - switch (nString) { - case UP: return "Op"; - case FIRST : return "F\u00F8rste"; - case PREVIOUS : return "Forrige"; - case NEXT : return "N\u00E6ste"; - case LAST : return "Sidste"; - case CONTENTS : return "Indhold"; - case INDEX : return "Stikord"; - case HOME : return "Hjem"; - case DIRECTORY: return "Mappe"; - case DOCUMENT: return "Dokument"; - } - } - if (sLocale.startsWith("nn")) { // Nynorsk - switch (nString) { - case UP: return "Opp"; - case FIRST : return "F\u00f8rste"; - case PREVIOUS : return "Forrige"; - case NEXT : return "Neste"; - case LAST : return "Siste"; - case CONTENTS : return "Innhald"; - case INDEX : return "Register"; - case HOME : return "Heim"; - case DIRECTORY: return "Mappe"; - case DOCUMENT: return "Dokument"; - } - } - if (sLocale.startsWith("pl")) { // Polish - switch (nString) { - case UP: return "W g\u00f3r\u0119"; - case FIRST : return "Pierwsza"; - case PREVIOUS : return "Poprzednia"; - case NEXT : return "Nast\u0119pna"; - case LAST : return "Ostatnia"; - case CONTENTS : return "Spis tre\u015bci"; - case INDEX : return "Indeks"; - case HOME : return "Pocz\u0105tek"; - case DIRECTORY: return "Katalog"; - case DOCUMENT: return "Dokument"; - } - } - if (sLocale.startsWith("fi")) { // Finnish - switch (nString) { - case UP: return "Yl\u00f6s"; - case FIRST : return "Ensimm\u00e4inen"; - case PREVIOUS : return "Edellinen"; - case NEXT : return "Seuraava"; - case LAST : return "Viimeinen"; - case CONTENTS : return "Sis\u00e4lt\u00f6"; - case INDEX : return "Indeksi"; - case HOME : return "Koti"; - case DIRECTORY: return "Hakemisto"; - case DOCUMENT: return "Dokumentti"; - } - } - if (sLocale.startsWith("ca")) { // Catalan - switch (nString) { - case UP: return "Amunt"; - case FIRST : return "Comen\u00e7ament"; - case PREVIOUS : return "Precedent"; - case NEXT : return "Seg\u00fcent"; - case LAST: return "Darrer"; - case CONTENTS : return "Contingut"; - case INDEX : return "\u00cdndex"; - case HOME : return "Arrel"; - case DIRECTORY: return "Directori"; - case DOCUMENT: return "Document"; - } - } - if (sLocale.startsWith("ru")) { // Russian - switch (nString) { - case UP: return "\u0412\u0432\u0435\u0440\u0445"; - case FIRST : return "\u041f\u0435\u0440\u0432\u0430\u044f"; - case PREVIOUS : return "\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f"; - case NEXT : return "\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f"; - case LAST : return "\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f"; - case CONTENTS : return "\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435"; - case INDEX : return "\u0421\u043f\u0438\u0441\u043e\u043a"; - case HOME : return "\u0414\u043e\u043c\u043e\u0439"; - case DIRECTORY: return "\u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f"; - case DOCUMENT: return "\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442"; - } - } - if (sLocale.startsWith("uk")) { // Ukrainian - switch (nString) { - case UP: return "\u041d\u0430\u0433\u043e\u0440\u0443"; - case FIRST : return "\u041f\u0435\u0440\u0448\u0430"; - case PREVIOUS : return "\u041f\u043e\u043f\u0435\u0440\u0435\u0434\u043d\u044f"; - case NEXT : return "\u041d\u0430\u0441\u0442\u0443\u043f\u043d\u0430"; - case LAST : return "\u041e\u0441\u0442\u0430\u043d\u043d\u044f"; - case CONTENTS : return "\u0417\u043c\u0456\u0441\u0442"; - case INDEX : return "\u0421\u043f\u0438\u0441\u043e\u043a"; - case HOME : return "\u0414\u043e\u0434\u043e\u043c\u0443"; - case DIRECTORY: return "\u0422\u0435\u043a\u0430"; - case DOCUMENT: return "\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442"; - } - } - if (sLocale.startsWith("tr")) { // Turkish - switch (nString) { - case UP: return "Yukar\u0131"; - case FIRST : return "\u0130lk"; - case PREVIOUS : return "\u00d6nceki"; - case NEXT : return "Sonraki"; - case LAST : return "Son"; - case CONTENTS : return "\u0130\u00e7indekiler"; - case INDEX : return "\u0130ndeks"; - case HOME : return "Ev"; - case DIRECTORY: return "Klas\u00f6r"; - case DOCUMENT: return "D\u00f6k\u00fcman"; - } - } - if (sLocale.startsWith("hr")) { // Croatian - switch (nString) { - case UP: return "Up"; - case FIRST : return "Prvi"; - case PREVIOUS : return "Prethodan"; - case NEXT : return "slijede\u0107i"; - case LAST : return "Zadnji"; - case CONTENTS : return "Sadr\u017Eaj"; - case INDEX : return "Indeks"; - case DIRECTORY: return "Directory"; - case DOCUMENT: return "Document"; - } - } - if (sLocale.startsWith("fa")) { // Farsi - switch (nString) { - case UP: return "\u0628\u0627\u0644\u0627"; - case FIRST : return "\u0627\u0648\u0644"; - case PREVIOUS : return "\u0642\u0628\u0644\u06cc"; - case NEXT : return "\u0628\u0639\u062f\u06cc"; - case LAST : return "\u0627\u062e\u0631\u06cc\u0646"; - //case CONTENTS : return "??"; - case INDEX : return "\u0641\u0647\u0631\u0633\u062a"; - case HOME : return "\u062e\u0627\u0646\u0647"; - case DIRECTORY: return "\u067e\u0648\u0634\u0647"; - case DOCUMENT: return "\u0645\u0633\u062a\u0646\u062f"; - } - } - // English - default - switch (nString) { - case UP: return "Up"; - case FIRST : return "First"; - case PREVIOUS : return "Previous"; - case NEXT : return "Next"; - case LAST: return "Last"; - case CONTENTS : return "Contents"; - case INDEX : return "Index"; - case HOME : return "Home"; - case DIRECTORY: return "Directory"; - case DOCUMENT: return "Document"; - } - return "???"; - } -} diff --git a/source/java/writer2latex/xhtml/TextConverter.java b/source/java/writer2latex/xhtml/TextConverter.java index 591ecf3..87928f9 100644 --- a/source/java/writer2latex/xhtml/TextConverter.java +++ b/source/java/writer2latex/xhtml/TextConverter.java @@ -40,6 +40,7 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Element; import writer2latex.util.Misc; +import writer2latex.xhtml.l10n.L10n; import writer2latex.office.FontDeclaration; import writer2latex.office.OfficeStyle; import writer2latex.office.XMLString; diff --git a/source/java/writer2latex/xhtml/l10n/L10n.java b/source/java/writer2latex/xhtml/l10n/L10n.java new file mode 100644 index 0000000..0eb0946 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/L10n.java @@ -0,0 +1,88 @@ +/************************************************************************ + * + * L10n.java + * + * 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 + * + * Copyright: 2002-2012 by Henrik Just + * + * All Rights Reserved. + * + * Version 1.4 (2012-03-16) + * + */ + +package writer2latex.xhtml.l10n; + +import java.util.Locale; +import java.util.ResourceBundle; + +/* This class handles localized strings (used for navigation links in the exported document) + * Note that the US-English strings need duplicated due to ResourceBundles' search order. + * Default strings are needed for the special case that neither strings for the document language, + * nor for the system default language are available. + * US-English strings are needed if the document language is English and the system locale is not. + */ +public class L10n { + public final static int UP = 0; + public final static int FIRST = 1; + public final static int PREVIOUS = 2; + public final static int NEXT = 3; + public final static int LAST = 4; + public final static int CONTENTS = 5; + public final static int INDEX = 6; + public final static int HOME = 7; + public final static int DIRECTORY = 8; + public final static int DOCUMENT = 9; + + private ResourceBundle resourceBundle = ResourceBundle.getBundle("writer2latex.xhtml.l10n.XhtmlStrings",Locale.getDefault()); + private Locale locale = null; + + public void setLocale(String sLanguage, String sCountry) { + if (sLanguage!=null) { + if (sCountry!=null) { + locale = new Locale(sLanguage,sCountry); + } + else { + locale = new Locale(sLanguage); + } + } + else { + locale = Locale.getDefault(); + } + + resourceBundle = ResourceBundle.getBundle("writer2latex.xhtml.l10n.XhtmlStrings",locale); + } + + public Locale getLocale() { + return locale; + } + + public String get(int nString) { + switch (nString) { + case UP: return resourceBundle.getString("up"); + case FIRST : return resourceBundle.getString("first"); + case PREVIOUS : return resourceBundle.getString("previous"); + case NEXT : return resourceBundle.getString("next"); + case LAST : return resourceBundle.getString("last"); + case CONTENTS : return resourceBundle.getString("contents"); + case INDEX : return resourceBundle.getString("index"); + case HOME : return resourceBundle.getString("home"); + case DIRECTORY: return resourceBundle.getString("directory"); + case DOCUMENT: return resourceBundle.getString("document"); + default: return "???"; + } + } +} diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings.properties new file mode 100644 index 0000000..6eb3ec7 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Up +first=First +previous=Previous +next=Next +last=Last +contents=Contents +index=Index +home=Home +directory=Directory +document=Document diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_ca.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_ca.properties new file mode 100644 index 0000000..3527740 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_ca.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Amunt +first=Comen\u00e7ament +previous=Precedent +next=Seg\u00fcent +last=Darrer +contents=Contingut +index=\u00cdndex +home=Arrel +directory=Directori +document=Document diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_cs.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_cs.properties new file mode 100644 index 0000000..baaf1e1 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_cs.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Nahoru +first=Prvn\u00ed +previous=P\u0159edchoz\u00ed +next=Dal\u0161\u00ed +last=Posledn\u00ed +contents=Obsah +index=Rejst\u0159\u00edk +home=Dom\u016f +directory=Adres\u00e1\u0159 (slo\u017eka) +document=Dokument diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_da.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_da.properties new file mode 100644 index 0000000..5560d9c --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_da.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Op +first=F\u00F8rste +previous=Forrige +next=N\u00E6ste +last=Sidste +contents=Indhold +index=Stikord +home=Hjem +directory=Mappe +document=Dokument diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_de.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_de.properties new file mode 100644 index 0000000..305fd07 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_de.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Nach oben +first=Anfang +previous=Vorheriges +next=N\u00e4chstes +last=Ende +contents=Inhalte +index=Index +home=Home +directory=Verzeichnis +document=Dokument \ No newline at end of file diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_en.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_en.properties new file mode 100644 index 0000000..6eb3ec7 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_en.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Up +first=First +previous=Previous +next=Next +last=Last +contents=Contents +index=Index +home=Home +directory=Directory +document=Document diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_es.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_es.properties new file mode 100644 index 0000000..4f816ce --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_es.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Arriba +first=Primero +previous=Previo +next=Siguiente +last=\u00daltimo +contents=Contenido +index=\u00cdndice +home=Inicio +directory=Directorio +document=Documento diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fa.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fa.properties new file mode 100644 index 0000000..5d97925 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fa.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=\u0628\u0627\u0644\u0627 +first=\u0627\u0648\u0644 +previous=\u0642\u0628\u0644\u06cc +next=\u0628\u0639\u062f\u06cc +last=\u0627\u062e\u0631\u06cc\u0646 +contents=Contents +index=\u0641\u0647\u0631\u0633\u062a +home=\u062e\u0627\u0646\u0647 +directory=\u067e\u0648\u0634\u0647 +document=\u0645\u0633\u062a\u0646\u062f diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fi.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fi.properties new file mode 100644 index 0000000..c86eaf4 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fi.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Yl\u00f6s +first=Ensimm\u00e4inen +previous=Edellinen +next=Seuraava +last=Viimeinen +contents=Sis\u00e4lt\u00f6 +index=Indeksi +home=Koti +directory=Hakemisto +document=Dokumentti diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fr.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fr.properties new file mode 100644 index 0000000..020bbeb --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_fr.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Haut +first=D\u00e9but +previous=Pr\u00e9c\u00e9dent +next=Suivant +last=Dernier +contents=Contenus +index=Index +home=Documents Personnels +directory=R\u00e9pertoire +document=Document diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_hr.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_hr.properties new file mode 100644 index 0000000..9af6c19 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_hr.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Up +first=Prvi +previous=Prethodan +next=slijede\u0107i +last=Zadnji +contents=Sadr\u017Eaj +index=Indeks +home=Home +directory=Directory +document=Document diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_it.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_it.properties new file mode 100644 index 0000000..d6f7df8 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_it.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Su +first=Inizio +previous=Precedente +next=Successivo +last=Fine +contents=Sommario +index=Indice +home=Home +directory=Cartella +document=Documento diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_nl.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_nl.properties new file mode 100644 index 0000000..b135ca5 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_nl.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Omhoog +first=Eerste +previous=Vorige +next=Volgende +last=Laatste +contents=Inhoud +index=Index +home=Hoofdpagina +directory=Directory +document=Document diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_nn.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_nn.properties new file mode 100644 index 0000000..53e41bc --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_nn.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Opp +first=F\u00f8rste +previous=Forrige +next=Neste +last=Siste +contents=Innhald +index=Register +home=Heim +directory=Mappe +document=Dokument diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_pl.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_pl.properties new file mode 100644 index 0000000..90e56b3 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_pl.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=W g\u00f3r\u0119 +first=Pierwsza +previous=Poprzednia +next=Nast\u0119pna +last=Ostatnia +contents=Spis tre\u015bci +index=Indeks +home=Pocz\u0105tek +directory=Katalog +document=Dokument diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_pt_BR.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_pt_BR.properties new file mode 100644 index 0000000..5430643 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_pt_BR.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Acima +first=Primeiro +previous=Anterior +next=Pr\u00f3ximo +last=\u00daltimo +contents=Conte\u00fado +index=\u00cdndice +home=Home +directory=Diret\u00f3rio +document=Documento diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_ru.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_ru.properties new file mode 100644 index 0000000..f95b19b --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_ru.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=\u0412\u0432\u0435\u0440\u0445 +first=\u041f\u0435\u0440\u0432\u0430\u044f +previous=\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f +next=\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f +last=\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f +contents=\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 +index=\u0421\u043f\u0438\u0441\u043e\u043a +home=\u0414\u043e\u043c\u043e\u0439 +directory=\u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f +document=\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442 diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_tr.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_tr.properties new file mode 100644 index 0000000..a8b97d8 --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_tr.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=Yukar\u0131 +first=\u0130lk +previous=\u00d6nceki +next=Sonraki +last=Son +contents=\u0130\u00e7indekiler +index=\u0130ndeks +home=Ev +directory=Klas\u00f6r +document=D\u00f6k\u00fcman diff --git a/source/java/writer2latex/xhtml/l10n/XhtmlStrings_uk.properties b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_uk.properties new file mode 100644 index 0000000..d40391b --- /dev/null +++ b/source/java/writer2latex/xhtml/l10n/XhtmlStrings_uk.properties @@ -0,0 +1,11 @@ +# XHTML specific strings for Writer2LaTeX +up=\u041d\u0430\u0433\u043e\u0440\u0443 +first=\u041f\u0435\u0440\u0448\u0430 +previous=\u041f\u043e\u043f\u0435\u0440\u0435\u0434\u043d\u044f +next=\u041d\u0430\u0441\u0442\u0443\u043f\u043d\u0430 +last=\u041e\u0441\u0442\u0430\u043d\u043d\u044f +contents=\u0417\u043c\u0456\u0441\u0442 +index=\u0421\u043f\u0438\u0441\u043e\u043a +home=\u0414\u043e\u0434\u043e\u043c\u0443 +directory=\u0422\u0435\u043a\u0430 +document=\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442 diff --git a/source/java/writer2latex/xmerge/DOMDocument.java b/source/java/writer2latex/xmerge/DOMDocument.java index 3ab26d0..7103fca 100644 --- a/source/java/writer2latex/xmerge/DOMDocument.java +++ b/source/java/writer2latex/xmerge/DOMDocument.java @@ -37,26 +37,24 @@ ************************************************************************/ // This version is adapted for writer2latex -// Version 1.2 (2010-03-15) +// Version 1.4 (2012-03-19) package writer2latex.xmerge; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; -//import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -//import java.io.ByteArrayInputStream; -//import java.io.IOException; - +import java.io.OutputStreamWriter; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.ParserConfigurationException; +import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.Element; import org.w3c.dom.Document; +import org.w3c.dom.NodeList; import org.xml.sax.SAXException; //import org.xml.sax.SAXParseException; @@ -221,133 +219,106 @@ public class DOMDocument } } - /** * Write out content to the supplied OutputStream. - * + * (with pretty printing) * @param os XML OutputStream. - * * @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); + OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8"); + osw.write("\n"); + write(getContentDOM().getDocumentElement(),0,osw); + osw.flush(); + osw.close(); } - - /** - *

Write out a org.w3c.dom.Document object into a - * byte array.

- * - *

TODO: remove dependency on com.sun.xml.tree.XmlDocument - * package!

- * - * @param Document DOM Document object. - * - * @return byte array of DOM Document - * 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")) { - Class jaxpDoc = Class.forName("com.sun.xml.tree.XmlDocument"); - - // The method is in the XMLDocument class itself, not a helper - meth = jaxpDoc.getMethod("write", - new Class[] { Class.forName("java.io.OutputStream") } ); - - meth.invoke(doc, new Object [] { baos } ); - } - else if (domImpl.equals("org.apache.crimson.tree.XmlDocument")) - { - Class crimsonDoc = Class.forName("org.apache.crimson.tree.XmlDocument"); - // The method is in the XMLDocument class itself, not a helper - meth = crimsonDoc.getMethod("write", - new Class[] { Class.forName("java.io.OutputStream") } ); - - meth.invoke(doc, new Object [] { baos } ); - } - else if (domImpl.equals("org.apache.xerces.dom.DocumentImpl") - || domImpl.equals("org.apache.xerces.dom.DeferredDocumentImpl")) { - // Try for Xerces - Class xercesSer = - Class.forName("org.apache.xml.serialize.XMLSerializer"); - - // Get the OutputStream constructor - // May want to use the OutputFormat parameter at some stage too - con = xercesSer.getConstructor(new Class [] - { Class.forName("java.io.OutputStream"), - Class.forName("org.apache.xml.serialize.OutputFormat") } ); - - - // Get the serialize method - meth = xercesSer.getMethod("serialize", - new Class [] { Class.forName("org.w3c.dom.Document") } ); - - - // Get an instance - Object serializer = con.newInstance(new Object [] { baos, null } ); - - - // Now call serialize to write the document - meth.invoke(serializer, new Object [] { doc } ); - } - else if (domImpl.equals("gnu.xml.dom.DomDocument")) { - - Class gnuSer = Class.forName("gnu.xml.dom.ls.DomLSSerializer"); - - // Get the serialize method - meth = gnuSer.getMethod("serialize", - new Class [] { Class.forName("org.w3c.dom.Node"), - Class.forName("java.io.OutputStream") } ); - - // Get an instance - Object serializer = gnuSer.newInstance(); - - // Now call serialize to write the document - meth.invoke(serializer, new Object [] { doc, baos } ); - } - else { - // We dont have another parser - throw new IOException("No appropriate API (JAXP/Xerces) to serialize XML document: " + domImpl); - } + // Write nodes; we only need element, text and comment nodes + private void write(Node node, int nLevel, OutputStreamWriter osw) throws IOException { + short nType = node.getNodeType(); + switch (nType) { + case Node.ELEMENT_NODE: + if (node.hasChildNodes()) { + // Block pretty print from this node? + NodeList list = node.getChildNodes(); + int nLen = list.getLength(); + boolean bBlockPrettyPrint = false; + if (nLevel>=0) { + for (int i = 0; i < nLen; i++) { + bBlockPrettyPrint |= list.item(i).getNodeType()==Node.TEXT_NODE; + } + } + // Print start tag + if (nLevel>=0) { writeSpaces(nLevel,osw); } + osw.write("<"+node.getNodeName()); + writeAttributes(node,osw); + osw.write(">"); + if (nLevel>=0 && !bBlockPrettyPrint) { osw.write("\n"); } + // Print children + for (int i = 0; i < nLen; i++) { + int nNextLevel; + if (bBlockPrettyPrint || nLevel<0) { nNextLevel=-1; } + else { nNextLevel=nLevel+1; } + write(list.item(i),nNextLevel,osw); + } + // Print end tag + if (nLevel>=0 && !bBlockPrettyPrint) { writeSpaces(nLevel,osw); } + osw.write(""); + if (nLevel>=0) { osw.write("\n"); } + } + else { // empty element + if (nLevel>=0) { writeSpaces(nLevel,osw); } + osw.write("<"+node.getNodeName()); + writeAttributes(node,osw); + osw.write(" />"); + if (nLevel>=0) { osw.write("\n"); } + } + break; + case Node.TEXT_NODE: + write(node.getNodeValue(),osw); + break; + case Node.COMMENT_NODE: + if (nLevel>=0) { writeSpaces(nLevel,osw); } + osw.write(""); + if (nLevel>=0) { osw.write("\n"); } } - catch (ClassNotFoundException cnfe) { - throw new IOException(cnfe.toString()); + } + + private void writeAttributes(Node node, OutputStreamWriter osw) throws IOException { + NamedNodeMap attr = node.getAttributes(); + int nLen = attr.getLength(); + for (int i=0; i'): osw.write(">"); break; + case ('&'): osw.write("&"); break; + case ('"'): osw.write("""); break; + case ('\''): osw.write( "'"); break; + default: osw.write(c); + } + } + } + /** * Initializes a new DOM Document with the content * containing minimum XML tags. diff --git a/source/java/writer2latex/xmerge/EmbeddedBinaryObject.java b/source/java/writer2latex/xmerge/EmbeddedBinaryObject.java index 6f31b38..7a2dc51 100644 --- a/source/java/writer2latex/xmerge/EmbeddedBinaryObject.java +++ b/source/java/writer2latex/xmerge/EmbeddedBinaryObject.java @@ -38,15 +38,10 @@ ************************************************************************/ // This version is adapted for Writer2LaTeX -// Version 1.0 (2008-11-22) +// Version 1.4 (2012-03-19) package writer2latex.xmerge; -import org.w3c.dom.Document; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -//import org.w3c.dom.Node; - /** * This class represents embedded object's in an OpenOffice.org document that @@ -105,39 +100,10 @@ public class EmbeddedBinaryObject extends EmbeddedObject { * * @param data A byte array containing data for the object. */ - public void setBinaryData(byte[] data) { + /*public void setBinaryData(byte[] data) { objData = data; hasChanged = true; - } - - /** - * Package private method for writing the data of the EmbeddedObject to a - * SX? file. - * - * @param zip An OfficeZip instance representing the file - * the data is to be written to. - */ - void write(OfficeZip zip) { - if (hasChanged) { - zip.setNamedBytes(objName, objData); - } - } - - - /** - * Package private method that constructs the manifest.xml entries for this - * embedded object. - * - * @return Document Document containing the manifest entries. - */ - void writeManifestData(Document manifestDoc) throws DOMException { - Element objNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE); - - objNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, objType); - objNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH, objName); - - manifestDoc.getDocumentElement().appendChild(objNode); - } + }*/ } diff --git a/source/java/writer2latex/xmerge/EmbeddedObject.java b/source/java/writer2latex/xmerge/EmbeddedObject.java index 1d8cad8..afd815e 100644 --- a/source/java/writer2latex/xmerge/EmbeddedObject.java +++ b/source/java/writer2latex/xmerge/EmbeddedObject.java @@ -37,15 +37,10 @@ ************************************************************************/ // This version is adapted for Writer2LaTeX +// Version 1.4 (2012-03-19) package writer2latex.xmerge; -import java.io.IOException; - -import org.w3c.dom.Document; -import org.w3c.dom.DOMException; - - public abstract class EmbeddedObject { protected String objName; protected String objType; @@ -110,20 +105,4 @@ public abstract class EmbeddedObject { return objType; } - /** - * Package private method for writing the data of the EmbeddedObject to a - * SX? file. - * - * @param zip An OfficeZip instance representing the file - * the data is to be written to. - */ - abstract void write(OfficeZip zip) throws IOException; - - /** - * Package private method that constructs the manifest.xml entries for this - * embedded object. - * - * @return Document Document containing the manifest entries. - */ - abstract void writeManifestData(Document manifestDoc) throws DOMException; } \ No newline at end of file diff --git a/source/java/writer2latex/xmerge/EmbeddedXMLObject.java b/source/java/writer2latex/xmerge/EmbeddedXMLObject.java index 6f497e7..f44c229 100644 --- a/source/java/writer2latex/xmerge/EmbeddedXMLObject.java +++ b/source/java/writer2latex/xmerge/EmbeddedXMLObject.java @@ -37,7 +37,7 @@ ************************************************************************/ // This version is adapted for Writer2LaTeX -// Version 1.0 (2008-11-23) +// Version 1.4 (2012-03-19) package writer2latex.xmerge; @@ -49,9 +49,6 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; //import org.xml.sax.EntityResolver; //import org.xml.sax.InputSource; @@ -128,10 +125,10 @@ public class EmbeddedXMLObject extends EmbeddedObject { * * @param content DOM representation of the object's content. */ - public void setContentDOM(Document content) { + /*public void setContentDOM(Document content) { contentDOM = content; hasChanged = true; - } + }*/ /** @@ -157,10 +154,10 @@ public class EmbeddedXMLObject extends EmbeddedObject { * * @param settings DOM representation of the object's settings. */ - public void setSettingsDOM(Document settings) { + /*public void setSettingsDOM(Document settings) { settingsDOM = settings; hasChanged = true; - } + }*/ /** @@ -186,10 +183,10 @@ public class EmbeddedXMLObject extends EmbeddedObject { * * @param styles DOM representation of the object's styles. */ - public void setStylesDOM(Document styles) { + /*public void setStylesDOM(Document styles) { stylesDOM = styles; hasChanged = true; - } + }*/ /** @@ -238,75 +235,5 @@ public class EmbeddedXMLObject extends EmbeddedObject { } - /** - * Package private method for writing the data of the EmbeddedObject to a - * SX? file. - * - * @param zip An OfficeZip instance representing the file - * the data is to be written to. - */ - void write(OfficeZip zip) throws IOException { - if (hasChanged == true) { - if (contentDOM != null) { - zip.setNamedBytes(new String(objName + "/content.xml"), - OfficeDocument.docToBytes(contentDOM)); - } - if (settingsDOM != null) { - zip.setNamedBytes(new String(objName + "/settings.xml"), - OfficeDocument.docToBytes(settingsDOM)); - } - if (stylesDOM != null) { - zip.setNamedBytes(new String(objName + "/styles.xml"), - OfficeDocument.docToBytes(stylesDOM)); - } - } - } - - /** - * Package private method that constructs the manifest.xml entries for this - * embedded object. - * - * @param manifestDoc Document containing the manifest entries. - */ - void writeManifestData(Document manifestDoc) throws DOMException { - Node root = manifestDoc.getDocumentElement(); - - if (contentDOM != null) { - Element contentNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE); - - contentNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml"); - contentNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH, - new String(objName + "/content.xml")); - - root.appendChild(contentNode); - } - - if (settingsDOM != null) { - Element settingsNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE); - - settingsNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml"); - settingsNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH, - new String(objName + "/settings.xml")); - - root.appendChild(settingsNode); - } - - if (stylesDOM != null) { - Element stylesNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE); - - stylesNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml"); - stylesNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH, - new String(objName + "/styles.xml")); - } - - - Element objectNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE); - - objectNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, objType); - objectNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH, - new String(objName + "/")); - - root.appendChild(objectNode); - } - + } \ No newline at end of file diff --git a/source/java/writer2latex/xmerge/NewDOMDocument.java b/source/java/writer2latex/xmerge/NewDOMDocument.java deleted file mode 100644 index 5bd28f3..0000000 --- a/source/java/writer2latex/xmerge/NewDOMDocument.java +++ /dev/null @@ -1,160 +0,0 @@ -/************************************************************************ - * - * NewDOMDocument.java - * - * 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 - * - * Copyright: 2002-2006 by Henrik Just - * - * All Rights Reserved. - * - * Version 0.5 (2006-10-01) - * - */ - -package writer2latex.xmerge; - -import org.w3c.dom.NodeList; -import org.w3c.dom.Node; -import org.w3c.dom.NamedNodeMap; - -import writer2latex.xmerge.DOMDocument; - -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.IOException; - -/** - * An extension of DOMDocument - * that overrides the write method. - * (This method fails with the version of xerces shipped with jre 1.5) - */ -public class NewDOMDocument extends DOMDocument { - - /** Constructor - */ - public NewDOMDocument(String sFileName, String sExtension) { - super(sFileName,sExtension); - } - - /** - * Write out content to the supplied OutputStream. - * (with pretty printing) - * @param os XML OutputStream. - * @throws IOException If any I/O error occurs. - */ - public void write(OutputStream os) throws IOException { - OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8"); - osw.write("\n"); - write(getContentDOM().getDocumentElement(),0,osw); - osw.flush(); - osw.close(); - } - - // Write nodes; we only need element, text and comment nodes - private void write(Node node, int nLevel, OutputStreamWriter osw) throws IOException { - short nType = node.getNodeType(); - switch (nType) { - case Node.ELEMENT_NODE: - if (node.hasChildNodes()) { - // Block pretty print from this node? - NodeList list = node.getChildNodes(); - int nLen = list.getLength(); - boolean bBlockPrettyPrint = false; - if (nLevel>=0) { - for (int i = 0; i < nLen; i++) { - bBlockPrettyPrint |= list.item(i).getNodeType()==Node.TEXT_NODE; - } - } - // Print start tag - if (nLevel>=0) { writeSpaces(nLevel,osw); } - osw.write("<"+node.getNodeName()); - writeAttributes(node,osw); - osw.write(">"); - if (nLevel>=0 && !bBlockPrettyPrint) { osw.write("\n"); } - // Print children - for (int i = 0; i < nLen; i++) { - int nNextLevel; - if (bBlockPrettyPrint || nLevel<0) { nNextLevel=-1; } - else { nNextLevel=nLevel+1; } - write(list.item(i),nNextLevel,osw); - } - // Print end tag - if (nLevel>=0 && !bBlockPrettyPrint) { writeSpaces(nLevel,osw); } - osw.write(""); - if (nLevel>=0) { osw.write("\n"); } - } - else { // empty element - if (nLevel>=0) { writeSpaces(nLevel,osw); } - osw.write("<"+node.getNodeName()); - writeAttributes(node,osw); - osw.write(" />"); - if (nLevel>=0) { osw.write("\n"); } - } - break; - case Node.TEXT_NODE: - write(node.getNodeValue(),osw); - break; - case Node.COMMENT_NODE: - if (nLevel>=0) { writeSpaces(nLevel,osw); } - osw.write(""); - if (nLevel>=0) { osw.write("\n"); } - } - } - - private void writeAttributes(Node node, OutputStreamWriter osw) throws IOException { - NamedNodeMap attr = node.getAttributes(); - int nLen = attr.getLength(); - for (int i=0; i'): osw.write(">"); break; - case ('&'): osw.write("&"); break; - case ('"'): osw.write("""); break; - case ('\''): osw.write( "'"); break; - default: osw.write(c); - } - } - } - -} - - - - - - - - diff --git a/source/java/writer2latex/xmerge/OfficeDocument.java b/source/java/writer2latex/xmerge/OfficeDocument.java index e3f5d49..f18aa30 100644 --- a/source/java/writer2latex/xmerge/OfficeDocument.java +++ b/source/java/writer2latex/xmerge/OfficeDocument.java @@ -37,22 +37,17 @@ ************************************************************************/ // This version is adapted for Writer2LaTeX -// Version 1.2 (2010-03-28) +// Version 1.4 (2012-03-19) package writer2latex.xmerge; 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 java.util.Iterator; import java.util.Map; import java.util.HashMap; @@ -64,26 +59,19 @@ import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Node; import org.w3c.dom.Element; import org.w3c.dom.Document; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.DocumentType; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.w3c.dom.NamedNodeMap; import org.xml.sax.SAXException; -//import org.xml.sax.SAXParseException; import writer2latex.office.MIMETypes; import writer2latex.util.Misc; -//import org.openoffice.xmerge.util.Resources; -//import org.openoffice.xmerge.util.Debug; - /** - * An implementation of Document for - * StarOffice documents. + * This class implements reading of ODF files */ public class OfficeDocument - implements writer2latex.xmerge.Document, OfficeConstants { + implements OfficeConstants { /** Factory for DocumentBuilder objects. */ private static DocumentBuilderFactory factory = @@ -107,9 +95,6 @@ public class OfficeDocument private String documentName = null; private String fileName = null; - /** Resources object. */ - //private Resources res = null; - /** * OfficeZip object to store zip contents from * read InputStream. Note that this member @@ -224,46 +209,6 @@ public class OfficeDocument } - /** - * Sets the content tree of the document. - * - * @param newDom Node containing the new content tree. - */ - public void setContentDOM( Node newDom) { - contentDoc = (Document)newDom; - } - - - /** - * Sets the meta tree of the document. - * - * @param newDom Node containing the new meta tree. - */ - public void setMetaDOM (Node newDom) { - metaDoc = (Document)newDom; - } - - - /** - * Sets the settings tree of the document. - * - * @param newDom Node containing the new settings tree. - */ - public void setSettingsDOM (Node newDom) { - settingsDoc = (Document)newDom; - } - - - /** - * Sets the style tree of the document. - * - * @param newDom Node containing the new style tree. - */ - public void setStyleDOM (Node newDom) { - styleDoc = (Document)newDom; - } - - /** * Return a DOM Document object of the style.xml file. * Note that this may return null if there is no style DOM. @@ -413,7 +358,7 @@ public class OfficeDocument * * @param embObj An instance of EmbeddedObject. */ - public void addEmbeddedObject(EmbeddedObject embObj) { + /*public void addEmbeddedObject(EmbeddedObject embObj) { if (embObj == null) { return; } @@ -423,7 +368,7 @@ public class OfficeDocument } embeddedObjects.put(embObj.getName(), embObj); - } + }*/ /** @@ -706,383 +651,6 @@ public class OfficeDocument } - /** - * Method to return the MIME type of the document. - * - * @return String The document's MIME type. - */ - // not really used... - protected String getDocumentMimeType() { return ""; } - - - /** - * Write out Office ZIP file format. - * - * @param os XML OutputStream. - * - * @throws IOException If any I/O error occurs. - */ - public void write(OutputStream os) throws IOException { - if (zip == null) { - zip = new OfficeZip(); - } - - initManifestDOM(); - - Element domEntry; - Element manifestRoot = manifestDoc.getDocumentElement(); - - // The EmbeddedObjects come first. - Iterator embObjs = getEmbeddedObjects(); - while (embObjs.hasNext()) { - EmbeddedObject obj = embObjs.next(); - obj.writeManifestData(manifestDoc); - - obj.write(zip); - } - - // Add in the entry for the Pictures directory. Always present. - domEntry = manifestDoc.createElement(TAG_MANIFEST_FILE); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_PATH, "Pictures/"); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_TYPE, ""); - manifestRoot.appendChild(domEntry); - - // Write content to the Zip file and then write any of the optional - // data, if it exists. - zip.setContentXMLBytes(docToBytes(contentDoc)); - - domEntry = manifestDoc.createElement(TAG_MANIFEST_FILE); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_PATH, "content.xml"); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml"); - - manifestRoot.appendChild(domEntry); - - if (styleDoc != null) { - zip.setStyleXMLBytes(docToBytes(styleDoc)); - - domEntry = manifestDoc.createElement(TAG_MANIFEST_FILE); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_PATH, "styles.xml"); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml"); - manifestRoot.appendChild(domEntry); - } - - if (metaDoc != null) { - zip.setMetaXMLBytes(docToBytes(metaDoc)); - - domEntry = manifestDoc.createElement(TAG_MANIFEST_FILE); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_PATH, "meta.xml"); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml"); - manifestRoot.appendChild(domEntry); - } - - if (settingsDoc != null) { - zip.setSettingsXMLBytes(docToBytes(settingsDoc)); - - domEntry = manifestDoc.createElement(TAG_MANIFEST_FILE); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_PATH, "settings.xml"); - domEntry.setAttribute(ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml"); - manifestRoot.appendChild(domEntry); - } - - zip.setManifestXMLBytes(docToBytes(manifestDoc)); - - zip.write(os); - } - - - /** - * Write out Office ZIP file format. - * - * @param os XML OutputStream. - * @param isZip boolean - * - * @throws IOException If any I/O error occurs. - */ - public void write(OutputStream os, boolean isZip) throws IOException { - - // Create an OfficeZip object if one does not exist. - if (isZip){ - write(os); - } - else{ - try{ - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder= builderFactory.newDocumentBuilder(); - DOMImplementation domImpl = builder.getDOMImplementation(); - domImpl.createDocumentType("office:document","-//OpenOffice.org//DTD OfficeDocument 1.0//EN",null); - org.w3c.dom.Document newDoc = domImpl.createDocument("http://openoffice.org/2000/office","office:document",null); - - - Element rootElement=newDoc.getDocumentElement(); - rootElement.setAttribute("xmlns:office","http://openoffice.org/2000/office"); - rootElement.setAttribute("xmlns:style","http://openoffice.org/2000/style" ); - rootElement.setAttribute("xmlns:text","http://openoffice.org/2000/text"); - rootElement.setAttribute("xmlns:table","http://openoffice.org/2000/table"); - - rootElement.setAttribute("xmlns:draw","http://openoffice.org/2000/drawing"); - rootElement.setAttribute("xmlns:fo","http://www.w3.org/1999/XSL/Format" ); - rootElement.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink" ); - rootElement.setAttribute("xmlns:dc","http://purl.org/dc/elements/1.1/" ); - rootElement.setAttribute("xmlns:meta","http://openoffice.org/2000/meta" ); - rootElement.setAttribute("xmlns:number","http://openoffice.org/2000/datastyle" ); - rootElement.setAttribute("xmlns:svg","http://www.w3.org/2000/svg" ); - rootElement.setAttribute("xmlns:chart","http://openoffice.org/2000/chart" ); - rootElement.setAttribute("xmlns:dr3d","http://openoffice.org/2000/dr3d" ); - rootElement.setAttribute("xmlns:math","http://www.w3.org/1998/Math/MathML" ); - rootElement.setAttribute("xmlns:form","http://openoffice.org/2000/form" ); - rootElement.setAttribute("xmlns:script","http://openoffice.org/2000/script" ); - rootElement.setAttribute("xmlns:config","http://openoffice.org/2001/config" ); - // #i41033# OASIS format needs the "office:class" set. - if(getDocumentMimeType() == SXC_MIME_TYPE) - rootElement.setAttribute("office:class","spreadsheet" ); - else if(getDocumentMimeType() == SXW_MIME_TYPE) - rootElement.setAttribute("office:class","text" ); - rootElement.setAttribute("office:version","1.0"); - - - NodeList nodeList; - Node tmpNode; - Node rootNode = (Node)rootElement; - if (metaDoc !=null){ - nodeList= metaDoc.getElementsByTagName(TAG_OFFICE_META); - if (nodeList.getLength()>0){ - tmpNode = newDoc.importNode(nodeList.item(0),true); - rootNode.appendChild(tmpNode); - } - }if (styleDoc !=null){ - nodeList= styleDoc.getElementsByTagName(TAG_OFFICE_STYLES); - if (nodeList.getLength()>0){ - tmpNode = newDoc.importNode(nodeList.item(0),true); - rootNode.appendChild(tmpNode); - } - - }if (settingsDoc !=null){ - nodeList= settingsDoc.getElementsByTagName(TAG_OFFICE_SETTINGS); - if (nodeList.getLength()>0){ - tmpNode = newDoc.importNode(nodeList.item(0),true); - rootNode.appendChild(tmpNode); - } - } - if (contentDoc !=null){ - nodeList= contentDoc.getElementsByTagName(TAG_OFFICE_AUTOMATIC_STYLES); - if (nodeList.getLength()>0){ - tmpNode = newDoc.importNode(nodeList.item(0),true); - rootNode.appendChild(tmpNode); - } - - nodeList= contentDoc.getElementsByTagName(TAG_OFFICE_BODY); - if (nodeList.getLength()>0){ - tmpNode = newDoc.importNode(nodeList.item(0),true); - rootNode.appendChild(tmpNode); - } - } - - byte contentBytes[] = docToBytes(newDoc); - os.write(contentBytes); - } - catch(Exception exc){ - System.err.println("\nException in OfficeDocument.write():" +exc); - } - //byte contentBytes[] = docToBytes(contentDoc); - } - } - - - /** - *

Write out a org.w3c.dom.Document object into a - * byte array.

- * - *

TODO: remove dependency on com.sun.xml.tree.XmlDocument - * package!

- * - * @param Document DOM Document object. - * - * @return byte array of DOM Document - * object. - * - * @throws IOException If any I/O error occurs. - */ - static byte[] docToBytes(Document doc) - throws IOException { - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - java.lang.reflect.Constructor con; - java.lang.reflect.Method meth; - - String domImpl = doc.getClass().getName(); - - /* - * We may have multiple XML parsers in the Classpath. - * Depending on which one is first, the actual type of - * doc may vary. Need a way to find out which API is being - * used and use an appropriate serialization method. - */ - try { - // First of all try for JAXP 1.0 - if (domImpl.equals("com.sun.xml.tree.XmlDocument")) { - - // Debug.log(Debug.INFO, "Using JAXP"); - - Class jaxpDoc = Class.forName("com.sun.xml.tree.XmlDocument"); - - // The method is in the XMLDocument class itself, not a helper - meth = jaxpDoc.getMethod("write", - new Class[] { Class.forName("java.io.OutputStream") } ); - - meth.invoke(doc, new Object [] { baos } ); - } - else if (domImpl.equals("org.apache.crimson.tree.XmlDocument")) - { - // Debug.log(Debug.INFO, "Using Crimson"); - - Class crimsonDoc = Class.forName("org.apache.crimson.tree.XmlDocument"); - // The method is in the XMLDocument class itself, not a helper - meth = crimsonDoc.getMethod("write", - new Class[] { Class.forName("java.io.OutputStream") } ); - - meth.invoke(doc, new Object [] { baos } ); - } - else if (domImpl.equals("org.apache.xerces.dom.DocumentImpl") - || domImpl.equals("org.apache.xerces.dom.DeferredDocumentImpl")) { - - // Debug.log(Debug.INFO, "Using Xerces"); - - // Try for Xerces - Class xercesSer = - Class.forName("org.apache.xml.serialize.XMLSerializer"); - - // Get the OutputStream constructor - // May want to use the OutputFormat parameter at some stage too - con = xercesSer.getConstructor(new Class [] - { Class.forName("java.io.OutputStream"), - Class.forName("org.apache.xml.serialize.OutputFormat") } ); - - - // Get the serialize method - meth = xercesSer.getMethod("serialize", - new Class [] { Class.forName("org.w3c.dom.Document") } ); - - - // Get an instance - Object serializer = con.newInstance(new Object [] { baos, null } ); - - - // Now call serialize to write the document - meth.invoke(serializer, new Object [] { doc } ); - } - else { - // 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 Document 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_FONT_DECLS); - root.appendChild(child); - - 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 the content - * containing minimum OpenOffice XML tags. - * - * @throws IOException If any I/O error occurs. - */ - public final void initSettingsDOM() throws IOException { - - settingsDoc = createSettingsDOM(TAG_OFFICE_DOCUMENT_SETTINGS); - - // 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 = settingsDoc.getDocumentElement(); - - Element child = settingsDoc.createElement(TAG_OFFICE_SETTINGS); - 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); - } - - /** - *

Creates a new DOM Document containing minimum - * OpenOffice XML tags.

- * - *

This method uses the subclass - * getOfficeClassAttribute method to get the - * attribute for office:class.

- * - * @param rootName root name of Document. - * - * @throws IOException If any I/O error occurs. - */ - private final Document createSettingsDOM(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:xlink", "http://openoffice.org/1999/xlink"); - root.setAttribute("xmlns:config", "http://openoffice.org/2001/config"); - root.setAttribute("office:version", "1.0"); - - return doc; - } - - /** *

Creates a new DOM Document containing minimum * OpenOffice XML tags.

@@ -1252,45 +820,5 @@ public class OfficeDocument } - /** - * Method to create the initial entries in the manifest.xml file stored - * in an SX? file. - */ - private void initManifestDOM() throws IOException { - - try { - DocumentBuilder builder = factory.newDocumentBuilder(); - DOMImplementation domImpl = builder.getDOMImplementation(); - - DocumentType docType = domImpl.createDocumentType(TAG_MANIFEST_ROOT, - "-//OpenOffice.org//DTD Manifest 1.0//EN", - "Manifest.dtd"); - manifestDoc = domImpl.createDocument("manifest", TAG_MANIFEST_ROOT, docType); - } catch (ParserConfigurationException ex) { - throw new OfficeDocumentException(ex); - } - - // Add the entry - Element manifestRoot = manifestDoc.getDocumentElement(); - - manifestRoot.setAttribute("xmlns:manifest", "http://openoffice.org/2001/manifest"); - - Element docRoot = manifestDoc.createElement(TAG_MANIFEST_FILE); - - docRoot.setAttribute(ATTRIBUTE_MANIFEST_FILE_PATH, "/"); - docRoot.setAttribute(ATTRIBUTE_MANIFEST_FILE_TYPE, getDocumentMimeType()); - - manifestRoot.appendChild(docRoot); - } - - // TODO: We need these because we implement OutputFile (but in fact we shouldn't) - public String getMIMEType() { - return ""; - } - - public boolean isMasterDocument() { - return false; - } - } diff --git a/source/java/writer2latex/xmerge/OfficeZip.java b/source/java/writer2latex/xmerge/OfficeZip.java index a9abe1d..e10b0e2 100644 --- a/source/java/writer2latex/xmerge/OfficeZip.java +++ b/source/java/writer2latex/xmerge/OfficeZip.java @@ -37,28 +37,22 @@ ************************************************************************/ // This version is adapted for Writer2LaTeX -// Version 1.0 (2008-11-22) +// Version 1.4 (2012-03-19) package writer2latex.xmerge; 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 + * OfficeDocument} to handle reading * from a ZIP file, as well as storing ZIP entries. * * @author Herbie Ong @@ -113,9 +107,6 @@ class OfficeZip { while ((ze = zis.getNextEntry()) != null) { String name = ze.getName(); - //System.out.println("Found "+name); - - // Debug.log(Debug.TRACE, "reading entry: " + name); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -240,31 +231,6 @@ class OfficeZip { } - /** - * This method sets the bytes for the named entry. It searches for a - * matching entry in the LinkedList. If no entry is found, a new one is - * created. - * - * Writing of data is defferred to setEntryBytes(). - * - * @param name The name of the entry to search for. - * @param bytes The new data to write. - */ - void setNamedBytes(String name, byte[] bytes) { - for (int i = 0; i < entryList.size(); i++) { - Entry e = entryList.get(i); - - if (e.zipEntry.getName().equals(name)) { - setEntryBytes(i, bytes, name); - return; - } - } - - // If we're here, no entry was found. Call setEntryBytes with an index - // of -1 to insert a new entry. - setEntryBytes(-1, bytes, name); - } - /** * Used by the getContentXMLBytes method and the * getStyleXMLBytes method to return the @@ -289,171 +255,6 @@ class OfficeZip { return bytes; } - - /** - * Set or replace the byte array for the - * CONTENTXML file. - * - * @param bytes byte array for the - * CONTENTXML file. - */ - void setContentXMLBytes(byte bytes[]) { - - contentIndex = setEntryBytes(contentIndex, bytes, CONTENTXML); - } - - - /** - * Set or replace the byte array for the - * STYLEXML file. - * - * @param bytes byte array for the - * STYLEXML file. - */ - void setStyleXMLBytes(byte bytes[]) { - - styleIndex = setEntryBytes(styleIndex, bytes, STYLEXML); - } - - - /** - * Set or replace the byte array for the - * METAXML file. - * - * @param bytes byte array for the - * METAXML file. - */ - void setMetaXMLBytes(byte bytes[]) { - - metaIndex = setEntryBytes(metaIndex, bytes, METAXML); - } - - - /** - * Set or replace the byte array for the - * SETTINGSXML file. - * - * @param bytes byte array for the - * SETTINGSXML file. - */ - void setSettingsXMLBytes(byte bytes[]) { - - settingsIndex = setEntryBytes(settingsIndex, bytes, SETTINGSXML); - } - - - /** - * Set or replace the byte array for the MANIFESTXML file. - * - * @param bytes byte array for the MANIFESTXML file. - */ - void setManifestXMLBytes(byte bytes[]) { - manifestIndex = setEntryBytes(manifestIndex, bytes, MANIFESTXML); - } - - /** - *

Used by the setContentXMLBytes method and - * the setStyleXMLBytes to either replace an - * existing Entry, or create a new entry in - * entryList.

- * - *

If there is an Entry object within - * entryList that corresponds to the index, replace the - * ZipEntry info.

- * - * @param index Index of Entry to modify. - * @param bytes Entry value. - * @param name Name of Entry. - * - * @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 = 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 OutputStream - * object. - * - * @param os OutputStream 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 = 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 ZipEntry object based on the given params. - * - * @param name Name for the ZipEntry. - * @param bytes byte array for ZipEntry. - * @param method ZIP method to be used for ZipEntry. - * - * @return A ZipEntry 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; - } - /** * This inner class is used as a data structure for holding * a ZipEntry info and its corresponding bytes.