public class POIXMLDocumentPart extends Object
Each POIXMLDocumentPart keeps a reference to the underlying a PackagePart
.
Modifier and Type | Field and Description |
---|---|
static org.apache.xmlbeans.XmlOptions |
DEFAULT_XML_OPTIONS |
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(PackagePart part,
PackageRelationship rel)
Creates an POIXMLDocumentPart representing the given package part and relationship.
|
POIXMLDocumentPart(POIXMLDocumentPart parent,
PackagePart part,
PackageRelationship rel)
Creates an POIXMLDocumentPart representing the given package part, relationship and parent
Called by
read(POIXMLFactory, java.util.Map) when reading in an exisiting file. |
Modifier and Type | Method and Description |
---|---|
void |
addRelation(String id,
POIXMLDocumentPart part)
Add a new child POIXMLDocumentPart
|
protected void |
clearMemoryPackagePart(PackagePart part) |
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) |
protected POIXMLDocumentPart |
createRelationship(POIXMLRelation descriptor,
POIXMLFactory factory,
int idx,
boolean noRelation)
Create a new child POIXMLDocumentPart
|
PackagePart |
getPackagePart()
Provides access to the underlying PackagePart
|
PackageRelationship |
getPackageRelationship()
Provides access to the PackageRelationship that identifies this POIXMLDocumentPart
|
POIXMLDocumentPart |
getParent()
Returns the parent POIXMLDocumentPart.
|
POIXMLDocumentPart |
getRelationById(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. |
protected int |
getRelationCounter() |
String |
getRelationId(POIXMLDocumentPart part)
Returns the
PackageRelationship.getId() of the
PackageRelationship , that sources from the PackagePart of
this POIXMLDocumentPart to the PackagePart of the given
parameter value. |
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.
|
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(Set<PackagePart> alreadySaved)
Save changes in the underlying OOXML package.
|
protected void |
read(POIXMLFactory factory,
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.
|
String |
toString() |
public static final org.apache.xmlbeans.XmlOptions DEFAULT_XML_OPTIONS
public POIXMLDocumentPart(OPCPackage pkg)
public POIXMLDocumentPart()
public POIXMLDocumentPart(PackagePart part, PackageRelationship rel)
read(POIXMLFactory, java.util.Map)
when reading in an exisiting file.part
- - The package part that holds xml data represenring this sheet.rel
- - the relationship of the given package partread(POIXMLFactory, java.util.Map)
public POIXMLDocumentPart(POIXMLDocumentPart parent, PackagePart part, PackageRelationship rel)
read(POIXMLFactory, java.util.Map)
when reading in an exisiting file.parent
- - Parent partpart
- - The package part that holds xml data represenring this sheet.rel
- - the relationship of the given package partread(POIXMLFactory, java.util.Map)
protected int getRelationCounter()
protected final void rebase(OPCPackage pkg) throws InvalidFormatException
InvalidFormatException
public final PackagePart getPackagePart()
public final PackageRelationship getPackageRelationship()
public final List<POIXMLDocumentPart> getRelations()
public final POIXMLDocumentPart getRelationById(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 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.part
- The POIXMLDocumentPart
for which the according
relation-id shall be found.PackageRelationship.getId()
or null, if
parts are not related.public final void addRelation(String id, POIXMLDocumentPart part)
part
- the child to addprotected final void removeRelation(POIXMLDocumentPart part)
protected final boolean removeRelation(POIXMLDocumentPart part, boolean removeUnusedParts)
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.public final POIXMLDocumentPart getParent()
null
for the root element.protected void commit() throws IOException
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();
}
IOException
protected final void onSave(Set<PackagePart> alreadySaved) throws IOException
commit()
for each package partalreadySaved
- context set containing already visited nodesIOException
public final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory)
descriptor
- the part descriptorfactory
- the factory that will create an instance of the requested relationpublic final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx)
protected final POIXMLDocumentPart 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.protected void read(POIXMLFactory factory, Map<PackagePart,POIXMLDocumentPart> context) throws OpenXML4JException
factory
- the factory object that creates POIXMLFactory instancescontext
- context map containing already visited noted keyed by targetURIOpenXML4JException
protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException
rel
- The relationshipInvalidFormatException
protected void onDocumentCreate() throws IOException
IOException
protected void onDocumentRead() throws IOException
IOException
protected void onDocumentRemove() throws IOException
IOException
protected void clearMemoryPackagePart(PackagePart part)
Copyright © 2020. All rights reserved.