Page 1 of 1

Missing Class / sfl4j

PostPosted: Thu Aug 22, 2013 9:53 am
by apderosso
I'm looking at the sample file "ContentControlsMergeXML.java" using the docx4j source code on my build path. I've created a sample program that does exactly what I want. Now that I'm incorporating docx4j into my application, when I use the binaries from the site there seems to be a class missing. I'm trying to use:

import org.docx4j.Docx4J;
...
Docx4J.bind

as demonstrated in the sample file.

I downloaded the latest nightly docx4j .jar which does contain the missing class, but now I'm getting class not found exceptions for slf4j. Am I missing something?

Re: Missing Class / sfl4j

PostPosted: Thu Aug 22, 2013 11:51 am
by jason
Hi, no, you are on the right track.

The nightly is what will eventually become 3.0, and it uses slf4j, instead of log4j.

You just need to add:

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>

Re: Missing Class / sfl4j

PostPosted: Fri Aug 23, 2013 6:44 am
by apderosso
Thanks for the response Jason, I at least got that much working. But now I'm getting an error when I try to bind the xml and the template. I'm getting the following error:

org.docx4j.openpackaging.exceptions.Docx4JException: Problems creating a org.w3c.dom.Document for the passed input stream.
at org.docx4j.Docx4J.bind(Docx4J.java:256)

Here's my code so far:

wordMLPackage = Docx4J.load(file);
FileInputStream xmlStream = new FileInputStream(xml);
Docx4J.bind(wordMLPackage, xmlStream, Docx4J.FLAG_BIND_INSERT_XML);


I've attached the xml and the docx file that I'm using, is there something wrong with the xml or docx files?

Re: Missing Class / sfl4j

PostPosted: Fri Aug 23, 2013 1:42 pm
by jason
Yes, there's a problem with your XML file:

Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
:
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at org.docx4j.Docx4J.bind(Docx4J.java:254)

the problem is at byte position 3331 (line 66): <perMill>�</perMill>

You can see this if you open it with SC UniPad, configured not to suppress load errors

Having fixed that, I see: "line 1:149 mismatched input '<EOF>' expecting LPAR" multiple times. I haven't seen that before, but it'd be from XPathEnhancerParser; possibly it doesn't like the full stop (period) characters in your xpaths? Output is produced, so it might not matter, but still, it would be good to understand/fix.

For what it is worth, I used Docx4J.FLAG_NONE (which you need to process repeats), and today's nightly, which contains a relevant fix: http://www.docx4java.org/docx4j/docx4j- ... 130823.jar

Re: Missing Class / sfl4j

PostPosted: Sat Aug 24, 2013 3:30 am
by apderosso
Awesome, that fixed it. Thank you for your help Jason!