Class Base

java.lang.Object
org.docx4j.openpackaging.Base
Direct Known Subclasses:
OpcPackage, Part

public abstract class Base extends Object
  • Field Details

    • log

      protected static org.slf4j.Logger log
    • relationships

      public RelationshipsPart relationships
      relationships - the package and each part can have one of these See eg 11. WordprocessingML [11.2 Package Structure]. (Each Part is also the _target_ of a RelationshipPart, so see Part for definition of a corresponding field.)
    • contentType

      protected ContentType contentType
    • partName

      @Deprecated public PartName partName
      Deprecated.
      The part name. (required by the specification [M1.1]) You should use the getter/setter, rather than accessing this field directly! Note that in docx4J, part names should be resolved, before being set, so that they are absolute (ie start with '/'). We will assume the Package has a part name of "/"
  • Constructor Details

    • Base

      public Base()
  • Method Details

    • getPackage

      public abstract OpcPackage getPackage()
    • getUserData

      public Object getUserData(String key)
      Parameters:
      key -
      Returns:
    • setUserData

      public void setUserData(String key, Object value)
      An object allowing the user of the docx4j API to associate arbitrary data with this package/part while the package is in memory. Note that the data is not saved when the package is saved.
      Parameters:
      key -
      value -
    • getRelationshipsPart

      public RelationshipsPart getRelationshipsPart()
      Get the relationship part. From 2.7.1, the part will be created if it doesn't exist. (SaveToZipFile will only save it if it contains rels)
      Returns:
      The relationship part name.
    • getRelationshipsPart

      public RelationshipsPart getRelationshipsPart(boolean createIfAbsent)
      Get the relationship part.
      Parameters:
      create - whether to create it if it doesn't exist
      Returns:
      Since:
      2.7.1
    • setRelationships

      public void setRelationships(RelationshipsPart relationships)
    • getContentType

      public String getContentType()
    • setContentType

      public void setContentType(ContentType contentType)
    • setPartName

      public void setPartName(PartName partName)
      Parameters:
      partName -
      Since:
      3.2.0
    • getPartName

      public PartName getPartName()
      Returns:
      the uri
    • setPartShortcut

      public abstract boolean setPartShortcut(Part part, String relationshipType)
      Tell the source Part about this target Part, so the source can use this part via a convenience method.
      Parameters:
      part -
      relationshipType -
      Returns:
      true if the source Part does use the target Part in a convenience method.
    • addTargetPart

      public Relationship addTargetPart(Part targetpart, RelationshipsPart.AddPartBehaviour mode) throws InvalidFormatException
      Convenience method to add a part to this Part's relationships. The package must be set on this part in order for this to work.
      Parameters:
      targetpart - The part to add to this part's relationships
      mode - whether to overwrite, rename or abort if the part name already exists
      proposedRelId -
      Returns:
      Throws:
      InvalidFormatException
      Since:
      2.7.1
    • addTargetPart

      public Relationship addTargetPart(Part targetpart) throws InvalidFormatException
      Convenience method to add a part to this Part's relationships. The package must be set on this part in order for this to work. The added part will replace any existing part with the same name (ie same target in the rels part). In other words, if you want to use the one image as the target of 2 rels, don't use this method.
      Parameters:
      targetpart - The part to add to this part's relationships
      Throws:
      InvalidFormatException
    • addTargetPart

      public Relationship addTargetPart(Part targetpart, String proposedRelId) throws InvalidFormatException
      Convenience method to add a part to this Part's relationships. The package must be set on this part in order for this to work. The added part will replace any existing part with the same name (ie same target in the rels part). In other words, if you want to use the one image as the target of 2 rels, don't use this method.
      Parameters:
      targetpart - The part to add to this part's relationships
      Throws:
      InvalidFormatException
    • addTargetPart

      public Relationship addTargetPart(Part targetpart, RelationshipsPart.AddPartBehaviour mode, String proposedRelId) throws InvalidFormatException
      Convenience method to add a part to this Part's relationships. The package must be set on this part in order for this to work. Whether the added part will replace any existing part with the same name depends on AddPartBehaviour setting.
      Parameters:
      targetpart - The part to add to this part's relationships
      mode - whether to overwrite, rename or abort if the part name already exists
      proposedRelId -
      Returns:
      Throws:
      InvalidFormatException
      Since:
      2.7.1
    • reset

      public void reset()
      Reinit fields so this pkg object can be re-used.
      Since:
      3.3.7