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. [image: Sad] here are the steps i have followed ...please tell me if i have missed out anything or gone wrong anywhere.
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.manifest 4) put the manifest.xml in a folder called META-INF. the manifest.xml is as follows Code: <?xml version="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="ProtocolHandlerAddon.xcu"/> <manifest:file-entry manifest:media-type="application/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.ProtocolHandler" }; 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, /*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 = 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 ProtocolHandlerAddon.xcu <?xml version='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 version='1.0' encoding='UTF-8'?> <oor:component-data xmlns:oor="http://openoffice.org/2001/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> </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? What does this mean in the Addons.xcu [image: Question] <prop oor:name="URL" oor:type="xs:string"> <value>org.openoffice.Office.addon.example:Function1</value> </prop> What is the maeaning of org.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? Please help me ... Thank you in advance.. With Regards Bharathy B <[EMAIL PROTECTED]>
