public abstract class PackagePart extends Object implements RelationshipSource, Comparable<PackagePart>
Constructor and Description |
---|
PackagePart(OPCPackage pack,
PackagePartName partName,
String contentType)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
PackageRelationship |
addExternalRelationship(String target,
String relationshipType)
Adds an external relationship to a part (except relationships part).
|
PackageRelationship |
addExternalRelationship(String target,
String relationshipType,
String id)
Adds an external relationship to a part (except relationships part).
|
PackageRelationship |
addRelationship(PackagePartName targetPartName,
TargetMode targetMode,
String relationshipType)
Add a relationship to a part (except relationships part).
|
PackageRelationship |
addRelationship(PackagePartName targetPartName,
TargetMode targetMode,
String relationshipType,
String id)
Add a relationship to a part (except relationships part).
|
PackageRelationship |
addRelationship(URI targetURI,
TargetMode targetMode,
String relationshipType)
Add a relationship to a part (except relationships part).
|
PackageRelationship |
addRelationship(URI targetURI,
TargetMode targetMode,
String relationshipType,
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.
|
String |
getContentType() |
ContentType |
getContentTypeDetails() |
InputStream |
getInputStream()
Get the input stream of this part to read its content.
|
OutputStream |
getOutputStream()
Get the output stream of this part.
|
OPCPackage |
getPackage() |
PackagePartName |
getPartName() |
PackagePart |
getRelatedPart(PackageRelationship rel)
Get the PackagePart that is the target of a relationship.
|
PackageRelationship |
getRelationship(String id)
Retrieves a package relationship from its id.
|
PackageRelationshipCollection |
getRelationships()
Retrieve all the relationships attached to this part.
|
PackageRelationshipCollection |
getRelationshipsByType(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(InputStream ios)
Load the content of this part.
|
void |
removeRelationship(String id)
Delete the relationship specified by its id.
|
abstract boolean |
save(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(String contentType)
Set the content type.
|
void |
setDeleted(boolean isDeleted) |
String |
toString() |
public PackagePart(OPCPackage pack, PackagePartName partName, 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(String target, 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(String target, String relationshipType, 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, 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, String relationshipType, 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.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(URI targetURI, TargetMode targetMode, 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(URI targetURI, TargetMode targetMode, String relationshipType, 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(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(String id)
getRelationship
in interface RelationshipSource
id
- ID of the package relationship to retrieve.RelationshipSource.getRelationship(java.lang.String)
public PackageRelationshipCollection getRelationshipsByType(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 InputStream getInputStream() throws IOException
null
.IOException
- If creating the input-stream fails.public OutputStream getOutputStream()
MemoryPackagePart
public PackagePartName getPartName()
public String getContentType()
public ContentType getContentTypeDetails()
public void setContentType(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 int compareTo(PackagePart other)
compareTo
in interface Comparable<PackagePart>
public abstract boolean save(OutputStream zos) throws OpenXML4JException
zos
- Output stream to save this part.OpenXML4JException
- If any exception occur.public abstract boolean load(InputStream ios) throws InvalidFormatException
ios
- The input stream of the content to load.InvalidFormatException
- Throws if the content format is invalid.public abstract void close()
public abstract void flush()
public void clear()
Copyright © 2010 - 2020 Adobe. All Rights Reserved