TruTruMaster opened a new pull request, #1600: URL: https://github.com/apache/poi/pull/1600
Item 4 of #1554. `removeBodyElement` removed the paragraph or table from the body but none of the relations its content used, so images, charts with their embedded workbooks, embedded objects and hyperlinks that only it referenced stayed in the package and in the written file. It now collects the relationship ids the removed element references (`r:embed`, `r:link`, `r:id` and the other attributes in the relationships namespace, including text boxes, VML and `mc:AlternateContent`) and removes each relation that nothing left in `document.xml` still references. The part itself is removed only when no relationship in the package targets it any more, so a picture also shown in a header, or a part an internal hyperlink targets, is kept. External relationships of hyperlinks and linked images go the same way. `pictures`, `packagePictures`, `charts` and the hyperlink list are kept in step. Two things worth a look: - **`POIXMLDocumentPart.removeRelation(id, true)`** now also checks `isRelationshipTarget()` before removing the top-level part, as `removeFromPackage` already does for child parts since #1543. It is needed for the body/header picture: the body's `XWPFPictureData` reaches a count of 0 while the header still has its own relationship to the same package part. All of `:poi-ooxml:test` passes with it (4456 tests). - **Headers and footers** referenced from a section break inside the removed paragraph are left alone. They belong to the section properties, and removing them would leave `headerFooterPolicy` out of step, so that seemed better as a separate decision. **Tests:** 10 new tests in `TestXWPFDocument` (picture, picture shared by two paragraphs, picture also in a header, table with a picture, chart with its workbook, hyperlink, OLE object, text box / AlternateContent / SmartArt / linked image, part kept by an internal hyperlink, plain paragraph). All 10 fail on trunk. The ones that check a part is kept fail too, because they then remove the last element that uses it and check that the part goes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
