Hi Adrian
Apart from the issue you have raised here, what practical problems is the current approach to 2010 documents causing you?
In the class JaxbXmlPartXPathAware, we have:
Using java Syntax Highlighting
try {
jaxbElement
= (E
) XmlUtils.
unwrap(binder.
unmarshal( doc
));
} catch (ClassCastException cce
) {
/*
* Work around for issue with JAXB binder, in Java 1.6
* encountered with /src/test/resources/jaxb-binder-issue.docx
* See http://old.nabble.com/BinderImpl.associ ... 56585.html
* and http://java.net/jira/browse/JAXB-874
*
* java.lang.ClassCastException: org.docx4j.wml.PPr cannot be cast to javax.xml.bind.JAXBElement
at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl$IntercepterLoader.intercept(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.endElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.endElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.endElement(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(Unknown Source)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.BinderImpl.associativeUnmarshal(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.BinderImpl.unmarshal(Unknown Source)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.unmarshal(MainDocumentPart.java:321)
*/
log.
warn("Binder not available for this docx");
Unmarshaller u
= jc.
createUnmarshaller();
jaxbElement
= (E
) XmlUtils.
unwrap(u.
unmarshal( doc
));
}
Parsed in 0.031 seconds, using
GeSHi 1.0.8.4
I just tested with the current JAXB reference implementation 2.2.6, and the problem still occurs.
So perhaps you could vote for
http://java.net/jira/browse/JAXB-874 and add a comment to that effect?
The workaround is to use something like:
Using java Syntax Highlighting
static class SdtPrFinder
extends CallbackImpl
{
List
<SdtPr
> sdtPrList
= new ArrayList
<SdtPr
>();
@Override
public List
<Object
> apply
(Object o
) {
if (o
instanceof org.
docx4j.
wml.
SdtBlock
|| o
instanceof org.
docx4j.
wml.
SdtRun
|| o
instanceof org.
docx4j.
wml.
CTSdtRow
|| o
instanceof org.
docx4j.
wml.
CTSdtCell ) {
SdtPr sdtPr
= OpenDoPEHandler.
getSdtPr(o
);
if (sdtPr
!=null) {
sdtPrList.
add(sdtPr
);
}
}
return null;
}
}
SdtPrFinder sdtPrFinder
= new SdtPrFinder
();
new TraversalUtil
(paragraphs, sdtPrFinder
);
for ( SdtPr sdtPr
: sdtPrFinder.
sdtPrList) { ...
Parsed in 0.016 seconds, using
GeSHi 1.0.8.4
In my code, I always use TraversalUtil. JAXB XPath is a nice idea, but there are too many bugs in the Sun/Oracle JAXB for it to be effective.