diff --git a/.unoproject b/.unoproject index fa56036..67bde5b 100644 --- a/.unoproject +++ b/.unoproject @@ -1,10 +1,10 @@ #UNO project configuration file -#Tue Apr 05 17:37:26 CEST 2016 +#Thu Mar 19 15:58:57 CET 2020 project.srcdir=/source -regclassname=org.libreoffice.example.comp.RegistrationHandler +regclassname=pro.litvinovg.libreoffice.metadata.RegistrationHandler javaversion=java5 -project.sdk=5.0.5.2 -project.ooo=LibreOffice 5.0 +project.sdk=6.3.5.2 +project.ooo=LibreOffice 6.3 \#1 project.implementation=comp project.build=build project.language=Java diff --git a/dialog/ActionOneDialog.xdl b/dialog/ActionOneDialog.xdl deleted file mode 100644 index 8bf5705..0000000 --- a/dialog/ActionOneDialog.xdl +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/registry/org/openoffice/Office/Accelerators.xcu b/registry/org/openoffice/Office/Accelerators.xcu index 07dad35..1374d70 100644 --- a/registry/org/openoffice/Office/Accelerators.xcu +++ b/registry/org/openoffice/Office/Accelerators.xcu @@ -7,7 +7,7 @@ - service:org.libreoffice.example.StarterProject?actionOne + service:pro.litvinovg.libreoffice.MetadataEditor?openGUI diff --git a/registry/org/openoffice/Office/Addons.xcu b/registry/org/openoffice/Office/Addons.xcu index 6726259..ed333cb 100644 --- a/registry/org/openoffice/Office/Addons.xcu +++ b/registry/org/openoffice/Office/Addons.xcu @@ -4,29 +4,29 @@ - + - service:org.libreoffice.example.StarterProject?openGUI + service:pro.litvinovg.libreoffice.MetadataEditor?openGUI - vnd.sun.star.extension://org.libreoffice.example.starterproject/images/actionOne_16.png + vnd.sun.star.extension://pro.litvinovg.libreoffice.metadata/images/actionOne_16.png - vnd.sun.star.extension://org.libreoffice.example.starterproject/images/actionOne_26.png + vnd.sun.star.extension://pro.litvinovg.libreoffice.metadata/images/actionOne_26.png - + Starter Project - service:org.libreoffice.example.StarterProject?openGUI + service:pro.litvinovg.libreoffice.MetadataEditor?openGUI _self diff --git a/registry/org/openoffice/Office/UI/WriterWindowState.xcu b/registry/org/openoffice/Office/UI/WriterWindowState.xcu index 3340e7f..4c6a311 100644 --- a/registry/org/openoffice/Office/UI/WriterWindowState.xcu +++ b/registry/org/openoffice/Office/UI/WriterWindowState.xcu @@ -6,7 +6,7 @@ - + Aktensystem diff --git a/source/org/libreoffice/example/comp/RegistrationHandler.classes b/source/org/libreoffice/example/comp/RegistrationHandler.classes deleted file mode 100644 index c145ca0..0000000 --- a/source/org/libreoffice/example/comp/RegistrationHandler.classes +++ /dev/null @@ -1 +0,0 @@ -org.libreoffice.example.comp.StarterProjectImpl diff --git a/source/org/libreoffice/example/dialog/ActionOneDialog.java b/source/org/libreoffice/example/dialog/ActionOneDialog.java deleted file mode 100644 index f3f398f..0000000 --- a/source/org/libreoffice/example/dialog/ActionOneDialog.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.libreoffice.example.dialog; - -import org.libreoffice.example.helper.DialogHelper; - -import com.sun.star.awt.XDialog; -import com.sun.star.awt.XDialogEventHandler; -import com.sun.star.lang.WrappedTargetException; -import com.sun.star.uno.XComponentContext; - - -public class ActionOneDialog implements XDialogEventHandler { - - private XDialog dialog; - private static final String actionOk = "actionOk"; - private String[] supportedActions = new String[] { actionOk }; - - public ActionOneDialog(XComponentContext xContext) { - this.dialog = DialogHelper.createDialog("ActionOneDialog.xdl", xContext, this); - } - - public void show() { - dialog.execute(); - } - - private void onOkButtonPressed() { - dialog.endExecute(); - } - - @Override - public boolean callHandlerMethod(XDialog dialog, Object eventObject, String methodName) throws WrappedTargetException { - if (methodName.equals(actionOk)) { - onOkButtonPressed(); - return true; // Event was handled - } - return false; // Event was not handled - } - - @Override - public String[] getSupportedMethodNames() { - return supportedActions; - } - -} diff --git a/source/org/libreoffice/example/helper/DialogHelper.java b/source/org/libreoffice/example/helper/DialogHelper.java deleted file mode 100644 index a6df22c..0000000 --- a/source/org/libreoffice/example/helper/DialogHelper.java +++ /dev/null @@ -1,184 +0,0 @@ -package org.libreoffice.example.helper; - -import java.io.File; - -import com.sun.star.awt.MessageBoxType; -import com.sun.star.awt.Point; -import com.sun.star.awt.XButton; -import com.sun.star.awt.XComboBox; -import com.sun.star.awt.XControl; -import com.sun.star.awt.XControlContainer; -import com.sun.star.awt.XControlModel; -import com.sun.star.awt.XDialog; -import com.sun.star.awt.XDialogEventHandler; -import com.sun.star.awt.XDialogProvider2; -import com.sun.star.awt.XFixedText; -import com.sun.star.awt.XListBox; -import com.sun.star.awt.XMessageBox; -import com.sun.star.awt.XMessageBoxFactory; -import com.sun.star.awt.XTextComponent; -import com.sun.star.awt.XToolkit; -import com.sun.star.awt.XWindow; -import com.sun.star.awt.XWindowPeer; -import com.sun.star.beans.PropertyVetoException; -import com.sun.star.beans.UnknownPropertyException; -import com.sun.star.beans.XPropertySet; -import com.sun.star.lang.WrappedTargetException; -import com.sun.star.uno.Exception; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XComponentContext; - -public class DialogHelper { - - /** - * Create a dialog from an xdl file. - * - * @param xdlFile - * The filename in the `dialog` folder - * @param context - * @return XDialog - */ - public static XDialog createDialog(String xdlFile, XComponentContext context, XDialogEventHandler handler) { - Object oDialogProvider; - try { - oDialogProvider = context.getServiceManager().createInstanceWithContext("com.sun.star.awt.DialogProvider2", - context); - XDialogProvider2 xDialogProv = (XDialogProvider2) UnoRuntime.queryInterface(XDialogProvider2.class, - oDialogProvider); - File dialogFile = FileHelper.getDialogFilePath(xdlFile, context); - return xDialogProv.createDialogWithHandler(convertToURL(context, dialogFile), handler); - } catch (Exception e) { - return null; - } - } - - /** Returns a URL to be used with XDialogProvider to create a dialog */ - public static String convertToURL(XComponentContext xContext, File dialogFile) { - String sURL = null; - try { - com.sun.star.ucb.XFileIdentifierConverter xFileConverter = (com.sun.star.ucb.XFileIdentifierConverter) UnoRuntime - .queryInterface(com.sun.star.ucb.XFileIdentifierConverter.class, xContext.getServiceManager() - .createInstanceWithContext("com.sun.star.ucb.FileContentProvider", xContext)); - sURL = xFileConverter.getFileURLFromSystemPath("", dialogFile.getAbsolutePath()); - } catch (com.sun.star.uno.Exception ex) { - return null; - } - return sURL; - } - - /** Returns a button (XButton) from a dialog */ - public static XButton getButton(XDialog dialog, String componentId) { - XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, - dialog); - Object control = xDlgContainer.getControl(componentId); - return (XButton) UnoRuntime.queryInterface(XButton.class, control); - } - - /** Returns a text field (XTextComponent) from a dialog */ - public static XTextComponent getEditField(XDialog dialog, String componentId) { - XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, - dialog); - Object control = xDlgContainer.getControl(componentId); - return (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, control); - } - - /** Returns a Combo box (XComboBox) from a dialog */ - public static XComboBox getCombobox(XDialog dialog, String componentId) { - XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, - dialog); - Object control = xDlgContainer.getControl(componentId); - return (XComboBox) UnoRuntime.queryInterface(XComboBox.class, control); - } - - /** Returns a List box (XListBox) from a dialog */ - public static XListBox getListBox(XDialog dialog, String componentId) { - XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, - dialog); - Object control = xDlgContainer.getControl(componentId); - return (XListBox) UnoRuntime.queryInterface(XListBox.class, control); - } - - /** Returns a label (XFixedText) from a dialog */ - public static XFixedText getLabel(XDialog dialog, String componentId) { - XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, - dialog); - Object control = xDlgContainer.getControl(componentId); - return (XFixedText) UnoRuntime.queryInterface(XFixedText.class, control); - } - - public static void EnableButton(XDialog dialog, String componentId, boolean enable) { - XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, - dialog); - // retrieve the control that we want to disable or enable - XControl xControl = UnoRuntime.queryInterface(XControl.class, xDlgContainer.getControl(componentId)); - XPropertySet xModelPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel()); - try { - xModelPropertySet.setPropertyValue("Enabled", Boolean.valueOf(enable)); - } catch (IllegalArgumentException | UnknownPropertyException | PropertyVetoException - | WrappedTargetException e) { - return; - } - } - - /** Set the focus to an input field */ - public static void SetFocus(XTextComponent editField) { - XWindow xControlWindow = UnoRuntime.queryInterface(XWindow.class, editField); - xControlWindow.setFocus(); - } - - public static void setPosition(XDialog dialog, int posX, int posY) { - XControlModel xDialogModel = UnoRuntime.queryInterface(XControl.class, dialog).getModel(); - XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xDialogModel); - try { - xPropSet.setPropertyValue("PositionX", posX); - xPropSet.setPropertyValue("PositionY", posY); - } catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException - | WrappedTargetException e) { - return; - } - } - - public static Point getPosition(XDialog dialog) { - int posX = 0; - int posY = 0; - XControlModel xDialogModel = UnoRuntime.queryInterface(XControl.class, dialog).getModel(); - XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xDialogModel); - try { - posX = (int) xPropSet.getPropertyValue("PositionX"); - posY = (int) xPropSet.getPropertyValue("PositionY"); - } catch (UnknownPropertyException | WrappedTargetException e) { - } - return new Point(posX, posY); - } - - public static void showInfoMessage(XComponentContext context, XDialog dialog, String message) { - showMessageBox(context, dialog, MessageBoxType.INFOBOX, "Info", message); - } - - public static void showWarningMessage(XComponentContext context, XDialog dialog, String message) { - showMessageBox(context, dialog, MessageBoxType.WARNINGBOX, "Warnung", message); - } - - public static void showErrorMessage(XComponentContext context, XDialog dialog, String message) { - showMessageBox(context, dialog, MessageBoxType.ERRORBOX, "Fehler", message); - } - - public static void showMessageBox(XComponentContext context, XDialog dialog, MessageBoxType type, String sTitle, String sMessage) { - XToolkit xToolkit; - try { - xToolkit = UnoRuntime.queryInterface(XToolkit.class, - context.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", context)); - } catch (Exception e) { - return; - } - XMessageBoxFactory xMessageBoxFactory = UnoRuntime.queryInterface(XMessageBoxFactory.class, xToolkit); - XWindowPeer xParentWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, dialog); - XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(xParentWindowPeer, type, - com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, sTitle, sMessage); - if (xMessageBox == null) - return; - - xMessageBox.execute(); - } - -} diff --git a/source/org/libreoffice/example/helper/DocumentHelper.java b/source/org/libreoffice/example/helper/DocumentHelper.java deleted file mode 100644 index 4d0be80..0000000 --- a/source/org/libreoffice/example/helper/DocumentHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.libreoffice.example.helper; - -import com.sun.star.frame.XDesktop; -import com.sun.star.frame.XFrame; -import com.sun.star.frame.XModel; -import com.sun.star.lang.XComponent; -import com.sun.star.lang.XMultiComponentFactory; -import com.sun.star.text.XTextDocument; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XComponentContext; - -public class DocumentHelper { - - /** Returns the curerent XDesktop */ - public static XDesktop getCurrentDesktop(XComponentContext xContext) { - XMultiComponentFactory xMCF = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, - xContext.getServiceManager()); - Object desktop = null; - try { - desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext); - } catch (Exception e) { - return null; - } - return (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop); - } - - /** Returns the current XComponent */ - private static XComponent getCurrentComponent(XComponentContext xContext) { - return (XComponent) getCurrentDesktop(xContext).getCurrentComponent(); - } - - /** Returns the current frame */ - public static XFrame getCurrentFrame(XComponentContext xContext) { - XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, getCurrentComponent(xContext)); - return xModel.getCurrentController().getFrame(); - } - - /** Returns the current text document (if any) */ - public static XTextDocument getCurrentDocument(XComponentContext xContext) { - return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, getCurrentComponent(xContext)); - } -} diff --git a/source/org/libreoffice/example/helper/FileHelper.java b/source/org/libreoffice/example/helper/FileHelper.java deleted file mode 100644 index e9596a2..0000000 --- a/source/org/libreoffice/example/helper/FileHelper.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.libreoffice.example.helper; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; - -import com.sun.star.deployment.PackageInformationProvider; -import com.sun.star.deployment.XPackageInformationProvider; -import com.sun.star.uno.Exception; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XComponentContext; -import com.sun.star.util.XURLTransformer; - -public class FileHelper { - - final static String DIALOG_RESOURCES = "dialog/"; - - /** - * Returns a path to a dialog file - */ - public static File getDialogFilePath(String xdlFile, XComponentContext xContext) { - return getFilePath(DIALOG_RESOURCES + xdlFile, xContext); - } - - /** - * Returns a file path for a file in the installed extension, or null on failure. - */ - public static File getFilePath(String file, XComponentContext xContext) { - XPackageInformationProvider xPackageInformationProvider = PackageInformationProvider.get(xContext); - String location = xPackageInformationProvider.getPackageLocation("org.libreoffice.example.starterproject"); - Object oTransformer; - try { - oTransformer = xContext.getServiceManager().createInstanceWithContext("com.sun.star.util.URLTransformer", xContext); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - XURLTransformer xTransformer = (XURLTransformer)UnoRuntime.queryInterface(XURLTransformer.class, oTransformer); - com.sun.star.util.URL[] oURL = new com.sun.star.util.URL[1]; - oURL[0] = new com.sun.star.util.URL(); - oURL[0].Complete = location + "/" + file; - xTransformer.parseStrict(oURL); - URL url; - try { - url = new URL(oURL[0].Complete); - } catch (MalformedURLException e1) { - return null; - } - File f; - try { - f = new File(url.toURI()); - } catch (URISyntaxException e1) { - return null; - } - return f; - } - -} diff --git a/source/pro/litvinovg/libreoffice/metadata/Document.java b/source/pro/litvinovg/libreoffice/metadata/Document.java index 178c9ce..e9c69f8 100644 --- a/source/pro/litvinovg/libreoffice/metadata/Document.java +++ b/source/pro/litvinovg/libreoffice/metadata/Document.java @@ -6,7 +6,6 @@ import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.Map; -import org.libreoffice.example.comp.MetadataInaccessableException; import com.sun.org.apache.bcel.internal.generic.NEW; import com.sun.star.beans.IllegalTypeException; diff --git a/source/org/libreoffice/example/comp/StarterProjectImpl.java b/source/pro/litvinovg/libreoffice/metadata/MetadataExtensionImpl.java similarity index 78% rename from source/org/libreoffice/example/comp/StarterProjectImpl.java rename to source/pro/litvinovg/libreoffice/metadata/MetadataExtensionImpl.java index e6320ef..b3a8c75 100644 --- a/source/org/libreoffice/example/comp/StarterProjectImpl.java +++ b/source/pro/litvinovg/libreoffice/metadata/MetadataExtensionImpl.java @@ -1,9 +1,8 @@ -package org.libreoffice.example.comp; +package pro.litvinovg.libreoffice.metadata; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; -import pro.litvinovg.libreoffice.metadata.Document; import pro.litvinovg.libreoffice.metadata.views.EditorGUI; import com.sun.star.lib.uno.helper.Factory; @@ -11,9 +10,6 @@ import com.sun.star.lib.uno.helper.Factory; import java.util.Arrays; import java.util.Comparator; -import org.libreoffice.example.dialog.ActionOneDialog; -import org.libreoffice.example.helper.DialogHelper; - import com.sun.star.beans.Property; import com.sun.star.beans.XPropertyContainer; import com.sun.star.beans.XPropertySet; @@ -29,7 +25,7 @@ import com.sun.star.registry.XRegistryKey; import com.sun.star.lib.uno.helper.WeakBase; -public final class StarterProjectImpl extends WeakBase +public final class MetadataExtensionImpl extends WeakBase implements com.sun.star.lang.XServiceInfo, com.sun.star.task.XJobExecutor { @@ -39,11 +35,11 @@ public final class StarterProjectImpl extends WeakBase private XComponent currentDocument; private XDocumentProperties documentProperties; private XDocumentPropertiesSupplier documentPropertiesSupplier; - private static final String m_implementationName = StarterProjectImpl.class.getName(); - private static final String[] m_serviceNames = { "org.libreoffice.example.StarterProject" }; + private static final String m_implementationName = MetadataExtensionImpl.class.getName(); + private static final String[] m_serviceNames = { "pro.litvinovg.libreoffice.MetadataEditor" }; - public StarterProjectImpl(XComponentContext componentContext) { + public MetadataExtensionImpl(XComponentContext componentContext) { context = componentContext; }; @@ -52,7 +48,7 @@ public final class StarterProjectImpl extends WeakBase XSingleComponentFactory xFactory = null; if ( sImplementationName.equals( m_implementationName ) ) - xFactory = Factory.createComponentFactory(StarterProjectImpl.class, m_serviceNames); + xFactory = Factory.createComponentFactory(MetadataExtensionImpl.class, m_serviceNames); return xFactory; } @@ -90,7 +86,6 @@ public final class StarterProjectImpl extends WeakBase EditorGUI.runGUI(doc); break; default: - DialogHelper.showErrorMessage(context, null, "Unknown action: " + action); } } diff --git a/source/org/libreoffice/example/comp/MetadataInaccessableException.java b/source/pro/litvinovg/libreoffice/metadata/MetadataInaccessableException.java similarity index 77% rename from source/org/libreoffice/example/comp/MetadataInaccessableException.java rename to source/pro/litvinovg/libreoffice/metadata/MetadataInaccessableException.java index da1ccb2..b4236bb 100644 --- a/source/org/libreoffice/example/comp/MetadataInaccessableException.java +++ b/source/pro/litvinovg/libreoffice/metadata/MetadataInaccessableException.java @@ -1,4 +1,4 @@ -package org.libreoffice.example.comp; +package pro.litvinovg.libreoffice.metadata; public class MetadataInaccessableException extends Exception { public MetadataInaccessableException(String errorMessage) { diff --git a/source/pro/litvinovg/libreoffice/metadata/RegistrationHandler.classes b/source/pro/litvinovg/libreoffice/metadata/RegistrationHandler.classes new file mode 100644 index 0000000..11d576c --- /dev/null +++ b/source/pro/litvinovg/libreoffice/metadata/RegistrationHandler.classes @@ -0,0 +1 @@ +pro.litvinovg.libreoffice.metadata.MetadataExtensionImpl diff --git a/source/org/libreoffice/example/comp/RegistrationHandler.java b/source/pro/litvinovg/libreoffice/metadata/RegistrationHandler.java similarity index 99% rename from source/org/libreoffice/example/comp/RegistrationHandler.java rename to source/pro/litvinovg/libreoffice/metadata/RegistrationHandler.java index 3819b73..a67e63e 100644 --- a/source/org/libreoffice/example/comp/RegistrationHandler.java +++ b/source/pro/litvinovg/libreoffice/metadata/RegistrationHandler.java @@ -35,7 +35,7 @@ * * ************************************************************************/ -package org.libreoffice.example.comp; +package pro.litvinovg.libreoffice.metadata; import java.io.IOException; import java.io.InputStream; diff --git a/source/pro/litvinovg/libreoffice/metadata/tests/UnoTests.java b/source/pro/litvinovg/libreoffice/metadata/tests/UnoTests.java new file mode 100644 index 0000000..197cf39 --- /dev/null +++ b/source/pro/litvinovg/libreoffice/metadata/tests/UnoTests.java @@ -0,0 +1,13 @@ +package pro.litvinovg.libreoffice.metadata.tests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; +import pro.litvinovg.libreoffice.metadata.tests.uno.WriterTest; + +import pro.litvinovg.libreoffice.metadata.tests.base.UnoSuite; + +@RunWith(UnoSuite.class) +@SuiteClasses({WriterTest.class}) +public class UnoTests { + +} diff --git a/source/pro/litvinovg/libreoffice/metadata/tests/base/UnoSuite.java b/source/pro/litvinovg/libreoffice/metadata/tests/base/UnoSuite.java new file mode 100644 index 0000000..96f31f6 --- /dev/null +++ b/source/pro/litvinovg/libreoffice/metadata/tests/base/UnoSuite.java @@ -0,0 +1,75 @@ +package pro.litvinovg.libreoffice.metadata.tests.base; + +import java.util.List; + +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.Suite; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.RunnerBuilder; + +import com.sun.star.frame.XDesktop; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +public class UnoSuite extends Suite { + + private static XComponentContext componentContext; + + public UnoSuite(Class klass, RunnerBuilder builder) throws InitializationError { + super(klass, builder); + } + + public UnoSuite(RunnerBuilder builder, Class[] classes) throws InitializationError { + super(builder, classes); + } + + public UnoSuite(Class klass, Class[] suiteClasses) throws InitializationError { + super(klass, suiteClasses); + } + + public UnoSuite(Class klass, List runners) throws InitializationError { + super(klass, runners); + } + + public UnoSuite(RunnerBuilder builder, Class klass, Class[] suiteClasses) throws InitializationError { + super(builder, klass, suiteClasses); + } + + @Override + public void run(RunNotifier arg0) { + try { + startOffice(); + } catch (Exception e) { + e.printStackTrace(); + } + super.run(arg0); + + stopOffice(); + } + + private void startOffice() throws Exception { + componentContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); + } + + private void stopOffice() { + try { + if (componentContext != null) { + // Only the uno test suite which started the office can stop it + XMultiComponentFactory xMngr = componentContext.getServiceManager(); + Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", componentContext); + XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, oDesktop); + + xDesktop.terminate(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static XComponentContext getComponentContext() { + return componentContext; + } + +} diff --git a/source/pro/litvinovg/libreoffice/metadata/tests/helper/UnoHelper.java b/source/pro/litvinovg/libreoffice/metadata/tests/helper/UnoHelper.java new file mode 100644 index 0000000..b639762 --- /dev/null +++ b/source/pro/litvinovg/libreoffice/metadata/tests/helper/UnoHelper.java @@ -0,0 +1,28 @@ +package pro.litvinovg.libreoffice.metadata.tests.helper; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.FrameSearchFlag; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.text.XTextDocument; +import com.sun.star.uno.Exception; +import com.sun.star.uno.UnoRuntime; + +import pro.litvinovg.libreoffice.metadata.tests.base.UnoSuite; + +public class UnoHelper { + + public static XTextDocument getWriterDocument() throws Exception { + XMultiComponentFactory xMngr = UnoSuite.getComponentContext().getServiceManager(); + Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", UnoSuite.getComponentContext()); + XComponentLoader xLoader = (XComponentLoader)UnoRuntime.queryInterface( + XComponentLoader.class, oDesktop); + + XComponent xDoc = xLoader.loadComponentFromURL("private:factory/swriter", "_default", + FrameSearchFlag.ALL, new PropertyValue[0]); + + return (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xDoc); + } + +} diff --git a/source/pro/litvinovg/libreoffice/metadata/tests/uno/WriterTest.java b/source/pro/litvinovg/libreoffice/metadata/tests/uno/WriterTest.java new file mode 100644 index 0000000..752bba8 --- /dev/null +++ b/source/pro/litvinovg/libreoffice/metadata/tests/uno/WriterTest.java @@ -0,0 +1,26 @@ +package pro.litvinovg.libreoffice.metadata.tests.uno; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +import com.sun.star.text.XTextDocument; + +import pro.litvinovg.libreoffice.metadata.tests.helper.UnoHelper; + +public class WriterTest { + + private XTextDocument xTextDocument; + + @Before + public void setUp() throws Exception { + xTextDocument = UnoHelper.getWriterDocument(); + } + + @Test + public void test() { + assertNotNull(xTextDocument); + } + +}