New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to replace paragraph in ODF Text Document #235
Comments
Dear Ralph, Michael is on vacation and I have my head currently wrapped around a different difficult problem, so let me just give you a pointer how I would solve it. BackgroundThis functionality comes likely from the IBM team that had abandoned ODFDOM, when IBM abandoned OpenOffice (OO). My guess for this abandonment: LibreOffice (LO) could copy new features from OO but OO could not copy features from LO due to copyright. Basic ApproachIf something does not work as expected, create a regression test (best reuse an existing one) and see what failes - narrow it down. I love to use command-line/bash on Linux to check this. Go into the test directory and search for "TextNavigation": /dev/odf/odftoolkit-latest/odfdom/src/test$ find . -name ".java" | xargs grep TextNavigation Does one of the tests is similar to your required functionality? I hope I could point you into some useful direction, Ralph! Godspeed and good luck! |
@svanteschubert thanks for your response. Gives me hope again that I am not alone ;-) I will post my results here..... |
@rsoika of course you are not alone - instantly reminded me of the song fragment: I double checked the JavaDoc problem you mentioned, I guess the docu is right but the access rights might not: Feel free improving the situation! You help (pull request) is very much welcome... :-) PS: the 'incubator' package was a bad idea to indicate beta versions, in Google Guava they are using |
Yes I verified this. Your are right, it is the wrong protection of the methods. Maybe I find time the next days to test it further. In the moment I have created an ugly search method in my project to solve the problem somehow. (not the perfect world). Regarding the incubator package: I would suggest to remove the package and place the code in a official package. Independent from this the problems can be fixed over the time. But with the incubator package other projects (like my own) have more problems by generating source code with need to be refactored too in the future which should not be the case... |
@svanteschubert I created a pull request fixing the issues with the See my pull request here: #236 And still think the package name should be changed form Please let me know what you think. |
@rsoika Although it is a little early for x-mas, but I would love to have a regression test (extended or added) that tests your functionality! Do not want to stretch it, but know you got it in your short term memory and it might be relative quick to produce for you! :-) Regarding the "incubator" I am on your side. I think, too, we should remove it, |
@svanteschubert I added an additional test method to test the behaviour. I also did a lot of testing of other aspects when I wrote my test. And changing of the content during the navigating through the document was the part that (in my opinion) never was working correctly. while (nav.hasNext()) {
result=nav.next();
...
} But this is not the case and the For example something like this did not work while (nav.hasNext()) {
result=nav.next();
if (.... && nav.hasNext()) {
// skip next
nav.next();
}
.....
...
} In deed the core implementation has the idea to navigate in a paragraph and does not provide the idea to manipulate a paragrpah and skip to the next one. But with my changes I think the code is fine and useful. Let me know what you think about my work.... |
Thanks again for your fix, Ralph! I did my part and merged your patch now into the master and have uploaded a Maven SNAPSHOT release. Have a nice weekend! |
I wrote a short tutorial about the TextNavigation: https://ralph.blog.imixs.com/2023/06/24/find-and-replace-in-odf-documents/ |
@svanteschubert I am sorry to bother you again, but I am still not happy with my last changes of the
This would lead to a much more clear API: textNav = new TextNavigation("myexpression", odt);
while (textNav.hasNext()) {
TextSelection selection = (TextSelection) textNav.next();
logger.info("...Position=" + selection.getIndex());
logger.info("...Text=" + selection.getText());
// fetch paragraph of current selection....
OdfElement paragraph = textNav.getElement();
String content=paragraph.getTextContent();
paragraph.setTextContent("Just a Example");}
} |
@rsoika Not a problem as software is an iterative process ;-) Let me come back to you in the next days, I got a summer flue and have to take some days off.. |
I need to replace a text fragment of a ODT Text Document with a new text.
My code looks something like this:
But this is not working.
The OdfTextDocument is not updated at all.
Also it is not possible to navigate to the next element as stated in the documentation [here](https://odftoolkit.org/api/odfdom/org/odftoolkit/odfdom/incubator/search/Navigation.html#getNextMatchElement(org.w3c.dom.Node).
There is no
getNextMatchElement
method in version 0.11.0 of this project.Can anybody help me out here.
I use the library successful for
OdfSpreadsheetDocument
objects and this works well.The text was updated successfully, but these errors were encountered: