private void writeHeaderRow() throws DataAccessObjectInitializationException { CSVColumnVisitor visitor = new CSVColumnVisitor(fileOut); try { visitHeaderColumns(this.columnNames, visitor); fileOut.newLine(); visitor.newRow(); } catch (IOException e) { String errMsg = Messages.getString("CSVWriter.errorWriting"); logger.error(errMsg, e); // $NON-NLS-1$ throw new DataAccessObjectInitializationException(errMsg, e); } }
/* * (non-Javadoc) * @see com.salesforce.dataloader.dao.csv.Writer#writeRow(java.util.Map) */ public boolean writeRow(Map<String, Object> columnValues) throws DataAccessObjectException { CSVColumnVisitor visitor = new CSVColumnVisitor(fileOut); try { visitColumns(columnNames, columnValues, visitor); fileOut.newLine(); visitor.newRow(); currentRowNumber++; return true; // success unless there's an exception } catch (IOException e) { logger.error(Messages.getString("CSVWriter.errorWriting"), e); // $NON-NLS-1$ throw new DataAccessObjectException( Messages.getString("CSVWriter.errorWriting"), e); // $NON-NLS-1$ } }
private static void visitColumns( List<String> columnNames, Map<String, Object> columnValues, CSVColumnVisitor visitor) throws IOException { for (String colName : columnNames) { Object colVal = columnValues.get(colName); visitor.visit(colVal != null ? colVal.toString() : ""); } }
private void visitHeaderColumns(List<String> columnNames, CSVColumnVisitor visitor) throws IOException { for (String colName : columnNames) { String outColName; if (colName != null) { if (this.capitalizedHeadings) { outColName = colName.toUpperCase(); } else { outColName = colName; } } else { outColName = ""; } visitor.visit(outColName); } }