Hello again!
I tryed to add the relationship with the example for hyperlinks
http://dev.plutext.org/trac/docx4j/browser/trunk/docx4j/src/main/java/org/docx4j/samples/HyperlinkTest.javaand changed id for comments
First I only want to add the relationship and test it. by storing the file I get NullPointer Exception.
My testDocument is a new Document with no content. I only opend a new document and saved.
Error
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:364)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:158)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:99)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:202)
at at.jku.dqm.annotation.TestComment.main(TestComment.java:38)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:364)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:411)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:359)
... 4 more
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:383)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:359)
... 6 more
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:364)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:158)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:99)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:202)
at at.jku.dqm.annotation.TestComment.main(TestComment.java:38)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:364)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:411)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:359)
... 4 more
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:383)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:359)
... 6 more
Code:
mlPackage = new WordprocessingMLPackage().load(new java.io.File(
document.getAbsolutePath()));
org.docx4j.relationships.ObjectFactory factory = new org.docx4j.relationships.ObjectFactory();
org.docx4j.relationships.Relationship rel = factory
.createRelationship();
rel.setType(Namespaces.COMMENTS);
rel.setId(mlPackage.getMainDocumentPart().getRelationshipsPart().getNextId());
rel.setTarget("comments.xml");
mlPackage.getMainDocumentPart().getRelationshipsPart()
.addRelationship(rel);
mlPackage.save(new java.io.File(System.getProperty("user.dir")
+ "/out-hyperlink.docx"));
Thanks again!