use of com.archimatetool.csv.export.CSVExporter in project archi by archimatetool.
the class ExportCSVProvider method run.
@Override
public void run(CommandLine commandLine) throws Exception {
if (!hasCorrectOptions(commandLine)) {
return;
}
IArchimateModel model = CommandLineState.getModel();
if (model == null) {
throw new IOException(Messages.ExportCSVProvider_1);
}
// Folder
String value = commandLine.getOptionValue(OPTION_EXPORT_CSV);
if (!StringUtils.isSet(value)) {
logError(Messages.ExportCSVProvider_2);
return;
}
File folderOutput = new File(value);
folderOutput.mkdirs();
if (!folderOutput.exists()) {
logError(NLS.bind(Messages.ExportCSVProvider_3, value));
return;
}
CSVExporter exporter = new CSVExporter(model);
// Delimiter
value = commandLine.getOptionValue(OPTION_DELIMITER);
if (StringUtils.isSet(value)) {
switch(value) {
case // $NON-NLS-1$
"\\t":
exporter.setDelimiter('\t');
break;
case // $NON-NLS-1$
";":
exporter.setDelimiter(';');
break;
default:
exporter.setDelimiter(',');
break;
}
}
// File prefix
value = commandLine.getOptionValue(OPTION_FILE_PREFIX);
if (StringUtils.isSet(value)) {
exporter.setFilePrefix(value);
}
// Encoding
value = commandLine.getOptionValue(OPTION_ENCODING);
if (StringUtils.isSet(value)) {
exporter.setEncoding(value);
}
// Use leading
exporter.setUseLeadingCharsHack(commandLine.hasOption(OPTION_LEADING_CHARS_HACK));
// Strip newlines
exporter.setStripNewLines(commandLine.hasOption(OPTION_STRIP_NEW_LINES));
logMessage(NLS.bind(Messages.ExportCSVProvider_4, model.getName(), folderOutput.getPath()));
exporter.export(folderOutput);
logMessage(Messages.ExportCSVProvider_5);
}
Aggregations