Exemplo n.º 1
0
  private Row getRow() throws HTMLReaderException {
    Row row = null;
    Row.Type type = null;

    while (current != null && !current.matchesStart("tr")) nextToken();

    if (current != null) nextToken();

    while (current != null && !current.matchesEnd("tr")) {
      if (type == null) {
        type = current.getText().equalsIgnoreCase("th") ? Row.Type.Header : Row.Type.Data;
        row = new Row();
        row.setType(type);
      }
      if (type == Row.Type.Header) {
        if (!current.matchesStart("th"))
          throw new HTMLReaderException("Expected <th> found " + current.getText());
      } else if (!current.matchesStart("td"))
        throw new HTMLReaderException("Expected <td> found " + current.getText());
      nextToken();

      if (current == null) throw new HTMLReaderException("Table incomplete");
      if (cellCreator == null) {
        row.addColumn(current.getType() == Element.Type.Text ? current.getText() : "");
      } else row.addColumn(cellCreator.getValue(this));

      if (current.getType() == Element.Type.End) nextToken();
    }
    return row;
  }
Exemplo n.º 2
0
  /**
   * Adds the rows of the DbUnit table to the given table.
   *
   * @param dbUnitTable The DbUnit table containing the rows, not null
   * @param table The table to add the rows to, not null
   * @param primaryKeyColumnNames The names of the pk columns, empty if there are none
   */
  protected void addRows(ITable dbUnitTable, Table table, List<String> primaryKeyColumnNames)
      throws DataSetException {
    org.dbunit.dataset.Column[] columns = dbUnitTable.getTableMetaData().getColumns();
    int rowCount = dbUnitTable.getRowCount();
    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
      Row row = new Row();
      table.addRow(row);

      for (org.dbunit.dataset.Column dbUnitColumn : columns) {
        String columnName = dbUnitColumn.getColumnName();
        DataType columnType = dbUnitColumn.getDataType();
        Object value = dbUnitTable.getValue(rowIndex, columnName);

        Column column = new Column(columnName, columnType, value);
        if (primaryKeyColumnNames.contains(columnName)) {
          row.addPrimaryKeyColumn(column);
        } else {
          row.addColumn(column);
        }
      }
    }
  }