Some minor bugfixing, refactoring and rearrangement

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@165 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2014-08-27 07:25:22 +00:00
parent 8a6e654344
commit 6249ef406e
31 changed files with 146 additions and 288 deletions

View file

@ -2,6 +2,8 @@ Changelog for Writer2LaTeX version 1.2 -> 1.4
---------- version 1.3.2 alpha ---------- ---------- version 1.3.2 alpha ----------
[all] Refactored and rearranged some code; in particular the last remaining bits of the old xmerge framework has been removed
[all] Optimized reading of package format: The settings.xml files are not parsed and the unused parts of the ZIP file are disposed [all] Optimized reading of package format: The settings.xml files are not parsed and the unused parts of the ZIP file are disposed
---------- version 1.3.1 alpha ---------- ---------- version 1.3.1 alpha ----------

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2012 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2012-03-22) * Version 1.4 (2014-08-27)
* *
*/ */
@ -240,15 +240,15 @@ XTypeProvider {
// Get base name from the URL provided by OOo // Get base name from the URL provided by OOo
String sName= getFileName(sURL); String sName= getFileName(sURL);
// Adapter for output stream (Main output file)
XOutputStreamToOutputStreamAdapter newxos =new XOutputStreamToOutputStreamAdapter(exportStream);
// Create converter // Create converter
Converter converter = ConverterFactory.createConverter(sdMime); Converter converter = ConverterFactory.createConverter(sdMime);
if (converter==null) { if (converter==null) {
throw new com.sun.star.uno.RuntimeException("Failed to create converter to "+sdMime); throw new com.sun.star.uno.RuntimeException("Failed to create converter to "+sdMime);
} }
// Adapter for output stream (Main output file)
XOutputStreamToOutputStreamAdapter newxos =new XOutputStreamToOutputStreamAdapter(exportStream);
// Apply the FilterData to the converter // Apply the FilterData to the converter
if (filterData!=null) { if (filterData!=null) {
FilterDataParser fdp = new FilterDataParser(xComponentContext); FilterDataParser fdp = new FilterDataParser(xComponentContext);

View file

@ -30,7 +30,6 @@ import java.util.Map;
import org.openoffice.da.comp.w2lcommon.filter.ConfigurationDialogBase; import org.openoffice.da.comp.w2lcommon.filter.ConfigurationDialogBase;
import org.openoffice.da.comp.w2lcommon.helper.DialogAccess; import org.openoffice.da.comp.w2lcommon.helper.DialogAccess;
import org.openoffice.da.comp.w2lcommon.helper.FilePicker;
import com.sun.star.container.NoSuchElementException; import com.sun.star.container.NoSuchElementException;
import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XServiceInfo;

View file

@ -16,21 +16,22 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2012 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2012-04-01) * Version 1.4 (2014-08-25)
* *
*/ */
package writer2latex.xmerge; package writer2latex.base;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.InputStream; import java.io.InputStream;
//import java.io.ByteArrayOutputStream; //import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import writer2latex.api.OutputFile;
import writer2latex.util.Misc; import writer2latex.util.Misc;
@ -43,7 +44,7 @@ import writer2latex.util.Misc;
* <p><code>GraphicsDocument</code> is used to create new graphics documents.</p> * <p><code>GraphicsDocument</code> is used to create new graphics documents.</p>
* *
*/ */
public class BinaryGraphicsDocument implements Document { public class BinaryGraphicsDocument implements OutputFile {
//private final static int BUFFERSIZE = 1024; //private final static int BUFFERSIZE = 1024;

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2012 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2012-03-19) * Version 1.4 (2014-08-26)
* *
*/ */
@ -40,13 +40,14 @@ import java.util.Map;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.DOMImplementation; import org.w3c.dom.DOMImplementation;
import writer2latex.api.ComplexOption; import writer2latex.api.ComplexOption;
import writer2latex.xmerge.DOMDocument;
public abstract class ConfigBase implements writer2latex.api.Config { public abstract class ConfigBase implements writer2latex.api.Config {
@ -127,7 +128,7 @@ public abstract class ConfigBase implements writer2latex.api.Config {
if (elm.getTagName().equals("option")) { if (elm.getTagName().equals("option")) {
String sName = elm.getAttribute("name"); String sName = elm.getAttribute("name");
String sValue = elm.getAttribute("value"); String sValue = elm.getAttribute("value");
if (sName!="") { setOption(sName,sValue); } if (sName.length()>0) { setOption(sName,sValue); }
} }
else { else {
readInner(elm); readInner(elm);
@ -154,9 +155,10 @@ public abstract class ConfigBase implements writer2latex.api.Config {
DocumentBuilder builder = builderFactory.newDocumentBuilder(); DocumentBuilder builder = builderFactory.newDocumentBuilder();
DOMImplementation domImpl = builder.getDOMImplementation(); DOMImplementation domImpl = builder.getDOMImplementation();
dom = domImpl.createDocument("","config",null); dom = domImpl.createDocument("","config",null);
} } catch (ParserConfigurationException e) {
catch (Throwable t) { // This will not happen
t.printStackTrace(); e.printStackTrace();
return;
} }
Element rootElement = dom.getDocumentElement(); Element rootElement = dom.getDocumentElement();

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-13) * Version 1.4 (2014-08-27)
* *
*/ */
@ -38,7 +38,6 @@ import writer2latex.api.Converter;
import writer2latex.api.ConverterResult; import writer2latex.api.ConverterResult;
import writer2latex.api.OutputFile; import writer2latex.api.OutputFile;
import writer2latex.office.EmbeddedObject; import writer2latex.office.EmbeddedObject;
import writer2latex.office.ImageLoader;
import writer2latex.office.MetaData; import writer2latex.office.MetaData;
import writer2latex.office.OfficeDocument; import writer2latex.office.OfficeDocument;
import writer2latex.office.OfficeReader; import writer2latex.office.OfficeReader;
@ -58,7 +57,7 @@ public abstract class ConverterBase implements Converter {
protected OfficeDocument odDoc; protected OfficeDocument odDoc;
protected OfficeReader ofr; protected OfficeReader ofr;
protected MetaData metaData; protected MetaData metaData;
protected ImageLoader imageLoader; protected ImageConverter imageConverter;
// The output file(s) // The output file(s)
protected String sTargetFileName; protected String sTargetFileName;
@ -114,8 +113,8 @@ public abstract class ConverterBase implements Converter {
private ConverterResult convert(String sTargetFileName) throws IOException { private ConverterResult convert(String sTargetFileName) throws IOException {
ofr = new OfficeReader(odDoc,false); ofr = new OfficeReader(odDoc,false);
metaData = new MetaData(odDoc); metaData = new MetaData(odDoc);
imageLoader = new ImageLoader(odDoc,true); imageConverter = new ImageConverter(odDoc,true);
imageLoader.setGraphicConverter(graphicConverter); imageConverter.setGraphicConverter(graphicConverter);
// Prepare output // Prepare output
this.sTargetFileName = sTargetFileName; this.sTargetFileName = sTargetFileName;
@ -136,7 +135,7 @@ public abstract class ConverterBase implements Converter {
public MetaData getMetaData() { return metaData; } public MetaData getMetaData() { return metaData; }
public ImageLoader getImageLoader() { return imageLoader; } public ImageConverter getImageCv() { return imageConverter; }
public void addDocument(OutputFile doc) { converterResult.addDocument(doc); } public void addDocument(OutputFile doc) { converterResult.addDocument(doc); }

View file

@ -1,15 +1,6 @@
/************************************************************************ /************************************************************************
* *
* The Contents of this file are made available subject to the terms of * DOMDocument.java
*
* - GNU Lesser General Public License Version 2.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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -25,21 +16,15 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* The Initial Developer of the Original Code is: Sun Microsystems, Inc. * Copyright: 2002-2014 by Henrik Just
*
* Copyright: 2000 by Sun Microsystems, Inc.
* *
* All Rights Reserved. * All Rights Reserved.
*
* Version 1.4 (2014-08-26)
* *
* Contributor(s): _______________________________________ */
*
*
************************************************************************/
// This version is adapted for writer2latex
// Version 1.4 (2012-03-19)
package writer2latex.xmerge; package writer2latex.base;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
@ -58,12 +43,13 @@ import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
//import org.xml.sax.SAXParseException; //import org.xml.sax.SAXParseException;
import writer2latex.api.OutputFile;
/** /**
* An implementation of <code>Document</code> for * This class represents XML-based documents. It is loosely based on a class from the former xmerge project
* StarOffice documents. * from OOo.
*/ */
public class DOMDocument public class DOMDocument implements OutputFile {
implements writer2latex.xmerge.Document {
/** Factory for <code>DocumentBuilder</code> objects. */ /** Factory for <code>DocumentBuilder</code> objects. */
private static DocumentBuilderFactory factory = private static DocumentBuilderFactory factory =
@ -352,9 +338,9 @@ public class DOMDocument
doc = builder.newDocument(); doc = builder.newDocument();
} catch (ParserConfigurationException ex) { } catch (ParserConfigurationException ex) {
// This will not happen
System.err.println("Error:"+ ex); System.err.println("Error:"+ ex);
throw new IOException(ex);
} }
Element root = (Element) doc.createElement(rootName); Element root = (Element) doc.createElement(rootName);

View file

@ -24,7 +24,7 @@
* *
*/ */
package writer2latex.office; package writer2latex.base;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
@ -34,15 +34,20 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import writer2latex.api.GraphicConverter; import writer2latex.api.GraphicConverter;
import writer2latex.office.EmbeddedBinaryObject;
import writer2latex.office.EmbeddedObject;
import writer2latex.office.MIMETypes;
import writer2latex.office.OfficeDocument;
import writer2latex.office.SVMReader;
import writer2latex.office.XMLString;
import writer2latex.util.Base64; import writer2latex.util.Base64;
import writer2latex.util.Misc; import writer2latex.util.Misc;
import writer2latex.xmerge.BinaryGraphicsDocument;
/** /**
* <p>This class extracts images from an OOo file. * <p>This class extracts images from an OOo file.
* The images are returned as BinaryGraphicsDocument.</p> * The images are returned as BinaryGraphicsDocument.</p>
*/ */
public final class ImageLoader { public final class ImageConverter {
// The Office document to load images from // The Office document to load images from
private OfficeDocument oooDoc; private OfficeDocument oooDoc;
@ -62,7 +67,7 @@ public final class ImageLoader {
private String sDefaultVectorFormat = null; private String sDefaultVectorFormat = null;
private HashSet<String> acceptedFormats = new HashSet<String>(); private HashSet<String> acceptedFormats = new HashSet<String>();
public ImageLoader(OfficeDocument oooDoc, boolean bExtractEPS) { public ImageConverter(OfficeDocument oooDoc, boolean bExtractEPS) {
this.oooDoc = oooDoc; this.oooDoc = oooDoc;
this.bExtractEPS = bExtractEPS; this.bExtractEPS = bExtractEPS;
this.formatter = new DecimalFormat("000"); this.formatter = new DecimalFormat("000");

View file

@ -16,27 +16,25 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2010 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2010-03-28) * Version 1.4 (2014-08-26)
* *
*/ */
package writer2latex.bibtex; package writer2latex.bibtex;
import writer2latex.xmerge.Document;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Enumeration; import java.util.Enumeration;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import writer2latex.api.ConverterFactory; import writer2latex.api.ConverterFactory;
import writer2latex.api.MIMETypes; import writer2latex.api.MIMETypes;
import writer2latex.api.OutputFile;
import writer2latex.latex.LaTeXConfig; import writer2latex.latex.LaTeXConfig;
import writer2latex.latex.i18n.ClassicI18n; import writer2latex.latex.i18n.ClassicI18n;
import writer2latex.latex.i18n.I18n; import writer2latex.latex.i18n.I18n;
@ -48,7 +46,7 @@ import writer2latex.office.BibMark;
* <p>Class representing a BibTeX document.</p> * <p>Class representing a BibTeX document.</p>
* *
*/ */
public class BibTeXDocument implements Document { public class BibTeXDocument implements OutputFile {
private static final String FILE_EXTENSION = ".bib"; private static final String FILE_EXTENSION = ".bib";
private String sName; private String sName;
@ -73,19 +71,6 @@ public class BibTeXDocument implements Document {
i18n = new ClassicI18n(new LaTeXConfig()); i18n = new ClassicI18n(new LaTeXConfig());
} }
/**
* <p>This method is supposed to read <code>byte</code> data from the InputStream.
* Currently it does nothing, since we don't need it.</p>
*
* @param is InputStream containing a BibTeX data file.
*
* @throws IOException In case of any I/O errors.
*/
public void read(InputStream is) throws IOException {
// Do nothing.
}
/** /**
* <p>Returns the <code>Document</code> name with no file extension.</p> * <p>Returns the <code>Document</code> name with no file extension.</p>
* *
@ -247,4 +232,3 @@ public class BibTeXDocument implements Document {
} }
} }

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2001-2012 by Henrik Just * Copyright: 2001-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* version 1.4 (2012-03-19) * version 1.4 (2014-08-26)
* *
*/ */
@ -35,7 +35,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.DocumentType; import org.w3c.dom.DocumentType;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import writer2latex.xmerge.DOMDocument; import writer2latex.base.DOMDocument;
/** This class creates the required META-INF/container.xml file for an EPUB package /** 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). * (see http://www.idpf.org/ocf/ocf1.0/download/ocf10.htm).

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2001-2011 by Henrik Just * Copyright: 2001-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* version 1.2 (2011-03-04) * version 1.4 (2014-08-27)
* *
*/ */
@ -49,12 +49,12 @@ public class EPUBWriter implements OutputFile {
private ConverterResult xhtmlResult; private ConverterResult xhtmlResult;
private String sFileName; private String sFileName;
private XhtmlConfig config; //private XhtmlConfig config;
public EPUBWriter(ConverterResult xhtmlResult, String sFileName, XhtmlConfig config) { public EPUBWriter(ConverterResult xhtmlResult, String sFileName, XhtmlConfig config) {
this.xhtmlResult = xhtmlResult; this.xhtmlResult = xhtmlResult;
this.sFileName = Misc.removeExtension(sFileName); this.sFileName = Misc.removeExtension(sFileName);
this.config = config; //this.config = config;
} }
public String getFileName() { public String getFileName() {

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2001-2012 by Henrik Just * Copyright: 2001-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* version 1.4 (2012-03-19) * version 1.4 (2014-08-26)
* *
*/ */
@ -39,8 +39,8 @@ import org.w3c.dom.Element;
import writer2latex.api.ContentEntry; import writer2latex.api.ContentEntry;
import writer2latex.api.ConverterResult; import writer2latex.api.ConverterResult;
import writer2latex.base.DOMDocument;
import writer2latex.util.Misc; import writer2latex.util.Misc;
import writer2latex.xmerge.DOMDocument;
/** This class creates the required NXC file for an EPUB document /** 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). * (see http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html#Section2.4).

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2001-2012 by Henrik Just * Copyright: 2001-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* version 1.4 (2012-03-19) * version 1.4 (2014-08-26)
* *
*/ */
@ -43,8 +43,8 @@ import org.w3c.dom.Element;
import writer2latex.api.ContentEntry; import writer2latex.api.ContentEntry;
import writer2latex.api.ConverterResult; import writer2latex.api.ConverterResult;
import writer2latex.api.OutputFile; import writer2latex.api.OutputFile;
import writer2latex.base.DOMDocument;
import writer2latex.util.Misc; import writer2latex.util.Misc;
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). /** This class writes an OPF-file for an EPUB document (see http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html).
*/ */

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-10) * Version 1.4 (2014-08-27)
* *
*/ */
@ -125,19 +125,19 @@ public final class ConverterPalette extends ConverterBase {
public void convertInner() throws IOException { public void convertInner() throws IOException {
sTargetFileName = Misc.trimDocumentName(sTargetFileName,".tex"); sTargetFileName = Misc.trimDocumentName(sTargetFileName,".tex");
String sSafeTargetFileName = new ExportNameCollection(true).getExportName(sTargetFileName); String sSafeTargetFileName = new ExportNameCollection(true).getExportName(sTargetFileName);
imageLoader.setBaseFileName(sSafeTargetFileName+"-img"); imageConverter.setBaseFileName(sSafeTargetFileName+"-img");
if (config.saveImagesInSubdir()) { if (config.saveImagesInSubdir()) {
imageLoader.setUseSubdir(sSafeTargetFileName+"-img"); imageConverter.setUseSubdir(sSafeTargetFileName+"-img");
} }
// Set graphics formats depending on backend // Set graphics formats depending on backend
if (config.getBackend()==LaTeXConfig.PDFTEX || config.getBackend()==LaTeXConfig.XETEX) { if (config.getBackend()==LaTeXConfig.PDFTEX || config.getBackend()==LaTeXConfig.XETEX) {
imageLoader.setDefaultFormat(MIMETypes.PNG); imageConverter.setDefaultFormat(MIMETypes.PNG);
imageLoader.setDefaultVectorFormat(MIMETypes.PDF); imageConverter.setDefaultVectorFormat(MIMETypes.PDF);
imageLoader.addAcceptedFormat(MIMETypes.JPEG); imageConverter.addAcceptedFormat(MIMETypes.JPEG);
} }
else if (config.getBackend()==LaTeXConfig.DVIPS) { else if (config.getBackend()==LaTeXConfig.DVIPS) {
imageLoader.setDefaultFormat(MIMETypes.EPS); imageConverter.setDefaultFormat(MIMETypes.EPS);
} }
// Other values: keep original format // Other values: keep original format

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-25) * Version 1.4 (2014-08-26)
* *
*/ */
@ -32,6 +32,7 @@ import java.util.Stack;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import writer2latex.base.BinaryGraphicsDocument;
import writer2latex.latex.util.BeforeAfter; import writer2latex.latex.util.BeforeAfter;
import writer2latex.latex.util.Context; import writer2latex.latex.util.Context;
import writer2latex.office.EmbeddedObject; import writer2latex.office.EmbeddedObject;
@ -41,7 +42,6 @@ import writer2latex.office.OfficeReader;
import writer2latex.office.XMLString; import writer2latex.office.XMLString;
import writer2latex.util.CSVList; import writer2latex.util.CSVList;
import writer2latex.util.Misc; import writer2latex.util.Misc;
import writer2latex.xmerge.BinaryGraphicsDocument;
/** /**
* <p>This class handles draw elements.</p> * <p>This class handles draw elements.</p>
@ -312,7 +312,7 @@ public class DrawConverter extends ConverterHelper {
(config.getBackend()==LaTeXConfig.DVIPS && MIMETypes.EPS_EXT.equals(sExt))); (config.getBackend()==LaTeXConfig.DVIPS && MIMETypes.EPS_EXT.equals(sExt)));
} }
else { // embedded or base64 encoded image else { // embedded or base64 encoded image
BinaryGraphicsDocument bgd = palette.getImageLoader().getImage(node); BinaryGraphicsDocument bgd = palette.getImageCv().getImage(node);
if (bgd!=null) { if (bgd!=null) {
palette.addDocument(bgd); palette.addDocument(bgd);
sFileName = bgd.getFileName(); sFileName = bgd.getFileName();

View file

@ -16,21 +16,19 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2010 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2010-03-28) * Version 1.4 (2014-08-27)
* *
*/ */
package writer2latex.latex; package writer2latex.latex;
import writer2latex.api.MIMETypes; import writer2latex.api.MIMETypes;
import writer2latex.xmerge.Document; import writer2latex.api.OutputFile;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@ -38,7 +36,7 @@ import java.io.OutputStreamWriter;
* <p>Class representing a LaTeX document.</p> * <p>Class representing a LaTeX document.</p>
* *
*/ */
public class LaTeXDocument implements Document { public class LaTeXDocument implements OutputFile {
private static final String FILE_EXTENSION = ".tex"; private static final String FILE_EXTENSION = ".tex";
private String sName; private String sName;
@ -68,19 +66,6 @@ public class LaTeXDocument implements Document {
contents = new LaTeXDocumentPortion(true); contents = new LaTeXDocumentPortion(true);
} }
/**
* <p>This method is supposed to read <code>byte</code> data from the InputStream.
* Currently it does nothing, since we don't need it.</p>
*
* @param is InputStream containing a LaTeX data file.
*
* @throws IOException In case of any I/O errors.
*/
public void read(InputStream is) throws IOException {
// Do nothing.
}
/** /**
* <p>Returns the <code>Document</code> name with no file extension.</p> * <p>Returns the <code>Document</code> name with no file extension.</p>
* *

View file

@ -146,7 +146,7 @@ public final class MathConverter extends ConverterHelper {
/** Try to convert a draw:frame or draw:g element as an (inline) TexMaths or OOoLaTeX equation /** Try to convert a draw:frame or draw:g element as an (inline) TexMaths or OOoLaTeX equation
* *
* @param the element containing the equation (draw:frame or draw:g) * @param node the element containing the equation (draw:frame or draw:g)
* @param ldp the LaTeXDocumentPortion to contain the converted equation * @param ldp the LaTeXDocumentPortion to contain the converted equation
* *
* @return true if this elements happen to be a TexMaths equation, otherwise false * @return true if this elements happen to be a TexMaths equation, otherwise false

View file

@ -40,8 +40,8 @@ public class EmbeddedBinaryObject extends EmbeddedObject {
* Package private constructor for use when reading an object from a * Package private constructor for use when reading an object from a
* package ODF file * package ODF file
* *
* @param name The name of the object. * @param sName The name of the object.
* @param type The MIME-type of the object. * @param sType The MIME-type of the object.
* @param source A <code>SimpleZipReader</code> containing the object * @param source A <code>SimpleZipReader</code> containing the object
*/ */
protected EmbeddedBinaryObject(String sName, String sType, SimpleZipReader source) { protected EmbeddedBinaryObject(String sName, String sType, SimpleZipReader source) {

View file

@ -37,9 +37,9 @@ public abstract class EmbeddedObject {
* @param sName The name of the object. * @param sName The name of the object.
* @param sType The MIME-type of the object. * @param sType The MIME-type of the object.
*/ */
protected EmbeddedObject(String name, String type) { protected EmbeddedObject(String sName, String sType) {
sName = name; this.sName = sName;
sType = type; this.sType = sType;
} }
/** Get the name of the embedded object represented by this instance. /** Get the name of the embedded object represented by this instance.

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-20) * Version 1.4 (2014-08-27)
* *
*/ */
@ -272,7 +272,7 @@ public class OfficeReader {
if (next.getNextSibling()!=null) { return next.getNextSibling(); } if (next.getNextSibling()!=null) { return next.getNextSibling(); }
// Then move to parent, if this is the text:p node, we are done // Then move to parent, if this is the text:p node, we are done
next = next.getParentNode(); next = next.getParentNode();
if (next.getNodeType()==Node.ELEMENT_NODE && if (next!=null && next.getNodeType()==Node.ELEMENT_NODE &&
next.getNodeName().equals(XMLString.TEXT_P)) { next.getNodeName().equals(XMLString.TEXT_P)) {
return null; return null;
} }

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2007 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 0.5 (2007-03-17) * Version 1.4 (2014-08-27)
* *
*/ */
@ -62,9 +62,9 @@ public class PropertySet {
public String getName() { return sName; } public String getName() { return sName; }
public void loadFromDOM(Node node) { public void loadFromDOM(Node node) {
sName = node.getNodeName();
// read the attributes of the node, if any // read the attributes of the node, if any
if (node!=null) { if (node!=null) {
sName = node.getNodeName();
NamedNodeMap attrNodes = node.getAttributes(); NamedNodeMap attrNodes = node.getAttributes();
if (attrNodes!=null) { if (attrNodes!=null) {
int nLen = attrNodes.getLength(); int nLen = attrNodes.getLength();

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2008 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.0 (2008-11-22) * Version 1.4 (2014-08-27)
* *
*/ */
@ -40,7 +40,7 @@ import writer2latex.util.Misc;
public class TocReader { public class TocReader {
Element tocSource = null; Element tocSource = null;
Element indexBody = null; //Element indexBody = null;
String sName=null; // (section) name for this toc String sName=null; // (section) name for this toc
String sStyleName=null; // section style name String sStyleName=null; // section style name
@ -181,7 +181,7 @@ public class TocReader {
/** <p>Return the generated content of this toc, if available</p> /** <p>Return the generated content of this toc, if available</p>
* @return the <code>text:index-body</code> element * @return the <code>text:index-body</code> element
*/ */
public Element getIndexBody() { return indexBody; } /* public Element getIndexBody() { return indexBody; } */
} }

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2012 by Henrik Just * Copyright: 2002-2014 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2012-02-26) * Version 1.4 (2014-08-27)
* *
*/ */
@ -63,9 +63,8 @@ public class Misc{
// Truncate a date+time to the date only // Truncate a date+time to the date only
public static final String dateOnly(String sDate) { public static final String dateOnly(String sDate) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = null;
try { try {
date = sdf.parse(sDate); sdf.parse(sDate);
} catch (ParseException e) { } catch (ParseException e) {
// If the date cannot be parsed according to the given pattern, return the original string // If the date cannot be parsed according to the given pattern, return the original string
return sDate; return sDate;

View file

@ -67,7 +67,7 @@ public class SimpleZipReader {
* You can only get an entry once: The <code>SimpleZipReader</code> removes the entry from the * You can only get an entry once: The <code>SimpleZipReader</code> removes the entry from the
* collection when this method is called (memory optimization). * collection when this method is called (memory optimization).
* *
* @param name the name (path) of the ZIP entry * @param sName the name (path) of the ZIP entry
* *
* @return a byte array with the contents of the entry, or null if the entry does not exist * @return a byte array with the contents of the entry, or null if the entry does not exist
*/ */

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-13) * Version 1.4 (2014-08-26)
* *
*/ */
@ -248,22 +248,22 @@ public class Converter extends ConverterBase {
l10n = new L10n(); l10n = new L10n();
if (isOPS()) { if (isOPS()) {
imageLoader.setBaseFileName("image"); imageConverter.setBaseFileName("image");
imageLoader.setUseSubdir("images"); imageConverter.setUseSubdir("images");
} }
else { else {
imageLoader.setBaseFileName(sTargetFileName+"-img"); imageConverter.setBaseFileName(sTargetFileName+"-img");
if (config.saveImagesInSubdir()) { if (config.saveImagesInSubdir()) {
imageLoader.setUseSubdir(sTargetFileName+"-img"); imageConverter.setUseSubdir(sTargetFileName+"-img");
} }
} }
imageLoader.setDefaultFormat(MIMETypes.PNG); imageConverter.setDefaultFormat(MIMETypes.PNG);
imageLoader.addAcceptedFormat(MIMETypes.JPEG); imageConverter.addAcceptedFormat(MIMETypes.JPEG);
imageLoader.addAcceptedFormat(MIMETypes.GIF); imageConverter.addAcceptedFormat(MIMETypes.GIF);
if (nType==XhtmlDocument.HTML5 && config.useSVG()) { // HTML supports (inline) SVG as well if (nType==XhtmlDocument.HTML5 && config.useSVG()) { // HTML supports (inline) SVG as well
imageLoader.setDefaultVectorFormat(MIMETypes.SVG); imageConverter.setDefaultVectorFormat(MIMETypes.SVG);
} }
styleCv = new StyleConverter(ofr,config,this,nType); styleCv = new StyleConverter(ofr,config,this,nType);

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-20) * Version 1.4 (2014-08-26)
* *
*/ */
@ -59,7 +59,7 @@ import org.w3c.dom.Element;
import writer2latex.util.Misc; import writer2latex.util.Misc;
import writer2latex.util.CSVList; import writer2latex.util.CSVList;
import writer2latex.util.SimpleXMLParser; import writer2latex.util.SimpleXMLParser;
import writer2latex.xmerge.BinaryGraphicsDocument; import writer2latex.base.BinaryGraphicsDocument;
import writer2latex.office.EmbeddedObject; import writer2latex.office.EmbeddedObject;
import writer2latex.office.EmbeddedXMLObject; import writer2latex.office.EmbeddedXMLObject;
import writer2latex.office.XMLString; import writer2latex.office.XMLString;
@ -480,7 +480,7 @@ public class DrawConverter extends ConverterHelper {
} }
} }
else { // embedded or base64 encoded image else { // embedded or base64 encoded image
bgd = converter.getImageLoader().getImage(onode); bgd = converter.getImageCv().getImage(onode);
if (bgd!=null) { if (bgd!=null) {
sFileName = bgd.getFileName(); sFileName = bgd.getFileName();
// If this is the cover image, add it to the converter result // If this is the cover image, add it to the converter result

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-20) * Version 1.4 (2014-08-26)
* *
*/ */
@ -33,7 +33,7 @@ import org.w3c.dom.NamedNodeMap;
import writer2latex.office.*; import writer2latex.office.*;
import writer2latex.util.Misc; import writer2latex.util.Misc;
import writer2latex.xmerge.BinaryGraphicsDocument; import writer2latex.base.BinaryGraphicsDocument;
import writer2latex.latex.StarMathConverter; import writer2latex.latex.StarMathConverter;
/** This class converts formulas: Either as MathML, as an image or as plain text (StarMath or LaTeX format) /** This class converts formulas: Either as MathML, as an image or as plain text (StarMath or LaTeX format)
@ -151,7 +151,7 @@ public class MathConverter extends ConverterHelper {
// Get the image from the ImageLoader // Get the image from the ImageLoader
String sHref = Misc.getAttribute(onode,XMLString.XLINK_HREF); String sHref = Misc.getAttribute(onode,XMLString.XLINK_HREF);
if (sHref==null || sHref.length()==0 || ofr.isInPackage(sHref)) { if (sHref==null || sHref.length()==0 || ofr.isInPackage(sHref)) {
BinaryGraphicsDocument bgd = converter.getImageLoader().getImage(image); BinaryGraphicsDocument bgd = converter.getImageCv().getImage(image);
if (bgd!=null) { if (bgd!=null) {
String sMIME = bgd.getDocumentMIMEType(); String sMIME = bgd.getDocumentMIMEType();
if (MIMETypes.PNG.equals(sMIME) || MIMETypes.JPEG.equals(sMIME) || MIMETypes.GIF.equals(sMIME)) { if (MIMETypes.PNG.equals(sMIME) || MIMETypes.JPEG.equals(sMIME) || MIMETypes.GIF.equals(sMIME)) {

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-13) * Version 1.4 (2014-08-27)
* *
*/ */
@ -966,15 +966,15 @@ public class TextConverter extends ConverterHelper {
ListCounter counter = getListCounter(ofr.getListStyle(styleName)); ListCounter counter = getListCounter(ofr.getListStyle(styleName));
// Restart numbering, if required // Restart numbering, if required
if (counter!=null) { //if (counter!=null) {
boolean bContinueNumbering = "true".equals(Misc.getAttribute(onode,XMLString.TEXT_CONTINUE_NUMBERING)); boolean bContinueNumbering = "true".equals(Misc.getAttribute(onode,XMLString.TEXT_CONTINUE_NUMBERING));
if (!bContinueNumbering && counter!=null) { if (!bContinueNumbering && counter!=null) {
counter.restart(nLevel); counter.restart(nLevel);
}
if (config.listFormatting()==XhtmlConfig.CSS1_HACK && counter.getValue(nLevel)>0) {
hnode.setAttribute("start",Integer.toString(counter.getValue(nLevel)+1));
}
} }
if (config.listFormatting()==XhtmlConfig.CSS1_HACK && counter.getValue(nLevel)>0) {
hnode.setAttribute("start",Integer.toString(counter.getValue(nLevel)+1));
}
//}
if (onode.hasChildNodes()) { if (onode.hasChildNodes()) {
NodeList nList = onode.getChildNodes(); NodeList nList = onode.getChildNodes();
@ -1001,7 +1001,9 @@ public class TextConverter extends ConverterHelper {
} }
else { else {
// add an li element // add an li element
sCurrentListLabel = counter.step(nLevel).getLabel(); //if (counter!=null) {
sCurrentListLabel = counter.step(nLevel).getLabel();
//}
currentListStyle = ofr.getListStyle(styleName); currentListStyle = ofr.getListStyle(styleName);
nCurrentListLevel = nLevel; nCurrentListLevel = nLevel;
Element item = converter.createElement("li"); Element item = converter.createElement("li");
@ -1016,9 +1018,9 @@ public class TextConverter extends ConverterHelper {
XMLString.TEXT_START_VALUE),1); XMLString.TEXT_START_VALUE),1);
if (bRestart) { if (bRestart) {
item.setAttribute("value",Integer.toString(nStartValue)); item.setAttribute("value",Integer.toString(nStartValue));
if (counter!=null) { //if (counter!=null) {
sCurrentListLabel = counter.restart(nLevel,nStartValue).getLabel(); sCurrentListLabel = counter.restart(nLevel,nStartValue).getLabel();
} //}
} }
} }
traverseListItem(child,nLevel,styleName,item); traverseListItem(child,nLevel,styleName,item);

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.4 (2014-08-13) * Version 1.4 (2014-08-26)
* *
*/ */
@ -32,20 +32,17 @@ package writer2latex.xhtml;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
//import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.DocumentType; import org.w3c.dom.DocumentType;
import org.w3c.dom.DOMImplementation; import org.w3c.dom.DOMImplementation;
//import org.xml.sax.SAXException;
//import org.xml.sax.SAXParseException;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import writer2latex.api.MIMETypes; import writer2latex.api.MIMETypes;
import writer2latex.base.DOMDocument;
import writer2latex.office.XMLString; import writer2latex.office.XMLString;
import writer2latex.xmerge.DOMDocument;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -262,15 +259,13 @@ public class XhtmlDocument extends DOMDocument {
/** /**
* Constructor. This constructor also creates the DOM (minimal: root, head, * Constructor. This constructor also creates the DOM (minimal: root, head,
* title and body node only) - unlike the constructors in * title and body node only)
* writer2latex.xmerge.DOMDocument. * @param name name of this document
* @param name <code>Document</code> name.
* @param nType the type of document * @param nType the type of document
*/ */
public XhtmlDocument(String name, int nType) { public XhtmlDocument(String name, int nType) {
super(name,sExtension[nType]); super(name,sExtension[nType]);
this.nType = nType; this.nType = nType;
// create DOM // create DOM
Document contentDOM = null; Document contentDOM = null;
@ -281,21 +276,21 @@ public class XhtmlDocument extends DOMDocument {
String[] sDocType = getDoctypeStrings(); String[] sDocType = getDoctypeStrings();
DocumentType doctype = domImpl.createDocumentType("html", sDocType[0], sDocType[1]); DocumentType doctype = domImpl.createDocumentType("html", sDocType[0], sDocType[1]);
contentDOM = domImpl.createDocument("http://www.w3.org/1999/xhtml","html",doctype); contentDOM = domImpl.createDocument("http://www.w3.org/1999/xhtml","html",doctype);
contentDOM.getDocumentElement().setAttribute("xmlns","http://www.w3.org/1999/xhtml");
// add head, title and body
headNode = contentDOM.createElement("head");
titleNode = contentDOM.createElement("title");
bodyNode = contentDOM.createElement("body");
contentDOM.getDocumentElement().appendChild(headNode);
headNode.appendChild(titleNode);
contentDOM.getDocumentElement().appendChild(bodyNode);
contentNode = bodyNode;
setContentDOM(contentDOM);
} }
catch (Throwable t) { catch (ParserConfigurationException e) {
t.printStackTrace(); // The newDocumentBuilder() method may in theory throw this, but this will not happen
e.printStackTrace();
} }
contentDOM.getDocumentElement().setAttribute("xmlns","http://www.w3.org/1999/xhtml");
// add head, title and body
headNode = contentDOM.createElement("head");
titleNode = contentDOM.createElement("title");
bodyNode = contentDOM.createElement("body");
contentDOM.getDocumentElement().appendChild(headNode);
headNode.appendChild(titleNode);
contentDOM.getDocumentElement().appendChild(bodyNode);
contentNode = bodyNode;
setContentDOM(contentDOM);
} }
@Override public String getMIMEType() { @Override public String getMIMEType() {

View file

@ -1,86 +0,0 @@
/************************************************************************
*
* The Contents of this file are made available subject to the terms of
*
* - GNU Lesser General Public License Version 2.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
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
* This version is adapted for Writer2LaTeX
* version 1.0 (2008-11-22)
*
************************************************************************/
package writer2latex.xmerge;
//import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
import writer2latex.api.OutputFile;
/**
* <p>A <code>Document</code> represents any <code>Document</code>
* to be converted and the resulting <code>Document</code> from any
* conversion.</p>
*
*
* @author Herbie Ong
*/
public interface Document extends OutputFile {
/**
* <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();
}

View file

@ -1,15 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>The package writer2latex.xmerge</title>
</head>
<body>
<p>Classes originating from OOo's xmerge.</p>
<p>Previously, Writer2LaTeX was based on xmerge, but this is not the case
anymore. The classes in this packages are reminiscent of that.</p>
<p>This package is supposed to go away in a future version and be replaced by
something else (probably ODFDOM)</p>
</body>
</html>