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 Details

    • log

      protected static org.slf4j.Logger log
      Logger.
    • pack

      protected OpcPackage pack
  • Constructor Details

    • Part

      public Part()
    • Part

      public Part(PartName partName) throws InvalidFormatException
      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

      public Part(PartName partName, String contentType) throws InvalidFormatException
      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

      public List<Relationship> getSourceRelationships()
      Since:
      2.7.1
    • getSourceRelationship

      @Deprecated public Relationship getSourceRelationship()
      Deprecated.
      Returns:
      the sourceRelationship
    • setSourceRelationship

      @Deprecated public void setSourceRelationship(Relationship sourceRelationship)
      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 String getRelationshipType()
    • setRelationshipType

      public void setRelationshipType(String relationshipType)
    • getOwningRelationshipPart

      @Deprecated public RelationshipsPart getOwningRelationshipPart()
      Deprecated.
    • setOwningRelationshipPart

      @Deprecated public void setOwningRelationshipPart(RelationshipsPart owningRelationshipPart)
      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

      public OpcPackage getPackage()
      Specified by:
      getPackage in class Base
    • setPackage

      public void setPackage(OpcPackage pack)
    • setPartShortcut

      public boolean setPartShortcut(Part part, String relationshipType)
      Description copied from class: Base
      Tell the source Part about this target Part, so the source can use this part via a convenience method.
      Specified by:
      setPartShortcut in class Base
      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

      public void rename(PartName newName)
      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

      public abstract boolean isContentEqual(Part other) throws Docx4JException
      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