Hi Tom, here the snippet that does not bootstrap an OO but connects to a listing OO. This is a equivalent to the "Bootstrap OpenOffice Snippet".
Greetings, Tobias
<?xml version="1.0"?> <!-- $RCSfile: $ last change: $Revision: $ $Author: $ $Date: $ (c)2003 by the copyright holders listed with the author-tags. If no explicit copyright holder is mentioned with a certain author, the author him-/herself is the copyright holder. All rights reserved. Public Documentation License Notice: The contents of this Documentation are subject to the Public Documentation License Version 1.0 (the "License"); you may only use this Documentation if you comply with the terms of this License. A copy of the License is available at http://www.openoffice.org/licenses/PDL.html The Original Documentation can be found in the CVS archives of openoffice.org at the place specified by RCSfile: in this header. The Initial Writer(s) of the Original Documentation are listed with the author-tags below. The Contributor(s) are listed with the author-tags below without the marker for being an initial author. All Rights Reserved. --> <snippet language="Java" application="Office"> <keywords> <keyword>bootstrap</keyword> <keyword>connect</keyword> </keywords> <authors> <author id="tobiaskrais" initial="false" email="[EMAIL PROTECTED]" copyright="It's free">Tobias Krais</author> </authors> <question heading="Connect to Listening OpenOffice">How to connect to a already listening OpenOffice? <p>You can start a OpenOffice in listening mode with e.g. this command:</p> <p>ooffice -accept="socket,host=localhost,port=9000;urp;StarOffice.ServiceManager"</p> <p>This commandline starts OpenOffice listening on port 9000</p> </question> <answer> <p>This method connect to a listening OpenOffice.</p> <listing>// You should import following classes: // import com.sun.star.beans.XPropertySet; // import com.sun.star.bridge.UnoUrlResolver; // import com.sun.star.bridge.XUnoUrlResolver; // import com.sun.star.comp.helper.Bootstrap; // import com.sun.star.lang.XMultiComponentFactory; // import com.sun.star.uno.UnoRuntime; // import com.sun.star.uno.XComponentContext; // You will need these Objects often, so define them global... Object desktop = null; XComponentContext xRemoteContext = null; XMultiComponentFactory xRemoteServiceManager = null; /** * 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 xRemoteContext = Bootstrap.createInitialComponentContext(null); // create a connector, so that it can contact the office XUnoUrlResolver urlResolver = UnoUrlResolver.create(xRemoteContext); Object initialObject = urlResolver.resolve( "uno:socket,host=localhost,port=" + ooport + ";urp;StarOffice.ServiceManager"); xRemoteServiceManager = (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, xRemoteServiceManager); // Get the default context from the office server. Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext"); // Query for the interface XComponentContext. xRemoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext); // now create the desktop service // NOTE: use the office component context here! desktop = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); } catch(Exception e){ System.out.println("No OpenOffice is listening. Cannot connect."); } } </listing> </answer> <versions> <version number="1.1.x" status="tested"/> </versions> <operating-systems> <operating-system name="All"/> </operating-systems> <changelog> <change author-id="tobiaskrais" date="2006-03-20">Initial version</change> </changelog> </snippet>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
