import org.thymeleaf.dom.Text; //导入依赖的package包/类
@Override
protected ProcessorResult doProcessElement(Arguments arguments, Element element, HttpServletRequest request,
HttpServletResponse response, HtmlTable htmlTable) {
if (htmlTable != null) {
HtmlColumn column = null;
String content = null;
if (element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":csv")
|| element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":xml")
|| element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":pdf")
|| element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":xls")
|| element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":xlsx")) {
if (element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":csv")) {
content = AttributeUtils.parseAttribute(arguments, element, DataTablesDialect.DIALECT_PREFIX + ":csv",
String.class);
element.removeAttribute(DataTablesDialect.DIALECT_PREFIX + ":csv");
column = new HtmlColumn(ReservedFormat.CSV);
column.setContent(new StringBuilder(content));
htmlTable.getLastBodyRow().addColumn(column);
}
if (element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":xml")) {
content = AttributeUtils.parseAttribute(arguments, element, DataTablesDialect.DIALECT_PREFIX + ":xml",
String.class);
element.removeAttribute(DataTablesDialect.DIALECT_PREFIX + ":xml");
column = new HtmlColumn(ReservedFormat.XML);
column.setContent(new StringBuilder(content));
htmlTable.getLastBodyRow().addColumn(column);
}
if (element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":pdf")) {
content = AttributeUtils.parseAttribute(arguments, element, DataTablesDialect.DIALECT_PREFIX + ":pdf",
String.class);
element.removeAttribute(DataTablesDialect.DIALECT_PREFIX + ":pdf");
column = new HtmlColumn(ReservedFormat.PDF);
column.setContent(new StringBuilder(content));
htmlTable.getLastBodyRow().addColumn(column);
}
if (element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":xls")) {
content = AttributeUtils.parseAttribute(arguments, element, DataTablesDialect.DIALECT_PREFIX + ":xls",
String.class);
element.removeAttribute(DataTablesDialect.DIALECT_PREFIX + ":xls");
column = new HtmlColumn(ReservedFormat.XLS);
column.setContent(new StringBuilder(content));
htmlTable.getLastBodyRow().addColumn(column);
}
if (element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":xlsx")) {
content = AttributeUtils.parseAttribute(arguments, element, DataTablesDialect.DIALECT_PREFIX + ":xlsx",
String.class);
element.removeAttribute(DataTablesDialect.DIALECT_PREFIX + ":xlsx");
column = new HtmlColumn(ReservedFormat.XLSX);
column.setContent(new StringBuilder(content));
htmlTable.getLastBodyRow().addColumn(column);
}
}
// If the element contains a Text node, the content of the text node
// will be displayed in all formats
else if (element.getFirstChild() instanceof Text) {
htmlTable.getLastBodyRow().addColumn(((Text) element.getFirstChild()).getContent().trim());
}
// Otherwise, an empty cell will be displayed
else {
logger.warn("Only cells containing plain text are supported, those containing HTML code are still not!");
htmlTable.getLastBodyRow().addColumn("");
}
}
// Remove internal attribute
if (element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":data")) {
element.removeAttribute(DataTablesDialect.DIALECT_PREFIX + ":data");
}
return ProcessorResult.OK;
}