ich habe ein Problem beim Schließen der Connection zu OpenOffice. Ich möchte ein Writer-Dokument öffnen, evtl. bearbeiten und dann alles schließen. In der Oberfläche klappt es auch soweit, aber im Task-Manager bleiben die Prozesse soffice.exe und soffice.bin weiterhin bestehen. Erst wenn ich den Writer einmal manuell schließe, verschwinden die Prozesse.
Es würde ja auch nicht weiter stören, wenn der Prozess soffice.bin nicht immer weiter Speicher saugen würde, wenn ich ein neues Dokument öffne.
Ich schließe die Verbindung wohl nicht richtig. Kann mir jemand helfen?
Code: Alles auswählen
private XComponentLoader componentLoader = null;
private XComponentContext remoteContext = null;
private XMultiComponentFactory remoteServiceManager = null;
public void testConnection() throws java.lang.Exception {
// Connection herstellen
XComponentLoader connection = openConnection();
// Dokument öffnen
PropertyValue loadProps[] = new PropertyValue[1];
loadProps[0] = new com.sun.star.beans.PropertyValue();
XComponent component = connection.loadComponentFromURL(
"file:///D:/temp/Test.ott", "_blank", 0, loadProps);
// Dokument schliessen
closeDocument(component);
// Connection schließen
connection = null;
}
private XComponentLoader openConnection() throws java.lang.Exception {
if (this.remoteContext == null && this.remoteServiceManager == null) {
// get the remote office context. If necessary a new office
// process is started
try {
this.remoteContext = com.sun.star.comp.helper.Bootstrap
.bootstrap();
System.out.println("Connected to a running office ...");
this.remoteServiceManager = this.remoteContext
.getServiceManager();
} catch (java.lang.Exception ex) {
log.error("Fehler beim Connect to OpenOffice!", ex);
}
}
// retrieve the Desktop object, we need its XComponentLoader
Object desktop = this.remoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", this.remoteContext);
this.componentLoader = (XComponentLoader) UnoRuntime.queryInterface(
XComponentLoader.class, desktop);
return this.componentLoader;
}
private void closeDocument(XComponent component) throws java.lang.Exception {
XModel model = (XModel) UnoRuntime.queryInterface(XModel.class,
component);
if (model != null) {
XCloseable xClosable = (XCloseable) UnoRuntime.queryInterface(
XCloseable.class, model);
int k = 0;
if (xClosable != null) {
while (k < 100 && xClosable != null) {
try {
xClosable.close(true);
xClosable = null;
} catch (com.sun.star.util.CloseVetoException exCloseVeto) {
System.out.println(exCloseVeto.toString());
Thread.sleep(1000);
k++;
}
}
} else {
XComponent disposable = (XComponent) UnoRuntime.queryInterface(
XComponent.class, model);
disposable.dispose();
}
}
}