I am trying to Create an impress document with one XDrawPage. I'm trying to
create a TitleTextShape on that XDrawPage and
Add some text to it. I have been able to do everything up until the add
text to it part. From the documentation, it says that you can call
setString() on a XText object, but I have been unable to get that to work.
My code creates the document, the slide and the title object, but the text
never gets added. I tried creating an XTextCursor from the XText object, but
any method I call on it raises a com.sun.star.lang.DisposedException
exception. Here is a snippet of my code.
XComponent document = jComponentLoader.loadComponentFromURL(
private:factory/simpress, _blank, 0, loadProps);
XDrawPagesSupplier xDrawPagesSupplier =
(XDrawPagesSupplier)UnoRuntime.queryInterface(
XDrawPagesSupplier.class, document);
XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
Object newPage = xDrawPages.getByIndex(0);
XDrawPage xNewPage =
(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, newPage);
XMultiServiceFactory factory = (XMultiServiceFactory)UnoRuntime
.queryInterface(XMultiServiceFactory.class, document);
Object title =
factory.createInstance(com.sun.star.presentation.TitleTextShape);
XShape xTitle = (XShape)UnoRuntime.queryInterface(XShape.class,
title);
XText xText = (XText)UnoRuntime.queryInterface(XText.class,
xTitle);
xText.setString(Some Text);
xNewPage.add(xTitle);
I then procede to storeToURL using the MS PowerPoint 97 conversionFilter.
When I open the generated ppt, the title object gets created fine, but with
no text.
I then tried to create an XTextCursor:
XTextCursor cursor = xText.createTextCursor();
But, any method call on this object raises a
com.sun.star.lang.DisposedException. I read somewhere that:
The problem here is the lifetime concept of UNO in general, and of
statements and result sets in particular. First (and in short), in UNO an
object is not necessarily alive just because you have a reference to it
Instead, objects can become disfunctional if they're disposed.
I'm not really sure what this means, but any help or clarification would be
much appreciated.