Hi Florian,
I could already fixed it in code for me just by deleting the special
case routine. (Build my own jar from source)
Don't know where I would ever need that routine anyway. At least for my
purposes it's not needed.
But anyway, thanks for the pointer and the workaround.
Regards,
Steffen
Am 07/19/13 14:13, schrieb Florian Hopf:
Hi Steffen,
coincidentally I just had a look at this bug today:
https://issues.apache.org/jira/browse/ODFTOOLKIT-362
Have a look at the workaround and see if it is sufficient for you.
Regards
Florian
On 16.07.2013 14:13, Steffen Börsig wrote:
Hi,
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.
Greetings,
Steffen
[1]
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 {
@Test
public void test() throws Exception {
TextDocument document = TextDocument.newTextDocument();
Table table = document.addTable(2, 1);
table.getCellByPosition(0,
0).setStringValue("TestPlaceholder");
table.getCellByPosition(0,
1).setStringValue("\n\nTestPlaceholder");
searchAndReplaceTestPlaceholder(document);
document.save("TestGeneratedTemplate.odt");
String textFromGenerate =
TextExtractor.getText(document.getContentRoot());
document.close();
document = TextDocument.loadDocument("TestTemplate.ott");
searchAndReplaceTestPlaceholder(document);
document.save("TestPrebuildTemplate.odt");
String textFromTemplate =
TextExtractor.getText(document.getContentRoot());
document.close();
assertEquals(textFromGenerate, textFromTemplate);
}
private static void searchAndReplaceTestPlaceholder(TextDocument
document) throws InvalidNavigationException {
TextNavigation nav = new TextNavigation("TestPlaceholder",
document);
while (nav.hasNext())
{
TextSelection nextSelection = (TextSelection)
nav.nextSelection();
nextSelection.replaceWith("Replaced Text");
}
}
}
[2]
public void advancedReplaceWith(String newText, CellValueAdapter
adapter) throws InvalidNavigationException {
super.replaceWith(newText);
if (mCell != null) {
String text = mCell.getDisplayText();
// update mCell value and value type.
mCell.setDisplayText(text, adapter);
}
}