views:

963

answers:

1

I'm trying to replace a field in an OpenOffice document using the OpenOffice Java API. I'm using the insertString method:

  xText.insertString(((XTextField) fieldMaster).getAnchor(), value.toString(), false);

The stacktrace is as follows:

    [junit] com.sun.star.uno.RuntimeException: 
    [junit]     at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:182)
    [junit]     at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:148)
    [junit]     at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:344)
    [junit]     at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:313)
    [junit]     at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:101)
    [junit]     at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:652)
    [junit]     at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:154)
    [junit]     at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:136)
    [junit]     at $Proxy14.insertString(Unknown Source)
...

If I interpret this correctly, it's telling me that it connected to a different proces from Java, something in the other proces failed, but it's not telling me what the problem is.

I found that there are some environment variables (PROT_REMOTE...) that would let me log messages from these remote (different process, same computer, btw) processes, but only if I run an OpenOffice version with debugging enabled?

I'm using an OpenOffice version from an deb repository on Ubuntu, and have to interest in compiling my own OpenOffice version.

Is there any way I can get some useful error messages from the remote process to help me understand why my code is failing?

A: 

I still haven't found a good way to determine what is causing RuntimeExceptions, but someone over on the OpenOffice.org forum solved my problem. I was using the API in a wrong way.

Instead of:

XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,document);
XText xText = xTextDocument.getText();
xText.insertString(((XTextField) fieldMaster).getAnchor(), value.toString(), false);

I should have used the text from the anchor:

XTextRange anchor = ((XTextField) fieldMaster).getAnchor();
anchor.getText().insertString(anchor, value.toString(), true);

Apparently, text in the headers isn't part of the document. Which makes sense if you open an OpenOffice file. The headers are stored in a separate XML document in your ODF file...

Andrej