Page 1 of 1

Creating hyperlink exception

PostPosted: Sun Apr 04, 2010 9:12 pm
by horstdieter2
Hi,

i try to add a hyperlink into a paragraph but it does not work.

This is my Code:
Code: Select all
private P.Hyperlink createHyperlink(String target, String text)
   {       
      //... creating Relationship with addRelationship() ...
      
      P.Hyperlink hyperlink = this.objectFactory.createPHyperlink();
      hyperlink.setId(relationship.getId());

      R run = this.objectFactory.createR();      
      RPr runProperties = this.objectFactory.createRPr();
      
      RStyle styleValue = this.objectFactory.createRStyle();
      styleValue.setVal("Hyperlink");
      runProperties.setRStyle(styleValue);
      
      run.setRPr(runProperties);
            
      Text xmlText = this.objectFactory.createText();
      xmlText.setValue(text);
      run.getRunContent().add(xmlText);
      
      hyperlink.getParagraphContent().add(run);
return hyperlink;
}


Code: Select all
P.Hyperlink hyperlink = this.createHyperlink("destination.docx", "text");
            
//create paragraph and add the hyperlink
paragraph = this.objectFactory.createP();
paragraph.getParagraphContent().add(hyperlink);

//adding the paragraph
wordMLPackage.getMainDocumentPart().addObject(paragraph);


The code is throwing the followed exception:

Code: Select all
javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "org.docx4j.wml.P$Hyperlink" as an element because it is missing an @XmlRootElement annotation]


If I try another workarround like this http://dev.plutext.org/trac/docx4j/browser/trunk/docx4j/src/main/java/org/docx4j/samples/HyperlinkTest.java example, this exception will be thrown:

Code: Select all
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"hyperlink"). Expected elements are <{urn:schemas-microsoft-com:office:office}OLEObject>,...


Can anybody help?

Re: Creating hyperlink exception

PostPosted: Mon Apr 05, 2010 11:54 am
by jason
Hmm, that's a regression; thanks for the report.

Fixed now in http://dev.plutext.org/trac/docx4j/changeset/1117

This is available in http://dev.plutext.org/docx4j/docx4j-ni ... 100405.jar
which is a drop-in replacement for the 2.3.0 jar.

cheers .. Jason