Hi Andy,
you are not by any chance the wildlife photographer, are you ?
I am trying to use the API from my portal on one Linux server to access
> OpenOffice running on a separate Linux server. I took all the jars from
> OpenOffice and made them part my portal but I could only get the API to
> work
> after I installed OpenOffice.org on the portal server as well. And I see
> that when I use the API for the first time on the portal server, OpenOffice
> is started up on the portal server.
>
> Do you have to have the complete OpenOffice.org application installed on
> the
> API client server and why does it start OpenOffice automatically on the
> client server?
>
> BTW I am using OpenOffice.org 2.4.
>
> Thanks for any info on this.
if you use something along the lines
xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
and then get the MultiComponentFactory from this context the API will
attempt to connect a local running office and in case it can't find one
start an Office instance.
To connect a running office on another machine you will have to start it on
that machine with command line parameters like
soffice -accept=socket,host=0,port=<PORT>;urp;
and in your java program on the client you will have to use something like
--------------------------------------
public static void main(String args[]) {
String sConnectionString =
"uno:socket,host=<HOST>,port=<PORT>;urp;StarOffice.NamingService";
XMultiServiceFactory xMSF = null;
// create connection(s) and get multiservicefactory
System.out.println( "getting MultiServiceFactory" );
try {
xMSF = connect( sConnectionString );
} catch( Exception Ex ) {
System.out.println( "Couldn't get MSF"+ Ex );
return;
}
System.out.println("Opening an empty Writer document");
myDoc = openWriter(xMSF);
}
public static XTextDocument openWriter(XMultiServiceFactory oMSF) {
//define variables
XInterface oInterface;
XDesktop oDesktop;
XComponentLoader oCLoader;
XTextDocument oDoc = null;
XComponent aDoc = null;
try {
oInterface = (XInterface) oMSF.createInstance(
"com.sun.star.frame.Desktop" );
oDesktop = ( XDesktop ) UnoRuntime.queryInterface(
XDesktop.class, oInterface );
oCLoader = ( XComponentLoader ) UnoRuntime.queryInterface(
XComponentLoader.class, oDesktop );
PropertyValue [] szEmptyArgs = new PropertyValue [0];
String doc = "private:factory/swriter";
aDoc = oCLoader.loadComponentFromURL(doc, "_blank", 0,
szEmptyArgs );
oDoc = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, aDoc);
} // end of try
catch(Exception e){
System.out.println(" Exception " + e);
} // end of catch
return oDoc;
}//end of openWriter
public static XMultiServiceFactory connect( String connectStr )
throws com.sun.star.uno.Exception,
com.sun.star.uno.RuntimeException, Exception {
// Get component context
XComponentContext xcomponentcontext =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(
null );
// initial serviceManager
XMultiComponentFactory xLocalServiceManager =
xcomponentcontext.getServiceManager();
// create a connector, so that it can contact the office
Object xUrlResolver =
xLocalServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xcomponentcontext );
XUnoUrlResolver urlResolver =
(XUnoUrlResolver)UnoRuntime.queryInterface(
XUnoUrlResolver.class, xUrlResolver );
Object rInitialObject = urlResolver.resolve( connectStr );
XNamingService rName = (XNamingService)UnoRuntime.queryInterface(
XNamingService.class, rInitialObject );
XMultiServiceFactory xMSF = null;
if( rName != null ) {
System.err.println( "got the remote naming service !" );
Object rXsmgr =
rName.getRegisteredObject("StarOffice.ServiceManager" );
xMSF = (XMultiServiceFactory)
UnoRuntime.queryInterface( XMultiServiceFactory.class, rXsmgr );
}
return ( xMSF );
}
--------------------------------------
which should open a writer document on your remote machine.
Hope that helps
Regards
Stephan