Bug 66040

Summary: XSLFTextParagraph uses the wrong text body when text shapes are copied from other slides
Product: POI Reporter: Axel Richter <axel.richter.privat>
Component: XSLFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 5.2.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Sample Java code and sample *,pptx file
Sample *.pptx file

Description Axel Richter 2022-04-28 06:11:25 UTC
Since apache poi 4 the apache developers decided using org.apache.poi.xddf.usermodel.text.* for text paragraphs and text runs also in XSLF. Up to apache poi 3.17 XSLF had have it's own classes for text paragraphs and text runs. Those are further present (maybe for backwards compatibility) but in versions greater than apache po 3.17 they are using the wrong text body when text shapes are copied from other slides. 

See https://stackoverflow.com/questions/72017058/apache-poi-changes-applied-to-the-wrong-slide for a complete example.
Comment 1 PJ Fanning 2022-08-15 13:00:51 UTC
I added some test cases - see r1903436

These test cases seem to pass ok - without any modifications to the core code.

If someone can provide a reproducible test case, I'll look at this again. XDDF/XSLF are not code bases I work with very often.
Comment 2 PJ Fanning 2022-08-15 13:09:13 UTC
I also added r1903437 with tests that clone slides and modify those new slides.
Comment 3 Axel Richter 2022-08-15 14:28:00 UTC
Created attachment 38365 [details]
Sample Java code and sample *,pptx file

OK, I will try to describe the problem again.

Take the code of PPTXCCopyTemplateSlideAndChange.java from attachment java.zip.
Do running it using the PPTXIn.pptx also attaches in java.zip.

Using the code part ...

///*  this works using apache poi 3.17 only but uses the wrong text body in version 5  
    List<XSLFTextParagraph> textBoxParagraphs = textShape.getTextParagraphs();
    List<XSLFTextRun> textBoxParagraphTextRuns = textBoxParagraphs.stream().map(XSLFTextParagraph::getTextRuns).flatMap(List::stream).collect(Collectors.toList());
    for (XSLFTextRun r : textBoxParagraphTextRuns) {
     r.setText("Replaced!");
    }
//*/

... the wrong text runs in  XSLFSlide template  gets changed instead of the ones in XSLFSlide newSlide.

Using the text part ...

/*  this works using apache poi 5.2.2 only but cannot work using version 3.17 because of usage of org.apache.poi.xddf.usermodel.text.*
    List<org.apache.poi.xddf.usermodel.text.XDDFTextParagraph> textBoxParagraphs = textShape.getTextBody().getParagraphs();
    List<org.apache.poi.xddf.usermodel.text.XDDFTextRun> textBoxParagraphTextRuns = textBoxParagraphs.stream().map(org.apache.poi.xddf.usermodel.text.XDDFTextParagraph::getTextRuns).flatMap(List::stream).collect(Collectors.toList());
    for (org.apache.poi.xddf.usermodel.text.XDDFTextRun r : textBoxParagraphTextRuns) {
     r.setText("Replaced!");
    }
*/

... the correct text runs in XSLFSlide newSlide get changed.
Comment 4 PJ Fanning 2022-08-15 14:41:02 UTC
java.zip has PPTXOut.pptx but not PPTXIn.pptx - could you provide the PPTXIn.pptx file?
Comment 5 Axel Richter 2022-08-15 15:21:03 UTC
Created attachment 38367 [details]
Sample *.pptx file

Sorry, wrong file in ZIP archive.
Comment 6 PJ Fanning 2022-08-19 13:37:04 UTC
Hi Alex - I haven't tested this yet but I applied the fix for https://bz.apache.org/bugzilla/show_bug.cgi?id=65473 today - is it possible that this fixes this? They do seem similar.