public abstract class PackagePart extends java.lang.Object implements RelationshipSource, java.lang.Comparable<PackagePart>
Modifier and Type | Field and Description |
---|---|
protected OPCPackage |
_container
This part's container.
|
protected ContentType |
_contentType
The type of content of this part.
|
protected PackagePartName |
_partName
The part name.
|
Modifier | Constructor and Description |
---|---|
protected |
PackagePart(OPCPackage pack,
PackagePartName partName,
ContentType contentType)
Constructor.
|
protected |
PackagePart(OPCPackage pack,
PackagePartName partName,
ContentType contentType,
boolean loadRelationships)
Constructor.
|
|
PackagePart(OPCPackage pack,
PackagePartName partName,
java.lang.String contentType)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
PackageRelationship |
addExternalRelationship(java.lang.String target,
java.lang.String relationshipType)
Adds an external relationship to a part (except relationships part).
|
PackageRelationship |
addExternalRelationship(java.lang.String target,
java.lang.String relationshipType,
java.lang.String id)
Adds an external relationship to a part (except relationships part).
|
PackageRelationship |
addRelationship(PackagePartName targetPartName,
TargetMode targetMode,
java.lang.String relationshipType)
Add a relationship to a part (except relationships part).
|
PackageRelationship |
addRelationship(PackagePartName targetPartName,
TargetMode targetMode,
java.lang.String relationshipType,
java.lang.String id)
Add a relationship to a part (except relationships part).
|
PackageRelationship |
addRelationship(java.net.URI targetURI,
TargetMode targetMode,
java.lang.String relationshipType)
Add a relationship to a part (except relationships part).
|
PackageRelationship |
addRelationship(java.net.URI targetURI,
TargetMode targetMode,
java.lang.String relationshipType,
java.lang.String id)
Add a relationship to a part (except relationships part).
|
void |
clear()
Allows sub-classes to clean up before new data is added.
|
void |
clearRelationships()
Delete all the relationships attached to this.
|
abstract void |
close()
Close this part : flush this part, close the input stream and output
stream.
|
int |
compareTo(PackagePart other)
Compare based on the package part name, using a natural sort order
|
PackageRelationship |
findExistingRelation(PackagePart packagePart)
Check if the new part was already added before via PackagePart.addRelationship()
|
abstract void |
flush()
Flush the content of this part.
|
java.lang.String |
getContentType() |
ContentType |
getContentTypeDetails() |
java.io.InputStream |
getInputStream()
Get the input stream of this part to read its content.
|
protected abstract java.io.InputStream |
getInputStreamImpl()
Method that gets the input stream for this part.
|
java.io.OutputStream |
getOutputStream()
Get the output stream of this part.
|
protected abstract java.io.OutputStream |
getOutputStreamImpl()
Method that gets the output stream for this part.
|
OPCPackage |
getPackage() |
PackagePartName |
getPartName() |
PackagePart |
getRelatedPart(PackageRelationship rel)
Get the PackagePart that is the target of a relationship.
|
PackageRelationship |
getRelationship(java.lang.String id)
Retrieves a package relationship from its id.
|
PackageRelationshipCollection |
getRelationships()
Retrieve all the relationships attached to this part.
|
PackageRelationshipCollection |
getRelationshipsByType(java.lang.String relationshipType)
Retrieve all relationships attached to this part which have the specified
type.
|
long |
getSize() |
boolean |
hasRelationships()
Knows if the part have any relationships.
|
boolean |
isDeleted() |
boolean |
isRelationshipExists(PackageRelationship rel)
Checks if the specified relationship is part of this package part.
|
boolean |
isRelationshipPart() |
abstract boolean |
load(java.io.InputStream ios)
Load the content of this part.
|
void |
removeRelationship(java.lang.String id)
Delete the relationship specified by its id.
|
abstract boolean |
save(java.io.OutputStream zos)
Save the content of this part and the associated relationships part (if
this part own at least one relationship) into the specified output
stream.
|
void |
setContentType(java.lang.String contentType)
Set the content type.
|
void |
setDeleted(boolean isDeleted) |
java.lang.String |
toString() |
protected OPCPackage _container
protected PackagePartName _partName
protected ContentType _contentType
protected PackagePart(OPCPackage pack, PackagePartName partName, ContentType contentType) throws InvalidFormatException
pack
- Parent package.partName
- The part name, relative to the parent Package root.contentType
- The content type.InvalidFormatException
- If the specified URI is not valid.protected PackagePart(OPCPackage pack, PackagePartName partName, ContentType contentType, boolean loadRelationships) throws InvalidFormatException
pack
- Parent package.partName
- The part name, relative to the parent Package root.contentType
- The content type.loadRelationships
- Specify if the relationships will be loadedInvalidFormatException
- If the specified URI is not valid.public PackagePart(OPCPackage pack, PackagePartName partName, java.lang.String contentType) throws InvalidFormatException
pack
- Parent package.partName
- The part name, relative to the parent Package root.contentType
- The Multipurpose Internet Mail Extensions (MIME) content type
of the part's data stream.InvalidFormatException
- If the specified URI is not valid.public PackageRelationship findExistingRelation(PackagePart packagePart)
packagePart
- to find the relationship forpublic PackageRelationship addExternalRelationship(java.lang.String target, java.lang.String relationshipType)
addExternalRelationship
in interface RelationshipSource
target
- External target of the relationshiprelationshipType
- Type of relationship.RelationshipSource.addExternalRelationship(java.lang.String,
java.lang.String)
public PackageRelationship addExternalRelationship(java.lang.String target, java.lang.String relationshipType, java.lang.String id)
addExternalRelationship
in interface RelationshipSource
target
- External target of the relationshiprelationshipType
- Type of relationship.id
- Relationship unique id.RelationshipSource.addExternalRelationship(java.lang.String,
java.lang.String)
public PackageRelationship addRelationship(PackagePartName targetPartName, TargetMode targetMode, java.lang.String relationshipType)
addRelationship
in interface RelationshipSource
targetPartName
- Name of the target part. This one must be relative to the
source root directory of the part.targetMode
- Mode [Internal|External].relationshipType
- Type of relationship.RelationshipSource.addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
org.apache.poi.openxml4j.opc.TargetMode, java.lang.String)
public PackageRelationship addRelationship(PackagePartName targetPartName, TargetMode targetMode, java.lang.String relationshipType, java.lang.String id)
Check rule M1.25: The Relationships part shall not have relationships to any other part. Package implementers shall enforce this requirement upon the attempt to create such a relationship and shall treat any such relationship as invalid.
addRelationship
in interface RelationshipSource
targetPartName
- Name of the target part. This one must be relative to the
source root directory of the part.targetMode
- Mode [Internal|External].relationshipType
- Type of relationship.id
- Relationship unique id.InvalidOperationException
- If a writing operation is done on a read only package or
invalid nested relations are created.java.lang.IllegalArgumentException
- if targetPartName, targetMode
or relationshipType are passed as nullRelationshipSource.addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
org.apache.poi.openxml4j.opc.TargetMode, java.lang.String, java.lang.String)
public PackageRelationship addRelationship(java.net.URI targetURI, TargetMode targetMode, java.lang.String relationshipType)
targetURI
- URI the target part. Must be relative to the source root
directory of the part.targetMode
- Mode [Internal|External].relationshipType
- Type of relationship.RelationshipSource.addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
org.apache.poi.openxml4j.opc.TargetMode, java.lang.String)
public PackageRelationship addRelationship(java.net.URI targetURI, TargetMode targetMode, java.lang.String relationshipType, java.lang.String id)
Check rule M1.25: The Relationships part shall not have relationships to any other part. Package implementers shall enforce this requirement upon the attempt to create such a relationship and shall treat any such relationship as invalid.
targetURI
- URI of the target part. Must be relative to the source root
directory of the part.targetMode
- Mode [Internal|External].relationshipType
- Type of relationship.id
- Relationship unique id.InvalidOperationException
- If the URI point to a relationship part URI.RelationshipSource.addRelationship(org.apache.poi.openxml4j.opc.PackagePartName,
org.apache.poi.openxml4j.opc.TargetMode, java.lang.String, java.lang.String)
public void clearRelationships()
RelationshipSource
clearRelationships
in interface RelationshipSource
RelationshipSource.clearRelationships()
public void removeRelationship(java.lang.String id)
removeRelationship
in interface RelationshipSource
id
- The ID identified the part to delete.RelationshipSource.removeRelationship(java.lang.String)
public PackageRelationshipCollection getRelationships() throws InvalidFormatException
getRelationships
in interface RelationshipSource
InvalidOperationException
- Throws if the package is open en write only mode.InvalidFormatException
RelationshipSource.getRelationships()
public PackageRelationship getRelationship(java.lang.String id)
getRelationship
in interface RelationshipSource
id
- ID of the package relationship to retrieve.RelationshipSource.getRelationship(java.lang.String)
public PackageRelationshipCollection getRelationshipsByType(java.lang.String relationshipType) throws InvalidFormatException
getRelationshipsByType
in interface RelationshipSource
relationshipType
- Relationship type filter.InvalidFormatException
- If an error occurs while parsing the part.InvalidOperationException
- If the package is open in write only mode.RelationshipSource.getRelationshipsByType(java.lang.String)
public boolean hasRelationships()
hasRelationships
in interface RelationshipSource
RelationshipSource.hasRelationships()
public boolean isRelationshipExists(PackageRelationship rel)
isRelationshipExists
in interface RelationshipSource
rel
- The relationship to check.RelationshipSource.isRelationshipExists(org.apache.poi.openxml4j.opc.PackageRelationship)
public PackagePart getRelatedPart(PackageRelationship rel) throws InvalidFormatException
rel
- A relationship from this part to another oneInvalidFormatException
- If the specified URI is not valid.public java.io.InputStream getInputStream() throws java.io.IOException
null
.java.io.IOException
- If creating the input-stream fails.public java.io.OutputStream getOutputStream()
MemoryPackagePart
public PackagePartName getPartName()
public java.lang.String getContentType()
public ContentType getContentTypeDetails()
public void setContentType(java.lang.String contentType) throws InvalidFormatException
contentType
- the contentType to setInvalidFormatException
- Throws if the content type is not valid.InvalidOperationException
- Throws if you try to change the content type whereas this
part is already attached to a package.public OPCPackage getPackage()
public boolean isRelationshipPart()
public boolean isDeleted()
public void setDeleted(boolean isDeleted)
isDeleted
- the isDeleted to setpublic long getSize()
public java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(PackagePart other)
compareTo
in interface java.lang.Comparable<PackagePart>
protected abstract java.io.InputStream getInputStreamImpl() throws java.io.IOException
java.io.IOException
- Throws if an IO Exception occur in the implementation
method.protected abstract java.io.OutputStream getOutputStreamImpl()
public abstract boolean save(java.io.OutputStream zos) throws OpenXML4JException
zos
- Output stream to save this part.POILogger
OpenXML4JException
- If any exception occur.public abstract boolean load(java.io.InputStream ios) throws InvalidFormatException
ios
- The input stream of the content to load.POILogger
InvalidFormatException
- Throws if the content format is invalid.public abstract void close()
public abstract void flush()
public void clear()
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.