use of org.loboevolution.html.dom.HTMLTableCellElement in project LoboEvolution by LoboEvolution.
the class HTMLTableRowElementImpl method insertCell.
private HTMLTableCellElementImpl insertCell(Object objIndex, String tagName) {
final Document doc = this.document;
if (doc == null) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
}
HTMLTableCellElementImpl cellElement = (HTMLTableCellElementImpl) doc.createElement(tagName);
int index = -1;
if (objIndex instanceof Double) {
index = ((Double) objIndex).intValue();
} else {
if (objIndex == null || "".equals(objIndex)) {
index = 0;
} else {
index = Integer.parseInt(objIndex.toString());
}
}
if (index == 0 || index == -1) {
appendChild(cellElement);
AtomicInteger cellIndex = new AtomicInteger(-1);
if (index == -1) {
NodeListImpl childNodes = (NodeListImpl) getParentNode().getChildNodes();
childNodes.forEach(node -> {
if (node instanceof HTMLTableCellElementImpl) {
cellIndex.incrementAndGet();
}
});
}
cellElement.setIndex(index == -1 ? cellIndex.get() : 0);
return cellElement;
}
AtomicInteger trcount = new AtomicInteger();
nodeList.forEach(node -> {
if (node instanceof HTMLTableCellElement) {
trcount.incrementAndGet();
}
});
if (trcount.get() < index) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "The index is greater than the number of cells in the table ");
} else {
cellElement.setIndex(index);
insertAt(cellElement, index);
}
return cellElement;
}
Aggregations