Use UNOPublisher in the w2l toolbar
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@203 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
88c3a7295d
commit
435bbee042
8 changed files with 475 additions and 602 deletions
|
@ -3,15 +3,15 @@ Changelog for Writer2LaTeX version 1.4 -> 1.6
|
|||
---------- version 1.5.1 ----------
|
||||
|
||||
[w2l] Merged the extension Writer4LaTeX into Writer2LaTeX, where it now appears as "the Writer2LaTeX toolbar".
|
||||
Replaced menu with a toolbar with four buttons: Insert BibTeX citation (not yet implemented), publish to LaTeX,
|
||||
view log files and edit custom format. (Publishing without showing the dialog is currently removed.)
|
||||
Using the toolbar bypasses the filter logic, which gives a significant performance gain for large documents.
|
||||
|
||||
[all] Implementation detail: Replaced Robert Harder's base 64 class with javax.xml.bind.DatatypeConverter
|
||||
|
||||
[w2x] Style maps for paragraphs and headings now support the attributes before and after. These define fixed texts
|
||||
to add before/after the content. (This is similar to the pseudo-elements ::before and ::after in CSS.)
|
||||
|
||||
[w4l] Replaced menu with a toolbar with four buttons: Insert BibTeX citation (not yet implemented), publish to LaTeX,
|
||||
view log files and edit custom format. (Publishing without showing the dialog is currently removed.)
|
||||
|
||||
[w2x] Added toolbar with four buttons: Publish directly to XHTML, publish directly to EPUB, edit EPUB metadata
|
||||
and edit custom configuration. Publishing directly implies that the file picker is not displayed. Instead
|
||||
the document will be exported to the same directory as the currently open document and with the same name.
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-10-22)
|
||||
* Version 1.6 (2014-11-03)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
|
||||
import writer2latex.util.Misc;
|
||||
|
@ -52,19 +53,23 @@ public class UNOPublisher {
|
|||
|
||||
public enum TargetFormat { xhtml, xhtml11, xhtml_mathml, html5, epub, latex };
|
||||
|
||||
private XComponentContext xContext;
|
||||
private XFrame xFrame;
|
||||
private XModel xModel=null;
|
||||
private String sAppName;
|
||||
|
||||
protected XComponentContext xContext;
|
||||
protected XFrame xFrame;
|
||||
private XModel xModel = null;
|
||||
private PropertyValue[] mediaProps = null;
|
||||
|
||||
/** Create a new <code>UNOPublisher</code> based on a loaded office document
|
||||
*
|
||||
* @param xContext the component context from which new UNO services are instantiated
|
||||
* @param xFrame the current frame
|
||||
* @param sAppName the name of the application using the <code>UNOPublisher</code>
|
||||
*/
|
||||
public UNOPublisher(XComponentContext xContext, XFrame xFrame) {
|
||||
public UNOPublisher(XComponentContext xContext, XFrame xFrame, String sAppName) {
|
||||
this.xContext = xContext;
|
||||
this.xFrame = xFrame;
|
||||
this.sAppName = sAppName;
|
||||
// Get the model for the document from the frame
|
||||
XController xController = xFrame.getController();
|
||||
if (xController!=null) {
|
||||
|
@ -72,28 +77,29 @@ public class UNOPublisher {
|
|||
}
|
||||
}
|
||||
|
||||
/** Publish the document associated with this <code>UNOPublisher</code>. This involves four steps:
|
||||
/** Publish the document associated with this <code>UNOPublisher</code>. This involves five steps:
|
||||
* (1) Check that the document is saved in the local file system.
|
||||
* (2) Display the options dialog.
|
||||
* (3) Save the document (if the modified flag is true).
|
||||
* (4) Convert the document.
|
||||
* (5) Post process the document, e.g. displaying the result
|
||||
*
|
||||
* @param format the target format
|
||||
* @return the URL of the converted document, or null if the document was not converted
|
||||
* @return true if the publishing was succesful
|
||||
*/
|
||||
public String publish(TargetFormat format) {
|
||||
public boolean publish(TargetFormat format) {
|
||||
if (documentSaved() && updateMediaProperties(format)) {
|
||||
// Create a (somewhat coarse grained) status indicator/progress bar
|
||||
XStatusIndicatorFactory xFactory = (com.sun.star.task.XStatusIndicatorFactory)
|
||||
UnoRuntime.queryInterface(com.sun.star.task.XStatusIndicatorFactory.class, xFrame);
|
||||
XStatusIndicator xStatus = xFactory.createStatusIndicator();
|
||||
xStatus.start("Writer2xhtml",10);
|
||||
xStatus.start(sAppName,10);
|
||||
xStatus.setValue(1); // At least we have started, that's 10% :-)
|
||||
|
||||
try {
|
||||
// Save document if required
|
||||
saveDocument();
|
||||
xStatus.setValue(4);
|
||||
xStatus.setValue(4); // Document saved, that's 40%
|
||||
|
||||
// Convert to desired format
|
||||
UNOConverter converter = new UNOConverter(mediaProps, xContext);
|
||||
|
@ -114,39 +120,82 @@ public class UNOPublisher {
|
|||
catch (IOException e) {
|
||||
xStatus.end();
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("Writer2xhtml","Error: Failed to export document");
|
||||
return null;
|
||||
msgBox.showMessage(sAppName,"Error: Failed to export document");
|
||||
return false;
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
xStatus.end();
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("Writer2xhtml","Error: Failed to export document");
|
||||
return null;
|
||||
msgBox.showMessage(sAppName,"Error: Failed to export document");
|
||||
return false;
|
||||
}
|
||||
xStatus.setValue(7); // Document is converted, that's 70%
|
||||
|
||||
postProcess(getTargetURL(format));
|
||||
|
||||
xStatus.setValue(10); // Export is finished (The user will usually not see this...)
|
||||
xStatus.end();
|
||||
return getTargetURL(format);
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean documentSaved() {
|
||||
/** Filter the file name to avoid unwanted characters
|
||||
*
|
||||
* @param sFileName the original file name
|
||||
* @return the filtered file name
|
||||
*/
|
||||
protected String filterFileName(String sFileName) {
|
||||
return sFileName;
|
||||
}
|
||||
|
||||
/** Post process the media properties after displaying the dialog
|
||||
*
|
||||
* @param mediaProps the media properties as set by the dialog
|
||||
* @return the updated media properties
|
||||
*/
|
||||
protected PropertyValue[] postProcessMediaProps(PropertyValue[] mediaProps) {
|
||||
return mediaProps;
|
||||
}
|
||||
|
||||
/** Post process the document after conversion.
|
||||
*
|
||||
* @param format URL of the converted document
|
||||
*/
|
||||
protected void postProcess(String sTargetURL) {
|
||||
}
|
||||
|
||||
/** Check that the document is saved in a location, we can use
|
||||
*
|
||||
* @return true if everthing is o.k.
|
||||
*/
|
||||
public boolean documentSaved() {
|
||||
String sDocumentUrl = xModel.getURL();
|
||||
if (sDocumentUrl.length()==0) { // The document has no location
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("Writer2xhtml","Please save the document before publishing the file");
|
||||
msgBox.showMessage(sAppName,"Please save the document before publishing the file");
|
||||
return false;
|
||||
}
|
||||
else if (!".odt".equals(Misc.getFileExtension(sDocumentUrl)) && !".fodt".equals(Misc.getFileExtension(sDocumentUrl))) {
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("Writer2xhtml","Please save the document in OpenDocument format (.odt)");
|
||||
msgBox.showMessage(sAppName,"Please save the document in OpenDocument format (.odt)");
|
||||
return false;
|
||||
}
|
||||
else if (!sDocumentUrl.startsWith("file:")) {
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("Writer2xhtml","Please save the document in the local file system");
|
||||
msgBox.showMessage(sAppName,"Please save the document in the local file system");
|
||||
return false;
|
||||
}
|
||||
else if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
// Avoid UNC paths (LaTeX does not like them)
|
||||
Pattern windowsPattern = Pattern.compile("^file:///[A-Za-z][|:].*");
|
||||
if (!windowsPattern.matcher(sDocumentUrl).matches()) {
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage(sAppName,
|
||||
"Please save the document on a location with a drive name");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -164,8 +213,33 @@ public class UNOPublisher {
|
|||
}
|
||||
|
||||
// Some utility methods
|
||||
private String getTargetURL(TargetFormat format) {
|
||||
return Misc.removeExtension(xModel.getURL())+getTargetExtension(format);
|
||||
|
||||
/** Get the target path (or null if the document is not saved)
|
||||
*
|
||||
* @return the path
|
||||
*/
|
||||
public String getTargetPath() {
|
||||
if (xModel.getURL().length()>0) {
|
||||
String sBaseURL = Misc.removeExtension(xModel.getURL());
|
||||
return Misc.getPath(sBaseURL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Get the target file name (or null if the document is not saved)
|
||||
*
|
||||
* @return the file name
|
||||
*/
|
||||
public String getTargetFileName() {
|
||||
if (xModel.getURL().length()>0) {
|
||||
String sBaseURL = Misc.removeExtension(xModel.getURL());
|
||||
return filterFileName(Misc.getFileName(sBaseURL));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getTargetURL(TargetFormat format) {
|
||||
return getTargetPath()+getTargetFileName()+getTargetExtension(format);
|
||||
}
|
||||
|
||||
private void prepareMediaProperties(TargetFormat format) {
|
||||
|
@ -194,7 +268,8 @@ public class UNOPublisher {
|
|||
XExecutableDialog xDialog = (XExecutableDialog)
|
||||
UnoRuntime.queryInterface(XExecutableDialog.class, dialog);
|
||||
if (xDialog.execute()==ExecutableDialogResults.OK) {
|
||||
mediaProps = xPropertyAccess.getPropertyValues();
|
||||
mediaProps = postProcessMediaProps(xPropertyAccess.getPropertyValues());
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -233,7 +308,7 @@ public class UNOPublisher {
|
|||
case xhtml_mathml: return "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialogMath";
|
||||
case html5: return "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialogMath";
|
||||
case epub: return "org.openoffice.da.comp.writer2xhtml.EpubOptionsDialog";
|
||||
case latex: return "org.openoffice.da.comp.writer2xhtml.LaTeXOptionsDialog";
|
||||
case latex: return "org.openoffice.da.comp.writer2latex.LaTeXOptionsDialog";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +320,7 @@ public class UNOPublisher {
|
|||
case xhtml_mathml: return "org.openoffice.da.writer2xhtml.mathml";
|
||||
case html5: return "org.openoffice.da.writer2xhtml5";
|
||||
case epub: return "org.openoffice.da.writer2xhtml.epub";
|
||||
case latex: return "org.openoffice.da.writer2latex.latex";
|
||||
case latex: return "org.openoffice.da.writer2latex";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,259 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* LaTeXUNOPublisher.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-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-11-03)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.writer2latex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.filter.UNOPublisher;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
|
||||
|
||||
import writer2latex.util.CSVList;
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class LaTeXUNOPublisher extends UNOPublisher {
|
||||
|
||||
// The TeXifier and associated data
|
||||
private TeXify texify = null;
|
||||
private String sBibinputs=null;
|
||||
private String sBackend = "generic";
|
||||
|
||||
public LaTeXUNOPublisher(XComponentContext xContext, XFrame xFrame, String sAppName) {
|
||||
super(xContext, xFrame, sAppName);
|
||||
}
|
||||
|
||||
/** Make a file name LaTeX friendly
|
||||
*/
|
||||
@Override protected String filterFileName(String sFileName) {
|
||||
String sResult = "";
|
||||
for (int i=0; i<sFileName.length(); i++) {
|
||||
char c = sFileName.charAt(i);
|
||||
if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) {
|
||||
sResult += Character.toString(c);
|
||||
}
|
||||
else {
|
||||
switch (c) {
|
||||
case '.': sResult += "."; break;
|
||||
case '-': sResult += "-"; break;
|
||||
case ' ' : sResult += "-"; break;
|
||||
case '_' : sResult += "-"; break;
|
||||
// Replace accented and national characters
|
||||
case '\u00c0' : sResult += "A"; break;
|
||||
case '\u00c1' : sResult += "A"; break;
|
||||
case '\u00c2' : sResult += "A"; break;
|
||||
case '\u00c3' : sResult += "A"; break;
|
||||
case '\u00c4' : sResult += "AE"; break;
|
||||
case '\u00c5' : sResult += "AA"; break;
|
||||
case '\u00c6' : sResult += "AE"; break;
|
||||
case '\u00c7' : sResult += "C"; break;
|
||||
case '\u00c8' : sResult += "E"; break;
|
||||
case '\u00c9' : sResult += "E"; break;
|
||||
case '\u00ca' : sResult += "E"; break;
|
||||
case '\u00cb' : sResult += "E"; break;
|
||||
case '\u00cc' : sResult += "I"; break;
|
||||
case '\u00cd' : sResult += "I"; break;
|
||||
case '\u00ce' : sResult += "I"; break;
|
||||
case '\u00cf' : sResult += "I"; break;
|
||||
case '\u00d0' : sResult += "D"; break;
|
||||
case '\u00d1' : sResult += "N"; break;
|
||||
case '\u00d2' : sResult += "O"; break;
|
||||
case '\u00d3' : sResult += "O"; break;
|
||||
case '\u00d4' : sResult += "O"; break;
|
||||
case '\u00d5' : sResult += "O"; break;
|
||||
case '\u00d6' : sResult += "OE"; break;
|
||||
case '\u00d8' : sResult += "OE"; break;
|
||||
case '\u00d9' : sResult += "U"; break;
|
||||
case '\u00da' : sResult += "U"; break;
|
||||
case '\u00db' : sResult += "U"; break;
|
||||
case '\u00dc' : sResult += "UE"; break;
|
||||
case '\u00dd' : sResult += "Y"; break;
|
||||
case '\u00df' : sResult += "sz"; break;
|
||||
case '\u00e0' : sResult += "a"; break;
|
||||
case '\u00e1' : sResult += "a"; break;
|
||||
case '\u00e2' : sResult += "a"; break;
|
||||
case '\u00e3' : sResult += "a"; break;
|
||||
case '\u00e4' : sResult += "ae"; break;
|
||||
case '\u00e5' : sResult += "aa"; break;
|
||||
case '\u00e6' : sResult += "ae"; break;
|
||||
case '\u00e7' : sResult += "c"; break;
|
||||
case '\u00e8' : sResult += "e"; break;
|
||||
case '\u00e9' : sResult += "e"; break;
|
||||
case '\u00ea' : sResult += "e"; break;
|
||||
case '\u00eb' : sResult += "e"; break;
|
||||
case '\u00ec' : sResult += "i"; break;
|
||||
case '\u00ed' : sResult += "i"; break;
|
||||
case '\u00ee' : sResult += "i"; break;
|
||||
case '\u00ef' : sResult += "i"; break;
|
||||
case '\u00f0' : sResult += "d"; break;
|
||||
case '\u00f1' : sResult += "n"; break;
|
||||
case '\u00f2' : sResult += "o"; break;
|
||||
case '\u00f3' : sResult += "o"; break;
|
||||
case '\u00f4' : sResult += "o"; break;
|
||||
case '\u00f5' : sResult += "o"; break;
|
||||
case '\u00f6' : sResult += "oe"; break;
|
||||
case '\u00f8' : sResult += "oe"; break;
|
||||
case '\u00f9' : sResult += "u"; break;
|
||||
case '\u00fa' : sResult += "u"; break;
|
||||
case '\u00fb' : sResult += "u"; break;
|
||||
case '\u00fc' : sResult += "ue"; break;
|
||||
case '\u00fd' : sResult += "y"; break;
|
||||
case '\u00ff' : sResult += "y"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sResult.length()==0) { return "writer2latex"; }
|
||||
else { return sResult; }
|
||||
}
|
||||
|
||||
/** Post process the filter data: Set bibliography options and
|
||||
* determine the backend and the BIBINPUTS directory
|
||||
*/
|
||||
@Override protected PropertyValue[] postProcessMediaProps(PropertyValue[] mediaProps) {
|
||||
sBackend = "generic";
|
||||
sBibinputs = null;
|
||||
|
||||
PropertyHelper mediaHelper = new PropertyHelper(mediaProps);
|
||||
Object filterData = mediaHelper.get("FilterData");
|
||||
if (filterData instanceof PropertyValue[]) {
|
||||
PropertyHelper filterHelper = new PropertyHelper((PropertyValue[])filterData);
|
||||
|
||||
// Get the backend
|
||||
Object backend = filterHelper.get("backend");
|
||||
if (backend instanceof String) {
|
||||
sBackend = (String) backend;
|
||||
}
|
||||
|
||||
// Set the bibliography options according to the settings
|
||||
RegistryHelper registry = new RegistryHelper(xContext);
|
||||
try {
|
||||
Object view = registry.getRegistryView(BibliographyDialog.REGISTRY_PATH, false);
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
String sBibTeXFiles = getFileList(XPropertySetHelper.getPropertyValueAsShort(xProps, "BibTeXLocation"),
|
||||
XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir"));
|
||||
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertZoteroCitations")) {
|
||||
filterHelper.put("zotero_bibtex_files", sBibTeXFiles);
|
||||
}
|
||||
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertJabRefCitations")) {
|
||||
filterHelper.put("jabref_bibtex_files", sBibTeXFiles);
|
||||
}
|
||||
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "UseExternalBibTeXFiles")) {
|
||||
filterHelper.put("external_bibtex_files", sBibTeXFiles);
|
||||
}
|
||||
filterHelper.put("include_original_citations",
|
||||
Boolean.toString(XPropertySetHelper.getPropertyValueAsBoolean(xProps, "IncludeOriginalCitations")));
|
||||
String sBibTeXDir = XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir");
|
||||
if (sBibTeXDir.length()>0) {
|
||||
// The separator character in BIBINPUTS is OS specific
|
||||
sBibinputs = sBibTeXDir+File.pathSeparatorChar;
|
||||
}
|
||||
filterHelper.put("use_natbib", Boolean.toString(XPropertySetHelper.getPropertyValueAsBoolean(xProps, "UseNatbib")));
|
||||
filterHelper.put("natbib_options", XPropertySetHelper.getPropertyValueAsString(xProps, "NatbibOptions"));
|
||||
|
||||
mediaHelper.put("FilterData",filterHelper.toArray());
|
||||
PropertyValue[] newMediaProps = mediaHelper.toArray();
|
||||
registry.disposeRegistryView(view);
|
||||
return newMediaProps;
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Failed to get registry view; return original media props
|
||||
return mediaProps;
|
||||
}
|
||||
}
|
||||
// No filter data; return original media props
|
||||
return mediaProps;
|
||||
}
|
||||
|
||||
/** Postprocess the converted document with LaTeX and display the result
|
||||
*/
|
||||
@Override protected void postProcess(String sURL) {
|
||||
if (texify==null) { texify = new TeXify(xContext); }
|
||||
File file = new File(Misc.urlToFile(getTargetPath()),getTargetFileName());
|
||||
|
||||
boolean bResult = true;
|
||||
|
||||
try {
|
||||
if (sBackend=="pdftex") {
|
||||
bResult = texify.process(file, sBibinputs, TeXify.PDFTEX, true);
|
||||
}
|
||||
else if (sBackend=="dvips") {
|
||||
bResult = texify.process(file, sBibinputs, TeXify.DVIPS, true);
|
||||
}
|
||||
else if (sBackend=="xetex") {
|
||||
bResult = texify.process(file, sBibinputs, TeXify.XETEX, true);
|
||||
}
|
||||
else if (sBackend=="generic") {
|
||||
bResult = texify.process(file, sBibinputs, TeXify.GENERIC, true);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("Writer2LaTeX","Error: "+e.getMessage());
|
||||
}
|
||||
|
||||
if (!bResult) {
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("Writer2LaTeX","Error: Failed to execute LaTeX - see log for details");
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileList(short nType, String sDirectory) {
|
||||
File dir;
|
||||
switch (nType) {
|
||||
case 0: // absolute path
|
||||
dir = new File(sDirectory);
|
||||
break;
|
||||
case 1: // relative path
|
||||
dir = new File(Misc.urlToFile(getTargetPath()),sDirectory);
|
||||
break;
|
||||
default: // document directory
|
||||
dir = Misc.urlToFile(getTargetPath());
|
||||
}
|
||||
|
||||
CSVList filelist = new CSVList(",");
|
||||
if (dir.isDirectory()) {
|
||||
File[] files = dir.listFiles();
|
||||
for (File file : files) {
|
||||
if (file.isFile() && file.getName().endsWith(".bib")) {
|
||||
//filelist.addValue(file.getAbsolutePath());
|
||||
filelist.addValue(Misc.removeExtension(file.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
String sFileList = filelist.toString();
|
||||
return sFileList.length()>0 ? sFileList : "dummy";
|
||||
}
|
||||
|
||||
}
|
|
@ -20,47 +20,25 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-10-29)
|
||||
* Version 1.6 (2014-11-03)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2latex;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.beans.XPropertyAccess;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.container.XNameAccess;
|
||||
import com.sun.star.frame.XController;
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.frame.XModel;
|
||||
import com.sun.star.frame.XStorable;
|
||||
import com.sun.star.lib.uno.helper.WeakBase;
|
||||
import com.sun.star.task.XStatusIndicator;
|
||||
import com.sun.star.task.XStatusIndicatorFactory;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MacroExpander;
|
||||
import org.openoffice.da.comp.w2lcommon.filter.UNOPublisher.TargetFormat;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
|
||||
|
||||
import writer2latex.util.CSVList;
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
/** This class implements the ui (dispatch) commands provided by the Writer2LaTeX toolbar.
|
||||
* The actual processing is done by the three core classes <code>TeXify</code>,
|
||||
* <code>LaTeXImporter</code> and <code>BibTeXImporter</code>
|
||||
* The actual processing is done by the core classes <code>UNOPublisher</code>,
|
||||
* <code>LaTeXImporter</code> and the dialogs
|
||||
*/
|
||||
public final class Writer2LaTeX extends WeakBase
|
||||
implements com.sun.star.lang.XServiceInfo,
|
||||
|
@ -73,14 +51,8 @@ public final class Writer2LaTeX extends WeakBase
|
|||
// From constructor+initialization
|
||||
private final XComponentContext m_xContext;
|
||||
private XFrame m_xFrame;
|
||||
private XModel xModel = null;
|
||||
private LaTeXUNOPublisher unoPublisher = null;
|
||||
|
||||
// Global data
|
||||
private TeXify texify = null;
|
||||
private PropertyValue[] mediaProps = null;
|
||||
private String sBasePath = null;
|
||||
private String sBaseFileName = null;
|
||||
|
||||
public static final String __implementationName = Writer2LaTeX.class.getName();
|
||||
public static final String __serviceName = "com.sun.star.frame.ProtocolHandler";
|
||||
private static final String[] m_serviceNames = { __serviceName };
|
||||
|
@ -96,11 +68,6 @@ public final class Writer2LaTeX extends WeakBase
|
|||
// The first item is the current frame
|
||||
m_xFrame = (com.sun.star.frame.XFrame) UnoRuntime.queryInterface(
|
||||
com.sun.star.frame.XFrame.class, object[0]);
|
||||
// Get the model for the document from the frame
|
||||
XController xController = m_xFrame.getController();
|
||||
if (xController!=null) {
|
||||
xModel = xController.getModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,8 +97,6 @@ public final class Writer2LaTeX extends WeakBase
|
|||
if ( aURL.Protocol.compareTo(PROTOCOL) == 0 ) {
|
||||
if ( aURL.Path.compareTo("ProcessDocument") == 0 )
|
||||
return this;
|
||||
else if ( aURL.Path.compareTo("ProcessDirectly") == 0 )
|
||||
return this;
|
||||
else if ( aURL.Path.compareTo("ViewLog") == 0 )
|
||||
return this;
|
||||
else if ( aURL.Path.compareTo("InsertBibTeX") == 0 )
|
||||
|
@ -160,16 +125,7 @@ public final class Writer2LaTeX extends WeakBase
|
|||
com.sun.star.beans.PropertyValue[] aArguments ) {
|
||||
if ( aURL.Protocol.compareTo(PROTOCOL) == 0 ) {
|
||||
if ( aURL.Path.compareTo("ProcessDocument") == 0 ) {
|
||||
if (updateLocation() && updateMediaProperties()) {
|
||||
process();
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if ( aURL.Path.compareTo("ProcessDirectly") == 0 ) {
|
||||
if (updateLocation()) {
|
||||
updateMediaPropertiesSilent();
|
||||
process();
|
||||
}
|
||||
process();
|
||||
return;
|
||||
}
|
||||
else if ( aURL.Path.compareTo("ViewLog") == 0 ) {
|
||||
|
@ -194,144 +150,17 @@ public final class Writer2LaTeX extends WeakBase
|
|||
// The actual commands...
|
||||
|
||||
private void process() {
|
||||
// Create a (somewhat coarse grained) status indicator/progress bar
|
||||
XStatusIndicatorFactory xFactory = (com.sun.star.task.XStatusIndicatorFactory)
|
||||
UnoRuntime.queryInterface(com.sun.star.task.XStatusIndicatorFactory.class, m_xFrame);
|
||||
XStatusIndicator xStatus = xFactory.createStatusIndicator();
|
||||
xStatus.start("Writer2LaTeX",10);
|
||||
xStatus.setValue(1); // At least we have started, that's 10% :-)
|
||||
|
||||
// First work a bit on the FilterData (get the backend and set bibliography options)
|
||||
String sBackend = "generic";
|
||||
String sBibinputs = null;
|
||||
|
||||
PropertyHelper mediaHelper = new PropertyHelper(mediaProps);
|
||||
Object filterData = mediaHelper.get("FilterData");
|
||||
if (filterData instanceof PropertyValue[]) {
|
||||
PropertyHelper filterHelper = new PropertyHelper((PropertyValue[])filterData);
|
||||
// Get the backend
|
||||
Object backend = filterHelper.get("backend");
|
||||
if (backend instanceof String) {
|
||||
sBackend = (String) backend;
|
||||
}
|
||||
|
||||
// Set the bibliography options according to the settings
|
||||
RegistryHelper registry = new RegistryHelper(m_xContext);
|
||||
try {
|
||||
Object view = registry.getRegistryView(BibliographyDialog.REGISTRY_PATH, false);
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
String sBibTeXFiles = getFileList(XPropertySetHelper.getPropertyValueAsShort(xProps, "BibTeXLocation"),
|
||||
XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir"));
|
||||
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertZoteroCitations")) {
|
||||
filterHelper.put("zotero_bibtex_files", sBibTeXFiles);
|
||||
}
|
||||
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertJabRefCitations")) {
|
||||
filterHelper.put("jabref_bibtex_files", sBibTeXFiles);
|
||||
}
|
||||
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "UseExternalBibTeXFiles")) {
|
||||
filterHelper.put("external_bibtex_files", sBibTeXFiles);
|
||||
}
|
||||
filterHelper.put("include_original_citations",
|
||||
Boolean.toString(XPropertySetHelper.getPropertyValueAsBoolean(xProps, "IncludeOriginalCitations")));
|
||||
String sBibTeXDir = XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir");
|
||||
if (sBibTeXDir.length()>0) {
|
||||
// The separator character in BIBINPUTS is OS specific
|
||||
sBibinputs = sBibTeXDir+File.pathSeparatorChar;
|
||||
}
|
||||
filterHelper.put("use_natbib", Boolean.toString(XPropertySetHelper.getPropertyValueAsBoolean(xProps, "UseNatbib")));
|
||||
filterHelper.put("natbib_options", XPropertySetHelper.getPropertyValueAsString(xProps, "NatbibOptions"));
|
||||
|
||||
mediaHelper.put("FilterData",filterHelper.toArray());
|
||||
mediaProps = mediaHelper.toArray();
|
||||
registry.disposeRegistryView(view);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Failed to get registry view
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Convert to LaTeX
|
||||
String sTargetUrl = sBasePath+sBaseFileName+".tex";
|
||||
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xModel);
|
||||
xStorable.storeToURL(sTargetUrl, mediaProps);
|
||||
}
|
||||
catch (com.sun.star.io.IOException e) {
|
||||
xStatus.end();
|
||||
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
|
||||
msgBox.showMessage("Writer2LaTeX","Error: Failed to export document to LaTeX");
|
||||
return;
|
||||
}
|
||||
|
||||
xStatus.setValue(6); // Export is finished, that's more than half :-)
|
||||
|
||||
if (texify==null) { texify = new TeXify(m_xContext); }
|
||||
File file = new File(urlToFile(sBasePath),sBaseFileName);
|
||||
|
||||
boolean bResult = true;
|
||||
|
||||
try {
|
||||
if (sBackend=="pdftex") {
|
||||
bResult = texify.process(file, sBibinputs, TeXify.PDFTEX, true);
|
||||
}
|
||||
else if (sBackend=="dvips") {
|
||||
bResult = texify.process(file, sBibinputs, TeXify.DVIPS, true);
|
||||
}
|
||||
else if (sBackend=="xetex") {
|
||||
bResult = texify.process(file, sBibinputs, TeXify.XETEX, true);
|
||||
}
|
||||
else if (sBackend=="generic") {
|
||||
bResult = texify.process(file, sBibinputs, TeXify.GENERIC, true);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
|
||||
msgBox.showMessage("Writer2LaTeX","Error: "+e.getMessage());
|
||||
}
|
||||
|
||||
xStatus.setValue(10); // The user will usually not see this...
|
||||
|
||||
if (!bResult) {
|
||||
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
|
||||
msgBox.showMessage("Writer2LaTeX","Error: Failed to execute LaTeX - see log for details");
|
||||
}
|
||||
|
||||
xStatus.end();
|
||||
createUNOPublisher();
|
||||
unoPublisher.publish(TargetFormat.latex);
|
||||
}
|
||||
|
||||
private String getFileList(short nType, String sDirectory) {
|
||||
File dir;
|
||||
switch (nType) {
|
||||
case 0: // absolute path
|
||||
dir = new File(sDirectory);
|
||||
break;
|
||||
case 1: // relative path
|
||||
dir = new File(urlToFile(sBasePath),sDirectory);
|
||||
break;
|
||||
default: // document directory
|
||||
dir = urlToFile(sBasePath);
|
||||
}
|
||||
|
||||
CSVList filelist = new CSVList(",");
|
||||
if (dir.isDirectory()) {
|
||||
File[] files = dir.listFiles();
|
||||
for (File file : files) {
|
||||
if (file.isFile() && file.getName().endsWith(".bib")) {
|
||||
//filelist.addValue(file.getAbsolutePath());
|
||||
filelist.addValue(Misc.removeExtension(file.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
String sFileList = filelist.toString();
|
||||
return sFileList.length()>0 ? sFileList : "dummy";
|
||||
}
|
||||
|
||||
private void viewLog() {
|
||||
if (updateLocation()) {
|
||||
createUNOPublisher();
|
||||
if (unoPublisher.documentSaved()) {
|
||||
// Execute the log viewer dialog
|
||||
try {
|
||||
Object[] args = new Object[1];
|
||||
args[0] = sBasePath+sBaseFileName;
|
||||
args[0] = unoPublisher.getTargetPath()+unoPublisher.getTargetFileName();
|
||||
Object dialog = m_xContext.getServiceManager()
|
||||
.createInstanceWithArgumentsAndContext(
|
||||
"org.openoffice.da.writer2latex.LogViewerDialog", args, m_xContext);
|
||||
|
@ -350,351 +179,11 @@ public final class Writer2LaTeX extends WeakBase
|
|||
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
|
||||
msgBox.showMessage("Writer2LaTeX","This feature is not implemented yet");
|
||||
}
|
||||
|
||||
// Some utility methods
|
||||
private void prepareMediaProperties() {
|
||||
// Create inital media properties
|
||||
mediaProps = new PropertyValue[2];
|
||||
mediaProps[0] = new PropertyValue();
|
||||
mediaProps[0].Name = "FilterName";
|
||||
mediaProps[0].Value = "org.openoffice.da.writer2latex";
|
||||
mediaProps[1] = new PropertyValue();
|
||||
mediaProps[1].Name = "Overwrite";
|
||||
mediaProps[1].Value = "true";
|
||||
}
|
||||
|
||||
private boolean updateMediaProperties() {
|
||||
prepareMediaProperties();
|
||||
|
||||
private void createUNOPublisher() {
|
||||
if (unoPublisher==null) {
|
||||
unoPublisher = new LaTeXUNOPublisher(m_xContext,m_xFrame,"Writer2latex");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Display options dialog
|
||||
Object dialog = m_xContext.getServiceManager()
|
||||
.createInstanceWithContext("org.openoffice.da.writer2latex.LaTeXOptionsDialog", m_xContext);
|
||||
|
||||
XPropertyAccess xPropertyAccess = (XPropertyAccess)
|
||||
UnoRuntime.queryInterface(XPropertyAccess.class, dialog);
|
||||
xPropertyAccess.setPropertyValues(mediaProps);
|
||||
|
||||
XExecutableDialog xDialog = (XExecutableDialog)
|
||||
UnoRuntime.queryInterface(XExecutableDialog.class, dialog);
|
||||
if (xDialog.execute()==ExecutableDialogResults.OK) {
|
||||
mediaProps = xPropertyAccess.getPropertyValues();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
mediaProps = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.beans.UnknownPropertyException e) {
|
||||
// setPropertyValues will not fail..
|
||||
mediaProps = null;
|
||||
return false;
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// getServiceManager will not fail..
|
||||
mediaProps = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String getOptionAsString(XPropertySet xProps, String sName) {
|
||||
Object value = XPropertySetHelper.getPropertyValue(xProps, sName);
|
||||
// Try to convert the value to a string
|
||||
if (value instanceof String) return (String) value;
|
||||
else if (value instanceof Boolean) return ((Boolean) value).toString();
|
||||
else if (value instanceof Integer) return ((Integer) value).toString();
|
||||
else if (value instanceof Short) return ((Short) value).toString();
|
||||
else return null;
|
||||
}
|
||||
|
||||
private void loadOption(XPropertySet xProps, PropertyHelper filterData, String sRegName, String sOptionName) {
|
||||
String sValue = getOptionAsString(xProps,sRegName);
|
||||
if (sValue!=null) {
|
||||
// Set the filter data
|
||||
filterData.put(sOptionName, sValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Read the configuration directly from the registry rather than using the dialog
|
||||
// TODO: Should probably do some refactoring in the Options dialogs to avoid this solution
|
||||
private void updateMediaPropertiesSilent() {
|
||||
prepareMediaProperties();
|
||||
|
||||
RegistryHelper registry = new RegistryHelper(m_xContext);
|
||||
|
||||
// Read the stored settings from the registry rather than displaying a dialog
|
||||
try {
|
||||
// Prepare registry view
|
||||
Object view = registry.getRegistryView("/org.openoffice.da.Writer2LaTeX.Options/LaTeXOptions",true);
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
|
||||
PropertyHelper filterData = new PropertyHelper();
|
||||
|
||||
// Read the configuration file
|
||||
short nConfig = XPropertySetHelper.getPropertyValueAsShort(xProps, "Config");
|
||||
switch (nConfig) {
|
||||
case 0: filterData.put("ConfigURL","*ultraclean.xml"); break;
|
||||
case 1: filterData.put("ConfigURL","*clean.xml"); break;
|
||||
case 2: filterData.put("ConfigURL","*default.xml"); break;
|
||||
case 3: filterData.put("ConfigURL","*pdfprint.xml"); break;
|
||||
case 4: filterData.put("ConfigURL","*pdfscreen.xml"); break;
|
||||
case 5: filterData.put("ConfigURL","$(user)/writer2latex.xml");
|
||||
filterData.put("AutoCreate","true"); break;
|
||||
default:
|
||||
// Get the actual URL from the registry
|
||||
String sConfigName = XPropertySetHelper.getPropertyValueAsString(xProps, "ConfigName");
|
||||
|
||||
Object configurations = XPropertySetHelper.getPropertyValue(xProps,"Configurations");
|
||||
XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,configurations);
|
||||
Object config = xNameAccess.getByName(sConfigName);
|
||||
XPropertySet xCfgProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,config);
|
||||
|
||||
MacroExpander expander = new MacroExpander(m_xContext);
|
||||
filterData.put("ConfigURL",expander.expandMacros(XPropertySetHelper.getPropertyValueAsString(xCfgProps,"ConfigURL")));
|
||||
}
|
||||
|
||||
// Read the options
|
||||
// General
|
||||
short nBackend = XPropertySetHelper.getPropertyValueAsShort(xProps,"Backend");
|
||||
switch (nBackend) {
|
||||
case 0: filterData.put("backend","generic"); break;
|
||||
case 1: filterData.put("backend","pdftex"); break;
|
||||
case 2: filterData.put("backend","dvips"); break;
|
||||
case 3: filterData.put("backend","xetex"); break;
|
||||
case 4: filterData.put("backend","unspecified");
|
||||
}
|
||||
short nInputencoding = XPropertySetHelper.getPropertyValueAsShort(xProps,"Inputencoding");
|
||||
switch (nInputencoding) {
|
||||
case 0: filterData.put("inputencoding", "ascii"); break;
|
||||
case 1: filterData.put("inputencoding", "latin1"); break;
|
||||
case 2: filterData.put("inputencoding", "latin2"); break;
|
||||
case 3: filterData.put("inputencoding", "iso-8859-7"); break;
|
||||
case 4: filterData.put("inputencoding", "cp1250"); break;
|
||||
case 5: filterData.put("inputencoding", "cp1251"); break;
|
||||
case 6: filterData.put("inputencoding", "koi8-r"); break;
|
||||
case 7: filterData.put("inputencoding", "utf8");
|
||||
}
|
||||
loadOption(xProps,filterData,"Multilingual","multilingual");
|
||||
loadOption(xProps,filterData,"GreekMath","greek_math");
|
||||
loadOption(xProps,filterData,"AdditionalSymbols","use_pifont");
|
||||
loadOption(xProps,filterData,"AdditionalSymbols","use_ifsym");
|
||||
loadOption(xProps,filterData,"AdditionalSymbols","use_wasysym");
|
||||
loadOption(xProps,filterData,"AdditionalSymbols","use_eurosym");
|
||||
loadOption(xProps,filterData,"AdditionalSymbols","use_tipa");
|
||||
|
||||
// Bibliography
|
||||
loadOption(xProps,filterData,"UseBibtex","use_bibtex");
|
||||
loadOption(xProps,filterData,"BibtexStyle","bibtex_style");
|
||||
|
||||
// Files
|
||||
boolean bWrapLines = XPropertySetHelper.getPropertyValueAsBoolean(xProps,"WrapLines");
|
||||
if (bWrapLines) {
|
||||
loadOption(xProps,filterData,"WrapLinesAfter","wrap_lines_after");
|
||||
}
|
||||
else {
|
||||
filterData.put("wrap_lines_after", "0");
|
||||
}
|
||||
loadOption(xProps,filterData,"SplitLinkedSections","split_linked_sections");
|
||||
loadOption(xProps,filterData,"SplitToplevelSections","split_toplevel_sections");
|
||||
loadOption(xProps,filterData,"SaveImagesInSubdir","save_images_in_subdir");
|
||||
|
||||
// Special content
|
||||
short nNotes = XPropertySetHelper.getPropertyValueAsShort(xProps, "Notes");
|
||||
switch (nNotes) {
|
||||
case 0: filterData.put("notes","ignore"); break;
|
||||
case 1: filterData.put("notes","comment"); break;
|
||||
case 2: filterData.put("notes","pdfannotation"); break;
|
||||
case 3: filterData.put("notes","marginpar");
|
||||
}
|
||||
loadOption(xProps,filterData,"Metadata","metadata");
|
||||
|
||||
// Figures and tables
|
||||
loadOption(xProps,filterData,"OriginalImageSize","original_image_size");
|
||||
boolean bOptimizeSimpleTables = XPropertySetHelper.getPropertyValueAsBoolean(xProps,"OptimizeSimpleTables");
|
||||
if (bOptimizeSimpleTables) {
|
||||
loadOption(xProps,filterData,"SimpleTableLimit","simple_table_limit");
|
||||
}
|
||||
else {
|
||||
filterData.put("simple_table_limit", "0");
|
||||
}
|
||||
loadOption(xProps,filterData,"FloatTables","float_tables");
|
||||
loadOption(xProps,filterData,"FloatFigures","float_figures");
|
||||
loadOption(xProps,filterData,"FloatOptions","float_options");
|
||||
short nFloatOptions = XPropertySetHelper.getPropertyValueAsShort(xProps, "FloatOptions");
|
||||
switch (nFloatOptions) {
|
||||
case 0: filterData.put("float_options", ""); break;
|
||||
case 1: filterData.put("float_options", "tp"); break;
|
||||
case 2: filterData.put("float_options", "bp"); break;
|
||||
case 3: filterData.put("float_options", "htp"); break;
|
||||
case 4: filterData.put("float_options", "hbp");
|
||||
}
|
||||
|
||||
// AutoCorrect
|
||||
loadOption(xProps,filterData,"IgnoreHardPageBreaks","ignore_hard_page_breaks");
|
||||
loadOption(xProps,filterData,"IgnoreHardLineBreaks","ignore_hard_line_breaks");
|
||||
loadOption(xProps,filterData,"IgnoreEmptyParagraphs","ignore_empty_paragraphs");
|
||||
loadOption(xProps,filterData,"IgnoreDoubleSpaces","ignore_empty_spaces");
|
||||
|
||||
registry.disposeRegistryView(view);
|
||||
|
||||
// Update the media properties with the FilterData
|
||||
PropertyHelper helper = new PropertyHelper(mediaProps);
|
||||
helper.put("FilterData",filterData.toArray());
|
||||
mediaProps = helper.toArray();
|
||||
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// Failed to get registry view, ignore
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateLocation() {
|
||||
String sDocumentUrl = xModel.getURL();
|
||||
if (sDocumentUrl.length()!=0) {
|
||||
if (sDocumentUrl.startsWith("file:")) {
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
Pattern windowsPattern = Pattern.compile("^file:///[A-Za-z][|:].*");
|
||||
if (!windowsPattern.matcher(sDocumentUrl).matches()) {
|
||||
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
|
||||
msgBox.showMessage("Please save the document on a location with a drive name!",
|
||||
"LaTeX does not support UNC paths");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Get the file name (without extension)
|
||||
File f = urlToFile(sDocumentUrl);
|
||||
sBaseFileName = f.getName();
|
||||
int iDot = sBaseFileName.lastIndexOf(".");
|
||||
if (iDot>-1) { // remove extension
|
||||
sBaseFileName = sBaseFileName.substring(0,iDot);
|
||||
}
|
||||
sBaseFileName=makeTeXSafe(sBaseFileName);
|
||||
|
||||
// Get the path
|
||||
int iSlash = sDocumentUrl.lastIndexOf("/");
|
||||
if (iSlash>-1) {
|
||||
sBasePath = sDocumentUrl.substring(0,iSlash+1);
|
||||
}
|
||||
else {
|
||||
sBasePath = "";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
|
||||
msgBox.showMessage("Please save the document locally!","LaTeX does not support documents in remote storages");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
|
||||
msgBox.showMessage("Document not saved!","Please save the document before processing the file");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String makeTeXSafe(String sArgument) {
|
||||
String sResult = "";
|
||||
for (int i=0; i<sArgument.length(); i++) {
|
||||
char c = sArgument.charAt(i);
|
||||
if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) {
|
||||
sResult += Character.toString(c);
|
||||
}
|
||||
else {
|
||||
switch (c) {
|
||||
case '.': sResult += "."; break;
|
||||
case '-': sResult += "-"; break;
|
||||
case ' ' : sResult += "-"; break;
|
||||
case '_' : sResult += "-"; break;
|
||||
// Replace accented and national characters
|
||||
case '\u00c0' : sResult += "A"; break;
|
||||
case '\u00c1' : sResult += "A"; break;
|
||||
case '\u00c2' : sResult += "A"; break;
|
||||
case '\u00c3' : sResult += "A"; break;
|
||||
case '\u00c4' : sResult += "AE"; break;
|
||||
case '\u00c5' : sResult += "AA"; break;
|
||||
case '\u00c6' : sResult += "AE"; break;
|
||||
case '\u00c7' : sResult += "C"; break;
|
||||
case '\u00c8' : sResult += "E"; break;
|
||||
case '\u00c9' : sResult += "E"; break;
|
||||
case '\u00ca' : sResult += "E"; break;
|
||||
case '\u00cb' : sResult += "E"; break;
|
||||
case '\u00cc' : sResult += "I"; break;
|
||||
case '\u00cd' : sResult += "I"; break;
|
||||
case '\u00ce' : sResult += "I"; break;
|
||||
case '\u00cf' : sResult += "I"; break;
|
||||
case '\u00d0' : sResult += "D"; break;
|
||||
case '\u00d1' : sResult += "N"; break;
|
||||
case '\u00d2' : sResult += "O"; break;
|
||||
case '\u00d3' : sResult += "O"; break;
|
||||
case '\u00d4' : sResult += "O"; break;
|
||||
case '\u00d5' : sResult += "O"; break;
|
||||
case '\u00d6' : sResult += "OE"; break;
|
||||
case '\u00d8' : sResult += "OE"; break;
|
||||
case '\u00d9' : sResult += "U"; break;
|
||||
case '\u00da' : sResult += "U"; break;
|
||||
case '\u00db' : sResult += "U"; break;
|
||||
case '\u00dc' : sResult += "UE"; break;
|
||||
case '\u00dd' : sResult += "Y"; break;
|
||||
case '\u00df' : sResult += "sz"; break;
|
||||
case '\u00e0' : sResult += "a"; break;
|
||||
case '\u00e1' : sResult += "a"; break;
|
||||
case '\u00e2' : sResult += "a"; break;
|
||||
case '\u00e3' : sResult += "a"; break;
|
||||
case '\u00e4' : sResult += "ae"; break;
|
||||
case '\u00e5' : sResult += "aa"; break;
|
||||
case '\u00e6' : sResult += "ae"; break;
|
||||
case '\u00e7' : sResult += "c"; break;
|
||||
case '\u00e8' : sResult += "e"; break;
|
||||
case '\u00e9' : sResult += "e"; break;
|
||||
case '\u00ea' : sResult += "e"; break;
|
||||
case '\u00eb' : sResult += "e"; break;
|
||||
case '\u00ec' : sResult += "i"; break;
|
||||
case '\u00ed' : sResult += "i"; break;
|
||||
case '\u00ee' : sResult += "i"; break;
|
||||
case '\u00ef' : sResult += "i"; break;
|
||||
case '\u00f0' : sResult += "d"; break;
|
||||
case '\u00f1' : sResult += "n"; break;
|
||||
case '\u00f2' : sResult += "o"; break;
|
||||
case '\u00f3' : sResult += "o"; break;
|
||||
case '\u00f4' : sResult += "o"; break;
|
||||
case '\u00f5' : sResult += "o"; break;
|
||||
case '\u00f6' : sResult += "oe"; break;
|
||||
case '\u00f8' : sResult += "oe"; break;
|
||||
case '\u00f9' : sResult += "u"; break;
|
||||
case '\u00fa' : sResult += "u"; break;
|
||||
case '\u00fb' : sResult += "u"; break;
|
||||
case '\u00fc' : sResult += "ue"; break;
|
||||
case '\u00fd' : sResult += "y"; break;
|
||||
case '\u00ff' : sResult += "y"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sResult.length()==0) { return "writer2latex"; }
|
||||
else { return sResult; }
|
||||
}
|
||||
|
||||
private File urlToFile(String sUrl) {
|
||||
try {
|
||||
return new File(new URI(sUrl));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
return new File(".");
|
||||
}
|
||||
}
|
||||
|
||||
/*private String urlToPath(String sUrl) {
|
||||
try {
|
||||
return (new File(new URI(sUrl))).getCanonicalPath();
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
return ".";
|
||||
}
|
||||
catch (IOException e) {
|
||||
return ".";
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-10-21)
|
||||
* Version 1.6 (2014-11-03)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -28,12 +28,6 @@ package org.openoffice.da.comp.writer2xhtml;
|
|||
|
||||
// TODO: Create common base for dispatcher classes
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lib.uno.helper.WeakBase;
|
||||
|
@ -41,9 +35,7 @@ import com.sun.star.ui.dialogs.XExecutableDialog;
|
|||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import org.openoffice.da.comp.w2lcommon.filter.UNOPublisher;
|
||||
import org.openoffice.da.comp.w2lcommon.filter.UNOPublisher.TargetFormat;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
|
||||
|
||||
/** This class implements the ui (dispatch) commands provided by Writer2xhtml.
|
||||
*/
|
||||
|
@ -58,7 +50,7 @@ public final class Writer2xhtml extends WeakBase
|
|||
// From constructor+initialization
|
||||
private final XComponentContext m_xContext;
|
||||
private XFrame m_xFrame;
|
||||
private UNOPublisher unoPublisher = null;
|
||||
private XhtmlUNOPublisher unoPublisher = null;
|
||||
|
||||
// Global data
|
||||
public static final String __implementationName = Writer2xhtml.class.getName();
|
||||
|
@ -178,38 +170,9 @@ public final class Writer2xhtml extends WeakBase
|
|||
|
||||
private void publish(TargetFormat format) {
|
||||
if (unoPublisher==null) {
|
||||
unoPublisher = new UNOPublisher(m_xContext,m_xFrame);
|
||||
unoPublisher = new XhtmlUNOPublisher(m_xContext,m_xFrame,"Writer2xhtml");
|
||||
}
|
||||
String sTargetURL = unoPublisher.publish(format);
|
||||
// Display the result
|
||||
File file = urlToFile(sTargetURL);
|
||||
if (file.exists()) {
|
||||
// Open the file in the default application on this system (if any)
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
try {
|
||||
desktop.open(file);
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
|
||||
msgBox.showMessage("Writer2xhtml","Error: Failed to open exported document");
|
||||
}
|
||||
}
|
||||
|
||||
private File urlToFile(String sUrl) {
|
||||
try {
|
||||
return new File(new URI(sUrl));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
return new File(".");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
unoPublisher.publish(format);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* XhtmlUNOPublisher.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-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-11-03)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.filter.UNOPublisher;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
|
||||
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class XhtmlUNOPublisher extends UNOPublisher {
|
||||
|
||||
public XhtmlUNOPublisher(XComponentContext xContext, XFrame xFrame, String sAppName) {
|
||||
super(xContext, xFrame, sAppName);
|
||||
}
|
||||
|
||||
|
||||
/** Display the converted document in the default application
|
||||
*
|
||||
* @param sURL the URL of the converted document
|
||||
*/
|
||||
@Override protected void postProcess(String sURL) {
|
||||
File file = Misc.urlToFile(sURL);
|
||||
if (file.exists()) {
|
||||
// Open the file in the default application on this system (if any)
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
try {
|
||||
desktop.open(file);
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("Writer2xhtml","Error: Failed to open exported document");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-10-23)
|
||||
* Version 1.6 (2014-11-03)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class ConverterFactory {
|
|||
|
||||
// Version information
|
||||
private static final String VERSION = "1.5.1";
|
||||
private static final String DATE = "2014-10-23";
|
||||
private static final String DATE = "2014-11-03";
|
||||
|
||||
/** Return the Writer2LaTeX version in the form
|
||||
* (major version).(minor version).(patch level)<br/>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2014-10-21)
|
||||
* Version 1.6 (2014-11-03)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -33,6 +33,7 @@ import java.io.IOException;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.Math;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.URLDecoder;
|
||||
import java.text.Collator;
|
||||
|
@ -295,6 +296,15 @@ public class Misc{
|
|||
return name;
|
||||
}
|
||||
|
||||
/** Get the path part of an URL
|
||||
*
|
||||
* @param sURL the URL from which the filename should be extracted
|
||||
* @return the file name
|
||||
*/
|
||||
public static final String getPath(String sURL) {
|
||||
return sURL.substring(0,sURL.lastIndexOf('/')+1);
|
||||
}
|
||||
|
||||
/** Get the file name part of an URL
|
||||
*
|
||||
* @param sURL the URL from which the filename should be extracted
|
||||
|
@ -464,7 +474,14 @@ public class Misc{
|
|||
return "error";
|
||||
}
|
||||
|
||||
|
||||
public static File urlToFile(String sUrl) {
|
||||
try {
|
||||
return new File(new URI(sUrl));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
return new File(".");
|
||||
}
|
||||
}
|
||||
|
||||
/** <p>Read an <code>InputStream</code> into a <code>byte</code>array</p>
|
||||
* @param is the <code>InputStream</code> to read
|
||||
|
|
Loading…
Add table
Reference in a new issue