com.gargoylesoftware.htmlunit.html.HtmlTableRow Java Examples

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlTableRow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HTMLTableRowElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the index of the row within the enclosing thead, tbody or tfoot.
 * @return the index of the row within the enclosing thead, tbody or tfoot
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms534621.aspx">MSDN Documentation</a>
 * @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-79105901">
 * DOM Level 1</a>
 */
@JsxGetter
public int getSectionRowIndex() {
    DomNode row = getDomNodeOrDie();
    final HtmlTable table = ((HtmlTableRow) row).getEnclosingTable();
    if (table == null) { // a not attached document.createElement('TR')
        return -1;
    }
    int index = -1;
    while (row != null) {
        if (row instanceof HtmlTableRow) {
            index++;
        }
        row = row.getPreviousSibling();
    }
    return index;
}
 
Example #2
Source File: HTMLTableRowElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Inserts a new cell at the specified index in the element's cells collection. If the index
 * is -1 or there is no index specified, then the cell is appended at the end of the
 * element's cells collection.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536455.aspx">MSDN Documentation</a>
 * @param index specifies where to insert the cell in the tr.
 *        The default value is -1, which appends the new cell to the end of the cells collection
 * @return the newly-created cell
 */
@JsxFunction
public Object insertCell(final Object index) {
    int position = -1;
    if (!Undefined.isUndefined(index)) {
        position = (int) Context.toNumber(index);
    }
    final HtmlTableRow htmlRow = (HtmlTableRow) getDomNodeOrDie();

    final boolean indexValid = position >= -1 && position <= htmlRow.getCells().size();
    if (indexValid) {
        final DomElement newCell = ((HtmlPage) htmlRow.getPage()).createElement("td");
        if (position == -1 || position == htmlRow.getCells().size()) {
            htmlRow.appendChild(newCell);
        }
        else {
            htmlRow.getCell(position).insertBefore(newCell);
        }
        return getScriptableFor(newCell);
    }
    throw Context.reportRuntimeError("Index or size is negative or greater than the allowed amount");
}
 
Example #3
Source File: HTMLTableRowElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the cell at the specified index in the element's cells collection. If the index
 * is -1 (or while simulating IE, when there is no index specified), then the last cell is deleted.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536406.aspx">MSDN Documentation</a>
 * @see <a href="http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-11738598">W3C DOM Level2</a>
 * @param index specifies the cell to delete.
 */
@JsxFunction
public void deleteCell(final Object index) {
    int position = -1;
    if (!Undefined.isUndefined(index)) {
        position = (int) Context.toNumber(index);
    }
    else if (getBrowserVersion().hasFeature(JS_TABLE_ROW_DELETE_CELL_REQUIRES_INDEX)) {
        throw Context.reportRuntimeError("No enough arguments");
    }

    final HtmlTableRow htmlRow = (HtmlTableRow) getDomNodeOrDie();

    if (position == -1) {
        position = htmlRow.getCells().size() - 1;
    }
    final boolean indexValid = position >= -1 && position <= htmlRow.getCells().size();
    if (!indexValid) {
        throw Context.reportRuntimeError("Index or size is negative or greater than the allowed amount");
    }

    htmlRow.getCell(position).remove();
}
 
Example #4
Source File: HTMLTableRowElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the cell at the specified index in the element's cells collection. If the index
 * is -1 (or while simulating IE, when there is no index specified), then the last cell is deleted.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536406.aspx">MSDN Documentation</a>
 * @see <a href="http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-11738598">W3C DOM Level2</a>
 * @param index specifies the cell to delete.
 */
@JsxFunction
public void deleteCell(final Object index) {
    int position = -1;
    if (index != Undefined.instance) {
        position = (int) Context.toNumber(index);
    }
    else if (getBrowserVersion().hasFeature(JS_TABLE_ROW_DELETE_CELL_REQUIRES_INDEX)) {
        throw Context.reportRuntimeError("No enough arguments");
    }

    final HtmlTableRow htmlRow = (HtmlTableRow) getDomNodeOrDie();

    if (position == -1) {
        position = htmlRow.getCells().size() - 1;
    }
    final boolean indexValid = position >= -1 && position <= htmlRow.getCells().size();
    if (!indexValid) {
        throw Context.reportRuntimeError("Index or size is negative or greater than the allowed amount");
    }

    htmlRow.getCell(position).remove();
}
 
Example #5
Source File: HTMLTableRowElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Inserts a new cell at the specified index in the element's cells collection. If the index
 * is -1 or there is no index specified, then the cell is appended at the end of the
 * element's cells collection.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536455.aspx">MSDN Documentation</a>
 * @param index specifies where to insert the cell in the tr.
 *        The default value is -1, which appends the new cell to the end of the cells collection
 * @return the newly-created cell
 */
