Package org.docx4j.openpackaging.parts
Class Part
java.lang.Object
org.docx4j.openpackaging.Base
org.docx4j.openpackaging.parts.Part
- Direct Known Subclasses:
BinaryPart,CustomXmlDataStoragePart,JaxbXmlPart,XmlPart
public abstract class Part extends Base
An abstraction of an Open Packaging Convention (OPC) Part.
OPC Parts are either XML, or binary (or text) documents.
Most are XML documents.
docx4j aims to represent XML parts using JAXB. We have
JAXB representations for all the common parts.
To instantiate a Part use (or create) an appropriate subclass.
When an existing document is being loaded, ContentTypeManager.getPart
will instantiate the appropriate subclass.
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.LoggerlogLogger.protected OpcPackagepack -
Constructor Summary
-
Method Summary
Modifier and Type Method Description longgetContentLengthAsLoaded()returns the size in bytes of this part as stored, or -1 if unknown.RelationshipsPartgetOwningRelationshipPart()Deprecated.OpcPackagegetPackage()java.lang.StringgetRelationshipType()RelationshipgetSourceRelationship()Deprecated.java.util.List<Relationship>getSourceRelationships()longgetVersion()abstract booleanisContentEqual(Part other)voidremove()Remove this part from the pkg.voidrename(PartName newName)Rename this part; updates source rels and parts collection.protected voidsetContentLengthAsLoaded(long contentLengthAsLoaded)voidsetOwningRelationshipPart(RelationshipsPart owningRelationshipPart)Deprecated.voidsetPackage(OpcPackage pack)booleansetPartShortcut(Part part, java.lang.String relationshipType)Tell the source Part about this target Part, so the source can use this part via a convenience method.voidsetRelationshipType(java.lang.String relationshipType)voidsetSourceRelationship(Relationship sourceRelationship)Deprecated.voidsetVersion(long version)Methods inherited from class org.docx4j.openpackaging.Base
addTargetPart, addTargetPart, addTargetPart, addTargetPart, getContentType, getPartName, getRelationshipsPart, getRelationshipsPart, getUserData, reset, setContentType, setPartName, setRelationships, setUserData
-
Field Details
-
Constructor Details
-
Part
public Part() -
Part
Constructor.- Parameters:
pack- Parent package.partName- The part name, relative to the parent Package root.- Throws:
InvalidFormatException- If the specified URI is not valid.
-
Part
Constructor.- Parameters:
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.- Throws:
InvalidFormatException
-
-
Method Details
-
getSourceRelationships
- Since:
- 2.7.1
-
getSourceRelationship
Deprecated.- Returns:
- the sourceRelationship
-
setSourceRelationship
Deprecated.NB a media part could be referenced from multiple source parts, but this method can only record one!- Parameters:
sourceRelationship- the sourceRelationship to set
-
getRelationshipType
public java.lang.String getRelationshipType() -
setRelationshipType
public void setRelationshipType(java.lang.String relationshipType) -
getOwningRelationshipPart
Deprecated. -
setOwningRelationshipPart
Deprecated. -
getContentLengthAsLoaded
public long getContentLengthAsLoaded()returns the size in bytes of this part as stored, or -1 if unknown.- Returns:
- the contentLengthAsLoaded
- Since:
- 3.0.0
-
setContentLengthAsLoaded
protected void setContentLengthAsLoaded(long contentLengthAsLoaded)- Parameters:
contentLengthAsLoaded- the contentLengthAsLoaded to set- Since:
- 3.0.0
-
getPackage
- Specified by:
getPackagein classBase
-
setPackage
-
setPartShortcut
Description copied from class:BaseTell the source Part about this target Part, so the source can use this part via a convenience method.- Specified by:
setPartShortcutin classBase- Returns:
- true if the source Part does use the target Part in a convenience method.
-
setVersion
public void setVersion(long version) -
getVersion
public long getVersion() -
rename
Rename this part; updates source rels and parts collection. Useful when merging documents, if you need to take action to avoid name collisions.- Parameters:
newName-- Since:
- 3.2.0
-
isContentEqual
- Throws:
Docx4JException
-
remove
public void remove()Remove this part from the pkg. Beware: it is up to you to make sure your content doesn't rely on this part being present! A symptom of that would be that Office now reports your file to be corrupt or in need of repair.- Since:
- 3.0.2
-