Search in sources :

Example 1 with HTMLTableCellElement

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;
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HTMLTableCellElement(org.loboevolution.html.dom.HTMLTableCellElement) Document(org.loboevolution.html.node.Document)

Aggregations

DOMException (com.gargoylesoftware.css.dom.DOMException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 HTMLTableCellElement (org.loboevolution.html.dom.HTMLTableCellElement)1 NodeListImpl (org.loboevolution.html.dom.nodeimpl.NodeListImpl)1 Document (org.loboevolution.html.node.Document)1