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
Represents a Relationship Part, which contains the relationships for a
given PackagePart or the Package.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.docx4j.openpackaging.parts.JaxbXmlPart
jaxbElement, jc, MAX_BYTES_Unmarshal_ErrorFields inherited from class org.docx4j.openpackaging.Base
contentType, partName, relationships -
Constructor Summary
ConstructorsConstructorDescriptionYou probably don't want this one (though it is useful for reflection).RelationshipsPart(Base sourceP) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddPart(Part part, RelationshipsPart.AddPartBehaviour mode, ContentTypeManager ctm) Add a newly created part, a relationship and the content type.addPart(Part part, RelationshipsPart.AddPartBehaviour mode, ContentTypeManager ctm, String relId) Add a newly created part, a relationship and the content type.booleanAdd the specified relationship to the collection.static RelationshipsPartstatic RelationshipsPartcreateRelationshipsPartForPart(Base sourcePart) differingContent(RelationshipsPart otherRP) Identify rels common to both parts, but where rels have different content.Gets a loaded Part by its idIs partname a target of any of these rels?Retrieves a package relationship based on its id.static RelationshipgetRelationshipByTarget(RelationshipsPart rp, String relativeTarget) getRelationshipByType(String type) Get the first rel with specified relationship type (see Namespaces for pre-defined constants)getRelationshipsByType(String type) static StringinferSourcePartName(String relationshipsPartName) Infer the source part's name from this rels part name.voidinit()booleanDeprecated.booleanThis Relationship Part is the package relationship part if its source is the Package.booleanisRelIdOccupied(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(OutputStream os) Marshal the content tree rooted at jaxbElement into an output stream, using org.docx4j.jaxb.NamespacePrefixMapper.voidMarshal the content tree rooted at jaxbElement into a DOM tree.removePart(PartName partName) Remove a part from this package, including its relationships part and all target parts.Remove all parts from this relationships partvoidremoveRelationship(PartName partName) voidRemove a relationship by its reference.voidRemove relationships by type (eg Namespaces.PRESENTATIONML_SLIDE_LAYOUT)voidAssumes 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.uniqueToOther(RelationshipsPart otherRP) Identify the rels in this relationships part which aren't in the otheruniqueToThis(RelationshipsPart otherRP) Identify the rels in this relationships part which aren't in the otherunmarshal(InputStream is) Unmarshal XML data from the specified InputStream and return the resulting content tree.Methods inherited from class org.docx4j.openpackaging.parts.JaxbXmlPart
addMcChoiceNamespace, getConfiguredUnmarshaller, getContents, getJAXBContext, getJaxbElement, getMcChoiceNamespaces, getMceIgnorable, getXML, inputStreamToXSR, isContentEqual, isUnmarshalled, marshal, marshal, pipe, pipe, pipe, preprocess, setContents, setJAXBContext, setJaxbElement, setJaxbElement, setMceIgnorable, transform, transformToDom, 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
-
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
-
isRelIdOccupied
-
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 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 targetctm- Content type manager- Returns:
- The Relationship
- Throws:
InvalidFormatException
-
addPart
public Relationship addPart(Part part, RelationshipsPart.AddPartBehaviour mode, ContentTypeManager ctm, 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 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
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:
jakarta.xml.bind.JAXBException- If any unexpected errors occur while unmarshalling
-
unmarshal
- Overrides:
unmarshalin classJaxbXmlPart<Relationships>- Throws:
jakarta.xml.bind.JAXBException
-
marshal
Description 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:
jakarta.xml.bind.JAXBException- If any unexpected problem occurs during the marshalling.
-
marshal
Description 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:
jakarta.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
Identify rels common to both parts, but where rels have different content.- Parameters:
otherRP-- Returns:
- Throws:
Docx4JException
-
getRelationshipByTarget
-
inferSourcePartName
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:
-