Please see my attached example. I tested it and it does work.

Make sure you are running AOO with the right options:
./soffice "-accept=socket,host=localhost,port=8100;urp"
or match the port to the initialObject string.

For a real-world implementation, you should probably extend WeakBase too,
in the class implementing the listener.

Regards
Damjan

On Wed, Jul 12, 2017 at 10:04 AM, Rushna Jabi <rushnajabi...@gmail.com>
wrote:

> Hello Sir,
> I have an UNO component and I implemented interface "com.sun.star.document.
> XDocumentEventBroadCaster", use UnoRuntime.queryInface() to get its
> XEventBroadcaster interface, calling addDocumentEventListener().
>
> please tell me from where I have to get "OnSave" or "OnSaveAs" events.I am
> not getting.
>
>
>
> Regards,
> Rushna Jabi
> Software Programmer
> 8447294601
>
> On Thu, Jul 6, 2017 at 12:48 PM, Rushna Jabi <rushnajabi...@gmail.com>
> wrote:
>
>> OK,I am working on this.
>>
>> Thanks.
>>
>>
>> On Thu, Jul 6, 2017 at 12:25 PM, Damjan Jovanovic <dam...@apache.org>
>> wrote:
>>
>>> You're looking for this then:
>>> https://wiki.openoffice.org/wiki/Documentation/DevGuide/Offi
>>> ceDev/Document_Events
>>>
>>> I'll only be able to test this later, but once you have an UNO component
>>> context or service manager, use it to create a
>>> "com.sun.star.frame.GlobalEventBroadcaster", use
>>> UnoRuntime.queryInface() to get its XEventBroadcaster interface, call
>>> addEventListener() to add your listener, and in that listener make sure the
>>> even name is "OnSave" or "OnSaveDone".
>>>
>>> Good luck
>>> Damjan
>>>
>>> On Thu, Jul 6, 2017 at 8:43 AM, Rushna Jabi <rushnajabi...@gmail.com>
>>> wrote:
>>>
>>>> Hello Sir,
>>>> I know this one,but i don't want to use macro.
>>>> I have to do it using code. If I use "ag.ion.noa_2.2.3"  Nice
>>>> OpenOffice Access Library , in this library some methods
>>>> OnSave(),OnSaveDone() in AbstractDocument class but I am unable to get
>>>> How to use it.
>>>>
>>>> Please help me out.
>>>>
>>>>
>>>> Thanks & Regards,
>>>> Rushna Jabi
>>>> Software Engineer
>>>> 8447294601
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Jul 6, 2017 at 11:49 AM, Damjan Jovanovic <dam...@apache.org>
>>>> wrote:
>>>>
>>>>> Hi Rushna
>>>>>
>>>>> Apparently, to do this manually:
>>>>>
>>>>> Click on "Tools" -> "Customize".
>>>>> Go to the "Events" tab.
>>>>> Select "Save document", and click on the "Macro" button, then assign
>>>>> your plugin.
>>>>>
>>>>> See this for screenshots:
>>>>> https://wiki.openoffice.org/wiki/Documentation/OOoAuthors_Us
>>>>> er_Manual/Getting_Started/How_to_run_a_macro
>>>>>
>>>>> Or, are you trying to get your plugin to automatically assign itself
>>>>> to be called on save, so that the above isn't required?
>>>>>
>>>>> Regards
>>>>> Damjan
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Jul 6, 2017 at 6:52 AM, Rushna Jabi <rushnajabi...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Thanks for your response.but I am already a member of OpenOffice
>>>>>> forum,
>>>>>> I have sent my issues there but "Villeroy" replied that "This is too
>>>>>> sophisticated to be discussed on this forum, I think. You should
>>>>>> write to
>>>>>> developers mailing list for LibreOffice or OpenOffice."
>>>>>>
>>>>>> Please help..
>>>>>>
>>>>>> Thanks & Regards,
>>>>>>
>>>>>> Rushna Jabi
>>>>>> Software Engineer
>>>>>> 8447294601
>>>>>>
>>>>>> On Wed, Jul 5, 2017 at 5:51 PM, FR web forum <ooofo...@free.fr>
>>>>>> wrote:
>>>>>>
>>>>>> > The better place to help end-users is:
>>>>>> > http://forum.openoffice.org
>>>>>> >
>>>>>> > ----- Mail original -----
>>>>>> > De: "Rushna Jabi" <rushnajabi...@gmail.com>
>>>>>> > À: dev@openoffice.apache.org
>>>>>> > Envoyé: Mercredi 5 Juillet 2017 12:04:52
>>>>>> > Objet: OpenOffice Query
>>>>>> >
>>>>>> > Hello Sir,
>>>>>> >
>>>>>> > I am working on Java Plugin for OpenOffice.I created a plugin but i
>>>>>> want to
>>>>>> > call
>>>>>> > this plugin before save event.
>>>>>> >
>>>>>> > please help me out.
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>> > Thanks & Regards,
>>>>>> > Rushna Jabi
>>>>>> > ACPL Systems Pvt. Ltd.
>>>>>> >
>>>>>> > ------------------------------------------------------------
>>>>>> ---------
>>>>>> > To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
>>>>>> > For additional commands, e-mail: dev-h...@openoffice.apache.org
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>
import javax.swing.JOptionPane;

import com.sun.star.beans.XPropertySet;
import com.sun.star.bridge.UnoUrlResolver;
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.document.EventObject;
import com.sun.star.document.XEventBroadcaster;
import com.sun.star.document.XEventListener;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public class Main {
    public static void main(String[] args) throws Exception {
        XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext(null);
        
        // create a connector, so that it can contact the office
        XUnoUrlResolver urlResolver = UnoUrlResolver.create(xcomponentcontext);
       
        Object initialObject = urlResolver.resolve(
            "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
       
        XMultiComponentFactory xOfficeFactory = (XMultiComponentFactory) UnoRuntime.queryInterface(
            XMultiComponentFactory.class, initialObject);
       
        // retrieve the component context as property (it is not yet exported from the office)
        // Query for the XPropertySet interface.
        XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface( 
            XPropertySet.class, xOfficeFactory);
       
        // Get the default context from the office server.
        Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext");
       
        // Query for the interface XComponentContext.
        XComponentContext xOfficeComponentContext = (XComponentContext) UnoRuntime.queryInterface(
            XComponentContext.class, oDefaultContext);
       
        
        
        
        Object globalEventBroadcasterObject = xOfficeFactory.createInstanceWithContext(
                "com.sun.star.frame.GlobalEventBroadcaster",
                xOfficeComponentContext);
        XEventBroadcaster globalEventBroadcaster = UnoRuntime.queryInterface(
                XEventBroadcaster.class, globalEventBroadcasterObject);
        globalEventBroadcaster.addEventListener(new XEventListener() {
            
            @Override
            public void disposing(com.sun.star.lang.EventObject event) {
            }
            
            @Override
            public void notifyEvent(EventObject event) {
                if (event.EventName.equals("OnSave") || event.EventName.equals("OnSaveAs")) {
                    JOptionPane.showMessageDialog(null, event.EventName, "Global event",
                            JOptionPane.OK_OPTION | JOptionPane.INFORMATION_MESSAGE);
                }
            }
        });
        // Don't exit yet?
        Thread.sleep(60*1000);
    }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
For additional commands, e-mail: dev-h...@openoffice.apache.org

Reply via email to