I am having problem to create a header.xml.rel file. I am getting an error which I am not sure if I do it correctly.
private RelationshipsPart createHeaderRel()
{
RelationshipsPart rPart = null;
try
{
PartName partName1 = new PartName("/word/_rels/"+"header2.xml.rel");
rPart = new RelationshipsPart(partName1);
Relationships relationships = relOf.createRelationships();
Relationship relationship = relOf.createRelationship();
relationship.setTarget("media/headerImage1");
relationship.setType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image");
relationship.setId("rId12");
relationships.getRelationship().add(relationship);
rPart.setJaxbElement(relationships);
}
catch(Exception e)
{
e.printStackTrace();
}
return rPart;
}
public Part getHeaderPart(String name) throws Exception
{
RelationshipsPart rPart = createHeaderRel();
PartName partName = new PartName(name);
HeaderPart headerPart = new HeaderPart(partName);
headerPart.setJAXBContext(getMicrosoftJAXBContext());
headerPart.setContentType(
new org.docx4j.openpackaging.contenttype.ContentType(
org.docx4j.openpackaging.contenttype.ContentTypes.EXTENSION_JPG_1));
Hdr hdr = this.getPictureWaterMark();
headerPart.setJaxbElement(hdr);
headerPart.setRelationships(rPart);
return headerPart;
}
Part headerPart2 = testDoc.getHeaderPartForImgWaterMark("/word/header2.xml");
docPart.addTargetPart(headerPart2);
I am getting the following error:
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:302)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:130)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:93)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:166)
at com.gdais.emtk.word.services.TestScratchDoc.main(TestScratchDoc.java:2792)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
org.docx4j.openpackaging.parts.relationships.RelationshipsPart marshalled
28.04.2009 14:50:17 *INFO * SaveToZipFile: PUT SUCCESS: word/_rels/header2.xml.rels (SaveToZipFile.java, line 176)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:302)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:343)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:297)
... 4 more
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:245)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:343)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:297)
... 6 more
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:302)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:130)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:93)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:166)
at com.gdais.emtk.word.services.TestScratchDoc.main(TestScratchDoc.java:2792)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:302)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:343)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:297)
... 4 more
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:245)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:343)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:297)
... 6 more
I am not sure if I am doing it right. Could you please help?
Thanks!
Betty