@JsxFunction
public Object insertCell(final Object index) {
    int position = -1;
    if (index != Undefined.instance) {
        position = (int) Context.toNumber(index);
    }
    final HtmlTableRow htmlRow = (HtmlTableRow) getDomNodeOrDie();

    final boolean indexValid = position >= -1 && position <= htmlRow.getCells().size();
    if (indexValid) {
        final DomElement newCell = ((HtmlPage) htmlRow.getPage()).createElement("td");
        if (position == -1 || position == htmlRow.getCells().size()) {
            htmlRow.appendChild(newCell);
        }
        else {
            htmlRow.getCell(position).insertBefore(newCell);
        }
        return getScriptableFor(newCell);
    }
    throw Context.reportRuntimeError("Index or size is negative or greater than the allowed amount");
}
 
Example #6
Source File: HTMLTableRowElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the index of the row within the enclosing thead, tbody or tfoot.
 * @return the index of the row within the enclosing thead, tbody or tfoot
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms534621.aspx">MSDN Documentation</a>
 * @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-79105901">
 * DOM Level 1</a>
 */
@JsxGetter
public int getSectionRowIndex() {
    DomNode row = getDomNodeOrDie();
    final HtmlTable table = ((HtmlTableRow) row).getEnclosingTable();
    if (table == null) { // a not attached document.createElement('TR')
        return -1;
    }
    int index = -1;
    while (row != null) {
        if (row instanceof HtmlTableRow) {
            index++;
        }
        row = row.getPreviousSibling();
    }
    return index;
}
 
Example #7
Source File: RowContainer.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the rows in the element.
 * @return the rows in the element
 */
@JsxGetter
public Object getRows() {
    return new HTMLCollection(getDomNodeOrDie(), false) {
        @Override
        protected boolean isMatching(final DomNode node) {
            return node instanceof HtmlTableRow && isContainedRow((HtmlTableRow) node);
        }

    };
}
 
Example #8
Source File: AbstractOIDCTest.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testEditClient() throws Exception {
    try (WebClient webClient = setupWebClientIDP("alice", "ecila")) {
        HtmlPage registeredClientPage = login(oidcEndpointBuilder("/console/clients/" + publicClientId),
            webClient);

        final HtmlPage editClientPage = registeredClientPage.getAnchorByText("public-client").click();

        final HtmlForm form = editClientPage.getForms().get(0);

        // Set new client values
        final HtmlTextInput clientNameInput = form.getInputByName("client_name");
        final String newClientName = "public-client-modified";
        clientNameInput.setValueAttribute(newClientName);
        final HtmlSelect clientTypeSelect = form.getSelectByName("client_type");
        assertTrue(clientTypeSelect.isDisabled());
        final HtmlTextInput redirectURIInput = form.getInputByName("client_redirectURI");
        assertEquals(REDIRECT_URL, redirectURIInput.getText());
        final HtmlTextInput clientAudienceURIInput = form.getInputByName("client_audience");
        assertEquals("https://ws.apache.org", clientAudienceURIInput.getText());
        final HtmlTextInput clientLogoutURI = form.getInputByName("client_logoutURI");
        assertEquals(LOGOUT_URL, clientLogoutURI.getText());

        registeredClientPage = form.getButtonByName("submit_button").click();
        assertNotNull(registeredClientPage.getAnchorByText(newClientName));

        final HtmlPage registeredClientsPage = registeredClientPage.getAnchorByText("registered Clients").click();

        HtmlTable table = registeredClientsPage.getHtmlElementById("registered_clients");
        assertEquals("2 clients", table.getRows().size(), 3);
        boolean updatedClientFound = false;
        for (final HtmlTableRow row : table.getRows()) {
            if (newClientName.equals(row.getCell(0).asText())) {
                updatedClientFound = true;
                break;
            }
        }
        assertTrue(updatedClientFound);
    }
}
 
Example #9
Source File: AbstractOIDCTest.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
private static String getClientIdByName(String clientName, HtmlPage registeredClientsPage) {
    final HtmlTable table = registeredClientsPage.getHtmlElementById("registered_clients");
    for (final HtmlTableRow row : table.getRows()) {
        if (clientName.equals(row.getCell(0).asText())) {
            final String clientId = row.getCell(1).asText();
            assertNotNull(clientId);
            return clientId;
        }
    }
    throw new IllegalArgumentException("Client '" + clientName + "' not found");
}
 
Example #10
Source File: HTMLTableCellElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the row element which contains this cell's HTML element; may return {@code null}.
 * @return the row element which contains this cell's HTML element
 */
private HtmlTableRow getRow() {
    DomNode node = getDomNodeOrDie();
    while (node != null && !(node instanceof HtmlTableRow)) {
        node = node.getParentNode();
    }
    return (HtmlTableRow) node;
}
 
Example #11
Source File: HTMLTableCellElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of this cell within the parent row.
 * @return the index of this cell within the parent row
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms533549.aspx">MSDN Documentation</a>
 */
@JsxGetter
public Integer getCellIndex() {
    final HtmlTableCell cell = (HtmlTableCell) getDomNodeOrDie();
    final HtmlTableRow row = cell.getEnclosingRow();
    if (row == null) { // a not attached document.createElement('TD')
        return Integer.valueOf(-1);
    }
    return Integer.valueOf(row.getCells().indexOf(cell));
}
 
Example #12
Source File: HTMLTableCellElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getOffsetWidth() {
    float w = super.getOffsetWidth();
    final MouseEvent event = MouseEvent.getCurrentMouseEvent();
    if (isAncestorOfEventTarget(event)) {
        return (int) w;
    }

    if (isDisplayNone()) {
        return 0;
    }

    final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
    if ("collapse".equals(style.getStyleAttribute(StyleAttributes.Definition.BORDER_COLLAPSE))) {
        final HtmlTableRow row = getRow();
        if (row != null) {
            final HtmlElement thiz = getDomNodeOrDie();
            final List<HtmlTableCell> cells = row.getCells();
            final boolean ie = getBrowserVersion().hasFeature(JS_TABLE_CELL_OFFSET_INCLUDES_BORDER);
            final boolean leftmost = cells.indexOf(thiz) == 0;
            final boolean rightmost = cells.indexOf(thiz) == cells.size() - 1;
            w -= (ie && leftmost ? 0 : 0.5) * style.getBorderLeftValue();
            w -= (ie && rightmost ? 0 : 0.5) * style.getBorderRightValue();
        }
    }

    return (int) w;
}
 
Example #13
Source File: HTMLTableRowElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the cells in the row.
 * @return the cells in the row
 */
@JsxGetter
public Object getCells() {
    final HtmlTableRow row = (HtmlTableRow) getDomNodeOrDie();
    return new HTMLCollection(row, false) {
        @Override
        protected List<DomNode> computeElements() {
            return new ArrayList<DomNode>(row.getCells());
        }
    };
}
 
Example #14
Source File: HTMLTableRowElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the row within the parent table.
 * @return the index of the row within the parent table
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms534377.aspx">MSDN Documentation</a>
 */
@JsxGetter
public int getRowIndex() {
    final HtmlTableRow row = (HtmlTableRow) getDomNodeOrDie();
    final HtmlTable table = row.getEnclosingTable();
    if (table == null) { // a not attached document.createElement('TR')
        return -1;
    }
    return table.getRows().indexOf(row);
}
 
Example #15
Source File: PropertyTable.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a new instance of {@link PropertyTable}.
 *
 * @param page
 *         the whole details HTML page
 * @param property
 *         the property tab to extract
 */
@SuppressFBWarnings("BC")
public PropertyTable(final HtmlPage page, final String property) {
    super(page);

    title = getTitleOfTable(page, property);

    DomElement propertyElement = page.getElementById(property);
    assertThat(propertyElement).isInstanceOf(HtmlTable.class);

    HtmlTable table = (HtmlTable) propertyElement;
    List<HtmlTableRow> tableHeaderRows = table.getHeader().getRows();
    assertThat(tableHeaderRows).hasSize(1);

    HtmlTableRow header = tableHeaderRows.get(0);
    List<HtmlTableCell> cells = header.getCells();
    assertThat(cells).hasSize(3);

    propertyName = cells.get(0).getTextContent();
    assertThat(cells.get(1).getTextContent()).isEqualTo("Total");
    assertThat(cells.get(2).getTextContent()).isEqualTo("Distribution");

    List<HtmlTableBody> bodies = table.getBodies();
    assertThat(bodies).hasSize(1);
    List<HtmlTableRow> contentRows = bodies.get(0).getRows();

    for (HtmlTableRow row : contentRows) {
        List<HtmlTableCell> rowCells = row.getCells();
        rows.add(new PropertyRow(rowCells));
    }
}
 
Example #16
Source File: HTMLTableCellElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the row element which contains this cell's HTML element; may return {@code null}.
 * @return the row element which contains this cell's HTML element
 */
