bootstrap connect Tobias Krais (www.design-to-use.de) How to connect to a already listening OpenOffice?

You can start a OpenOffice in listening mode with e.g. this command:

ooffice -accept="socket,host=localhost,port=9000;urp;StarOffice.ServiceManager"

This commandline starts OpenOffice listening on port 9000

This method connect to a listening OpenOffice.

import {%see com.sun.star.beans.XPropertySet}; import {%see com.sun.star.bridge.UnoUrlResolver}; import {%see com.sun.star.bridge.XUnoUrlResolver}; import {%see com.sun.star.comp.helper.Bootstrap}; import {%see com.sun.star.lang.XMultiComponentFactory}; import {%see com.sun.star.uno.UnoRuntime}; import {%see com.sun.star.uno.XComponentContext}; /** * This method connects to a running OpenOffice. This OpenOffice is * listening on a specific port. It connects to this port. * * @param ooport * @return */ public void connectListeningOpenOffice(String ooport) { try{ // Create an OO Component Context XComponentContext xCC = Bootstrap.createInitialComponentContext(null); // create a connector, so that it can contact the office XUnoUrlResolver urlResolver = UnoUrlResolver.create(xCC); Object initialObject = urlResolver.resolve( "uno:socket,host=localhost,port=" + ooport + ";urp;StarOffice.ServiceManager"); XMultiComponentFactory xMCF = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, initialObject); // retrieve the component context as property (it is not yet // exported from the office). Query for the XPropertySet interface. XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xMCF); // Get the default context from the office server. Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext"); // Query for the interface XComponentContext. xCC = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext); // now create the desktop service // NOTE: use the office component context here! Object desktop = xMCF.createInstanceWithContext( "com.sun.star.frame.Desktop", xCC); } catch(Exception e){ } }
Linking imports Initial version