Object instance = null;
log.println( "creating a test environment" );
oText = xTextDoc.getText();
XTextCursor oCursor = oText.createTextCursor();
XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
try {
XTextSectionsSupplier oTSSupp = (XTextSectionsSupplier)
UnoRuntime.queryInterface
( XTextSectionsSupplier.class, xTextDoc );
XNameAccess oTSSuppName = oTSSupp.getTextSections();
//cleanup if necessary
if (oTSSuppName.hasByName("SwXTextSection")) {
XTextSection old = (XTextSection) AnyConverter.toObject(
new Type(XTextSection.class),
oTSSuppName.getByName("SwXTextSection"));
XComponent oldC = (XComponent)
UnoRuntime.queryInterface(XComponent.class,old);
oldC.dispose();
oText.setString("");
}
//insert two sections parent and child
oTS = (XInterface) oDocMSF.createInstance
("com.sun.star.text.TextSection");
instance = oDocMSF.createInstance("com.sun.star.text.TextSection");
XTextContent oTSC = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class, oTS);
oText.insertTextContent(oCursor, oTSC, false);
XWordCursor oWordC = (XWordCursor)
UnoRuntime.queryInterface(XWordCursor.class, oCursor);
oCursor.setString("End of TextSection");
oCursor.gotoStart(false);
oCursor.setString("Start of TextSection ");
oWordC.gotoEndOfWord(false);
XInterface oTS2 = (XInterface) oDocMSF.createInstance
("com.sun.star.text.TextSection");
oTSC = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, oTS2);
oText.insertTextContent(oCursor, oTSC, false);