Jimmy wrote:
How can I dispatch a macro Url from my Java Add-on?

I'd like to dispatch the following function in the Tools/ModuleControles Library:

StoreDocument(oDocument as Object, FilterNames() as String, DefaultName as String, DisplayDirectory as String, Optional iAddProcedure as Integer)

I'd like to call this function from my add-on. It would be best if I could call this function from my Addons.xcu but this leads to a crash since I don't know how to set the oDocument parameter in the xcu file. Is there any other chance to call the macro? I can catch the dispatch for the corresponding button but don't know how to go any further..
Hi Jimmy,

It's not possible to create a script URL with complex parameters like Object (argument 1) or a sequence (argument 2). Therefore you have to create your own DispatchProvider and forward the call to your script via dispatch API.


Thanks

public void dispatch(URL arg0, PropertyValue[] arg1) {
       if (arg0.Protocol.compareTo("org.openoffice.addon.MyAddon:") == 0) {
           if (arg0.Path.compareTo("FuncExport") == 0) {
               try {
                   Iterator iterOn = frames.iterator();
                   while (iterOn.hasNext()) {
                       FrameInfo actFrameInfo = (FrameInfo) iterOn.next();
                       if (actFrameInfo.getXComp() == ElementController
                               .getXComponent()) {
                           convertElml = actFrameInfo.getXmlConverter();
                           break;
                       }
                   }
                                  // NOW CALL THE MACRO

               } catch (java.lang.Exception e) {
                   e.printStackTrace();
               }
           }
       }
   }


You should read the following Developer's Guide chapter 18.6.1 Scripting Framework URI Specification. You have to dispatch a "vnd.sun.star.script:"-URL which refers to your Basic macro. The arguments for your script function have to be passed within the ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > argument. The first entry should match your first argument.

So your code would look like that (pseudo code):
Sequence< OUString >      aSeqFilterNames(1):
Sequence< PropertyValue > aSeqArgs(4);
OUString                  aDefaultName;
OUString                  aDirectory;

...

aSeqArgs[0].Value = makeAny( xMyDocument );
aSeqArgs[1].Value = makeAny( aSeqFilterNames );
aSeqArgs[2].Value = makeAny( aDefaultName );
aSeqArgs[3].Value = makeAny( aDirectory );

com::sun::star::util::URL aURL;
aURL.Complete = OUString( "vnd.sun.star.script:Library.Module.StoreDocument?language=Basic&location=application" );

xDispatch->dispatch( aURL, aSeqArgs );

Regards,
Carsten

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to