UNOPublisher
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 UNOPublisher
*/
- 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 UNOPublisher
. This involves four steps:
+ /** Publish the document associated with this UNOPublisher
. 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 "";
}
}
diff --git a/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java b/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java
new file mode 100644
index 0000000..56f5adb
--- /dev/null
+++ b/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java
@@ -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; iTeXify
,
- * LaTeXImporter
and BibTeXImporter
+ * The actual processing is done by the core classes UNOPublisher
,
+ * LaTeXImporter
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; iRead an InputStream
into a byte
array
InputStream
to read