public class POIXMLDocumentPart
extends java.lang.Object
Each POIXMLDocumentPart keeps a reference to the underlying a PackagePart
.
Modifier and Type | Class and Description |
---|---|
static class |
POIXMLDocumentPart.RelationPart
The RelationPart is a cached relationship between the document, which contains the RelationPart,
and one of its referenced child document parts.
|
Constructor and Description |
---|
POIXMLDocumentPart()
Creates new POIXMLDocumentPart - called by client code to create new parts from scratch.
|
POIXMLDocumentPart(OPCPackage pkg)
Construct POIXMLDocumentPart representing a "core document" package part.
|
POIXMLDocumentPart(OPCPackage pkg,
java.lang.String coreDocumentRel)
Construct POIXMLDocumentPart representing a custom "core document" package part.
|
POIXMLDocumentPart(PackagePart part)
Creates an POIXMLDocumentPart representing the given package part and relationship.
|
POIXMLDocumentPart(POIXMLDocumentPart parent,
PackagePart part)
Creates an POIXMLDocumentPart representing the given package part, relationship and parent
Called by
read(POIXMLFactory, java.util.Map) when reading in an existing file. |
Modifier and Type | Method and Description |
---|---|
static void |
_invokeOnDocumentRead(POIXMLDocumentPart part)
Deprecated.
|
POIXMLDocumentPart.RelationPart |
addRelation(java.lang.String relId,
POIXMLRelation relationshipType,
POIXMLDocumentPart part)
Add a new child POIXMLDocumentPart
|
protected void |
commit()
Save the content in the underlying package part.
|
POIXMLDocumentPart |
createRelationship(POIXMLRelation descriptor,
POIXMLFactory factory)
Create a new child POIXMLDocumentPart
|
POIXMLDocumentPart |
createRelationship(POIXMLRelation descriptor,
POIXMLFactory factory,
int idx)
Create a new child POIXMLDocumentPart
|
POIXMLDocumentPart.RelationPart |
createRelationship(POIXMLRelation descriptor,
POIXMLFactory factory,
int idx,
boolean noRelation)
Create a new child POIXMLDocumentPart
|
protected int |
getNextPartNumber(POIXMLRelation descriptor,
int minIdx)
Identifies the next available part number for a part of the given type,
if possible, otherwise -1 if none are available.
|
PackagePart |
getPackagePart()
Provides access to the underlying PackagePart
|
POIXMLDocumentPart |
getParent()
Returns the parent POIXMLDocumentPart.
|
POIXMLDocumentPart |
getRelationById(java.lang.String id)
Returns the target
POIXMLDocumentPart , where a
PackageRelationship is set from the PackagePart of this
POIXMLDocumentPart to the PackagePart of the target
POIXMLDocumentPart with a PackageRelationship.getId()
matching the given parameter value. |
java.lang.String |
getRelationId(POIXMLDocumentPart part)
Returns the first
PackageRelationship.getId() of the
PackageRelationship , that sources from the PackagePart of
this POIXMLDocumentPart to the PackagePart of the given
parameter value. |
POIXMLDocumentPart.RelationPart |
getRelationPartById(java.lang.String id)
Returns the target
POIXMLDocumentPart.RelationPart , where a
PackageRelationship is set from the PackagePart of this
POIXMLDocumentPart to the PackagePart of the target
POIXMLDocumentPart with a PackageRelationship.getId()
matching the given parameter value. |
java.util.List<POIXMLDocumentPart.RelationPart> |
getRelationParts()
Returns the list of child relations for this POIXMLDocumentPart
|
java.util.List<POIXMLDocumentPart> |
getRelations()
Returns the list of child relations for this POIXMLDocumentPart
|
protected PackagePart |
getTargetPart(PackageRelationship rel)
Get the PackagePart that is the target of a relationship from this Part.
|
boolean |
isCommited()
Deprecated.
use @link{#isCommitted()}
|
boolean |
isCommitted()
to check whether embedded part is already committed
|
protected void |
onDocumentCreate()
Fired when a new package part is created
|
protected void |
onDocumentRead()
Fired when a package part is read
|
protected void |
onDocumentRemove()
Fired when a package part is about to be removed from the package
|
protected void |
onSave(java.util.Set<PackagePart> alreadySaved)
Save changes in the underlying OOXML package.
|
protected void |
prepareForCommit()
Ensure that a memory based package part does not have lingering data from previous
commit() calls.
|
protected void |
read(POIXMLFactory factory,
java.util.Map<PackagePart,POIXMLDocumentPart> context)
Iterate through the underlying PackagePart and create child POIXMLFactory instances
using the specified factory
|
protected void |
rebase(OPCPackage pkg)
When you open something like a theme, call this to
re-base the XML Document onto the core child of the
current core document
|
protected void |
removeRelation(POIXMLDocumentPart part)
Remove the relation to the specified part in this package and remove the
part, if it is no longer needed.
|
protected boolean |
removeRelation(POIXMLDocumentPart part,
boolean removeUnusedParts)
Remove the relation to the specified part in this package and remove the
part, if it is no longer needed and flag is set to true.
|
protected void |
removeRelation(java.lang.String partId)
Remove the relation to the specified part in this package and remove the
part, if it is no longer needed.
|
void |
setCommited(boolean isCommitted)
Deprecated.
use @link{#setCommitted(isCommitted)}
|
void |
setCommitted(boolean isCommitted)
setter method to set embedded part is committed
|
java.lang.String |
toString() |
public POIXMLDocumentPart(OPCPackage pkg)
pkg
- the OPCPackage containing this documentpublic POIXMLDocumentPart(OPCPackage pkg, java.lang.String coreDocumentRel)
pkg
- the OPCPackage containing this documentcoreDocumentRel
- the relation type of this documentpublic POIXMLDocumentPart()
public POIXMLDocumentPart(PackagePart part)
read(POIXMLFactory, java.util.Map)
when reading in an existing file.part
- - The package part that holds xml data representing this sheet.read(POIXMLFactory, java.util.Map)
public POIXMLDocumentPart(POIXMLDocumentPart parent, PackagePart part)
read(POIXMLFactory, java.util.Map)
when reading in an existing file.parent
- - Parent partpart
- - The package part that holds xml data representing this sheet.read(POIXMLFactory, java.util.Map)
@Removal(version="5.0.0") @Deprecated public boolean isCommited()
public boolean isCommitted()
@Removal(version="5.0.0") @Deprecated public void setCommited(boolean isCommitted)
isCommitted
- boolean valuepublic void setCommitted(boolean isCommitted)
isCommitted
- boolean valueprotected final void rebase(OPCPackage pkg) throws InvalidFormatException
pkg
- the package to be rebasedInvalidFormatException
- if there was an error in the core document relationjava.lang.IllegalStateException
- if there are more than one core document relationspublic final PackagePart getPackagePart()
public final java.util.List<POIXMLDocumentPart> getRelations()
public final java.util.List<POIXMLDocumentPart.RelationPart> getRelationParts()
public final POIXMLDocumentPart getRelationById(java.lang.String id)
POIXMLDocumentPart
, where a
PackageRelationship
is set from the PackagePart
of this
POIXMLDocumentPart
to the PackagePart
of the target
POIXMLDocumentPart
with a PackageRelationship.getId()
matching the given parameter value.id
- The relation id to look forpublic final POIXMLDocumentPart.RelationPart getRelationPartById(java.lang.String id)
POIXMLDocumentPart.RelationPart
, where a
PackageRelationship
is set from the PackagePart
of this
POIXMLDocumentPart
to the PackagePart
of the target
POIXMLDocumentPart
with a PackageRelationship.getId()
matching the given parameter value.id
- The relation id to look forpublic final java.lang.String getRelationId(POIXMLDocumentPart part)
PackageRelationship.getId()
of the
PackageRelationship
, that sources from the PackagePart
of
this POIXMLDocumentPart
to the PackagePart
of the given
parameter value.
There can be multiple references to the given POIXMLDocumentPart
and only the first in the order of creation is returned.
part
- The POIXMLDocumentPart
for which the according
relation-id shall be found.PackageRelationship.getId()
or null, if
parts are not related.public final POIXMLDocumentPart.RelationPart addRelation(java.lang.String relId, POIXMLRelation relationshipType, POIXMLDocumentPart part)
relId
- the preferred relation id, when null the next free relation id will be usedrelationshipType
- the package relationship typepart
- the child to addprotected final void removeRelation(POIXMLDocumentPart part)
If there are multiple relationships to the same part, this will only
remove the first relationship in the order of creation. The removal
via the part id (removeRelation(String)
is preferred.
part
- the part which relation is to be removed from this documentprotected final boolean removeRelation(POIXMLDocumentPart part, boolean removeUnusedParts)
If there are multiple relationships to the same part, this will only
remove the first relationship in the order of creation. The removal
via the part id (removeRelation(String, boolean)
is preferred.
part
- The related part, to which the relation shall be removed.removeUnusedParts
- true, if the part shall be removed from the package if not
needed any longer.protected final void removeRelation(java.lang.String partId)
If there are multiple relationships to the same part, this will only
remove the first relationship in the order of creation. The removal
via the part id (removeRelation(String)
is preferred.
partId
- the part id which relation is to be removed from this documentpublic final POIXMLDocumentPart getParent()
null
for the root element.public java.lang.String toString()
toString
in class java.lang.Object
protected void commit() throws java.io.IOException
Sub-classes should override and add logic to marshal the "model" into Ooxml4J.
For example, the code saving a generic XML entry may look as follows:
protected void commit() throws IOException { PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); XmlObject bean = getXmlBean(); //the "model" which holds changes in memory bean.save(out, DEFAULT_XML_OPTIONS); out.close(); }
java.io.IOException
- a subclass may throw an IOException if the changes can't be committedprotected final void onSave(java.util.Set<PackagePart> alreadySaved) throws java.io.IOException
commit()
for each package partalreadySaved
- context set containing already visited nodesjava.io.IOException
- a related part may throw an IOException if the changes can't be savedprotected void prepareForCommit()
Note: This is overwritten for some objects, as *PictureData seem to store the actual content in the part directly without keeping a copy like all others therefore we need to handle them differently.
public final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory)
descriptor
- the part descriptorfactory
- the factory that will create an instance of the requested relationPartAlreadyExistsException
- If rule M1.12 is not verified : Packages shall not contain
equivalent part names and package implementers shall neither
create nor recognize packages with equivalent part names.public final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx)
descriptor
- the part descriptorfactory
- the factory that will create an instance of the requested relationidx
- part numberPartAlreadyExistsException
- If rule M1.12 is not verified : Packages shall not contain
equivalent part names and package implementers shall neither
create nor recognize packages with equivalent part names.protected final int getNextPartNumber(POIXMLRelation descriptor, int minIdx)
createRelationship(POIXMLRelation, POIXMLFactory, int)
or
createRelationship(POIXMLRelation, POIXMLFactory, int, boolean)
without naming clashes.
If parts with other types are already claiming a name for this relationship
type (eg a XSSFRelation.CHART
using the drawing part namespace
normally used by XSSFRelation.DRAWINGS
), those will be considered
when finding the next spare number.descriptor
- The relationship type to find the part number forminIdx
- The minimum free index to assign, use -1 for anypublic final POIXMLDocumentPart.RelationPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation)
descriptor
- the part descriptorfactory
- the factory that will create an instance of the requested relationidx
- part numbernoRelation
- if true, then no relationship is added.PartAlreadyExistsException
- If rule M1.12 is not verified : Packages shall not contain
equivalent part names and package implementers shall neither
create nor recognize packages with equivalent part names.protected void read(POIXMLFactory factory, java.util.Map<PackagePart,POIXMLDocumentPart> context) throws OpenXML4JException
factory
- the factory object that creates POIXMLFactory instancescontext
- context map containing already visited noted keyed by targetURIOpenXML4JException
- thrown when a related part can't be readprotected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException
rel
- The relationshipInvalidFormatException
- thrown if the related part has is erroneousprotected void onDocumentCreate() throws java.io.IOException
java.io.IOException
- a subclass may throw an IOException on document creationprotected void onDocumentRead() throws java.io.IOException
java.io.IOException
- a subclass may throw an IOException when a document is readprotected void onDocumentRemove() throws java.io.IOException
java.io.IOException
- a subclass may throw an IOException when a document is removed@Internal @Deprecated public static void _invokeOnDocumentRead(POIXMLDocumentPart part) throws java.io.IOException
This method only exists to allow access to protected onDocumentRead()
from XWPFDocument
without reflection. It should be removed.
part
- the part which is to be readjava.io.IOException
- if the part can't be readCopyright 2020 The Apache Software Foundation or its licensors, as applicable.