use of java.util.regex.PatternSyntaxException in project stocator by SparkTC.
the class ObjectStoreGlobFilter method init.
void init(String filePattern, PathFilter filter) throws IOException {
try {
userFilter = filter;
pattern = new GlobPattern(filePattern);
} catch (PatternSyntaxException e) {
throw new IOException("Illegal file pattern: " + e.getMessage(), e);
}
}
use of java.util.regex.PatternSyntaxException 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 java.util.regex.PatternSyntaxException in project knime-core by knime.
the class LineReaderConfig method loadConfigurationInModel.
/**
* Load configuration in NodeModel.
* @param settings To load from.
* @throws InvalidSettingsException If invalid.
*/
final void loadConfigurationInModel(final NodeSettingsRO settings) throws InvalidSettingsException {
m_url = settings.getString(CFG_URL);
m_rowPrefix = settings.getString("rowPrefix");
if (m_rowPrefix == null) {
throw new InvalidSettingsException("Invalid (null) row prefix");
}
m_columnHeader = settings.getString("columnHeader");
if (m_columnHeader == null || m_columnHeader.length() == 0) {
throw new InvalidSettingsException("Invalid (empty) column header");
}
m_skipEmptyLines = settings.getBoolean("skipEmptyLines");
m_limitRowCount = settings.getInt("limitRowCount");
m_regex = settings.getString("regex", "");
if (!"".equals(m_regex)) {
try {
Pattern.compile(m_regex);
} catch (PatternSyntaxException e) {
throw new InvalidSettingsException("Invalid Regex: " + m_regex, e);
}
}
}
use of java.util.regex.PatternSyntaxException 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_localdirectory.getSelectedFile();
if (location.trim().isEmpty()) {
throw new InvalidSettingsException("Please select a file!");
}
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);
m_localdirectory.addToHistory();
}
use of java.util.regex.PatternSyntaxException in project knime-core by knime.
the class PatternAggregationTableModel method updateRegex.
private void updateRegex(final int row, final String pattern, final boolean isRegex, final PatternAggregator old) {
// create a new operator each time it is updated to guarantee that
// each column has its own operator instance
final AggregationMethod methodClone = AggregationMethods.getMethod4Id(old.getMethodTemplate().getId());
final PatternAggregator regexAggregator = new PatternAggregator(pattern, isRegex, methodClone, old.inclMissingCells());
if (!regexAggregator.isValid()) {
try {
Pattern.compile(pattern);
} catch (PatternSyntaxException e) {
final Component root = SwingUtilities.getRoot(m_panel);
JOptionPane.showMessageDialog(root, "<html><body><p>Invalid regular expression:</p><p>" + pattern + "</p><p>" + e.getDescription() + " at position " + e.getIndex() + "</p>", "Invalid regular expression", JOptionPane.ERROR_MESSAGE);
}
}
updateRow(row, regexAggregator);
}
Aggregations