WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.load(new java.io.File(
System.getProperty("user.dir")
+ "/SmartArt/OUT-xx.docx"));
Relationship r = wordMLPackage.getMainDocumentPart().getRelationshipsPart().getRelationshipByType(Namespaces.DRAWINGML_DIAGRAM_DATA);
if (r==null) {
System.out.println("No DDP!");
return;
}
DiagramDataPart thisPart = (DiagramDataPart)wordMLPackage.getMainDocumentPart().getRelationshipsPart().getPart(r);
thisPart.setFriendlyIds(thisPart.getJaxbElement());
System.out.println( XmlUtils.marshaltoString(thisPart.getJaxbElement(), true, true));
// What does it look like in our format?
DiagramDataUnflatten diagramDataUnflatten = new DiagramDataUnflatten(thisPart);
String exchange= XmlUtils.marshaltoString(diagramDataUnflatten.convert(), true, true);
System.out.println( exchange );
PrintWriter out = new PrintWriter(System.getProperty("user.dir")
+ "/SmartArt/12hi.xml");
out.println(exchange);
out.flush();
out.close();
// Check our format templates
List<JAXBElement<CTTextBody>> textFormats = diagramDataUnflatten.getTextFormats();
System.out.println("Template list =============== ");
for (JAXBElement<CTTextBody> tb : textFormats) {
System.out.println( XmlUtils.marshaltoString(tb, true, true));
}
System.out.println("============================= ");
// Now fix the IDs in the drawing part to match
// TODO: just drop this part altogether; we don't need it
Relationship r2 = wordMLPackage.getMainDocumentPart().getRelationshipsPart().getRelationshipByType(Namespaces.DRAWINGML_DIAGRAM_DRAWING);
if (r2==null) {
System.out.println("No DDrawingP!");
} else {
DiagramDrawingPart drawingPart = (DiagramDrawingPart)wordMLPackage.getMainDocumentPart().getRelationshipsPart().getPart(r2);
drawingPart.setFriendlyIds(thisPart.map);