https://issues.apache.org/bugzilla/show_bug.cgi?id=51265
Bug #: 51265
Summary: Enhance Handling of Picture Parts
Product: POI
Version: unspecified
Platform: PC
Status: NEW
Severity: enhancement
Priority: P2
Component: XWPF
AssignedTo: [email protected]
ReportedBy: [email protected]
Classification: Unclassified
In OOXML, multiple references of the same picture refer to the same picture
part inside the package. This applies, even if multiple parts refer to the same
image, for example a header, footer and the main document.
Up to now, there is no functionality in POI to support this behavior for any
new image. Instead, adding the same picture n times, will create n new parts
with identical content. This potentially increases the package size
daramatically, given a scenario where a larger picture is referrenced several
times.
In order to support the image part reuse, all available images must be managed
in a central spot. All OPCPackages have one main part, which in Word is the
XWPFDocument. This results in XWPFDocument being a subclass of POIXMLDocument,
whereas all other XWPFClasses, which represent a package, subclass
POIXMLDocumentPart only.
The XWPFDocument herewith not only represents the main document, but also
represents the package and all package-wide settings & data. Therefore,
managing all package-known pictures should take place in the XWPFDocument.
Besides the management of all package-pictureparts, the document also manages
all those picture-parts, which are related to the main document part. This is
the same task, that applies to headers and footers as well. They must take care
for all picture-parts related by their corresponding package-part.
Enabling reuse of picture parts complicates the removal of package parts. As
long as every part is referenced once, the removal of the reference goes along
with removing the part. Removing an image part, in case a reference to this
part was removed, may corrupt the document, as other references may still
require that part. A solution to this issue is a simple reference counter,
which is increased whenever a new relationship is created, and decreased
whenever a relationship is removed. If the last relationship counter reaches
zero, when a relation is removed, the target part can be deleted.
While changing POIXMLDocumentPart, the relation-handling was reworked. Instead
of keeping a simple list of all related parts, a Map was used, which uses the
relation-ID as key and the target part as value. This eases the handling of all
parts, but required some changes to the API (changes to XSSFDrawing have been
applied). Additionally, the original list was kept in order to represent the
relation-sequence, as these appear in the _rels XML document and several
Unit-tests rely on this sequence. I do not recommend to rely on it, as a
relation is defined by id, type and target only, whereas the position in the
according _rels is not part of the information a PackageRelationship is defined
of, in terms of the OPC.
Among the changes done to POIXMLDocumentPart concerning relation-handling, the
behavior of the method "createRelationship" was slightly altered. So far, it
always added the new part to the "relations" list of the affected part. But
this is only valid, if a new PackageRelationship was created between the new
part and the current part. If this step was skipped, adding the new part to the
relations is wrong. And closing the package and reload it will not load the new
part into the relations list again, if no PackageRelationship exists between
these parts.
Finally, in order to write test all new methods, I moved TestXWPFDocument into
the org.apache.poi.xwpf.usermodel package. This allows to test methods with
default-visibility, which seemed quite reasonable for a testcase.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]