if (a.getPart().getContentType().equals(ContentTypes.RELATIONSHIPS_PART)) {
parentPart.setRelationships(null);
} else {
removedParts.addAll(
parentPart.getRelationshipsPart().removePart(
new PartName(xmlpart.getName())) );
}
}
// -- Modifications
for (Alteration a : alterations.getPartsModified() ) {
log.info("Applying modifications to part: " + a.getPart().getName() );
if (a.getPart().getContentType().equals(ContentTypes.RELATIONSHIPS_PART)) {
RelationshipsPart newRP = null; //FlatOpcXmlImporter.createRelationshipsPart(a.getPart());
if (a.getSourcePartName().equals("/")) {
newRP = otherPackage.getRelationshipsPart(true);
// otherPackage.setRelationships(newRP);
// newRP.setSourceP(otherPackage);
} else {
Part parentPart = otherPackage.getParts().get(a.getSourcePartName());
newRP = parentPart.getRelationshipsPart(true);
// parentPart.setRelationships(newRP);
// newRP.setSourceP(parentPart);
}
FlatOpcXmlImporter.populateRelationshipsPart(newRP, a.getPart().getXmlData().getAny());
} else {
Part targetPart = otherPackage.getParts().get(
new PartName(a.getPart().getName()));
if (targetPart==null) {
log.error("Couldn't find " + a.getPart().getName() + " @ " + a.getSourcePartName().getName() );
continue;
}
Part tmpPart = FlatOpcXmlImporter.getRawPart(otherPackage.getContentTypeManager(),
a.getPart(), null);
if (targetPart instanceof JaxbXmlPart) {
((JaxbXmlPart)targetPart).setJaxbElement(
((JaxbXmlPart)tmpPart).getJaxbElement() );
} else if (targetPart instanceof XmlPart) {
((XmlPart)targetPart).setDocument(
((XmlPart)tmpPart).getDocument() );
} else if (targetPart instanceof CustomXmlDataStoragePart) {
((CustomXmlDataStoragePart)targetPart).setData(
((CustomXmlDataStoragePart)tmpPart).getData() );
// TODO: check that
} else if (targetPart instanceof BinaryPart) {
((BinaryPart)targetPart).setBinaryData(
((BinaryPart)tmpPart).getBuffer() );
} else {
log.error("TODO: handle " + targetPart.getClass().getName() );
}
}
}
// -- Additions
for (Alteration a : alterations.getPartsAdded() ) {
log.info("Adding part: " + a.getPart().getName() );
if (a.getPart().getContentType().equals(ContentTypes.RELATIONSHIPS_PART)) {
RelationshipsPart newRP = null; //FlatOpcXmlImporter.createRelationshipsPart(a.getPart());
if (a.getSourcePartName().equals("/")) {
newRP = otherPackage.getRelationshipsPart(true);
// otherPackage.setRelationships(newRP);
// newRP.setSourceP(otherPackage);
} else {
Part parentPart = otherPackage.getParts().get(a.getSourcePartName());
newRP = parentPart.getRelationshipsPart(true);
// parentPart.setRelationships(newRP);
// newRP.setSourceP(parentPart);
}
FlatOpcXmlImporter.populateRelationshipsPart(newRP, a.getPart().getXmlData().getAny());
} else {
Part parentPart = otherPackage.getParts().get(a.getSourcePartName());
Part newPart = FlatOpcXmlImporter.getRawPart(otherPackage.getContentTypeManager(),
a.getPart(), null);
// There will already be a rel for the new part,
// since we will already have modified or added the rels part
// so don't do AddTargetPart (which will probably create a new rel id,
// which will cause problems)
newPart.setOwningRelationshipPart(parentPart.getRelationshipsPart());
newPart.getSourceRelationships().add(
parentPart.getRelationshipsPart().getRel(new PartName(a.getPart().getName())));
otherPackage.getParts().put(newPart);
newPart.setPackage( otherPackage );
// TODO: add content type if necessary
}