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:
henrikjust 2014-11-03 19:52:41 +00:00
parent 88c3a7295d
commit 435bbee042
8 changed files with 475 additions and 602 deletions

View file

@ -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);
}
}

View file

@ -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");
}
}
}