von kulrich » Fr, 20.01.2006 18:09
Alles Klar,
ICh habe eben probiert openoffice als server zu starten :
Mit
Code: Alles auswählen
.../soffice.exe" -invisible accept=uno:host=localhost,port=8100;urp;StarOffice.ServiceManager
scheint er gestartet zu sein. (keine fehlermenldungen)
Kann ich das irgend wie testen ?
ich kann nähmlich nicht mit
Code: Alles auswählen
[...]
Object objectInitial = xurlresolver.resolve("uno:host=localhost,port=8100;urp;StarOffice.ServiceManager" );
[...]
den server erreichen.
Ich bekomme dann eine Exception :
Code: Alles auswählen
com.sun.star.connection.ConnectionSetupException: no Connector for host=localhost
at com.sun.star.comp.connections.Implementation.getConnectionService(Implementation.java:102)
at com.sun.star.comp.connections.Connector.connect(Connector.java:146)
at com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:133)
at org.thing.ooo.test.RemoteContact.main(RemoteContact.java:49)
irgend eine Idee ?
Gruß Kai
An bei meine Test Klasse :
Code: Alles auswählen
package org.thing.ooo.test;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XCloseable;
public class RemoteContact {
public static void main(String[] args) {
try {
/* Bootstraps a component context with the jurt base components
registered. Component context to be granted to a component for running.
Arbitrary values can be retrieved from the context. */
XComponentContext xcomponentcontext =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
/* Gets the service manager instance to be used (or null). This method has
been added for convenience, because the service manager is a often used
object. */
XMultiComponentFactory xmulticomponentfactory =
xcomponentcontext.getServiceManager();
/* Creates an instance of the component UnoUrlResolver which
supports the services specified by the factory. */
Object objectUrlResolver =
xmulticomponentfactory.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xcomponentcontext );
// Create a new url resolver
XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
UnoRuntime.queryInterface( XUnoUrlResolver.class,
objectUrlResolver );
// Resolves an object that is specified as follow:
// uno:<connection description>;<protocol description>;<initial object name>
Object objectInitial = xurlresolver.resolve(
"uno:host=localhost,port=8100;urp;StarOffice.ServiceManager" );
// Create a service manager from the initial object
xmulticomponentfactory = ( XMultiComponentFactory )
UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );
// Query for the XPropertySet interface.
XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory );
// Get the default context from the office server.
Object objectDefaultContext =
xpropertysetMultiComponentFactory.getPropertyValue( "DefaultContext" );
// Query for the interface XComponentContext.
xcomponentcontext = ( XComponentContext ) UnoRuntime.queryInterface(
XComponentContext.class, objectDefaultContext );
/* A desktop environment contains tasks with one or more
frames in which components can be loaded. Desktop is the
environment for components which can instanciate within
frames. */
XComponentLoader xcomponentloader = ( XComponentLoader )
UnoRuntime.queryInterface( XComponentLoader.class,
xmulticomponentfactory.createInstanceWithContext(
"com.sun.star.frame.Desktop", xcomponentcontext ) );
System.out.println( "Got Desktop" );
System.out.println( "Got ComponentLoader" );
// Preparing properties for loading the document
PropertyValue propertyvalue[] = new PropertyValue[ 1 ];
// Setting the flag for hidding the open document
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "Hidden";
propertyvalue[ 0 ].Value = new Boolean(true);
String foulder = "file:///C:/Dokumente und Einstellungen/k.ulrich/Desktop/";
String srcUrl = foulder + "Meetingprotokoll Webreb 060110.doc";
System.out.println( "Load Datei ... " + srcUrl );
Object objectDocumentToStore = xcomponentloader.loadComponentFromURL( srcUrl, "_blank", 0, propertyvalue );
XStorable xstorable = ( XStorable ) UnoRuntime.queryInterface( XStorable.class, objectDocumentToStore );
System.out.println( "Save Datei ... " + srcUrl );
// Preparing properties for converting the document
propertyvalue = new PropertyValue[ 2 ];
// Setting the flag for overwriting
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "Overwrite";
propertyvalue[ 0 ].Value = new Boolean(true);
// Setting the filter name
propertyvalue[ 1 ] = new PropertyValue();
propertyvalue[ 1 ].Name = "FilterName";
propertyvalue[ 1 ].Value = "swriter: Text";
String targetUrl = foulder + "Meetingprotokoll Webreb 060110.txt";
// Storing and converting the document
xstorable.storeAsURL( targetUrl, propertyvalue );
XCloseable xcloseable = (XCloseable)UnoRuntime.queryInterface( XCloseable.class,xstorable );
// Closing the converted document
if ( xcloseable != null )
xcloseable.close(false);
else {
// If Xcloseable is not supported (older versions,
// use dispose() for closing the document
XComponent xComponent = ( XComponent ) UnoRuntime.queryInterface(
XComponent.class, xstorable );
xComponent.dispose();
}
System.out.println( "Datei cloesed... " + srcUrl );
}catch (java.lang.Exception e){
e.printStackTrace();
}finally {
System.exit(0);
}
}
}
Alles Klar,
ICh habe eben probiert openoffice als server zu starten :
Mit
[code].../soffice.exe" -invisible accept=uno:host=localhost,port=8100;urp;StarOffice.ServiceManager
[/code]
scheint er gestartet zu sein. (keine fehlermenldungen)
Kann ich das irgend wie testen ?
ich kann nähmlich nicht mit
[code][...]
Object objectInitial = xurlresolver.resolve("uno:host=localhost,port=8100;urp;StarOffice.ServiceManager" );
[...]
[/code]
den server erreichen.
Ich bekomme dann eine Exception :
[code]com.sun.star.connection.ConnectionSetupException: no Connector for host=localhost
at com.sun.star.comp.connections.Implementation.getConnectionService(Implementation.java:102)
at com.sun.star.comp.connections.Connector.connect(Connector.java:146)
at com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:133)
at org.thing.ooo.test.RemoteContact.main(RemoteContact.java:49)
[/code]
irgend eine Idee ?
Gruß Kai
An bei meine Test Klasse :
[code]package org.thing.ooo.test;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XCloseable;
public class RemoteContact {
public static void main(String[] args) {
try {
/* Bootstraps a component context with the jurt base components
registered. Component context to be granted to a component for running.
Arbitrary values can be retrieved from the context. */
XComponentContext xcomponentcontext =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
/* Gets the service manager instance to be used (or null). This method has
been added for convenience, because the service manager is a often used
object. */
XMultiComponentFactory xmulticomponentfactory =
xcomponentcontext.getServiceManager();
/* Creates an instance of the component UnoUrlResolver which
supports the services specified by the factory. */
Object objectUrlResolver =
xmulticomponentfactory.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xcomponentcontext );
// Create a new url resolver
XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
UnoRuntime.queryInterface( XUnoUrlResolver.class,
objectUrlResolver );
// Resolves an object that is specified as follow:
// uno:<connection description>;<protocol description>;<initial object name>
Object objectInitial = xurlresolver.resolve(
"uno:host=localhost,port=8100;urp;StarOffice.ServiceManager" );
// Create a service manager from the initial object
xmulticomponentfactory = ( XMultiComponentFactory )
UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );
// Query for the XPropertySet interface.
XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory );
// Get the default context from the office server.
Object objectDefaultContext =
xpropertysetMultiComponentFactory.getPropertyValue( "DefaultContext" );
// Query for the interface XComponentContext.
xcomponentcontext = ( XComponentContext ) UnoRuntime.queryInterface(
XComponentContext.class, objectDefaultContext );
/* A desktop environment contains tasks with one or more
frames in which components can be loaded. Desktop is the
environment for components which can instanciate within
frames. */
XComponentLoader xcomponentloader = ( XComponentLoader )
UnoRuntime.queryInterface( XComponentLoader.class,
xmulticomponentfactory.createInstanceWithContext(
"com.sun.star.frame.Desktop", xcomponentcontext ) );
System.out.println( "Got Desktop" );
System.out.println( "Got ComponentLoader" );
// Preparing properties for loading the document
PropertyValue propertyvalue[] = new PropertyValue[ 1 ];
// Setting the flag for hidding the open document
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "Hidden";
propertyvalue[ 0 ].Value = new Boolean(true);
String foulder = "file:///C:/Dokumente und Einstellungen/k.ulrich/Desktop/";
String srcUrl = foulder + "Meetingprotokoll Webreb 060110.doc";
System.out.println( "Load Datei ... " + srcUrl );
Object objectDocumentToStore = xcomponentloader.loadComponentFromURL( srcUrl, "_blank", 0, propertyvalue );
XStorable xstorable = ( XStorable ) UnoRuntime.queryInterface( XStorable.class, objectDocumentToStore );
System.out.println( "Save Datei ... " + srcUrl );
// Preparing properties for converting the document
propertyvalue = new PropertyValue[ 2 ];
// Setting the flag for overwriting
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "Overwrite";
propertyvalue[ 0 ].Value = new Boolean(true);
// Setting the filter name
propertyvalue[ 1 ] = new PropertyValue();
propertyvalue[ 1 ].Name = "FilterName";
propertyvalue[ 1 ].Value = "swriter: Text";
String targetUrl = foulder + "Meetingprotokoll Webreb 060110.txt";
// Storing and converting the document
xstorable.storeAsURL( targetUrl, propertyvalue );
XCloseable xcloseable = (XCloseable)UnoRuntime.queryInterface( XCloseable.class,xstorable );
// Closing the converted document
if ( xcloseable != null )
xcloseable.close(false);
else {
// If Xcloseable is not supported (older versions,
// use dispose() for closing the document
XComponent xComponent = ( XComponent ) UnoRuntime.queryInterface(
XComponent.class, xstorable );
xComponent.dispose();
}
System.out.println( "Datei cloesed... " + srcUrl );
}catch (java.lang.Exception e){
e.printStackTrace();
}finally {
System.exit(0);
}
}
}
[/code]