Search in sources :

Example 51 with PatternSyntaxException

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);
    }
}
Also used : GlobPattern(org.apache.hadoop.fs.GlobPattern) IOException(java.io.IOException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 52 with PatternSyntaxException

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);
}
Also used : URIException(org.apache.commons.httpclient.URIException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Filter(org.knime.base.node.io.listfiles.ListFiles.Filter) File(java.io.File) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 53 with PatternSyntaxException

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);
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 54 with PatternSyntaxException

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();
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Filter(org.knime.base.node.io.listfiles2.ListFiles.Filter) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 55 with PatternSyntaxException

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);
}
Also used : AggregationMethod(org.knime.base.data.aggregation.AggregationMethod) Component(java.awt.Component) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

PatternSyntaxException (java.util.regex.PatternSyntaxException)355 Pattern (java.util.regex.Pattern)190 Matcher (java.util.regex.Matcher)115 ArrayList (java.util.ArrayList)46 IOException (java.io.IOException)25 List (java.util.List)19 File (java.io.File)14 Map (java.util.Map)12 HashMap (java.util.HashMap)9 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Iterator (java.util.Iterator)7 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 BufferedReader (java.io.BufferedReader)6 Collection (java.util.Collection)6 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)5 InputStreamReader (java.io.InputStreamReader)4 SQLException (java.sql.SQLException)4 LinkedHashMap (java.util.LinkedHashMap)4