Carsten Driesner schrieb:
Could you please tell me more about the context where your code runs. Especially when you can see that it doesn't work. Currently it looks like a bug, but without more information this is hard to confirm. I would like to debug your scenario, but therefore I need more information.
Hello,

I try to open the document to fill some textfields with content.

I have pack all code in a class to demonstrate the problem (the Programm terminate not correct). To execute the class OpenOffice must run and listen on port 8000.

1. run it works,
2. run OpenOffice pop up.
3. run ok
4. run OpenOffice pop up
and so on.

[code]
import com.sun.star.beans.PropertyValue;
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.frame.FrameSearchFlag;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDesktop;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;


public class Debug {

   XMultiComponentFactory xMCF;
   XComponentContext xComponentContext;
   String docPath = "file:///home/daniel/.twc/documents/1256202722289.sxw";

   public Debug() throws Exception {
       startOpenOffice();
       open();
   }

   public static void main(String[] args) throws Exception {
       new Debug();
   }

   private void open() throws Exception {

       PropertyValue[] properties = new PropertyValue[1];
       properties[0] = new PropertyValue();
       properties[0].Name = "Hidden";
       properties[0].Value = new Boolean(true);

       XDesktop xDesktop;
       // Get the desktop object.
           Object desktop = xMCF.createInstanceWithContext(
                   "com.sun.star.frame.Desktop", xComponentContext);
       // Get the XDesktop so you can close OpenOffice.org correctly
xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);

       XComponentLoader xComponentLoader;
xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);

       xComponentLoader.loadComponentFromURL(
               docPath,
               "_default",
               FrameSearchFlag.CREATE,
properties);
   }

   private void startOpenOffice() throws Exception {
       // Create an OO Component Context
       XComponentContext xInitialComponentContext =
               Bootstrap.createInitialComponentContext(null);

       // create a connector, so that it can contact the office
       XUnoUrlResolver urlResolver =
               UnoUrlResolver.create(xInitialComponentContext);

       Object initialObject = urlResolver.resolve(
"uno:socket,host=127.0.0.1,port=8000;urp;StarOffice.ServiceManager");
       xMCF = (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, xMCF);
       // Get the default context from the office server.
Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext");
       // Query for the interface XComponentContext.
xComponentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext);
   }
}
[/code]

Regards,
Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to