public abstract class PackagePart extends Object implements RelationshipSource
| Modifier and Type | Field and Description | 
|---|---|
| protected OPCPackage | _containerThis part's container. | 
| protected ContentType | _contentTypeThe type of content of this part. | 
| protected PackagePartName | _partNameThe 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,
           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 | clearRelationships()Delete all the relationships attached to this. | 
| abstract void | close()Close this part : flush this part, close the input stream and output
 stream. | 
| abstract void | flush()Flush the content of this part. | 
| String | getContentType() | 
| InputStream | getInputStream()Get the input stream of this part to read its content. | 
| protected abstract InputStream | getInputStreamImpl()Abtract method that get the input stream of this part. | 
| OutputStream | getOutputStream()Get the output stream of this part. | 
| protected abstract OutputStream | getOutputStreamImpl()Abstract method that 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. | 
| 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() | 
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, 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.InvalidFormatExceptionpublic PackageRelationship addExternalRelationship(String target, String relationshipType)
addExternalRelationship in interface RelationshipSourcetarget - 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 RelationshipSourcetarget - 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 RelationshipSourcetargetPartName - 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.zkoss.poi.openxml4j.opc.PackagePartName,
      org.zkoss.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 RelationshipSourcetargetPartName - 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.InvalidFormatException - If the URI point to a relationship part URI.RelationshipSource.addRelationship(org.zkoss.poi.openxml4j.opc.PackagePartName,
      org.zkoss.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.zkoss.poi.openxml4j.opc.PackagePartName,
      org.zkoss.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.InvalidFormatException - If the URI point to a relationship part URI.RelationshipSource.addRelationship(org.zkoss.poi.openxml4j.opc.PackagePartName,
      org.zkoss.poi.openxml4j.opc.TargetMode, java.lang.String, java.lang.String)public void clearRelationships()
RelationshipSourceclearRelationships in interface RelationshipSourceRelationshipSource.clearRelationships()public void removeRelationship(String id)
removeRelationship in interface RelationshipSourceid - The ID identified the part to delete.RelationshipSource.removeRelationship(java.lang.String)public PackageRelationshipCollection getRelationships() throws InvalidFormatException
getRelationships in interface RelationshipSourceOpenXML4JExceptionInvalidFormatExceptionRelationshipSource.getRelationships()public PackageRelationship getRelationship(String id)
getRelationship in interface RelationshipSourceid - ID of the package relationship to retrieve.RelationshipSource.getRelationship(java.lang.String)public PackageRelationshipCollection getRelationshipsByType(String relationshipType) throws InvalidFormatException
getRelationshipsByType in interface RelationshipSourcerelationshipType - 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 RelationshipSourceRelationshipSource.hasRelationships()public boolean isRelationshipExists(PackageRelationship rel)
isRelationshipExists in interface RelationshipSourcerel - The relationship to check.RelationshipSource.isRelationshipExists(org.zkoss.poi.openxml4j.opc.PackageRelationship)public PackagePart getRelatedPart(PackageRelationship rel) throws InvalidFormatException
rel - A relationship from this part to another oneInvalidFormatExceptionpublic InputStream getInputStream() throws IOException
null.IOExceptionpublic OutputStream getOutputStream()
MemoryPackagePartpublic PackagePartName getPartName()
public String getContentType()
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 setprotected abstract InputStream getInputStreamImpl() throws IOException
IOException - Throws if an IO Exception occur in the implementation
                method.protected abstract OutputStream getOutputStreamImpl()
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()
Copyright © 2020. All rights reserved.