incubator-odf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steffen Börsig <>
Subject Problem with prebuild template (CellSelection.replaceWith(...))
Date Tue, 16 Jul 2013 12:13:44 GMT

today I stumbled upon a weird problem. I use the latest build of the ODF 
Toolkit and Oracles Java 1.7 on Debian 6.
It's basically a problem with CellSelection.advancedReplaceWith(...) 
[2]. The replacetext is inserted more than once into the cell. 
Everything seems to be fine until mCell.setDisplayText(text, adapter). 
The problem emerges if I create a Writer-Template in OpenOffice.org3 and 
then replace it with the ODF-Toolkit. If the document is created through 
ODF-Toolkit and then the same procedure happens the problem does not 
exist. The problem also does only emerge if the placeholder has one or 
more linebreaks before it in the same cell!

Since it's not the most exact problem description I appended a JUnit 
Testcase [1] which should explain everything. One example 
Template-Document is appended to this email. I did test several 
different templates, the problem does persist.
I'm not experienced with the API yet so I don't blame it on a bug. Maybe 
it's me just not using the API in the right way. Would love to get some 
input from you guys.


import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.odftoolkit.simple.TextDocument;
import org.odftoolkit.simple.common.TextExtractor;
import org.odftoolkit.simple.common.navigation.InvalidNavigationException;
import org.odftoolkit.simple.common.navigation.TextNavigation;
import org.odftoolkit.simple.common.navigation.TextSelection;
import org.odftoolkit.simple.table.Table;

public class TemplateReplaceTest {

     public void test() throws Exception {
         TextDocument document = TextDocument.newTextDocument();
         Table table = document.addTable(2, 1);
         table.getCellByPosition(0, 0).setStringValue("TestPlaceholder");

         String textFromGenerate = 

         document = TextDocument.loadDocument("");
         String textFromTemplate = 

         assertEquals(textFromGenerate, textFromTemplate);

     private static void searchAndReplaceTestPlaceholder(TextDocument 
document) throws InvalidNavigationException {
         TextNavigation nav = new TextNavigation("TestPlaceholder", 
         while (nav.hasNext())
             TextSelection nextSelection = (TextSelection) 
             nextSelection.replaceWith("Replaced Text");


     public void advancedReplaceWith(String newText, CellValueAdapter 
adapter) throws InvalidNavigationException {
         if (mCell != null) {
             String text = mCell.getDisplayText();
             // update mCell value and value type.
             mCell.setDisplayText(text, adapter);

View raw message