Page 1 of 1

[Solved] OpenOffice Plugin call before save event

Posted: Mon Jun 12, 2017 12:01 pm
by Rushna
Hey everyone!
I have written to program a Java AddOn (extension) in Netbeans 8.0.2 with Java (1.8) for OpenOffice Writer. I already downloaded the Apache OpenOffice Plugin for Netbeans8.2 and I have created a AddOn but I want to call this addOn before save event Pragmatically.

Re: OpenOffice Plugin call before save event

Posted: Mon Jun 12, 2017 7:14 pm
by Villeroy

Re: OpenOffice Plugin call before save event

Posted: Wed Jun 14, 2017 12:02 pm
by Rushna
Hi Villeroy,

thanks for your response ! i have updated my code based on your recommended link but i am still missing something. could you please provide me an example about how to call my plugin before save event to the OpenOffice Writer ?

Re: OpenOffice Plugin call before save event

Posted: Fri Jun 23, 2017 12:17 pm
by Rushna
Hi All...,
I am using ag.ion.noa_2.2.3 (noa) jar file to call plugin before save event and there is a AbstractDocument class in which onSave() ,onSaveAs() but don't know how to call
in my plugin code.
Please help me out.

my code to create plugin:

Code: Select all

public final class Test1AddOn extends WeakBase 
   implements com.sun.star.frame.XDispatchProvider,
              com.sun.star.frame.XDispatch,
              com.sun.star.lang.XServiceInfo,
              com.sun.star.lang.XInitialization
{

   
    
    private final XComponentContext m_xContext;
    private com.sun.star.frame.XFrame m_xFrame;
    private static final String m_implementationName = Test1AddOn.class.getName();
    private static final String m_implementationName1="Rushna World!";
    private static final String[] m_serviceNames = {
        "com.sun.star.frame.ProtocolHandler" };
    private Object xStorable;


    public Test1AddOn( XComponentContext context )
    {
        m_xContext = context;
        System.out.println("Hello Test");
    };

    public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
        XSingleComponentFactory xFactory = null;

        if ( sImplementationName.equals( m_implementationName ) )
            xFactory = Factory.createComponentFactory(Test1AddOn.class, m_serviceNames);
        return xFactory;
    }

    public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) {
        System.out.println("Hello writeRegistryService");
        return Factory.writeRegistryServiceInfo(m_implementationName,
                                                m_serviceNames,
                                                xRegistryKey);
        
    }

    // com.sun.star.frame.XDispatchProvider:
    public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL,
                                                       String sTargetFrameName,
                                                       int iSearchFlags )
    {
        if ( aURL.Protocol.compareTo("com.example.test1addon:") == 0 )
        {
            if ( aURL.Path.compareTo("Rushna") == 0 )
           return this;
        }
        return null;
    }

    // com.sun.star.frame.XDispatchProvider:
    public com.sun.star.frame.XDispatch[] queryDispatches(
         com.sun.star.frame.DispatchDescriptor[] seqDescriptors )
    {
        int nCount = seqDescriptors.length;
        com.sun.star.frame.XDispatch[] seqDispatcher =
            new com.sun.star.frame.XDispatch[seqDescriptors.length];

        for( int i=0; i < nCount; ++i )
        {
            seqDispatcher[i] = queryDispatch(seqDescriptors[i].FeatureURL,
                                             seqDescriptors[i].FrameName,
                                             seqDescriptors[i].SearchFlags );
        }
      
        return seqDispatcher;
    }

    // com.sun.star.frame.XDispatch:
     public void dispatch( com.sun.star.util.URL aURL,
                           com.sun.star.beans.PropertyValue[] aArguments )
    {
         if ( aURL.Protocol.compareTo("com.example.test1addon:") == 0 )
        {
            if ( aURL.Path.compareTo("Rushna") == 0 )
            {   


            Main_Form r=new Main_Form();
                r.setVisible(true);      
              
   XTextDocument xDoc = (XTextDocument) UnoRuntime.queryInterface(
XTextDocument.class, m_xFrame.getController().getModel());
//xDoc.getText().setString(“Hello World”); 
 
 xDoc.getText().setString(m_implementationName1);
    
                return;
            }
        }//create a text file in D drive.
         
         
    }
    
    public void addStatusListener( com.sun.star.frame.XStatusListener xControl,
                                    com.sun.star.util.URL aURL )
    {
       // add your own code here
    }

    public void removeStatusListener( com.sun.star.frame.XStatusListener xControl,
                                       com.sun.star.util.URL aURL )
    {
        // add your own code here
    }

    // com.sun.star.lang.XServiceInfo:
    public String getImplementationName() {
       
         return m_implementationName;
    }

    public boolean supportsService( String sService ) {
        int len = m_serviceNames.length;

        for( int i=0; i < len; i++) {
            if (sService.equals(m_serviceNames[i]))
 
                return true;
        }
        return false;
    }

    public String[] getSupportedServiceNames() {
       System.out.println("Hello Support");
       return m_serviceNames;
    }

    // com.sun.star.lang.XInitialization:
    public void initialize( Object[] object )
        throws com.sun.star.uno.Exception
    {
        if ( object.length > 0 )
        {
            m_xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
                com.sun.star.frame.XFrame.class, object[0]);
            
           }
           
        }

    
    }

Re: OpenOffice Plugin call before save event

Posted: Fri Jun 23, 2017 6:55 pm
by Villeroy
This is too sophisticated to be discussed on this forum, I think. You should write to developers mailing list for LibreOffice or OpenOffice.

Re: OpenOffice Plugin call before save event

Posted: Mon Jul 03, 2017 12:56 pm
by Rushna
please share with me email id of OpenOffice or LibreOffice developers.

Re: OpenOffice Plugin call before save event

Posted: Mon Jul 03, 2017 2:07 pm
by robleyd

Re: [Solved] OpenOffice Plugin call before save event

Posted: Thu Jul 20, 2017 12:35 pm
by Rushna
Hi All,
"OnSave" and "OnSaveAs" should be delivered before the document is saved, and "OnSaveDone " and "OnSaveAsDone" after it is saved.

But I am getting the same result "OnSaveAs" and "OnSaveAsDone" it's delivered after the save in both cases.
please help.