cn.mapway.document.helper.html.HtmlTable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-tools-doc Show documentation
Show all versions of api-tools-doc Show documentation
auto gen doc from api with ui
The newest version!
package cn.mapway.document.helper.html;
import org.nutz.lang.Strings;
import java.util.ArrayList;
public abstract class HtmlTable {
ArrayList> table;
public HtmlTable() {
table = new ArrayList<>();
}
protected void setCellAttr(int row, int col, int rowspan, int colspan, String text, String css) {
Cell cell = table.get(row).get(col);
cell.colspan = colspan;
cell.rowspan = rowspan;
cell.text = text;
if (!Strings.isBlank(css)) {
cell.css = css;
}
}
protected void initTable(int row, int col) {
table = new ArrayList<>();
for (int i = 0; i < row + 1; i++) {
ArrayList rows = new ArrayList<>(col);
for (int j = 0; j < col; j++) {
rows.add(new Cell());
}
table.add(rows);
}
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("");
for (int i = 0; i < table.size(); i++) {
ArrayList row = table.get(i);
sb.append("");
for (int j = 0; j < row.size(); j++) {
Cell cell = row.get(j);
if (j < getLevel()) {
if (cell.text != null) {
String style = findStyle(cell.css);
sb.append("").append(cell.text).append(" ");
}
} else {
if (cell.text != null) {
String style = findStyle(cell.css);
sb.append("").append(cell.text).append(" ");
}
}
}
sb.append(" ");
}
sb.append(" | ");
return sb.toString();
}
/**
* 获取目录的列数
*
* @return
*/
public abstract int getLevel();
private String findStyle(String css) {
if (Strings.isBlank(css)) {
return "";
} else {
return "class=\"" + css + "\"";
}
}
}
|