Hallo Andreas,
>>> To make OOo call such "external" code you have to use commands with your
>>> own naming scheme and implement and install a so called "protocol
>>> handler" that handles commands using the scheme. All this is described
>>> in the Developers Guide in the chapters about Dispatching and Add-Ons.
>> 1. adding a menu and toolbar item with the commandURL
>> "vnd.twc.oo.oocom:SaveACopy" (I did this already and the menu item is
>> grey - it is not known up to now).
> The menu item is gray, because there is no code bound to this command.
> You have to register a ProtocolHandler for this URL.
[...]
> b) But if use JAVA-remote you can add/remove such ProtocolHandler during
> an instance of OOo runs. But believe me: patching of the ProtocolHandler
> configuration is an easy task (and will work of course) ...
Although it sounds very good, I have no idea and found no hints how to
do this. I have to fall back to your second solution. Or may be you have
some hints for me...
> registration of an UNO component at runtime isnt so easy .-)
> And I know - removing of such component at runtime isnt realy possible
> in general. Because you cant be sure that such ProtocolHandler instance
> is not cached (e.g. by the toolbar implementation) !
I did now following:
-----%<----
// Conditions:
// opened OO Document
// XMultiComponentFactory xRemoteServiceManager
XMultiServiceFactory xMultiServiceManager = (XMultiServiceFactory)
UnoRuntime.queryInterface( XMultiServiceFactory.class,
xRemoteServiceManager );
Object oProtocolHandler = xMultiServiceManager.createInstance(
"de.twc.oocom.SaveACopy" );
// get the XDispatchProvider and XInitialization interfaces
XDispatchProvider xDispatchProvider = (XDispatchProvider)
UnoRuntime.queryInterface(
XDispatchProvider.class, oProtocolHandler );
XInitialization xInitialization = (XInitialization)
UnoRuntime.queryInterface(
XInitialization.class, oProtocolHandler );
-----%<----
The Object oProtocolHandler always is null. If I understand right, I
need a class de.twc.oocom.SaveACopy. I created it and you can find it at
the end of the mail (it is nearly the same as
http://kingyo.tutms.tut.ac.jp/~toshi/StarSuite/Chap4/EX4710/).
How can I tell UNO where to find the class de.twc.oocom.SaveACopy?
Greetings, Tobias
-----%<-----
package de.twc.oocom;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.DispatchDescriptor;
import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XStatusListener;
import com.sun.star.lang.XInitialization;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lib.uno.helper.ComponentBase;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.URL;
/** SaveACopy service implementation */
public class SaveACopy extends ComponentBase
implements XServiceInfo, XDispatchProvider, XInitialization
{
private XComponentContext xContext;
private XFrame xFrame;
/** Dispatch object as inner class */
class OwnDispatch implements XDispatch {
/** take over all necessary parameters from outside. */
public OwnDispatch(XComponentContext context, XFrame frame) {
xContext = context;
xFrame = frame;
}
/** execute the functionality, which is described by this URL. */
public void dispatch(URL aURL, PropertyValue[] lArgs) {
System.out.println("Hallo Dispatcher Welt!");
}
/** register a new listener and bind it toe given URL. */
public void addStatusListener(XStatusListener l, URL url) {
}
/** deregister a listener for this URL. */
public void removeStatusListener(XStatusListener l, URL url) {
}
}
/** initialize a new instance of this class with default values. */
public SaveACopy( XComponentContext context ) {
xContext = context;
}
// ------------------------------------------------------------
/** XInitialization implementation */
public void initialize(Object[] object)
throws com.sun.star.uno.Exception {
if (object.length > 0) {
xFrame = (XFrame)UnoRuntime.queryInterface(
XFrame.class, object[0] );
}
}
/** XDispatchProvider implementation */
public XDispatch queryDispatch(
com.sun.star.util.URL aURL, String sTarget, int nFlags )
{
System.out.println(aURL.Complete);
if (aURL.Protocol.equals("vnd.twc.oo.oocom:SaveACopy")) {
return new OwnDispatch( xContext, xFrame );
}
return null;
}
public XDispatch[] queryDispatches(DispatchDescriptor[] descs)
{
XDispatch[] lDispatcher = new XDispatch[descs.length];
for(int i = 0; i < descs.length; ++i ) {
lDispatcher[i] = queryDispatch(descs[i].FeatureURL,
descs[i].FrameName,
descs[i].SearchFlags );
}
return lDispatcher;
}
/** XServiceInfo implementation */
static final String SERVICENAME =
"com.sun.star.frame.ProtocolHandler";
public String getImplementationName() {
return getClass().getName();
}
public boolean supportsService(String serviceName) {
if (serviceName.equals(SERVICENAME))
return true;
return false;
}
public String[] getSupportedServiceNames() {
return new String[] {
SERVICENAME
};
}
}
-----%<-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]