diff --git a/source/java/org/openoffice/da/comp/w2lcommon/filter/ExportFilterBase.java b/source/java/org/openoffice/da/comp/w2lcommon/filter/ExportFilterBase.java index 6e7ce0c..ca6d439 100644 --- a/source/java/org/openoffice/da/comp/w2lcommon/filter/ExportFilterBase.java +++ b/source/java/org/openoffice/da/comp/w2lcommon/filter/ExportFilterBase.java @@ -45,7 +45,6 @@ import com.sun.star.xml.XExportFilter; import org.openoffice.da.comp.w2lcommon.helper.MessageBox; import writer2latex.api.Converter; import writer2latex.api.ConverterFactory; -import writer2latex.api.ConverterResult; import writer2latex.api.OutputFile; import writer2latex.util.Misc; import writer2latex.util.SimpleDOMBuilder; @@ -226,105 +225,97 @@ XTypeProvider { public void convert (org.w3c.dom.Document dom,com.sun.star.io.XOutputStream exportStream) throws com.sun.star.uno.RuntimeException, IOException { - // Initialize the file access - sfa2 = null; - try { - Object sfaObject = xComponentContext.getServiceManager().createInstanceWithContext( - "com.sun.star.ucb.SimpleFileAccess", xComponentContext); - sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject); - } - catch (com.sun.star.uno.Exception e) { - // failed to get SimpleFileAccess service (should not happen) - } - - // Get base name from the URL provided by OOo - String sName= getFileName(sURL); - - // Create converter + // Create converter and supply it with filter data and a suitable graphic converter Converter converter = ConverterFactory.createConverter(sdMime); if (converter==null) { 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 if (filterData!=null) { FilterDataParser fdp = new FilterDataParser(xComponentContext); fdp.applyFilterData(filterData,converter); } - - // Do conversion converter.setGraphicConverter(new GraphicConverterImpl(xComponentContext)); + + // Do conversion. The base name is take from the URL provided by the office + Iterator docEnum = converter.convert(dom,Misc.makeFileName(getFileName(sURL))).iterator(); - ConverterResult dataOut = converter.convert(dom,Misc.makeFileName(sName)); - - // Write out files - Iterator docEnum = dataOut.iterator(); - - // Remove the file name part of the URL - String sNewURL = null; - if (sURL.lastIndexOf("/")>-1) { - // Take the URL up to and including the last slash - sNewURL = sURL.substring(0,sURL.lastIndexOf("/")+1); + if (docEnum.hasNext()) { + // The master document is written to the XOutStream supplied by the XMLFilterAdaptor + XOutputStreamToOutputStreamAdapter newxos =new XOutputStreamToOutputStreamAdapter(exportStream); + docEnum.next().write(newxos); + newxos.flush(); + newxos.close(); + + if (docEnum.hasNext() && sURL.startsWith("file:")) { + // Additional files are written directly using UCB + // Initialize the file access (used to write all additional output files) + sfa2 = null; + try { + Object sfaObject = xComponentContext.getServiceManager().createInstanceWithContext( + "com.sun.star.ucb.SimpleFileAccess", xComponentContext); + sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject); + } + catch (com.sun.star.uno.Exception e) { + // failed to get SimpleFileAccess service (should not happen) + } + + if (sfa2!=null) { + // Remove the file name part of the URL + String sNewURL = null; + if (sURL.lastIndexOf("/")>-1) { + // Take the URL up to and including the last slash + sNewURL = sURL.substring(0,sURL.lastIndexOf("/")+1); + } + else { + // The URL does not include a path; this should not really happen, + // but in this case we will write to the current default directory + sNewURL = ""; + } + + while (docEnum.hasNext()) { + OutputFile docOut = docEnum.next(); + // Get the file name and the (optional) directory name + String sFullFileName = Misc.makeHref(docOut.getFileName()); + String sDirName = ""; + String sFileName = sFullFileName; + int nSlash = sFileName.indexOf("/"); + if (nSlash>-1) { + sDirName = sFileName.substring(0,nSlash); + sFileName = sFileName.substring(nSlash+1); + } + + try{ + // Create subdirectory if required + if (sDirName.length()>0 && !sfa2.exists(sNewURL+sDirName)) { + sfa2.createFolder(sNewURL+sDirName); + } + + // writeFile demands an InputStream, so we need a pipe + Object xPipeObj=xMSF.createInstance("com.sun.star.io.Pipe"); + XInputStream xInStream = (XInputStream) UnoRuntime.queryInterface(XInputStream.class, xPipeObj ); + XOutputStream xOutStream = (XOutputStream) UnoRuntime.queryInterface(XOutputStream.class, xPipeObj ); + OutputStream outStream = new XOutputStreamToOutputStreamAdapter(xOutStream); + // Feed the pipe with content... + docOut.write(outStream); + outStream.flush(); + outStream.close(); + xOutStream.closeOutput(); + // ...and then write the content to the URL + sfa2.writeFile(sNewURL+sFullFileName,xInStream); + } + catch (Throwable e){ + MessageBox msgBox = new MessageBox(xComponentContext); + msgBox.showMessage(__displayName+": Error writing files", + e.toString()+" at "+e.getStackTrace()[0].toString()); + } + } + } + } } else { - // The URL does not include a path; this should not really happen, - // but in this case we will write to the current default directory - sNewURL = ""; - } - - while (docEnum.hasNext() && sURL.startsWith("file:")) { - OutputFile docOut = docEnum.next(); - - if (dataOut.getMasterDocument()==docOut) { - // The master document is written to the XOutStream supplied - // by the XMLFilterAdaptor - docOut.write(newxos); - newxos.flush(); - newxos.close(); - } - else { - // Additional files are written directly using UCB - - // Get the file name and the (optional) directory name - String sFullFileName = Misc.makeHref(docOut.getFileName()); - String sDirName = ""; - String sFileName = sFullFileName; - int nSlash = sFileName.indexOf("/"); - if (nSlash>-1) { - sDirName = sFileName.substring(0,nSlash); - sFileName = sFileName.substring(nSlash+1); - } - - try{ - // Create subdirectory if required - if (sDirName.length()>0 && !sfa2.exists(sNewURL+sDirName)) { - sfa2.createFolder(sNewURL+sDirName); - } - - // writeFile demands an InputStream, so we need a pipe - Object xPipeObj=xMSF.createInstance("com.sun.star.io.Pipe"); - XInputStream xInStream - = (XInputStream) UnoRuntime.queryInterface(XInputStream.class, xPipeObj ); - XOutputStream xOutStream - = (XOutputStream) UnoRuntime.queryInterface(XOutputStream.class, xPipeObj ); - OutputStream outStream = new XOutputStreamToOutputStreamAdapter(xOutStream); - // Feed the pipe with content... - docOut.write(outStream); - outStream.flush(); - outStream.close(); - xOutStream.closeOutput(); - // ...and then write the content to the URL - sfa2.writeFile(sNewURL+sFullFileName,xInStream); - } - catch (Throwable e){ - MessageBox msgBox = new MessageBox(xComponentContext); - msgBox.showMessage(__displayName+": Error writing files", - e.toString()+" at "+e.getStackTrace()[0].toString()); - } - } + // The converter did not produce any files (should not happen) + MessageBox msgBox = new MessageBox(xComponentContext); + msgBox.showMessage(__displayName+": Conversion failed","Internal error"); } } diff --git a/source/java/writer2latex/api/ConverterFactory.java b/source/java/writer2latex/api/ConverterFactory.java index 9ab05fe..a1b7448 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-08-25) + * Version 1.4 (2012-08-27) * */ @@ -33,7 +33,7 @@ public class ConverterFactory { // Version information private static final String VERSION = "1.3.2"; - private static final String DATE = "2014-08-24"; + private static final String DATE = "2014-08-27"; /** Return the Writer2LaTeX version in the form * (major version).(minor version).(patch level)
diff --git a/source/java/writer2latex/base/BatchConverterBase.java b/source/java/writer2latex/base/BatchConverterBase.java index cebf051..04999d3 100644 --- a/source/java/writer2latex/base/BatchConverterBase.java +++ b/source/java/writer2latex/base/BatchConverterBase.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2008 by Henrik Just + * Copyright: 2002-2014 by Henrik Just * * All Rights Reserved. * - * Version 1.0 (2008-10-15) + * Version 1.4 (2014-08-27) * */ @@ -175,7 +175,7 @@ public abstract class BatchConverterBase implements BatchConverter { handler.endFile(infile.getPath(),true); - return dataOut.getMasterDocument().getFileName(); + return dataOut.iterator().next().getFileName(); } diff --git a/source/java/writer2latex/latex/PageStyleConverter.java b/source/java/writer2latex/latex/PageStyleConverter.java index ecc1411..3bc2a88 100644 --- a/source/java/writer2latex/latex/PageStyleConverter.java +++ b/source/java/writer2latex/latex/PageStyleConverter.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-2014 by Henrik Just * * All Rights Reserved. * - * Version 1.2 (2009-09-17) + * Version 1.4 (2014-08-27) * */ @@ -157,7 +157,7 @@ public class PageStyleConverter extends StyleConverter { context.setInHeaderFooter(true); - Enumeration styles = ofr.getMasterPages().getStylesEnumeration(); + Enumeration styles = ofr.getMasterPages().getStylesEnumeration(); ldp.append("% Pages styles").nl(); if (!config.useFancyhdr()) { ldp.append("\\makeatletter").nl(); @@ -385,7 +385,7 @@ public class PageStyleConverter extends StyleConverter { boolean bIncludeHead = false; boolean bIncludeFoot = false; // Look through all applied page layouts and use largest heights - Enumeration masters = ofr.getMasterPages().getStylesEnumeration(); + Enumeration masters = ofr.getMasterPages().getStylesEnumeration(); while (masters.hasMoreElements()) { MasterPage master = (MasterPage) masters.nextElement(); if (styleNames.containsName(getDisplayName(master.getName()))) { diff --git a/source/java/writer2latex/office/OfficeReader.java b/source/java/writer2latex/office/OfficeReader.java index 72e90d5..fb9891e 100644 --- a/source/java/writer2latex/office/OfficeReader.java +++ b/source/java/writer2latex/office/OfficeReader.java @@ -519,7 +519,7 @@ public class OfficeReader { * @return the iso language */ public String getMajorityLanguage() { - Hashtable langs = new Hashtable(); + Hashtable langs = new Hashtable(); // Read the default language from the default paragraph style String sDefaultLang = null; @@ -529,7 +529,7 @@ public class OfficeReader { } // Collect languages from paragraph styles - Enumeration enumeration = getParStyles().getStylesEnumeration(); + Enumeration enumeration = getParStyles().getStylesEnumeration(); while (enumeration.hasMoreElements()) { style = (StyleWithProperties) enumeration.nextElement(); String sLang = style.getProperty(XMLString.FO_LANGUAGE); @@ -546,9 +546,9 @@ public class OfficeReader { // Find the most common language int nMaxCount = 0; String sMajorityLanguage = null; - enumeration = langs.keys(); - while (enumeration.hasMoreElements()) { - String sLang = (String) enumeration.nextElement(); + Enumeration langenum = langs.keys(); + while (langenum.hasMoreElements()) { + String sLang = langenum.nextElement(); int nCount = langs.get(sLang).intValue(); if (nCount>nMaxCount) { nMaxCount = nCount; diff --git a/source/java/writer2latex/office/OfficeStyleFamily.java b/source/java/writer2latex/office/OfficeStyleFamily.java index c9cc939..cfb6f39 100644 --- a/source/java/writer2latex/office/OfficeStyleFamily.java +++ b/source/java/writer2latex/office/OfficeStyleFamily.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2008 by Henrik Just + * Copyright: 2002-2014 by Henrik Just * * All Rights Reserved. * - * Version 1.0 (2008-11-23) + * Version 1.4 (2014-08-27) * */ @@ -33,8 +33,8 @@ import writer2latex.util.Misc; /** Container class representing a style family in OOo */ public class OfficeStyleFamily { - private Hashtable styles = new Hashtable(); - private Class styleClass; + private Hashtable styles = new Hashtable(); + private Class styleClass; private Hashtable displayNames = new Hashtable(); @@ -44,7 +44,7 @@ public class OfficeStyleFamily { * @param styleClass the subclass of OfficeStyle used to represent styles * in this family */ - public OfficeStyleFamily(Class styleClass) { + public OfficeStyleFamily(Class styleClass) { this.styleClass = styleClass; } @@ -70,7 +70,7 @@ public class OfficeStyleFamily { */ public OfficeStyle getStyle(String sName) { if (sName==null) { return null; } - else { return (OfficeStyle) styles.get(sName); } + else { return styles.get(sName); } } /** Get a style by display name. Automatic styles does not have a display @@ -101,7 +101,7 @@ public class OfficeStyleFamily { /** Get all named styles in the family (ie. excluding the default style) * @return an enumeration of all styles represented by OfficeStyle objects */ - public Enumeration getStylesEnumeration(){ + public Enumeration getStylesEnumeration(){ return styles.elements(); } @@ -113,7 +113,7 @@ public class OfficeStyleFamily { String sName = Misc.getAttribute(node,XMLString.STYLE_NAME); if (sName!=null) { try { - OfficeStyle style = (OfficeStyle) styleClass.newInstance(); + OfficeStyle style = styleClass.newInstance(); style.sName=sName; style.family=this; style.bAutomatic=bAutomatic; diff --git a/source/java/writer2latex/xhtml/Converter.java b/source/java/writer2latex/xhtml/Converter.java index 15b787d..a644129 100644 --- a/source/java/writer2latex/xhtml/Converter.java +++ b/source/java/writer2latex/xhtml/Converter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.4 (2014-08-26) + * Version 1.4 (2014-08-27) * */ @@ -100,8 +100,8 @@ public class Converter extends ConverterBase { private XhtmlDocument htmlDoc; // current outfile private Document htmlDOM; // current DOM, usually within htmlDoc private boolean bNeedHeaderFooter = false; - private int nTocFileIndex = -1; - private int nAlphabeticalIndex = -1; + //private int nTocFileIndex = -1; + //private int nAlphabeticalIndex = -1; // Hyperlinks Hashtable targets = new Hashtable(); @@ -201,7 +201,7 @@ public class Converter extends ConverterBase { protected void setTocFile(String sTarget) { converterResult.setTocFile(new ContentEntryImpl(l10n.get(L10n.CONTENTS),1,htmlDoc,sTarget)); - nTocFileIndex = nOutFileIndex; + //nTocFileIndex = nOutFileIndex; } protected void setLofFile(String sTarget) { @@ -214,7 +214,7 @@ public class Converter extends ConverterBase { protected void setIndexFile(String sTarget) { converterResult.setIndexFile(new ContentEntryImpl(l10n.get(L10n.INDEX),1,htmlDoc,sTarget)); - nAlphabeticalIndex = nOutFileIndex; + //nAlphabeticalIndex = nOutFileIndex; } protected void setCoverFile(String sTarget) {