TruTruMaster commented on PR #1600: URL: https://github.com/apache/poi/pull/1600#issuecomment-7240656659
Thanks for the review, these were good catches. Reworked in 7666ed4: - **Existing callers:** `removeBodyElement(int)` behaves exactly as on trunk again. The cleanup moved to a new opt-in `removeBodyElement(int pos, boolean removeUnusedParts)` (`@since 6.1.0`). Its javadoc says what is removed and warns not to use it when the element is put back. `testRemoveBodyElementKeepsPartsByDefault` moves a paragraph with a picture the way you described (copy the `CTP`, remove, insert, `setParagraph`) and checks the picture after a round trip. - **Allow-list:** only relations of the kinds body content can own are touched: image, hyperlink, chart, oleObject, package, and the diagram parts. `testRemoveBodyElementKeepsDocumentParts` adds a `w:hyperlink` with the styles relation id. With the allow-list disabled it fails (the styles relation is gone), and with it the styles stay. - **Read-only:** nothing is cleaned up when the package was opened with `PackageAccess.READ`. `testRemoveBodyElementOnReadOnlyPackage` removes a paragraph with a picture and one with a hyperlink from a read-only package. Without the check it fails with `InvalidOperationException: Operation not allowed, document open in read only mode!`. - **Cost:** the `POIXMLDocumentPart.removeRelation` change is reverted, so other formats pay nothing extra. The "still used elsewhere" check that the header picture needs is now in a new `protected final removeRelationAndUnusedPart(String)`, which only the opt-in path calls. That path still scans the remaining `document.xml` once per removal that has candidate ids, so removing many such elements in a loop is linear in the document each time. Since it's opt-in, I left it simple. If you'd prefer, I can add a variant that removes several positions with one scan. The 10 earlier tests now call the opt-in method. All 4459 `poi-ooxml` tests pass. The `CONTENTCONTROL` case you mentioned (the `w:sdt` stays in the XML) is untouched. I can look at it separately. -- 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]
