Class RelationshipsPart
java.lang.Object
org.docx4j.openpackaging.Base
org.docx4j.openpackaging.parts.Part
org.docx4j.openpackaging.parts.JaxbXmlPart<Relationships>
org.docx4j.openpackaging.parts.relationships.RelationshipsPart
public final class RelationshipsPart extends JaxbXmlPart<Relationships>
Represents a Relationship Part, which contains the relationships for a
given PackagePart or the Package.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRelationshipsPart.AddPartBehaviour -
Field Summary
Fields inherited from class org.docx4j.openpackaging.parts.JaxbXmlPart
jaxbElement, jc, MAX_BYTES_Unmarshal_Error -
Constructor Summary
Constructors Constructor Description RelationshipsPart()You probably don't want this one (though it is useful for reflection).RelationshipsPart(Base sourceP)Constructor. -
Method Summary
Modifier and Type Method Description RelationshipaddPart(Part part, RelationshipsPart.AddPartBehaviour mode, ContentTypeManager ctm)Add a newly created part, a relationship and the content type.RelationshipaddPart(Part part, RelationshipsPart.AddPartBehaviour mode, ContentTypeManager ctm, java.lang.String relId)Add a newly created part, a relationship and the content type.booleanaddRelationship(Relationship rel)Add the specified relationship to the collection.static RelationshipsPartcreatePackageRels()static RelationshipsPartcreateRelationshipsPartForPart(Base sourcePart)java.util.List<Relationship>differingContent(RelationshipsPart otherRP)Identify rels common to both parts, but where rels have different content.java.lang.StringgetNextId()PartgetPart(java.lang.String id)Gets a loaded Part by its idPartgetPart(Relationship r)PartNamegetPartName()RelationshipgetRel(PartName partName)Is partname a target of any of these rels?RelationshipgetRelationshipByID(java.lang.String id)Retrieves a package relationship based on its id.static RelationshipgetRelationshipByTarget(RelationshipsPart rp, java.lang.String relativeTarget)RelationshipgetRelationshipByType(java.lang.String type)Get the first rel with specified relationship type (see Namespaces for pre-defined constants)RelationshipsgetRelationships()java.util.List<Relationship>getRelationshipsByType(java.lang.String type)BasegetSourceP()java.net.URIgetSourceURI()static java.lang.StringinferSourcePartName(java.lang.String relationshipsPartName)Infer the source part's name from this rels part name.voidinit()booleanisATarget(PartName partName)Deprecated.booleanisPackageRelationshipPart()This Relationship Part is the package relationship part if its source is the Package.booleanisRelIdOccupied(java.lang.String relId)booleanisTarget(PartName partName, Relationship rel)Is partName the target of the specified rel?voidloadPart(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).voidmarshal(java.io.OutputStream os)Marshal the content tree rooted at jaxbElement into an output stream, using org.docx4j.jaxb.NamespacePrefixMapper.voidmarshal(org.w3c.dom.Node node)Marshal the content tree rooted at jaxbElement into a DOM tree.java.util.List<PartName>removePart(PartName partName)Remove a part from this package, including its relationships part and all target parts.java.util.List<PartName>removeParts()Remove all parts from this relationships partvoidremoveRelationship(PartName partName)voidremoveRelationship(Relationship rel)Remove a relationship by its reference.voidremoveRelationshipsByType(java.lang.String type)Remove relationships by type (eg Namespaces.PRESENTATIONML_SLIDE_LAYOUT)voidresetIdAllocator()Assumes relationship ids are all of the form 'rIdn' where n is a positive integer.voidsetRelationships(Relationships jaxbElement)voidsetSourceP(Base sourcePart)intsize()Get the number of relationships in the collection.java.util.List<Relationship>uniqueToOther(RelationshipsPart otherRP)Identify the rels in this relationships part which aren't in the otherjava.util.List<Relationship>uniqueToThis(RelationshipsPart otherRP)Identify the rels in this relationships part which aren't in the otherRelationshipsunmarshal(java.io.InputStream is)Unmarshal XML data from the specified InputStream and return the resulting content tree.Relationshipsunmarshal(org.w3c.dom.Element el)Methods inherited from class org.docx4j.openpackaging.parts.JaxbXmlPart
addMcChoiceNamespace, getContents, getJAXBContext, getJaxbElement, getMcChoiceNamespaces, getMceIgnorable, getXML, isContentEqual, isUnmarshalled, marshal, marshal, pipe, pipe, pipe, setContents, setJAXBContext, setJaxbElement, setJaxbElement, setMceIgnorable, transform, variableReplaceMethods inherited from class org.docx4j.openpackaging.parts.Part
getContentLengthAsLoaded, getOwningRelationshipPart, getPackage, getRelationshipType, getSourceRelationship, getSourceRelationships, getVersion, remove, rename, setContentLengthAsLoaded, setOwningRelationshipPart, setPackage, setPartShortcut, setRelationshipType, setSourceRelationship, setVersionMethods inherited from class org.docx4j.openpackaging.Base
addTargetPart, addTargetPart, addTargetPart, addTargetPart, getContentType, getRelationshipsPart, getRelationshipsPart, getUserData, reset, setContentType, setPartName, setRelationships, setUserData
-
Constructor Details
-
RelationshipsPart
Constructor. Creates an appropriately named .rels XML document. Often invoked via sourceP.getRelationshipsPart(true) // create rels part- Parameters:
sourceP- Source part for these relationships- Throws:
InvalidFormatException- If the specified URI is not valid.
-
RelationshipsPart
You probably don't want this one (though it is useful for reflection). If you do use it, you need to setPartName- Throws:
InvalidFormatException
-
-
Method Details
-
createPackageRels
- Returns:
- Throws:
InvalidFormatException- Since:
- 3.2.0, at which time related constructor was made private
-
init
public void init() -
getPartName
- Overrides:
getPartNamein classBase- Returns:
- the uri
-
createRelationshipsPartForPart
-
getRelationships
-
setRelationships
-
getSourceP
-
setSourceP
-
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
Gets a loaded Part by its id -
getRelationshipByID
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
Get the first rel with specified relationship type (see Namespaces for pre-defined constants)- Parameters:
type-- Returns:
-
getRelationshipsByType
- Parameters:
type-- Returns:
- Since:
- 3.3.0
-
getPart
-
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
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
public Relationship addPart(Part part, RelationshipsPart.AddPartBehaviour mode, ContentTypeManager ctm) throws InvalidFormatExceptionAdd 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 targetctm- Content type manager- Returns:
- The Relationship
- Throws:
InvalidFormatException
-
addPart
public Relationship addPart(Part part, RelationshipsPart.AddPartBehaviour mode, ContentTypeManager ctm, java.lang.String relId) throws InvalidFormatExceptionAdd 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 targetctm- Content type managerrelId- the relId we wish to use (provided it is not in use)- Returns:
- The Relationship
- Throws:
InvalidFormatException
-
addRelationship
Add the specified relationship to the collection.- Parameters:
rel- The relationship to add.- Throws:
InvalidOperationException
-
removeParts
Remove all parts from this relationships part -
removePart
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. -
getRel
Is partname a target of any of these rels?- Parameters:
partName-- Returns:
-
isTarget
Is partName the target of the specified rel?- Parameters:
partName-rel-- Returns:
- Since:
- 2.6.0
-
removeRelationship
Remove a relationship by its reference.- Parameters:
rel- The relationship to delete.
-
removeRelationship
-
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
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:
unmarshalin classJaxbXmlPart<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
- Overrides:
unmarshalin classJaxbXmlPart<Relationships>- Throws:
javax.xml.bind.JAXBException
-
marshal
public void marshal(org.w3c.dom.Node node) throws javax.xml.bind.JAXBExceptionDescription copied from class:JaxbXmlPartMarshal the content tree rooted at jaxbElement into a DOM tree.- Overrides:
marshalin classJaxbXmlPart<Relationships>- Parameters:
node- DOM nodes will be added as children of this node. This parameter must be a Node that accepts children (Document,DocumentFragment, orElement)- 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.JAXBExceptionDescription copied from class:JaxbXmlPartMarshal the content tree rooted at jaxbElement into an output stream, using org.docx4j.jaxb.NamespacePrefixMapper.- Overrides:
marshalin classJaxbXmlPart<Relationships>- Parameters:
os- XML will be added to this stream.- Throws:
javax.xml.bind.JAXBException- If any unexpected problem occurs during the marshalling.
-
uniqueToThis
Identify the rels in this relationships part which aren't in the other- Parameters:
otherRP- the other RelationshipsPart
-
uniqueToOther
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 Docx4JExceptionIdentify 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:
-