Page 1 of 1

missing StyleDefinitionsPart

PostPosted: Thu Jul 18, 2013 9:13 pm
by ctekin
Hi,

I'm very new to docx4j.

I want to use docx4j to produce .docx reports from my java application. I have tried to compile and check some of the example code which worked fine. But when I tried to use the very same code in my application; as I try to extract the StyleDefinitionsPart from WordprocessingMLPackage I get null.

I surely do something wrong but I don't know what. I can supply the source code here but I don't think it would be of any use.

Any help would be greatly appreciated.

Regards,

Cem.

Re: missing StyleDefinitionsPart

PostPosted: Thu Jul 18, 2013 10:21 pm
by jason
Is it a docx you have created, or one you have loaded?

A docx does not necessarily have a StyleDefinitionsPart. If it doesn't, you'll get null.

WordprocessingMLPackage.createPackage() does add a StyleDefinitionsPart

Re: missing StyleDefinitionsPart

PostPosted: Thu Jul 18, 2013 11:23 pm
by ctekin
It's the .docx I created.

I use "WordprocessingMLPackage.createPackage()" and I get null when I call "xx.getMainDocumentPart().getStyleDefinitionsPart()".

Is there any dependencies when it comes to creation of StyleDefinitionsPart?

Re: missing StyleDefinitionsPart

PostPosted: Thu Jul 18, 2013 11:49 pm
by ctekin
I get the following error when I tried to create and unmarshall the StyleDefinitionsPart manually:

ERROR org.docx4j.utils.ResourceUtils .getResource line 40 - Couldn't get resource: org/docx4j/openpackaging/parts/WordprocessingML/styles.xml
java.lang.NullPointerException
at org.docx4j.utils.ResourceUtils.getResource(ResourceUtils.java:45)
at org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart.unmarshalDefaultStyles(StyleDefinitionsPart.java:120)

Re: missing StyleDefinitionsPart

PostPosted: Fri Jul 19, 2013 8:22 am
by jason
That'd be the problem. styles.xml should be in your docx4j jar file.

Did you build docx4j yourself, or download a jar file from somewhere? If you downloaded it, can you please provide the link.

Re: missing StyleDefinitionsPart

PostPosted: Fri Jul 19, 2013 4:58 pm
by ctekin
Jason hi,

I've downloaded the .jar from docx4j.org and the styles.xml is where it should be, no problems there. The problem is that I'm not using the system classloader in my application and I think the org.docx4j.utils.ResourceUtils is looking for the resource in the system classloader.

I haven't decided which way to go yet; any suggestions?

Re: missing StyleDefinitionsPart

PostPosted: Fri Jul 19, 2013 6:10 pm
by ctekin
I decided to load all docx4j related packages via the system classloader and the problem is solved.

Thanks to all for offering such a useful library and maintaining it.

Cem.