XHTMLMapper继承 XWPFDocumentVisitor:
由于endVisitTableCell是抽象方法,XHTMLMapper中必须要实现;
existErr()子类是否重写都是自由的;
java
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;}
}
java
public class XHTMLMapper extends XWPFDocumentVisitor<Object, XHTMLOptions, XHTMLMasterPage> {
@Override
protected void endVisitTableCell(XWPFTableCell cell, Object tableContainer, Object tableCellContainer) throws Exception {
endElement(TD_ELEMENT);
}
@Override
public boolean existErr(){
return SAXHelper.existErr(contentHandler);
}
}
java
XHTMLMapper mapper = new XHTMLMapper(document, contentHandler, options);
mapper.start(); // 执行父类的start(),start()内部的 existErr()会调用子类的 existErr()