@@ -0,0 +1,1646 @@
+package org.libreoffice.example.helper;%0A%0Aimport com.sun.star.frame.XDesktop;%0Aimport com.sun.star.frame.XFrame;%0Aimport com.sun.star.frame.XModel;%0Aimport com.sun.star.lang.XComponent;%0Aimport com.sun.star.lang.XMultiComponentFactory;%0Aimport com.sun.star.text.XTextDocument;%0Aimport com.sun.star.uno.UnoRuntime;%0Aimport com.sun.star.uno.XComponentContext;%0A%0Apublic class DocumentHelper %7B%0A%09%0A%09/** Returns the curerent XDesktop */%0A%09public static XDesktop getCurrentDesktop(XComponentContext xContext) %7B%0A%09%09XMultiComponentFactory xMCF = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class,%0A%09%09%09%09xContext.getServiceManager());%0A        Object desktop = null;%0A%09%09try %7B%0A%09%09%09desktop = xMCF.createInstanceWithContext(%22com.sun.star.frame.Desktop%22, xContext);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09return null;%0A%09%09%7D%0A        return (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop);%0A%09%7D%0A%09%0A%09/** Returns the current XComponent */%0A    private static XComponent getCurrentComponent(XComponentContext xContext) %7B%0A        return (XComponent) getCurrentDesktop(xContext).getCurrentComponent();%0A    %7D%0A    %0A    /** Returns the current frame */%0A    public static XFrame getCurrentFrame(XComponentContext xContext) %7B%0A    %09XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, getCurrentComponent(xContext));%0A    %09return xModel.getCurrentController().getFrame();%0A    %7D%0A%0A    /** Returns the current text document (if any) */%0A    public static XTextDocument getCurrentDocument(XComponentContext xContext) %7B%0A        return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, getCurrentComponent(xContext));%0A    %7D%0A%7D%0A

Add helper to retrieve frame, document etc