Page 1 of 1

Jetty - default SAXParserFactory: null?

PostPosted: Thu May 26, 2011 3:53 pm
by tosswang
i want to replace a image with another image in word07,my code is

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
 public static byte[] insertPicToDocx(InputStream in,List<ByteArrayInputStream> fushionChartList,List<String> chartIndicatorType)throws Exception
 {
                LoadFromZipNG z = new LoadFromZipNG();
                WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage)z.get(in);
               
                MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
               
                wordMLPackage.getParts().get(new PartName("/word/_rels/document.xml.rels"));
               
                /**2011-5-25 新图的ID+图的描述**/
                final HashMap<String,String> picMap=new HashMap<String,String>();
               
                /**2011-5-25 将所有生成的图片绑定到文档**/
                for(int i=0;i<fushionChartList.size();i++)
                {
                        BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, getBytesFromFile(fushionChartList.get(i)));
                        picMap.put(imagePart.getSourceRelationship().getId(), chartIndicatorType.get(i));
                }
                org.docx4j.wml.Document wmlDocumentEl = documentPart.getJaxbElement();
               
                Body body = wmlDocumentEl.getBody();
               
                new TraversalUtil(body,

                                new Callback()
                                {
                                       
                                        String indent = "";
                                       
                                        public List<Object> apply(Object o)
                                        {                                              
                                                String text = "";
                                                /**是否是在图片部分*/
                                                if (o instanceof org.docx4j.wml.Drawing)
                                                {
                                                       
                                                        String desc=((Anchor) ((org.docx4j.wml.Drawing) o).getAnchorOrInline().get(0)).getDocPr()
                                                                                        .getDescr();
                                                       
                                                        for (int k = 0; k < picMap.keySet().size(); k++)
                                                        {
                                                                String key =(String) picMap.keySet().toArray()[k];
                                                                String value = "[["+picMap.get(key)+"]]";
                                                               
                                                                if(!value.equals(desc))
                                                                {                                                                                                                                                                                                                                                                                              
                                                                        continue;                                                                      
                                                                }
                                                                else
                                                                {
                                                                        ((Anchor) ((org.docx4j.wml.Drawing) o)
                                                                                        .getAnchorOrInline().get(0)).getGraphic()
                                                                                        .getGraphicData().getPic().getBlipFill()
                                                                                        .getBlip().setEmbed(key);
                                                                        break;
                                                                }
                                                        }
                                                                                                                                                                       
                                                }
                                                return null;
                                        }
                                       
                                        public boolean shouldTraverse(Object o)
                                        {
                                                return true;
                                        }
                                       
                                        // Depth first
                                        public void walkJAXBElements(Object parent)
                                        {
                                               
                                                indent += "    ";
                                               
                                                List children = getChildren(parent);
                                                if (children != null)
                                                {
                                                       
                                                        for (Object o : children)
                                                        {
                                                               
                                                                // if its wrapped in javax.xml.bind.JAXBElement, get its
                                                                // value
                                                                o = XmlUtils.unwrap(o);
                                                                System.out.println("类型:"+o);
                                                                this.apply(o);
                                                               
                                                                if (this.shouldTraverse(o))
                                                                {
                                                                        walkJAXBElements(o);
                                                                }
                                                               
                                                        }
                                                }
                                               
                                                indent = indent.substring(0, indent.length() - 4);
                                        }
                                       
                                        public List<Object> getChildren(Object o)
                                        {
                                                return TraversalUtil.getChildrenImpl(o);
                                        }
                                       
                                }

                                );
                                ByteArrayOutputStream fos=new ByteArrayOutputStream();         
                                SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
                                saver.save(fos);
                                byte[] reval=fos.toByteArray();
               
               
                return reval;
}
 
Parsed in 0.021 seconds, using GeSHi 1.0.8.4


now,my code occurs a issue, when i first run this code,there is information
JAXB: Using RI WARN :
[2011-05-26 11:18:31,988] org.docx4j.XmlUtils:116 - Using default SAXParserFactory: null

in eclipse's console, how can i do ?

thanks in advance

tosswang

Re: default SAXParserFactory: null?

PostPosted: Thu May 26, 2011 6:52 pm
by Richard
I think this message occurs if docx4j only finds the standard SAXP provided by the jdk in your classpath. This shouldn't be a problem at all.

But to avoid this warning you can use the xercesImpl.jar, which is included in the Xerces2 Java library (http://xerces.apache.org/mirrors.cgi). I have downloaded http://apache.prosite.de//xerces/j/Xerc ... 2.11.0.zip and added (at least) xercesImpl.jar to my classpath. At the moment I'm not sure about further dependencies which need to be resolved but this should give you a point to start from.

Hope that helps,
Richard

Re: default SAXParserFactory: null?

PostPosted: Thu May 26, 2011 9:24 pm
by tosswang
Richard wrote:I think this message occurs if docx4j only finds the standard SAXP provided by the jdk in your classpath. This shouldn't be a problem at all.

But to avoid this warning you can use the xercesImpl.jar, which is included in the Xerces2 Java library (http://xerces.apache.org/mirrors.cgi). I have downloaded http://apache.prosite.de//xerces/j/Xerc ... 2.11.0.zip and added (at least) xercesImpl.jar to my classpath. At the moment I'm not sure about further dependencies which need to be resolved but this should give you a point to start from.

Hope that helps,
Richard


thanks Richard,my english level is poor ,i try to describe the issue detailedly, the code is a part of a web application, my web server is jetty,my jdk is jdk1.5,when i start server and first run the code,the message that "org.docx4j.XmlUtils:116 - Using default SAXParserFactory: null " occurs,the web application stop working, but i run the code again and again,the message doesn't occur, the web application work normally。 when i stop server, start it again ,the previous message occur again……

Re: default SAXParserFactory: null?

PostPosted: Fri May 27, 2011 8:20 pm
by tosswang
please help me !

Re: Jetty - default SAXParserFactory: null?

PostPosted: Fri May 27, 2011 10:08 pm
by jason
You might post somewhere where jetty users can help you (but please, still let us know what you discover!)

Possibly relevant http://stackoverflow.com/questions/1016 ... ars-api-in

Re: Jetty - default SAXParserFactory: null?

PostPosted: Sat May 28, 2011 12:38 am
by tosswang
jason wrote:You might post somewhere where jetty users can help you (but please, still let us know what you discover!)

Possibly relevant http://stackoverflow.com/questions/1016 ... ars-api-in


hi,json,the issue is resolved,i replace my jdk1.5 wth jdk1.6!!! :P

Re: Jetty - default SAXParserFactory: null?

PostPosted: Thu Jun 02, 2011 12:38 am
by tosswang
sorry,make an necessary corrections,the issue which i meet has nothing to do with jdk and docx4j