Page 1 of 1

setting the core properties

PostPosted: Sun Mar 27, 2011 9:09 am
by nhanus09
Hello. I have been using docx4j and POI for a couple months now.. docx4j is great!.

my issue is setting the core properties... I basicaly have a "template.docx" file that I load and add a few custom properties and a set a few core properties. The issue is with the core props. I cannot for the life of me figure out how to satisfy the
org.docx4j.docProps.core.CoreProperties.setDescription(javax.xml.bind.JAXBElement<SimpleLiteral> value); method
I have search for 2 days and just cannot figure out how to create a javax.xml.bind.JAXBElement I jsut want to set the comments/description field and the title field.....

i found some code to "add" extended props... and tried to modify it for core props.. but was not working. as these props are strings and ints not JAXBElement

//CoreProperties props = CorePropsfactory.createCoreProperties();
//props.setApplication("Microsoft Word 12.1.0");
//props.setAppVersion("12.0256");
//extendedPart.setJaxbElement(props);`

here is a link to my code.
http://67.76.184.81/_work/docx4j/template_docx.jsp
src: http://67.76.184.81/_work/docx4j/template_docx.zip

thanks much!
nate

Re: setting the core properties

PostPosted: Sun Mar 27, 2011 2:03 pm
by jason
Good question.

Answer:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        org.docx4j.docProps.core.ObjectFactory CorePropsfactory = new org.docx4j.docProps.core.ObjectFactory();
        org.docx4j.docProps.core.dc.elements.ObjectFactory dcElfactory = new org.docx4j.docProps.core.dc.elements.ObjectFactory();
        SimpleLiteral literal = dcElfactory.createSimpleLiteral();
        literal.getContent().add("My description 1");
        coreProps.setDescription( dcElfactory.createDescription(literal));
 
Parsed in 0.022 seconds, using GeSHi 1.0.8.4

Re: setting the core properties

PostPosted: Sun Mar 27, 2011 7:34 pm
by nhanus09
Jason...

Thank you for the fast and correct answer:) It works perfectly of course :)

Man I searched in the javadocs and all through the examples, I just could not find anything that showed this...
I was just 4 lines off lol

---
org.docx4j.docProps.core.dc.elements.ObjectFactory dcElfactory = new org.docx4j.docProps.core.dc.elements.ObjectFactory();
SimpleLiteral literal = dcElfactory.createSimpleLiteral();
literal.getContent().add("My description 1");
coreProps.setDescription(dcElfactory.createDescription(literal));

thanks again

nate. :D