Class RelationshipsPart

java.lang.Object

public final class RelationshipsPart
extends JaxbXmlPart<Relationships>
Represents a Relationship Part, which contains the relationships for a given PackagePart or the Package.
  • Constructor Details

  • Method Details

    • createPackageRels

      public static RelationshipsPart createPackageRels() throws InvalidFormatException
      Returns:
      Throws:
      InvalidFormatException
      Since:
      3.2.0, at which time related constructor was made private
    • init

      public void init()
    • getPartName

      public PartName getPartName()
      Overrides:
      getPartName in class Base
      Returns:
      the uri
    • createRelationshipsPartForPart

      public static RelationshipsPart createRelationshipsPartForPart​(Base sourcePart)
    • getRelationships

      public Relationships getRelationships()
    • setRelationships

      public void setRelationships​(Relationships jaxbElement)
    • getSourceP

      public Base getSourceP()
    • setSourceP

      public void setSourceP​(Base sourcePart)
    • getSourceURI

      public java.net.URI getSourceURI()
    • isPackageRelationshipPart

      public boolean isPackageRelationshipPart()
      This Relationship Part is the package relationship part if its source is the Package.
    • getPart

      public Part getPart​(java.lang.String id)
      Gets a loaded Part by its id
    • getRelationshipByID

      public Relationship getRelationshipByID​(java.lang.String id)
      Retrieves a package relationship based on its id.
      Parameters:
      id - ID of the package relationship to retrieve.
      Returns:
      The package relationship identified by the specified id.
    • getRelationshipByType

      public Relationship getRelationshipByType​(java.lang.String type)
      Get the first rel with specified relationship type (see Namespaces for pre-defined constants)
      Parameters:
      type -
      Returns:
    • getRelationshipsByType

      public java.util.List<Relationship> getRelationshipsByType​(java.lang.String type)
      Parameters:
      type -
      Returns:
      Since:
      3.3.0
    • getPart

      public Part getPart​(Relationship r)
    • getNextId

      public java.lang.String getNextId()
    • isRelIdOccupied

      public boolean isRelIdOccupied​(java.lang.String relId)
    • resetIdAllocator

      public void resetIdAllocator()
      Assumes relationship ids are all of the form 'rIdn' where n is a positive integer.
    • loadPart

      public void loadPart​(Part part, Relationship sourceRelationship)
      Loads a pre-existing target part into the package (but does not load its contents as such; that is done elsewhere). The target part is assumed to be specified already in this relationship part. Generally this will be used by io.load classes.
      Parameters:
      part - The part to add.
    • addPart

      Add a newly created part, a relationship and the content type.
      Parameters:
      part - The part to add.
      overwriteExistingTarget - Whether to replace any part with the same target
      ctm - Content type manager
      Returns:
      The Relationship
      Throws:
      InvalidFormatException
    • addPart

      public Relationship addPart​(Part part, RelationshipsPart.AddPartBehaviour mode, ContentTypeManager ctm, java.lang.String relId) throws InvalidFormatException
      Add a newly created part, a relationship and the content type.
      Parameters:
      part - The part to add.
      overwriteExistingTarget - Whether to replace any part with the same target
      ctm - Content type manager
      relId - the relId we wish to use (provided it is not in use)
      Returns:
      The Relationship
      Throws:
      InvalidFormatException
    • addRelationship

      public boolean addRelationship​(Relationship rel) throws InvalidOperationException
      Add the specified relationship to the collection.
      Parameters:
      rel - The relationship to add.
      Throws:
      InvalidOperationException
    • removeParts

      public java.util.List<PartName> removeParts()
      Remove all parts from this relationships part
    • removePart

      public java.util.List<PartName> removePart​(PartName partName)
      Remove a part from this package, including its relationships part and all target parts. Do so recursively. If this part is relationship part, then delete all relationships in the source part.
      Parameters:
      partName - The part name of the part to remove.
    • isATarget

      @Deprecated public boolean isATarget​(PartName partName)
      Deprecated.
      See Also:
      getRel(org.docx4j.openpackaging.parts.PartName)
    • getRel

      public Relationship getRel​(PartName partName)
      Is partname a target of any of these rels?
      Parameters:
      partName -
      Returns:
    • isTarget

      public boolean isTarget​(PartName partName, Relationship rel)
      Is partName the target of the specified rel?
      Parameters:
      partName -
      rel -
      Returns:
      Since:
      2.6.0
    • removeRelationship

      public void removeRelationship​(Relationship rel)
      Remove a relationship by its reference.
      Parameters:
      rel - The relationship to delete.
    • removeRelationship

      public void removeRelationship​(PartName partName)
    • removeRelationshipsByType

      public void removeRelationshipsByType​(java.lang.String type)
      Remove relationships by type (eg Namespaces.PRESENTATIONML_SLIDE_LAYOUT)
      Parameters:
      type -
      Since:
      3.2.0
    • size

      public int size()
      Get the number of relationships in the collection.
    • unmarshal

      public Relationships unmarshal​(java.io.InputStream is) throws javax.xml.bind.JAXBException
      Unmarshal XML data from the specified InputStream and return the resulting content tree. Validation event location information may be incomplete when using this form of the unmarshal API.

      Implements Unmarshal Global Root Element.

      Overrides:
      unmarshal in class JaxbXmlPart<Relationships>
      Parameters:
      is - the InputStream to unmarshal XML data from
      Returns:
      the newly created root object of the java content tree
      Throws:
      javax.xml.bind.JAXBException - If any unexpected errors occur while unmarshalling
    • unmarshal

      public Relationships unmarshal​(org.w3c.dom.Element el) throws javax.xml.bind.JAXBException
      Overrides:
      unmarshal in class JaxbXmlPart<Relationships>
      Throws:
      javax.xml.bind.JAXBException
    • marshal

      public void marshal​(org.w3c.dom.Node node) throws javax.xml.bind.JAXBException
      Description copied from class: JaxbXmlPart
      Marshal the content tree rooted at jaxbElement into a DOM tree.
      Overrides:
      marshal in class JaxbXmlPart<Relationships>
      Parameters:
      node - DOM nodes will be added as children of this node. This parameter must be a Node that accepts children (Document, DocumentFragment, or Element)
      Throws:
      javax.xml.bind.JAXBException - If any unexpected problem occurs during the marshalling.
    • marshal

      public void marshal​(java.io.OutputStream os) throws javax.xml.bind.JAXBException
      Description copied from class: JaxbXmlPart
      Marshal the content tree rooted at jaxbElement into an output stream, using org.docx4j.jaxb.NamespacePrefixMapper.
      Overrides:
      marshal in class JaxbXmlPart<Relationships>
      Parameters:
      os - XML will be added to this stream.
      Throws:
      javax.xml.bind.JAXBException - If any unexpected problem occurs during the marshalling.
    • uniqueToThis

      public java.util.List<Relationship> uniqueToThis​(RelationshipsPart otherRP)
      Identify the rels in this relationships part which aren't in the other
      Parameters:
      otherRP - the other RelationshipsPart
    • uniqueToOther

      public java.util.List<Relationship> uniqueToOther​(RelationshipsPart otherRP)
      Identify the rels in this relationships part which aren't in the other
      Parameters:
      otherRP - the other RelationshipsPart
    • differingContent

      public java.util.List<Relationship> differingContent​(RelationshipsPart otherRP) throws Docx4JException
      Identify rels common to both parts, but where rels have different content.
      Parameters:
      otherRP -
      Returns:
      Throws:
      Docx4JException
    • getRelationshipByTarget

      public static Relationship getRelationshipByTarget​(RelationshipsPart rp, java.lang.String relativeTarget)
    • inferSourcePartName

      public static java.lang.String inferSourcePartName​(java.lang.String relationshipsPartName)
      Infer the source part's name from this rels part name. eg word/_rels/document.xml.rels gives word/document.xml and /_rels/.rels gives /
      Parameters:
      relationshipsPartName -
      Returns: