/** * Returns a rendering of this table with all cells converted to text. **/ public String[][] asText() { String[][] result = new String[ getRowCount() ][ getColumnCount() ]; for (int i = 0; i < result.length; i++) { for (int j= 0; j < result[0].length; j++) { result[i][j] = getCellAsText( i, j ); } } return result; }
private WebTable toWebTable( Element element ) { return new WebTable( _response, _frame, element, _baseURL, _baseTarget, _characterSet ); }
/** * Returns the contents of the specified table cell with a given ID * @return TableCell with given ID or null if ID is not found. **/ public TableCell getTableCellWithID( String id ) { for (int i = 0; i < getRowCount(); i++) { for (int j = 0; j < getColumnCount(); j++) { final TableCell tableCell = getCells()[i][j]; if (tableCell!=null && tableCell.getID().equals( id )) return tableCell; } } return null; }
for (int j = 0; j < tbl.getRowCount(); j++) { for (int k = 0; k < tbl.getColumnCount(); k++) { TableCell cell = tbl.getTableCell(j,k); if (cell != null) { WebTable tt = findPendingRoleTable(cell); if( tbl.getColumnCount()<4 ) continue; if( tbl.getCellAsText(0,2).indexOf("Roles requested")==-1 ) continue; if( tbl.getCellAsText(0,3).indexOf("Operations")==-1 ) continue;
/** * Returns the table with the specified text in its summary attribute. **/ private WebTable getTableSatisfyingPredicate( WebTable[] tables, HTMLElementPredicate predicate, Object value ) { for (int i = 0; i < tables.length; i++) { if (predicate.matchesCriteria( tables[i], value )) { return tables[i]; } else { for (int j = 0; j < tables[i].getRowCount(); j++) { for (int k = 0; k < tables[i].getColumnCount(); k++) { TableCell cell = tables[i].getTableCell(j,k); if (cell != null) { WebTable[] innerTables = cell.getTables(); if (innerTables.length != 0) { WebTable result = getTableSatisfyingPredicate( innerTables, predicate, value ); if (result != null) return result; } } } } } } return null; }
for( int i=1; i<t.getRowCount(); i++ ) { if( !t.getCellAsText(i,0).trim().equals(user.getName()) ) continue; if( !t.getCellAsText(i,2).trim().equals(roleName) ) continue; TableCell opCell = t.getTableCell(i,3); Element input = Util.getFirstElementChild((Element)opCell.getDOM()); if(!input.getTagName().equalsIgnoreCase("input"))
users.purgeEmptyCells(); int numRows = users.getRowCount(); JNUser user = root.getUser(users.getCellAsText(r,0).trim()); String cell = users.getCellAsText(r, 2);
protected Object scrape() throws IOException, SAXException, ProcessingException { WebResponse response = goTo(project._getURL()+"/servlets/SummarizeList?listName="+name); WebTable listInfo = response.getTableStartingWith("List address"); if (listInfo == null) throw new ProcessingException("Unable to find the list table"); description = listInfo.getCellAsText(1,1); totalMessages = new Integer(listInfo.getCellAsText(2,1)); WebTable monthInfo = response.getTableStartingWith("Month"); messagesPerMonth = new ArrayList<MessagePerMonth>(); if(monthInfo==null) { if(totalMessages==0) return null; //this is to be expected else throw new ProcessingException("month table not found, even though the total message count isn't 0"); } int numRows = monthInfo.getRowCount(); // we start at row 1, since the row 0 is the header for (int r = 1; r < numRows; r++) { String month = monthInfo.getCellAsText(r,0).trim(); String messages = monthInfo.getCellAsText(r,1).trim(); messagesPerMonth.add( new MessagePerMonth(month,Integer.parseInt(messages)) ); } return null; } }.run();
/** * Returns the contents of the specified table cell as text. * The row and column numbers are zero-based. * @throws IndexOutOfBoundsException if the specified cell numbers are not valid **/ public TableCell getTableCell( int row, int column ) { return getCells()[ row ][ column ]; }
private void readTable() { TableRow[] rows = getRows(); int[] columnsRequired = new int[ rows.length ]; for (int i = 0; i < rows.length; i++) { TableCell[] cells = rows[i].getCells(); for (int j = 0; j < cells.length; j++) { int spannedRows = Math.min( columnsRequired.length-i, cells[j].getRowSpan() ); for (int k = 0; k < spannedRows; k++) { columnsRequired[ i+k ]+= cells[j].getColSpan(); } } } int numColumns = 0; for (int i = 0; i < columnsRequired.length; i++) { numColumns = Math.max( numColumns, columnsRequired[i] ); } _cells = new TableCell[ columnsRequired.length ][ numColumns ]; for (int i = 0; i < rows.length; i++) { TableCell[] cells = rows[i].getCells(); for (int j = 0; j < cells.length; j++) { int spannedRows = Math.min( columnsRequired.length-i, cells[j].getRowSpan() ); for (int k = 0; k < spannedRows; k++) { for (int l = 0; l < cells[j].getColSpan(); l++) { placeCell( i+k, j+l, cells[j] ); } } } } }
protected Object scrape() throws IOException, SAXException, ProcessingException { WebResponse response = goTo(_getURL()+"/servlets/ProjectApproval"); WebTable table = response.getTableStartingWith("Project"); int rows = table.getRowCount(); boolean found = false; String approveElementName = null; for (int r = 1; r < rows && !found; r++ ) { TableCell c1 = table.getTableCell(r, 0); if (c1.getLinks().length > 0) { String link = c1.getLinks()[0].getURLString(); if (link.equals(_getURL()+'/')) { TableCell c2 = table.getTableCell(r, 3); String[] names = c2.getElementNames(); if (names.length > 0) { approveElementName = names[0]; found = true; } } } } if (!found) throw new ProcessingException("Unable to find project "+projectName+" in the approval page"); // we already have the info we need to approve the project, now, do it WebForm form = Util.getFormWithAction(response,"ProjectApproval"); form.setParameter(approveElementName, approve ? "Approve" : "Disapprove"); form.setParameter("disapprovalReason",reason); checkError(form.submit()); return null; } }
/** * Returns the contents of the specified table cell as text. * The row and column numbers are zero-based. * @throws IndexOutOfBoundsException if the specified cell numbers are not valid **/ public String getCellAsText( int row, int column ) { TableCell cell = getTableCell( row, column ); return (cell == null) ? "" : cell.getText(); }
protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) { getWebTable( pot ).addRow( (TableRow) htmlElement ); } }
public boolean matchesCriteria( Object htmlElement, Object criteria ) { return HttpUnitUtils.matches( ((WebTable) htmlElement).getSummary(), (String) criteria ); }; };
public ScriptableDelegate getParentDelegate() { return _webTable.getParentDelegate(); } }
int numRowsWithText = 0; int numColumnsWithText = 0; boolean rowHasText[] = new boolean[ getRowCount() ]; boolean columnHasText[] = new boolean[ getColumnCount() ]; Hashtable spanningCells = new Hashtable(); if (getCellAsText(row,col).trim().length() == 0) continue; if (getTableCell(row,col).getColSpan() == 1 && getTableCell(row,col).getRowSpan() == 1) { if (!rowHasText[row]) numRowsWithText++; if (!columnHasText[col]) numColumnsWithText++; rowHasText[row] = columnHasText[col] = true; } else if (!spanningCells.containsKey( getTableCell(row,col) )) { if (spanningCells.get( getTableCell(row,col) ) == null ) { if (!rowHasText[row]) numRowsWithText++; if (!columnHasText[col]) numColumnsWithText++; rowHasText[row] = columnHasText[col] = true; spanningCells.put( getTableCell(row,col), new int[] { row, col } ); } }
/** * Returns the table with the specified text in its summary attribute. **/ private WebTable getTableSatisfyingPredicate( WebTable[] tables, HTMLElementPredicate predicate, Object value ) { for (int i = 0; i < tables.length; i++) { if (predicate.matchesCriteria( tables[i], value )) { return tables[i]; } else { for (int j = 0; j < tables[i].getRowCount(); j++) { for (int k = 0; k < tables[i].getColumnCount(); k++) { TableCell cell = tables[i].getTableCell(j,k); if (cell != null) { WebTable[] innerTables = cell.getTables(); if (innerTables.length != 0) { WebTable result = getTableSatisfyingPredicate( innerTables, predicate, value ); if (result != null) return result; } } } } } } return null; }
/** * Returns the number of rows in the table. **/ public int getRowCount() { return getCells().length; }
private void readTable() { TableRow[] rows = getRows(); int[] columnsRequired = new int[ rows.length ]; for (int i = 0; i < rows.length; i++) { TableCell[] cells = rows[i].getCells(); for (int j = 0; j < cells.length; j++) { int spannedRows = Math.min( columnsRequired.length-i, cells[j].getRowSpan() ); for (int k = 0; k < spannedRows; k++) { columnsRequired[ i+k ]+= cells[j].getColSpan(); } } } int numColumns = 0; for (int i = 0; i < columnsRequired.length; i++) { numColumns = Math.max( numColumns, columnsRequired[i] ); } _cells = new TableCell[ columnsRequired.length ][ numColumns ]; for (int i = 0; i < rows.length; i++) { TableCell[] cells = rows[i].getCells(); for (int j = 0; j < cells.length; j++) { int spannedRows = Math.min( columnsRequired.length-i, cells[j].getRowSpan() ); for (int k = 0; k < spannedRows; k++) { for (int l = 0; l < cells[j].getColSpan(); l++) { placeCell( i+k, j+l, cells[j] ); } } } } }
/** * Returns the contents of the specified table cell as text. * The row and column numbers are zero-based. * @throws IndexOutOfBoundsException if the specified cell numbers are not valid **/ public String getCellAsText( int row, int column ) { TableCell cell = getTableCell( row, column ); return (cell == null) ? "" : cell.getText(); }