The GitHub Actions job "Java CI with Gradle" on poi.git/trunk has succeeded.
Run started by GitHub user pjfanning (triggered by pjfanning).

Head commit for run:
cfa95de29539d2b45acff85fde651dab3949c1b3 / TruTruMaster 
<[email protected]>
XWPFDocument: add removeBodyElement(int, boolean) to remove the parts only the 
element used (#1600)

* XWPFDocument.removeBodyElement: remove the parts that only the removed 
element used (#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 (item 4 of 
#1554).

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
only removed 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 are removed the same way. The document's lists of pictures, 
package pictures, charts
and hyperlinks are kept in step.

Headers and footers referenced from a section break inside the removed 
paragraph are left alone:
they belong to the section properties rather than to the content.

For the top-level part, POIXMLDocumentPart.removeRelation(id, true) now also 
checks that no other
relationship in the package targets the part before removing it, as 
removeFromPackage already does
for child parts since #1543. A package part can be represented by more than one 
document part, as
with a picture used in the body and in a header.

* XWPFDocument: make removing the parts of a removed body element opt-in

removeBodyElement(int) works as before again, so code that moves an element by
copying, removing and inserting it keeps its pictures and links. The cleanup is
in the new removeBodyElement(int, boolean). It only removes relations of the
kinds body content owns (pictures, hyperlinks, charts, OLE objects, embedded
packages, diagrams), so a malformed reference to the id of a document part
such as the styles can't remove that part, and it does nothing when the package
was opened read-only.

The change to POIXMLDocumentPart.removeRelation is reverted, so removing parts
costs the same as before in every format. The check that a picture is still
used by a header is in the new protected removeRelationAndUnusedPart(String),
which only this cleanup calls.

* XWPFDocument: keep a relation a VML o:relid still uses; give the removal test 
assertions messages

* XWPFDocument.removeBodyElement: clean up o:relid pictures, parts without a 
document part and content controls

- collect the ids of VML o:relid attributes of the removed element too, so a 
picture only
  used that way is removed
- remove the target of an internal relationship that has no document part, e.g. 
a chart
  skipped on read, together with the parts only it relates to
- list a picture again in getAllPictures() when the body is related again to a 
part that
  stayed in the package for a header
- remove a block level content control from the xml and the content control list
- document that the element stays removed when removing a part fails

Co-Authored-By: Claude Fable 5.2 <[email protected]>

---------

Co-authored-by: PJ Fanning <[email protected]>
Co-authored-by: Claude Fable 5.2 <[email protected]>

Report URL: https://github.com/apache/poi/actions/runs/46961604450

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to