i meet an issue when i parse a big document which have 124 pages.the exception is
- Code: Select all
java.lang.ClassCastException: org.docx4j.dml.CTGvmlGroupShape
at com.richfit.bi.erpt.util.ParseWordTemplate$2.walkJAXBElements(ParseWordTemplate.java:584)
at com.richfit.bi.erpt.util.ParseWordTemplate$2.walkJAXBElements(ParseWordTemplate.java:589)
at com.richfit.bi.erpt.util.ParseWordTemplate$2.walkJAXBElements(ParseWordTemplate.java:589)
at com.richfit.bi.erpt.util.ParseWordTemplate$2.walkJAXBElements(ParseWordTemplate.java:589)
at com.richfit.bi.erpt.util.ParseWordTemplate$2.walkJAXBElements(ParseWordTemplate.java:589)
at org.docx4j.TraversalUtil.<init>(TraversalUtil.java:150)
at com.richfit.bi.erpt.util.ParseWordTemplate.parseTemplatePlain1(ParseWordTemplate.java:501)
at com.richfit.bi.erpt.util.ParseWordTemplate.parseTemplate(ParseWordTemplate.java:154)
at com.richfit.bi.erpt.controller.WordTemplateController.getWordByte(WordTemplateController.java:882)
at com.richfit.bi.erpt.controller.WordTemplateController.runTemplate(WordTemplateController.java:255)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:163)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:163)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at com.richfit.bi.domain.support.ThreadLocalRequestFilter.doFilter(ThreadLocalRequestFilter.java:26)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at com.richfit.bi.domain.support.ThreadLocalRequestFilter.doFilter(ThreadLocalRequestFilter.java:26)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:451)
at com.richfit.bi.erpt.util.ParseWordTemplate$2.walkJAXBElements(ParseWordTemplate.java:584),
at com.richfit.bi.erpt.util.ParseWordTemplate$2.walkJAXBElements(ParseWordTemplate.java:589)
point to my below code,
- Code: Select all
// fix for JAXB Bug
((Child) child).setParent(parent);--584
walkJAXBElements(child);--589
my complete code is
- Code: Select all
public byte[] parseTemplatePlain1(InputStream in, Map map,
String publishDate) throws Exception
{
try
{
LoadFromZipNG z = new LoadFromZipNG();
WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage) z
.get(in);
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
wordMLPackage.getParts().get(
new PartName("/word/_rels/document.xml.rels"));
final HashMap textIndicatorMap = (HashMap)map;
org.docx4j.wml.Document wmlDocumentEl = documentPart.getJaxbElement();
Body body = wmlDocumentEl.getBody();
new TraversalUtil(body,
new Callback()
{
public List<Object> apply(Object o)
{
String text = "";
if (o instanceof org.docx4j.wml.Text)
{
org.docx4j.wml.Text t = (org.docx4j.wml.Text) o;
text = t.getValue().trim();
int preIndex=text.indexOf("[[");
if(preIndex!=-1)
{
int lastIndex=text.indexOf("]]");
String tmp=text.substring(preIndex+2,lastIndex);
if(textIndicatorMap.containsKey(tmp))
{
String value =(String)textIndicatorMap.get(tmp);
t.setValue(value);
}
}
}
return null;
}
// 2011-9-13 优化替换
// public List<Object> apply(Object o)
// {
//
// String text = "";
//
// if (o instanceof org.docx4j.wml.Text)
// {
// org.docx4j.wml.Text t = (org.docx4j.wml.Text) o;
//
// text = t.getValue().trim();
//
// for (int k = 0; k < textIndicatorMap.keySet().size(); k++)
// {
// String key = "[["+(String) textIndicatorMap.keySet().toArray()[k]+"]]";
// String value = (String)textIndicatorMap.get((String) textIndicatorMap.keySet().toArray()[k]);
//
// if (!key.equals(text))
// {
// continue;
// }
// else
// {
// t.setValue(value);
// break;
// }
// }
//
// }
// return null;
// }
public boolean shouldTraverse(Object o)
{
return true;
}
// Depth first
public void walkJAXBElements(Object parent)
{
List children = getChildren(parent);
if (children != null) {
for (Object child: children) {
child = XmlUtils.unwrap(child);
// fix for JAXB Bug
((Child) child).setParent(parent);
this.apply(child);
if (this.shouldTraverse(child)) {
walkJAXBElements(child);
}
}
}
}
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;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
i use docx4j-2.7.0.jar\jdk1.5.0
Any info would be greatly appreciated!