plutext / docx4j

JAXB-based Java library for Word docx, Powerpoint pptx, and Excel xlsx files
https://www.docx4java.org/
2.12k stars 1.2k forks source link

Word2003XmlConverter Bug #131

Open allenfoxtc opened 10 years ago

allenfoxtc commented 10 years ago

When i try to load a word 2003 xml Using Word2003XmlConverter, i got a Exception like this:

Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
There's no ObjectFactory with an @XmlElementDecl for the element {http://schemas.microsoft.com/office/word/2012/wordml}dataBinding.
    this problem is related to the following location:
        at protected java.util.List org.docx4j.wml.SdtPr.rPrOrAliasOrLock
        at org.docx4j.wml.SdtPr
        at protected org.docx4j.wml.SdtPr org.docx4j.wml.SdtBlock.sdtPr
        at org.docx4j.wml.SdtBlock
        at protected java.util.List org.docx4j.wml.Body.content
        at org.docx4j.wml.Body
        at protected org.docx4j.wml.Body org.docx4j.wml.Document.body
        at org.docx4j.wml.Document
        at public org.docx4j.wml.Document org.docx4j.wml.ObjectFactory.createDocument()
        at org.docx4j.wml.ObjectFactory
        at protected java.util.List org.docx4j.wml.CTPictureBase.anyAndAny
        at org.docx4j.wml.CTPictureBase
        at org.docx4j.wml.Pict
        at protected org.docx4j.wml.Pict org.docx4j.wml.Numbering$NumPicBullet.pict
        at org.docx4j.wml.Numbering$NumPicBullet
        at protected java.util.List org.docx4j.wml.Numbering.numPicBullet
        at org.docx4j.wml.Numbering
        at protected org.docx4j.wml.Numbering org.docx4j.convert.in.word2003xml.Transition03To06.numbering
        at org.docx4j.convert.in.word2003xml.Transition03To06
        at public org.docx4j.convert.in.word2003xml.Transition03To06 org.docx4j.convert.in.word2003xml.ObjectFactory.createTransition03To06()
        at org.docx4j.convert.in.word2003xml.ObjectFactory

    at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:191)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:290)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
    at org.docx4j.convert.in.word2003xml.Word2003XmlConverter.<init>(Word2003XmlConverter.java:60)
    at demo.Demo.main(Demo.java:18)

{http://schemas.microsoft.com/office/word/2012/wordml}dataBinding's @XmlElementDecl is in org.docx4j.w15.ObjectFactory. I don't know why he can't find it.

BTW, is there a chance to add a way to save as 97~2003 Doc format?

PS. Why org.docx4j.convert.in.word2003xml.Word2003XmlConverter.getWordprocessingMLPackage() is private?

allenfoxtc commented 10 years ago

I got a solution to resovle @XmlElementDecl not defined problem:

org.docx4j.convert.in.word2003xml.Word2003XmlConverter.Word2003XmlConverter(Source source) {
    ...
    // add w14 & w15 ObjectFactory
    JAXBResult result = new JAXBResult(JAXBContext.newInstance(org.docx4j.convert.in.word2003xml.ObjectFactory.class, org.docx4j.w14.ObjectFactory.class, org.docx4j.w15.ObjectFactory.class));
    ...
}

But the output docx file lost some elements.