// Fill the defaults in the tableDescription.
// This allows easy-to-write table descriptions
// (or even null table descriptions).
for (int i = 0; i < line.length; i++) {
ColumnDescription tempColumnDescription =
(columnDescriptions.isEmpty() || columnDescriptions.get(i) == null)
? null
: columnDescriptions.get(i);
String id =
((tempColumnDescription == null) || (tempColumnDescription.getId() == null))
? "Col" + (i) : tempColumnDescription.getId();
ValueType type =
((tempColumnDescription == null) || (tempColumnDescription.getType() == null))
? ValueType.TEXT : tempColumnDescription.getType();
String label =
((tempColumnDescription == null) || (tempColumnDescription.getLabel() == null))
? "Column" + i : tempColumnDescription.getLabel();
String pattern =
((tempColumnDescription == null) || (tempColumnDescription.getPattern() == null))
? "" : tempColumnDescription.getPattern();
tempColumnDescription = new ColumnDescription(id, type, label);
tempColumnDescription.setPattern(pattern);
tempColumnDescriptions.add(tempColumnDescription);
}
// Deal with header rows.
if (headerRow) {
for (int i = 0; i < line.length; i++) {
String string = line[i];
if (string == null) {
tempColumnDescriptions.get(i).setLabel("");
} else {
tempColumnDescriptions.get(i).setLabel(line[i].trim());
}
}
}
columnDescriptions = tempColumnDescriptions;
dataTable = new DataTable();
dataTable.addColumns(columnDescriptions);
}
if (!(firstLine && headerRow)) {
// Need to parse the first line as a regular row.
TableRow tableRow = new TableRow();
for (int i = 0; i < line.length; i++) {
ColumnDescription columnDescription = columnDescriptions.get(i);
ValueType valueType = columnDescription.getType();
String string = line[i];
if (string != null) {
string = string.trim();
}
String pattern = columnDescription.getPattern();
ValueFormatter valueFormatter;
if (pattern == null || pattern.equals("")) {
valueFormatter = defaultFormatters.get(valueType);
} else {
valueFormatter = ValueFormatter.createFromPattern(valueType, pattern, locale);