Hi there

I need to look for a relationship in the ".rels" file of the format-specific 
document, not the main package itself.
By this I mean not in the "_rels/.rels" file in the top level but in (say) the 
"xl/_rels/workbook.xml.rels" file.
The OPCPackage class looks promising, but so far I have only been able to make 
it work with the former file.

Is there an elegant way to do this, or must I do something like:


OPCPackage pkg = OPCPackage.open(filename);

PackageRelationship relationship = 
pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
PackagePart part = pkg.getPart(relationship);
String mainEntryName = part.getPartName().getName();
String[] parts = mainEntryName.split("/");
String docRels = "/" + parts[1] + "/_rels/" + parts[2] + ".rels";  // e.g. 
"/xl/_rels/workbook.xml.rels"
Pattern p = Pattern.compile(docRels);

PackagePart p2 = pkg.getPartsByName(p).get(0);

...

This seems clumsy!  It also has to work for all 3 OOXML types (pptx, dock, 
xlxx).

Thanks,

- Chris

Chris Bamford
Senior Developer
m: +44 7860 405292
p: +44 207 847 8700
w: www.mimecast.com
Address click here: www.mimecast.com/About-us/Contact-us/






Reply via email to