use of org.knime.base.node.io.listfiles.ListFiles.Filter in project knime-core by knime.
the class ListFilesNodeDialog method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
// check if all entered Locations are valid
String location = m_locations.getEditor().getItem().toString();
if (location.trim().isEmpty()) {
throw new InvalidSettingsException("Please select a file!");
}
String[] files = location.split(";");
for (int i = 0; i < files.length; i++) {
File currentFile = new File(files[i]);
if (!currentFile.isDirectory()) {
// check if it was an URL;
String s = files[i];
try {
if (s.startsWith("file:")) {
s = s.substring(5);
}
currentFile = new File(URIUtil.decode(s));
} catch (URIException ex) {
throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory", ex);
}
if (!currentFile.isDirectory()) {
throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory");
}
}
}
ListFilesSettings set = new ListFilesSettings();
set.setLocationString(location);
set.setRecursive(m_recursive.isSelected());
set.setCaseSensitive(m_caseSensitive.isSelected());
String extensions = m_extensionField.getEditor().getItem().toString();
set.setExtensionsString(extensions);
// save the selected radio-Button
Filter filter;
if (m_filterALLRadio.isSelected()) {
filter = Filter.None;
} else if (m_filterExtensionsRadio.isSelected()) {
filter = Filter.Extensions;
} else if (m_filterRegExpRadio.isSelected()) {
if (extensions.trim().isEmpty()) {
throw new InvalidSettingsException("Enter valid regular expressin pattern");
}
try {
String pattern = extensions;
Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
throw new InvalidSettingsException("Error in pattern: ('" + pse.getMessage(), pse);
}
filter = Filter.RegExp;
} else if (m_filterWildCardsRadio.isSelected()) {
if ((extensions).length() <= 0) {
throw new InvalidSettingsException("Enter valid wildcard pattern");
}
try {
String pattern = extensions;
pattern = WildcardMatcher.wildcardToRegex(pattern);
Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
throw new InvalidSettingsException("Error in pattern: '" + pse.getMessage(), pse);
}
filter = Filter.Wildcards;
} else {
// one button must be selected though
filter = Filter.None;
}
set.setFilter(filter);
set.saveSettingsTo(settings);
}
use of org.knime.base.node.io.listfiles.ListFiles.Filter in project GenericKnimeNodes by genericworkflownodes.
the class ListDirectoryConfiguration method loadSettingsInDialog.
/**
* Load the configuration.
*
* @param settings The <code>NodeSettings</code> to read from
*/
void loadSettingsInDialog(final NodeSettingsRO settings) {
m_directory = settings.getString(LOCATION_SETTINGS, "");
m_extensionsString = settings.getString(EXTENSION_SETTINGS, "");
m_expressionsString = settings.getString(EXPRESSIONS_SETTINGS, "");
m_recursive = settings.getBoolean(RECURSIVE_SETTINGS, true);
final Filter defFilter = Filter.None;
String filterS = settings.getString(FILTER_SETTINGS, defFilter.name());
if (filterS == null) {
filterS = defFilter.name();
}
try {
m_filter = Filter.valueOf(filterS);
} catch (IllegalArgumentException iae) {
m_filter = defFilter;
}
m_caseSensitive = settings.getBoolean(CASE_SENSITIVE_STRING, false);
}
use of org.knime.base.node.io.listfiles.ListFiles.Filter in project knime-core by knime.
the class ListFilesSettings method loadSettingsInDialog.
/**
* Load settings in dialog (no fail).
*
* @param settings To load from.
*/
protected void loadSettingsInDialog(final NodeSettingsRO settings) {
m_locationString = settings.getString(LOCATION_SETTINGS, "");
m_extensionsString = settings.getString(EXTENSIONS_SETTINGS, "");
m_recursive = settings.getBoolean(RECURSIVE_SETTINGS, false);
final Filter defFilter = Filter.None;
String filterS = settings.getString(FILTER_SETTINGS, defFilter.name());
if (filterS == null) {
filterS = defFilter.name();
}
try {
m_filter = Filter.valueOf(filterS);
} catch (IllegalArgumentException iae) {
m_filter = defFilter;
}
m_caseSensitive = settings.getBoolean(CASE_SENSITIVE_STRING, false);
}
use of org.knime.base.node.io.listfiles.ListFiles.Filter in project GenericKnimeNodes by genericworkflownodes.
the class MimeDirectoryImporterNodeDialog method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
ListDirectoryConfiguration config = new ListDirectoryConfiguration();
// Set setting only from the correct panel
if (m_connectionInformation != null) {
config.setDirectory(m_directory.getSelection());
} else {
config.setDirectory(m_localdirectory.getSelectedFile());
}
config.setRecursive(m_recursive.isSelected());
config.setCaseSensitive(m_caseSensitive.isSelected());
String extension = m_extensionField.getEditor().getItem().toString();
config.setExtensionsString(extension);
String expression = m_expressionField.getEditor().getItem().toString();
config.setExpressionsString(expression);
// save the selected radio-Button
Filter filter;
if (m_filterALLRadio.isSelected()) {
filter = Filter.None;
} else if (m_filterRegExpRadio.isSelected()) {
if (expression.trim().isEmpty()) {
throw new InvalidSettingsException("Enter valid regular expressin pattern");
}
try {
String pattern = expression;
Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
throw new InvalidSettingsException("Error in pattern: ('" + pse.getMessage(), pse);
}
filter = Filter.RegExp;
} else if (m_filterWildCardsRadio.isSelected()) {
if ((expression).length() <= 0) {
throw new InvalidSettingsException("Enter valid wildcard pattern");
}
try {
String pattern = expression;
pattern = WildcardMatcher.wildcardToRegex(pattern);
Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
throw new InvalidSettingsException("Error in pattern: '" + pse.getMessage(), pse);
}
filter = Filter.Wildcards;
} else {
// one button must be selected though
filter = Filter.None;
}
config.setFilter(filter);
if (extension.isEmpty() | !extension.startsWith(".")) {
throw new InvalidSettingsException("Enter valid extension");
}
config.saveSettingsTo(settings);
m_localdirectory.addToHistory();
}
use of org.knime.base.node.io.listfiles.ListFiles.Filter in project GenericKnimeNodes by genericworkflownodes.
the class MimeDirectoryImporterNodeModel method filterFiles.
/**
* @param files
* @return
*/
private RemoteFile<? extends Connection>[] filterFiles(final RemoteFile<? extends Connection>[] files) {
String extString = m_configuration.getExtensionsString();
String expString = m_configuration.getExpressionsString();
Filter filter = m_configuration.getFilter();
m_extension = extString;
switch(filter) {
case None:
break;
case RegExp:
// no break;
case Wildcards:
String patternS;
if (filter.equals(Filter.Wildcards)) {
patternS = WildcardMatcher.wildcardToRegex(expString);
} else {
patternS = expString;
}
if (m_configuration.isCaseSensitive()) {
m_regExpPattern = Pattern.compile(patternS);
} else {
m_regExpPattern = Pattern.compile(patternS, Pattern.CASE_INSENSITIVE);
}
break;
default:
throw new IllegalStateException("Unknown filter: " + filter);
}
m_analyzedFiles = 0;
m_currentRowID = 0;
List<RemoteFile<? extends Connection>> filteredFiles = new ArrayList<RemoteFile<? extends Connection>>();
for (RemoteFile<?> f : files) {
try {
if (f.isDirectory() || satisfiesFilter(f.getName())) {
filteredFiles.add(f);
}
} catch (Exception e) {
// catch or throw?
}
}
return filteredFiles.toArray(new RemoteFile[filteredFiles.size()]);
}
Aggregations