Base sourcePart,
Base targetPart,
Set<String> relationshipTypes) throws Docx4JException {
RelationshipsPart sourceRelationshipsPart = sourcePart.getRelationshipsPart(false);
Relationships sourceRelationships = (sourceRelationshipsPart != null ?
sourceRelationshipsPart.getRelationships() :
null);
List<Relationship> sourceRelationshipList = (sourceRelationships != null ?
sourceRelationships.getRelationship() :
null);
RelationshipsPart targetRelationshipsPart = null;
Relationships targetRelationships = null;
Relationship sourceRelationship = null;
Relationship targetRelationship = null;
Part sourceChild = null;
Part targetChild = null;
if ((sourceRelationshipList != null) &&
(!sourceRelationshipList.isEmpty())) {
targetRelationshipsPart = targetPart.getRelationshipsPart(); //create if needed
targetRelationships = targetRelationshipsPart.getRelationships();
for (int i=0; i<sourceRelationshipList.size(); i++) {
sourceRelationship = sourceRelationshipList.get(i);
//the Relationship doesn't have any references to parts, therefore it can be reused
targetRelationships.getRelationship().add(sourceRelationship);
if (sourceRelationship.getTargetMode()==null
// per ECMA 376 4ed Part 2, capitalisation should be thus: "External"
// but we can relax this..
|| !"external".equals(sourceRelationship.getTargetMode().toLowerCase())) {