use of eu.esdihumboldt.hale.io.csv.reader.DefaultCSVLookupReader in project hale by halestudio.
the class CSVLookupReader method execute.
/**
* @see eu.esdihumboldt.hale.common.core.io.impl.AbstractIOProvider#execute(eu.esdihumboldt.hale.common.core.io.ProgressIndicator,
* eu.esdihumboldt.hale.common.core.io.report.IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
int keyColumn = getParameter(LookupTableExportConstants.LOOKUP_KEY_COLUMN).as(Integer.class);
int valueColumn = getParameter(LookupTableExportConstants.LOOKUP_VALUE_COLUMN).as(Integer.class);
boolean skipFirst = getParameter(LookupTableExportConstants.PARAM_SKIP_FIRST_LINE).as(Boolean.class);
DefaultCSVLookupReader reader = new DefaultCSVLookupReader();
Map<Value, Value> values = reader.read(getSource().getInput(), getCharset(), CSVUtil.getSep(this), CSVUtil.getQuote(this), CSVUtil.getEscape(this), skipFirst, keyColumn, valueColumn);
lookupTable = new LookupTableInfoImpl((new LookupTableImpl(values)), getName(), getDescription());
reporter.setSuccess(true);
return reporter;
}
use of eu.esdihumboldt.hale.io.csv.reader.DefaultCSVLookupReader in project hale by halestudio.
the class LookupTablePage method readLookupTable.
// read lookup table from file (specified by provider in corresponding
// wizard)
private Map<Value, Value> readLookupTable() {
Map<Value, Value> lookupTable = new HashMap<Value, Value>();
try {
LookupTableImport provider = getWizard().getProvider();
if (provider instanceof CSVLookupReader) {
DefaultCSVLookupReader reader = new DefaultCSVLookupReader();
lookupTable = reader.read(provider.getSource().getInput(), provider.getCharset(), provider.getParameter(CSVConstants.PARAM_SEPARATOR).as(String.class).charAt(0), provider.getParameter(CSVConstants.PARAM_QUOTE).as(String.class).charAt(0), provider.getParameter(CSVConstants.PARAM_ESCAPE).as(String.class).charAt(0), skip, keyColumn.getSelectionIndex(), valueColumn.getSelectionIndex());
} else {
Workbook workbook;
// write xls file
String file = provider.getSource().getLocation().getPath();
String fileExtension = file.substring(file.lastIndexOf("."), file.length());
if (fileExtension.equals(".xls")) {
workbook = new HSSFWorkbook(provider.getSource().getInput());
} else // write xlsx file
if (fileExtension.equals(".xlsx")) {
workbook = new XSSFWorkbook(provider.getSource().getInput());
} else
return new HashMap<Value, Value>();
DefaultXLSLookupTableReader reader = new DefaultXLSLookupTableReader();
lookupTable = reader.read(workbook, skip, keyColumn.getSelectionIndex(), valueColumn.getSelectionIndex(), ignoreEmptyString.getSelection());
}
} catch (IOException e) {
return lookupTable;
}
return lookupTable;
}
Aggregations