connect bootstrap UNO.CLS Rony G. Flatscher How to connect to a already listening OpenOffice?

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

soffice -accept=socket,host=localhost,port=8100;urp;

This commandline starts OpenOffice listening on port 8100.

This snippet connects to a listening OpenOffice and creates a wordprocessor document.

/* Demonstrate how to connect to a remote OOo server and use it via ooRexx ({%external http://www.ooRexx.org}) Assumes that an instance of OOo got started that listens on port 8100; one can create such an instance via the commandline, using the following command: soffice -accept=socket,host=localhost,port=8100;urp; to start an instance without a visible window on the server, you may use the command: soffice -invisible -accept=socket,host=localhost,port=8100;urp; or soffice -headless -accept=socket,host=localhost,port=8100;urp; OOo can be configured to listen on a specific port, cf. "Developer's Guide" for further information on this. The code in this snippet could be transcribed to Java in a 1:1 mapping. This version is based upon the pure BSF4Rexx version that can be found here: {%internal ./Office.ConnectToListeningOpenOfficeVariant2_BSF4Rexx_.snip} */ /* initialize connection to server, get its Desktop-service and XComponentLoader interface */ call UNO.CLS /* get special UNO ooRexx support, which itself calls the module BSF.CLS, thereby establishing full access to Java using BSF4Rexx */ /****************************/ /* ===> Bootstrapping <=== */ /****************************/ /* note: the class "{%see com.sun.star.comp.helper.Bootstrap}" is pre-registered under the name "bootstrap" in a directory which can be addressed using the environment symbol ".uno" */ localCC = .uno~bootstrap~createInitialComponentContext(.nil) /* create a local ComponentContext */ localSM = localCC~getServiceManager /* create its ServiceManager */ /* query the XUrlResolver interface from the local UnoUrlResolver object */ /* create the URL resolver service object */ localUUR = localSM~createInstanceWithContext("{%see com.sun.star.bridge.UnoUrlResolver}", localCC) localXUUR = localUUR~{%see com.sun.star.bridge.XUnoUrlResolver%XUnoUrlResolver} /* query the XNamingService interface from the remote service object */ hostname = "localhost" /* can be any host on the Internet */ hostport = 8100 /* port on which OOo listens for clients */ /* URL to use for connecting to server */ unoUrl = "uno:socket,host="hostname",port="hostport";urp;StarOffice.NamingService" say "connecting using the URL:" pp(unoURL)"..." /* resolve URL, thereby retrieving the remote NamingService service object */ remoteXNS = localXUUR~resolve(unoUrl)~{%see com.sun.star.uno.XNamingService%XNamingService} /* query the XMultiServiceFactory interface from the remote service object */ remoteXMSF = remoteXNS~getRegisteredObject("StarOffice.ServiceManager")~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory} /* query the XDesktop interface from the remote service object */ remoteXD = remoteXMSF~createInstance("{%see com.sun.star.frame.Desktop}")~{%see com.sun.star.frame.XDesktop%XDesktop} /* query the XComponentLoader interface from the remote service object */ remoteXCL = remoteXD~{%see com.sun.star.frame.XComponentLoader%XComponentLoader} /*********************************************************************/ /* ===> Now we are ready to load/open and/or create documents <=== */ /*********************************************************************/ /* load an empty text document into a (local) new window */ /* note: an instance of an empty array of type "{%see com.sun.star.beans.PropertyValue}" is pre-registered under the name "noProps" in a directory which can be addressed using the environment symbol ".uno" */ writerComponent = remoteXCL~loadComponentFromURL("private:factory/swriter", "_blank", 0, .uno~noProps)
Initial version