use of eu.esdihumboldt.hale.common.core.io.IOProvider in project hale by halestudio.
the class ReadConfigurationPage method onShowPage.
/**
* @see HaleWizardPage#onShowPage(boolean)
*/
@Override
protected void onShowPage(boolean firstShow) {
super.onShowPage(firstShow);
IOProvider p = getWizard().getProvider();
String[] separatorSelection = new String[] { "TAB", ",", "|", ".", ";" };
try {
BufferedReader streamReader = new BufferedReader(new InputStreamReader(getWizard().getProvider().getSource().getInput(), p.getCharset()));
String line = streamReader.readLine();
int tab = 0, comma = 0, pipe = 0, semicolon = 0;
if (line != null) {
tab = countChar(line, '\t');
comma = countChar(line, ',');
pipe = countChar(line, '|');
semicolon = countChar(line, ';');
}
if (Math.max(tab, comma) == tab && Math.max(tab, pipe) == tab && Math.max(tab, semicolon) == tab) {
p.setParameter(CSVConstants.PARAM_SEPARATOR, Value.of("TAB"));
} else if (Math.max(comma, tab) == comma && Math.max(comma, pipe) == comma && Math.max(comma, semicolon) == comma) {
p.setParameter(CSVConstants.PARAM_SEPARATOR, Value.of(","));
} else if (Math.max(semicolon, tab) == semicolon && Math.max(semicolon, comma) == semicolon && Math.max(semicolon, pipe) == semicolon) {
p.setParameter(CSVConstants.PARAM_SEPARATOR, Value.of(";"));
} else {
p.setParameter(CSVConstants.PARAM_SEPARATOR, Value.of("|"));
}
} catch (IOException e) {
e.printStackTrace();
}
String selection = getWizard().getProvider().getParameter(CSVConstants.PARAM_SEPARATOR).as(String.class);
for (int i = 0; i < separatorSelection.length; i++) {
if (separatorSelection[i].equals(selection)) {
getSeparator().select(i);
break;
} else {
getSeparator().select(0);
}
}
if (p instanceof InstanceReader) {
QName name = QName.valueOf(p.getParameter(CommonSchemaConstants.PARAM_TYPENAME).as(String.class));
if (getLast_name() == null || !(getLast_name().equals(name))) {
TypeDefinition type = ((InstanceReader) p).getSourceSchema().getType(name);
CSVConfiguration config = type.getConstraint(CSVConfiguration.class);
String sep = String.valueOf(config.getSeparator());
if (getBmap().inverse().get(sep) != null) {
getSeparator().setText(getBmap().inverse().get(sep));
} else {
getSeparator().setText(sep);
}
String qu = String.valueOf(config.getQuote());
if (getBmap().inverse().get(qu) != null) {
getQuote().setText(getBmap().inverse().get(qu));
} else {
getQuote().setText(qu);
}
String esc = String.valueOf(config.getEscape());
if (getBmap().inverse().get(esc) != null) {
getSeparator().setText(getBmap().inverse().get(esc));
} else {
getEscape().setText(esc);
}
setLast_name(name);
}
}
setPageComplete(true);
}
use of eu.esdihumboldt.hale.common.core.io.IOProvider in project hale by halestudio.
the class ReadInstanceConfigurationPage method onShowPage.
/**
* @see HaleWizardPage#onShowPage(boolean)
*/
@Override
protected void onShowPage(boolean firstShow) {
super.onShowPage(firstShow);
IOProvider p = getWizard().getProvider();
QName name = QName.valueOf(p.getParameter(CommonSchemaConstants.PARAM_TYPENAME).as(String.class));
if (getLast_name() == null || !(getLast_name().equals(name))) {
TypeDefinition type = ((InstanceReader) p).getSourceSchema().getType(name);
CSVConfiguration config = type.getConstraint(CSVConfiguration.class);
String sep = String.valueOf(config.getSeparator());
if (getBmap().inverse().get(sep) != null) {
getSeparator().setText(getBmap().inverse().get(sep));
} else {
getSeparator().setText(sep);
}
String qu = String.valueOf(config.getQuote());
if (getBmap().inverse().get(qu) != null) {
getQuote().setText(getBmap().inverse().get(qu));
} else {
getQuote().setText(qu);
}
String esc = String.valueOf(config.getEscape());
if (getBmap().inverse().get(esc) != null) {
getSeparator().setText(getBmap().inverse().get(esc));
} else {
getEscape().setText(esc);
}
setLast_name(name);
}
setPageComplete(true);
}
use of eu.esdihumboldt.hale.common.core.io.IOProvider in project hale by halestudio.
the class ProjectResourcesUtil method executeConfiguration.
/**
* Execute a single I/O configuration with a custom advisor.
*
* @param conf the I/O configuration
* @param customAdvisor the custom advisor to use or <code>null</code>
* @param publishReport if the report should be published
* @param cacheCallback call back that is notified on cache changes for the
* I/O configuration, may be <code>null</code>
*/
public static void executeConfiguration(IOConfiguration conf, IOAdvisor<?> customAdvisor, boolean publishReport, CacheCallback cacheCallback) {
// get provider ...
IOProvider provider = null;
IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (descriptor != null) {
try {
provider = descriptor.createExtensionObject();
} catch (Exception e) {
log.error(MessageFormat.format("Could not execute I/O configuration, provider with ID {0} could not be created.", conf.getProviderId()), e);
return;
}
// ... and advisor
final String actionId = conf.getActionId();
IOAdvisor<?> advisor = customAdvisor;
if (advisor == null) {
List<IOAdvisorFactory> advisors = IOAdvisorExtension.getInstance().getFactories(new FactoryFilter<IOAdvisor<?>, IOAdvisorFactory>() {
@Override
public boolean acceptFactory(IOAdvisorFactory factory) {
return factory.getActionID().equals(actionId);
}
@Override
public boolean acceptCollection(ExtensionObjectFactoryCollection<IOAdvisor<?>, IOAdvisorFactory> collection) {
return true;
}
});
if (advisors != null && !advisors.isEmpty()) {
try {
advisor = advisors.get(0).createAdvisor(actionId, HaleUI.getServiceProvider());
} catch (Exception e) {
log.error(MessageFormat.format("Could not execute I/O configuration, advisor with ID {0} could not be created.", advisors.get(0).getIdentifier()), e);
return;
}
}
}
if (advisor != null) {
// configure settings
provider.loadConfiguration(conf.getProviderConfiguration());
if (provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setCache(conf.getCache());
}
// execute provider
executeProvider(provider, advisor, publishReport, cacheCallback);
} else {
log.error(MessageFormat.format("Could not execute I/O configuration, no advisor for action {0} found.", actionId));
}
} else {
log.error(MessageFormat.format("Could not execute I/O configuration, provider with ID {0} not found.", conf.getProviderId()));
}
}
Aggregations