try
{
if (_dest == null)
{
throw new DatabaseUnitException("'_dest' is a required attribute of the <export> step.");
}
IDataSet dataset = getExportDataSet(connection);
log("dataset tables: " + Arrays.asList(dataset.getTableNames()), Project.MSG_VERBOSE);
// Write the dataset
if (_format.equals(FORMAT_CSV))
{
CsvDataSetWriter.write(dataset, _dest);
}
else
{
OutputStream out = new FileOutputStream(_dest);
try
{
if (_format.equalsIgnoreCase(FORMAT_FLAT))
{
FlatXmlWriter writer = new FlatXmlWriter(out, getEncoding());
writer.setDocType(_doctype);
writer.write(dataset);
}
else if (_format.equalsIgnoreCase(FORMAT_XML))
{
XmlDataSet.write(dataset, out, getEncoding());
}
else if (_format.equalsIgnoreCase(FORMAT_DTD))
{
//TODO Should DTD also support encoding? It is basically an XML file...
FlatDtdDataSet.write(dataset, out);//, getEncoding());
}
else if (_format.equalsIgnoreCase(FORMAT_XLS))
{
XlsDataSet.write(dataset, out);
}
else
{
throw new IllegalArgumentException("The given format '"+_format+"' is not supported.");
}
}
finally
{
out.close();
}
}
log("Successfully wrote file '" + _dest + "'", Project.MSG_INFO);
}
catch (SQLException e)
{
throw new DatabaseUnitException(e);
}
catch (IOException e)
{
throw new DatabaseUnitException(e);
}
}