XHTMLMapper继承 XWPFDocumentVisitor:
由于endVisitTableCell是抽象方法,XHTMLMapper中必须要实现;
existErr()子类是否重写都是自由的;
public abstract class XWPFDocumentVisitor<T, O extends Options, E extends IXWPFMasterPage> implements IMasterPageHandler<E> {public void start() throws Exception {......existErr()}protected abstract void endVisitTableCell(XWPFTableCell cell, T tableContainer, T tableCellContainer)throws Exception;public boolean existErr(){return false;}
}
public class XHTMLMapper extends XWPFDocumentVisitor<Object, XHTMLOptions, XHTMLMasterPage> {@Overrideprotected void endVisitTableCell(XWPFTableCell cell, Object tableContainer, Object tableCellContainer) throws Exception {endElement(TD_ELEMENT);}@Overridepublic boolean existErr(){return SAXHelper.existErr(contentHandler);}
}
XHTMLMapper mapper = new XHTMLMapper(document, contentHandler, options);
mapper.start(); // 执行父类的start(),start()内部的 existErr()会调用子类的 existErr()