private HtmlTableRow getRow() {
    DomNode node = getDomNodeOrDie();
    while (node != null && !(node instanceof HtmlTableRow)) {
        node = node.getParentNode();
    }
    return (HtmlTableRow) node;
}
 
Example #17
Source File: HTMLTableCellElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of this cell within the parent row.
 * @return the index of this cell within the parent row
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms533549.aspx">MSDN Documentation</a>
 */
@JsxGetter
public Integer getCellIndex() {
    final HtmlTableCell cell = (HtmlTableCell) getDomNodeOrDie();
    final HtmlTableRow row = cell.getEnclosingRow();
    if (row == null) { // a not attached document.createElement('TD')
        return Integer.valueOf(-1);
    }
    return Integer.valueOf(row.getCells().indexOf(cell));
}
 
Example #18
Source File: HTMLTableCellElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getOffsetWidth() {
    float w = super.getOffsetWidth();
    final MouseEvent event = MouseEvent.getCurrentMouseEvent();
    if (isAncestorOfEventTarget(event)) {
        return (int) w;
    }

    if (isDisplayNone()) {
        return 0;
    }

    final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
    if ("collapse".equals(style.getStyleAttribute(StyleAttributes.Definition.BORDER_COLLAPSE))) {
        final HtmlTableRow row = getRow();
        if (row != null) {
            final HtmlElement thiz = getDomNodeOrDie();
            final List<HtmlTableCell> cells = row.getCells();
            final boolean ie = getBrowserVersion().hasFeature(JS_TABLE_CELL_OFFSET_INCLUDES_BORDER);
            final boolean leftmost = cells.indexOf(thiz) == 0;
            final boolean rightmost = cells.indexOf(thiz) == cells.size() - 1;
            w -= (ie && leftmost ? 0 : 0.5) * style.getBorderLeftValue();
            w -= (ie && rightmost ? 0 : 0.5) * style.getBorderRightValue();
        }
    }

    return (int) w;
}
 
Example #19
Source File: HTMLTableRowElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the cells in the row.
 * @return the cells in the row
 */
@JsxGetter
public Object getCells() {
    final HtmlTableRow row = (HtmlTableRow) getDomNodeOrDie();
    return new HTMLCollection(row, false) {
        @Override
        protected List<DomNode> computeElements() {
            return new ArrayList<>(row.getCells());
        }
    };
}
 
Example #20
Source File: HTMLTableRowElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the row within the parent table.
 * @return the index of the row within the parent table
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms534377.aspx">MSDN Documentation</a>
 */
@JsxGetter
public int getRowIndex() {
    final HtmlTableRow row = (HtmlTableRow) getDomNodeOrDie();
    final HtmlTable table = row.getEnclosingTable();
    if (table == null) { // a not attached document.createElement('TR')
        return -1;
    }
    return table.getRows().indexOf(row);
}
 
Example #21
Source File: RowContainer.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the rows in the element.
 * @return the rows in the element
 */
@JsxGetter
public Object getRows() {
    return new HTMLCollection(getDomNodeOrDie(), false) {
        @Override
        protected boolean isMatching(final DomNode node) {
            return node instanceof HtmlTableRow && isContainedRow((HtmlTableRow) node);
        }

    };
}
 
Example #22
Source File: HTMLTableElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Indicates if the row belongs to this container.
 * @param row the row to test
 * @return {@code true} if it belongs to this container
 */
@Override
protected boolean isContainedRow(final HtmlTableRow row) {
    final DomNode parent = row.getParentNode(); // the tbody, thead or tfoo
    return (parent != null) && parent.getParentNode() == getDomNodeOrDie();
}
 
Example #23
Source File: HTMLTableElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Indicates if the row belongs to this container.
 * @param row the row to test
 * @return {@code true} if it belongs to this container
 */
@Override
protected boolean isContainedRow(final HtmlTableRow row) {
    final DomNode parent = row.getParentNode(); // the tbody, thead or tfoo
    return (parent != null) && parent.getParentNode() == getDomNodeOrDie();
}
 
Example #24
Source File: RowContainer.java    From HtmlUnit-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Indicates if the row belongs to this container.
 * @param row the row to test
 * @return {@code true} if it belongs to this container
 */
protected boolean isContainedRow(final HtmlTableRow row) {
    return row.getParentNode() == getDomNodeOrDie();
}
 
Example #25
Source File: RowContainer.java    From htmlunit with Apache License 2.0 2 votes vote down vote up
/**
 * Indicates if the row belongs to this container.
 * @param row the row to test
 * @return {@code true} if it belongs to this container
 */
protected boolean isContainedRow(final HtmlTableRow row) {
    return row.getParentNode() == getDomNodeOrDie();
}