bharathy b wrote:
Hi i tried to add a Addon to Writer using ProtocolHandlerAddon.java given in the SDK . ProtocolHandleraddon.java found in OpenOffice.org2.0_SDK\examples\DevelopersGuide\Components\Addons\ProtocolHandlerAddon_java The addon creates toolbar button in openoffice writer and should display a message box when it is clicked. I used UNOPKG to do it instead of pkgchk. The toolbar buttons appear. but they are not activated here are the steps i have followed ...please tell me if i have missed out anything or gone wrong anywhere.

Hi bharathy,

First of all I don't understand why you do the build by hand. The SDK examples create a installable package automatically if you build them with make. If you do it by hand there are many ways to do something wrong.


1) compile the ProtocolHandlerAddon.java and get the ProtocolHandlerAddon.class and ProtocolHandlerAddon$ProtocolHandlerAddonImpl.class 2) write the ProtocolHandlerAddon.uno.manifest file which Contains Code: RegistrationClassName:ProtocolHandlerAddon \n 3) Using this command i get ProtocolHandlerAddon.uno.jar file Code: jar cvf ProtocolHandlerAddon.uno.jar ProtocolHandlerAddon. class ProtocolHandlerAddon$ProtocolHandlerAddonImpl.class ProtocolHandlerAddon.uno.manifest 4) put the manifest.xml in a folder called META-INF. the manifest.xml is as follows Code: <?xml versionfiltered="1.0" encoding="UTF-8"?> <!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd"> <manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest";> <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" manifest:full-path=" Addons.xcu"/> <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" manifest:full-path="ProtocolHandler.xcu"/> <manifest:file-entry manifest:media-type="applicatio n/vnd.sun.star.uno-component;type\u003dJava" manifest:full-path\u003d"\nProtocolHandlerAddon.uno.jar"/> </manifest:manifest> 5) now zip the following files into ProtocolHandlerAddon.uno.zip i) ProtocolHandlerAddon.uno.jar which inturn contains META-INF/MANIFEST.MF \n ProtocolHandlerAddon.class ProtocolHandlerAddon$ProtocolHandlerAddonImpl.class ProtocolHandlerAddon.uno.manifest ii)Addons.xcu iii) ProtocolHandler.xcu iv) META-INF/manifest.xml 6) exit OpenOffice(including Quickstart) and add the package using \n unopkg add ProtocolHandlerAddon.uno.zip Here is the ProtocolHandlerAddon.java I hav used import com.sun.star.uno.XComponentContext; import com.sun.star.lib.uno.helper.Factory; import com.sun.star.lang.XSingleComponentFactory\n; import com.sun.star.lib.uno.helper.WeakBase; import com.sun.star.uno.UnoRuntime; import com.sun.star.registry.XRegistryKey; import com.sun.star.lang.XInitialization; import com.sun.star.lang.XTypeProvider\n; import com.sun.star.lang.XServiceInfo; import com.sun.star.uno.Type; import com.sun.star.frame.XStatusListener; import com.sun.star.frame.XDispatchProvider; import com.sun.star.frame.XDispatch; import \ncom.sun.star.frame.XModel; import com.sun.star.frame.XFrame; import com.sun.star.frame.DispatchDescriptor; import com.sun.star.awt.XToolkit; import com.sun.star.awt.XWindowPeer; import com.sun.star.awt.XMessageBox\n; import com.sun.star.awt.WindowAttribute; import com.sun.star.awt.WindowClass; import com.sun.star.awt.WindowDescriptor; import com.sun.star.awt.Rectangle; public class ProtocolHandlerAddon { \npublic static class ProtocolHandlerAddonImpl extends WeakBase implements XDispatchProvider, XDispatch, XInitialization, XServiceInfo { static private final String[] m_serviceNames \u003d { "com.sun.star.frame.ProtocolHand",1] ); //-->n/vnd.sun.star.uno-component;type=Java" manifest:full-path=" ProtocolHandlerAddon.uno.jar"/> </manifest:manifest> 5) now zip the following files into ProtocolHandlerAddon.uno.zip i) ProtocolHandlerAddon.uno.jar which inturn contains META-INF/MANIFEST.MF ProtocolHandlerAddon.class ProtocolHandlerAddon$ProtocolHandlerAddonImpl.class ProtocolHandlerAddon.uno.manifest ii)Addons.xcu iii) ProtocolHandler.xcu iv) META-INF/manifest.xml 6) exit OpenOffice(including Quickstart) and add the package using unopkg add ProtocolHandlerAddon.uno.zip Here is the ProtocolHandlerAddon.java I hav used import com.sun.star.uno.XComponentContext; import com.sun.star.lib.uno.helper.Factory; import com.sun.star.lang.XSingleComponentFactory ; import com.sun.star.lib.uno.helper.WeakBase; import com.sun.star.uno.UnoRuntime; import com.sun.star.registry.XRegistryKey; import com.sun.star.lang.XInitialization; import com.sun.star.lang.XTypeProvider ; import com.sun.star.lang.XServiceInfo; import com.sun.star.uno.Type; import com.sun.star.frame.XStatusListener; import com.sun.star.frame.XDispatchProvider; import com.sun.star.frame.XDispatch; import com.sun.star.frame.XModel; import com.sun.star.frame.XFrame; import com.sun.star.frame.DispatchDescriptor; import com.sun.star.awt.XToolkit; import com.sun.star.awt.XWindowPeer; import com.sun.star.awt.XMessageBox ; import com.sun.star.awt.WindowAttribute; import com.sun.star.awt.WindowClass; import com.sun.star.awt.WindowDescriptor; import com.sun.star.awt.Rectangle; public class ProtocolHandlerAddon { public static class ProtocolHandlerAddonImpl extends WeakBase implements XDispatchProvider, XDispatch, XInitialization, XServiceInfo { static private final String[] m_serviceNames = { "com.sun.star.frame.ProtocolHand ler\n" }; private XComponentContext m_xCmpCtx; private XToolkit m_xToolkit; private XFrame m_xFrame; private XStatusListener m_xStatusListener; public ProtocolHandlerAddonImpl( XComponentContext xComponentContext ) { \n m_xCmpCtx \u003d xComponentContext; } public void initialize( Object[] object ) throws com.sun.star.uno.Exception { if ( object.length > 0 ) { m_xFrame \u003d ( XFrame ) UnoRuntime.queryInterface( \n XFrame.class, object[ 0 ] ); } m_xToolkit \u003d (XToolkit) UnoRuntime.queryInterface( XToolkit.class, m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xCmpCtx)); \n } public String[] getSupportedServiceNames() { return getServiceNames(); } public static String[] getServiceNames() { return m_serviceNames;} public boolean supportsService( String sService ) { \nint len \u003d m_serviceNames.length; for( int i\u003d0; i < len; i++) { if ( sService.equals( m_serviceNames[i] ) ) return true; } return false; } public String getImplementationName() { return ProtocolHandlerAddonImpl.class.getName\n(); } // XDispatchProvider public XDispatch queryDispatch( __/*IN*/com.sun.star.util.URL aURL, __/*IN*/String sTargetFrameName, __/*IN*/int iSearchFlags ) { XDispatch xRet \u003d null; if ( aURL.Protocol.compareTo\n("org.openoffice.Office.addon.example:") \u003d\u003d 0 ) { if ( aURL.Path.compareTo( "Function1" ) \u003d\u003d 0 ) xRet \u003d this; if ( aURL.Path.compareTo( "Function2" ) \u003d\u003d 0 ) \n xRet \u003d this; } return xRet; } public XDispatch[] queryDispatches( __/*IN*/DispatchDescriptor[] seqDescripts ) { int nCount \u003d seqDescripts.length; XDispatch[] lDispatcher \u003d new XDispatch[nCount]; \n

for( int i\u003d0; i<nCount; ++i ) lDispatcher[i] \u003d queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags ); ",1] ); //-->ler " }; private XComponentContext m_xCmpCtx; private XToolkit m_xToolkit; private XFrame m_xFrame; private XStatusListener m_xStatusListener; public ProtocolHandlerAddonImpl( XComponentContext xComponentContext ) { m_xCmpCtx = xComponentContext; } public void initialize( Object[] object ) throws com.sun.star.uno.Exception { if ( object.length > 0 ) { m_xFrame = ( XFrame ) UnoRuntime.queryInterface( XFrame.class, object[ 0 ] ); } m_xToolkit = (XToolkit) UnoRuntime.queryInterface( XToolkit.class, m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xCmpCtx)); } public String[] getSupportedServiceNames() { return getServiceNames(); } public static String[] getServiceNames() { return m_serviceNames;} 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 getImplementationName() { return ProtocolHandlerAddonImpl.class.getName (); } // XDispatchProvider public XDispatch queryDispatch( __/*IN*/com.sun.star.util.URL aURL, __/*IN*/String sTargetFrameName, __/*IN*/int iSearchFlags ) { XDispatch xRet = null; if ( aURL.Protocol.compareTo ("org.openoffice.Office.addon.example:") == 0 ) { if ( aURL.Path.compareTo( "Function1" ) == 0 ) xRet = this; if ( aURL.Path.compareTo( "Function2" ) == 0 ) xRet = this; } return xRet; } public XDispatch[] queryDispatches( __/*IN*/DispatchDescriptor[] seqDescripts ) { int nCount = seqDescripts.length; XDispatch[] lDispatcher = new XDispatch[nCount]; for( int i=0; i<nCount; ++i ) lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags ); return lDispatcher; } // XDispatch public void dispatch( __/*IN*/com.sun.star.util.URL aURL, \n __/*IN*/com.sun.star.beans.PropertyValue[] aArguments ) { if ( aURL.Protocol.compareTo("org.openoffice.Office.addon.example:") \u003d\u003d 0 ) { if ( aURL.Path.compareTo\n( "Function1" ) \u003d\u003d 0 ) { showMessageBox("SDK DevGuide Add-On example", "Function 1 activated");} if ( aURL.Path.compareTo( "Function2" ) \u003d\u003d 0 ) \n { showMessageBox("SDK DevGuide Add-On example", "Function 2 activated");} }} public void addStatusListener( __/*IN*/XStatusListener xControl, __/*IN*/com.sun.star.util.URL aURL ) {} \npublic void removeStatusListener( __/*IN*/XStatusListener xControl, __/*IN*/com.sun.star.util.URL aURL ) {} public void showMessageBox(String sTitle, String sMessage) { try { if ( null !\u003d m_xFrame && null !\u003d m_xToolkit ) { \n // describe window properties. WindowDescriptor aDescriptor \u003d new WindowDescriptor(); aDescriptor.Type \u003d WindowClass.MODALTOP; aDescriptor.WindowServiceName \u003d new String( "infobox" ); aDescriptor.ParentIndex\n \u003d -1; aDescriptor.Parent (XWindowPeer)UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow()); aDescriptor.Bounds \u003d new Rectangle(0,0,300,200); aDescriptor.WindowAttributes \u003d WindowAttribute.BORDER\n |WindowAttribute.MOVEABLE | WindowAttribute.CLOSEABLE; XWindowPeer xPeer \u003d m_xToolkit.createWindow( aDescriptor ); if ( null !\u003d xPeer ) { XMessageBox xMsgBox \u003d (XMessageBox)UnoRuntime.queryInterface( \nXMessageBox.class, xPeer); if ( null !\u003d xMsgBox ) { xMsgBox.setCaptionText( sTitle ); xMsgBox.setMessageText( sMessage ); xMsgBox.execute(); }}}} catch ( com.sun.star.uno.Exception e) { // do your error handling \n }} } public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) { ",1] ); //--> return lDispatcher; } // XDispatch public void dispatch( __/*IN*/com.sun.star.util.URL aURL, __/*IN*/com.sun.star.beans.PropertyValue[] aArguments ) { if ( aURL.Protocol.compareTo("org.openoffice.Office.addon.example:") == 0 ) { if ( aURL.Path.compareTo ( "Function1" ) == 0 ) { showMessageBox("SDK DevGuide Add-On example", "Function 1 activated");} if ( aURL.Path.compareTo( "Function2" ) == 0 ) { showMessageBox("SDK DevGuide Add-On example", "Function 2 activated");} }} public void addStatusListener( __/*IN*/XStatusListener xControl, __/*IN*/com.sun.star.util.URL aURL ) {} public void removeStatusListener( __/*IN*/XStatusListener xControl, __/*IN*/com.sun.star.util.URL aURL ) {} public void showMessageBox(String sTitle, String sMessage) { try { if ( null != m_xFrame && null != m_xToolkit ) { // describe window properties. WindowDescriptor aDescriptor = new WindowDescriptor(); aDescriptor.Type = WindowClass.MODALTOP; aDescriptor.WindowServiceName = new String( "infobox" ); aDescriptor.ParentIndex = -1; aDescriptor.Parent (XWindowPeer)UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow()); aDescriptor.Bounds = new Rectangle(0,0,300,200); aDescriptor.WindowAttributes = WindowAttribute.BORDER |WindowAttribute.MOVEABLE | WindowAttribute.CLOSEABLE; XWindowPeer xPeer = m_xToolkit.createWindow( aDescriptor ); if ( null != xPeer ) { XMessageBox xMsgBox = (XMessageBox)UnoRuntime.queryInterface( XMessageBox.class, xPeer); if ( null != xMsgBox ) { xMsgBox.setCaptionText( sTitle ); xMsgBox.setMessageText( sMessage ); xMsgBox.execute(); }}}} catch ( com.sun.star.uno.Exception e) { // do your error handling }} } public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) { XSingleComponentFactory xFactory \u003d null; if ( sImplementationName.equals( ProtocolHandlerAddonImpl.class.getName\n() ) ) xFactory \u003d Factory.createComponentFactory(ProtocolHandlerAddonImpl.class, ProtocolHandlerAddonImpl.getServiceNames()); return xFactory; } public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) { \n return Factory.writeRegistryServiceInfo( ProtocolHandlerAddonImpl.class.getName(), ProtocolHandlerAddonImpl.getServiceNames(),xRegistryKey )}} This is the ProtocolHandlerAddon.xcu <?xml version\u003d\'\n1.0\' encoding\u003d\'UTF-8\'?> <oor:component-data oor:name\u003d"ProtocolHandler" oor:package\u003d"org.openoffice.Office" xmlns:oor\u003d"http://openoffice.org/2001/registry\n"; xmlns:xs\u003d"http://www.w3.org/2001/XMLSchema"; xmlns:xsi\u003d"http://www.w3.org/2001/XMLSchema-instance\n";> <node oor:name\u003d"HandlerSet"> <node oor:name\u003d"ProtocolHandlerAddon$ProtocolHandlerAddonImpl" oor:op\u003d"replace"> <prop oor:name\u003d"Protocols" oor:type\u003d"oor:string-list"> \n <value>org.openoffice.Office.addon.example:*</value> </prop> </node> </node> </oor:component-data> Here is the Addons.xcu\n that adds a toolbar buttons <?xml version\u003d\'1.0\' encoding\u003d\'UTF-8\'?> <oor:component-data xmlns:oor\u003d"http://openoffice.org/2001",1] ); //--> XSingleComponentFactory xFactory = null; if ( sImplementationName.equals( ProtocolHandlerAddonImpl.class.getName () ) ) xFactory = Factory.createComponentFactory(ProtocolHandlerAddonImpl.class, ProtocolHandlerAddonImpl.getServiceNames()); return xFactory; } public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) { return Factory.writeRegistryServiceInfo( ProtocolHandlerAddonImpl.class.getName(), ProtocolHandlerAddonImpl.getServiceNames(),xRegistryKey )}} This is the ProtocolHandler.xcu <?xml versionfiltered=' 1.0' encoding='UTF-8'?> <oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry " xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "> <node oor:name="HandlerSet"> <node oor:name="ProtocolHandlerAddon$ProtocolHandlerAddonImpl" oor:op="replace"> <prop oor:name="Protocols" oor:type="oor:string-list"> <value>org.openoffice.Office.addon.example:*</value> </prop> </node> </node> </oor:component-data> Here is the Addons.xcu that adds a toolbar buttons <?xml versionfiltered='1.0' encoding='UTF-8'?> <oor:component-data xmlns:oor="http://openoffice.org/2001 /registry" xmlns:xs\u003d"\nhttp://www.w3.org/2001/XMLSchema"; oor:name\u003d"Addons" oor:package\u003d"org.openoffice.Office"> <node oor:name\u003d"AddonUI"> <node oor:name\u003d"OfficeToolBar"> \n <node oor:name\u003d"org.openoffice.Office.addon.example" oor:op\u003d"replace"> <node oor:name\u003d"m1" oor:op\u003d"replace"> <prop oor:name\u003d"URL" oor:type\u003d"xs:string"> \n <value>org.openoffice.Office.addon.example:Function1</value> </prop> <prop oor:name\u003d"ImageIdentifier" oor:type\u003d"xs:string"> <value/> </prop> \n<prop oor:name\u003d"Title" oor:type\u003d"xs:string"> <value/> <value xml:lang\u003d"en-US">Function 1</value> </prop> <prop oor:name\u003d"Target" oor:type\u003d"xs:string"> \n <value>_self</value> </prop> <prop oor:name\u003d"Context" oor:type\u003d"xs:string"> <value>com.sun.star.text.TextDocument</value> </prop> </node> \n <node oor:name\u003d"m2" oor:op\u003d"replace"> <prop oor:name\u003d"URL" oor:type\u003d"xs:string"> <value>org.openoffice.Office.addon.example:Function2\n</value> </prop> <prop oor:name\u003d"ImageIdentifier" oor:type\u003d"xs:string"> <value/> </prop> <prop oor:name\u003d"Title" oor:type\u003d"xs:string"> \n <value/> <value xml:lang\u003d"en-US">Function 2</value> </prop> <prop oor:name\u003d"Target" oor:type\u003d"xs:string"> <value>_self</value> ",1] ); //-->/registry" xmlns:xs=" http://www.w3.org/2001/XMLSchema"; oor:name="Addons" oor:package="org.openoffice.Office"> <node oor:name="AddonUI"> <node oor:name="OfficeToolBar"> <node oor:name="org.openoffice.Office.addon.example" oor:op="replace"> <node oor:name="m1" oor:op="replace"> <prop oor:name="URL" oor:type="xs:string"> <value>org.openoffice.Office.addon.example:Function1</value> </prop> <prop oor:name="ImageIdentifier" oor:type="xs:string"> <value/> </prop> <prop oor:name="Title" oor:type="xs:string"> <value/> <value xml:lang="en-US">Function 1</value> </prop> <prop oor:name="Target" oor:type="xs:string"> <value>_self</value> </prop> <prop oor:name="Context" oor:type="xs:string"> <value>com.sun.star.text.TextDocument</value> </prop> </node> <node oor:name="m2" oor:op="replace"> <prop oor:name="URL" oor:type="xs:string"> <value>org.openoffice.Office.addon.example:Function2 </value> </prop> <prop oor:name="ImageIdentifier" oor:type="xs:string"> <value/> </prop> <prop oor:name="Title" oor:type="xs:string"> <value/> <value xml:lang="en-US">Function 2</value> </prop> <prop oor:name="Target" oor:type="xs:string"> <value>_self</value> \n</prop> <prop oor:name\u003d"Context" oor:type\u003d"xs:string" <value>com.sun.star.text.TextDocument</value> </prop> </node> </node> </node> \n </oor:component-data> Why are the buttons in the toolbar not getting activated? What does this mean in the Addons.xcu \n <prop oor:name\u003d"URL" oor:type\u003d"xs:string"> <value>org.openoffice.Office.addon.example:Function1</value> </prop> What is the maeaning of \norg.openoffice.Office.addon.example:Function1 What is Function1? Is it Function1.java? Where should I place Function1? Should I include it in the ProtocolHandlerAddon.uno.zip\n? Please help me ... Thank you in advance.. With Regards Bharathy B
\n\n
",0] ); D(["ce"]);  //-->
</prop> <prop oor:name="Context" oor:type="xs:string" <value>com.sun.star.text.TextDocument</value> </prop> </node> </node> </node> </oor:component-data> Why are the buttons in the toolbar not getting activated?
If a button is disabled it can have the following reasons:
- The statusChanged function from the controller notified the button , which is bound to the command, that it has to be disabled. - The button cannot find a dispatcher for the its command URL. This can have several reasons.
  - There is no registered protocol handler.
  - The dispatcher doesn't implement the function.

