Page 1 of 1

TraversalUtil fails after five runs.

PostPosted: Tue Jul 08, 2014 10:41 pm
by christian
Hello,

i want to modify an existing docx document from a Servlet.
The original document have an header for the first page and one for other pages.
The other pages header contains a text box with an background color.

I can take the original document five times and replace text of an org.docx4j.wml.Text element inside the header text box. Everything runs fine.
The sixt run fails, docx4j creates the document, but the header text box is gone.

Why does it work for five runs and fails at the sixt run? After tomcat restart, it works 5 times than fails and so on.
Can someone help?

Regards
Christian

Re: TraversalUtil fails after five runs.

PostPosted: Tue Jul 08, 2014 10:49 pm
by jason
Are you modifying the original pkg object each time? Depending on what you are doing, this might be a bad idea:- you might want to use a clone.

What is the XML content of the header, prior to the 6th run. You can get that with by invoking getXml() on the header part, or by using XmlUtils.marshalToString

Re: TraversalUtil fails after five runs.

PostPosted: Tue Jul 08, 2014 11:07 pm
by christian
clone was a good keyword, thank you

But after cloning instead of copying the file, i get the same error.

Final result: I made another mistake, i'm loading the original docx every run.

not working
Code: Select all
   public void export(Export export, Model model) {
      try {
         
         File original= new java.io.File("/original.docx");
         WordprocessingMLPackage wordMLPackageOrig = Docx4J.load(original);
         WordprocessingMLPackage wordMLPackage = Docx4J.clone(wordMLPackageOrig);
         ...


working
Code: Select all
static WordprocessingMLPackage wordMLPackageOrig;
   
   public void export(Export export, Model model) {
      try {
         if(wordMLPackageOrig==null){
            File original= new java.io.File("/original.docx");
            wordMLPackageOrig = Docx4J.load(original);
         }
         WordprocessingMLPackage wordMLPackage = Docx4J.clone(wordMLPackageOrig);
         ..