What does this mean in the Addons.xcu
<prop oor:name="URL" oor:type="xs:string"> <value>org.openoffice.Office.addon.example:Function1</value> </prop>
This is the definition of a command URL. A command URL describes a function which can be dispatched using the com.sun.star.frame.XDispatch interface.

What is the maeaning of org.openoffice.Office.addon.example:Function1
This is a command URL with the protocol part "org.openoffice.Office.addon" and the function "function1".

What is Function1? Is it Function1.java?
No. Function1 refers to a function with the name "function1". It doesn't refer to an implementation file.

Where should I place Function1? Should I include it in the ProtocolHandlerAddon.uno.zip ?
Your dispatcher implementation has to support this function. Your add-on must register itself for the protocol part of the command URL. The ProtocolHandler.xcu is responsible to create association between protocol and UNO service.


Please help me ...
Did you read the Developer's Guide where most of your questions are answered? There is a chapter about protocol handler (4.7.1) and add-ons (4.7.3). You should first read it and if you don't understand some parts, please ask.
You can find the Developer's Guide here: http://api.openoffice.org/

Regards,
Carsten

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

  • [api-... bharathy b
    • ... Carsten Driesner - Sun Germany - ham02 - Hamburg - Software Engineer
      • ... bharathy b
        • ... Mathias Bauer
          • ... bharathy b

Reply via email to