Search in sources :

Example 56 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project drools by kiegroup.

the class SplitFunction method invoke.

public FEELFnResult<List<String>> invoke(@ParameterName("input") String input, @ParameterName("delimiter") String delimiter, @ParameterName("flags") String flags) {
    if (input == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "input", "cannot be null"));
    }
    if (delimiter == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "delimiter", "cannot be null"));
    }
    try {
        int f = processFlags(flags);
        Pattern p = Pattern.compile(delimiter, f);
        String[] split = p.split(input);
        return FEELFnResult.ofResult(Arrays.asList(split));
    } catch (PatternSyntaxException e) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "delimiter", "is invalid and can not be compiled", e));
    } catch (IllegalArgumentException t) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "flags", "contains unknown flags", t));
    } catch (Throwable t) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "delimiter", "is invalid and can not be compiled", t));
    }
}
Also used : Pattern(java.util.regex.Pattern) InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 57 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project checker-framework by typetools.

the class RegexUtil method asRegex.

/**
 * Returns the argument as a {@code @Regex(groups) String} if it is a regex with at least the
 * given number of groups, otherwise throws an error. The purpose of this method is to suppress
 * Regex Checker warnings. It should be very rarely needed.
 *
 * @param s string to check for being a regular expression
 * @param groups number of groups expected
 * @return its argument
 * @throws Error if argument is not a regex
 */
// RegexUtil
@SuppressWarnings("regex")
@SideEffectFree
// RegexAnnotatedTypeFactory.
@Regex
public static String asRegex(String s, int groups) {
    try {
        Pattern p = Pattern.compile(s);
        int actualGroups = getGroupCount(p);
        if (actualGroups < groups) {
            throw new Error(regexErrorMessage(s, groups, actualGroups));
        }
        return s;
    } catch (PatternSyntaxException e) {
        throw new Error(e);
    }
}
Also used : Pattern(java.util.regex.Pattern) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 58 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project checker-framework by typetools.

the class RegexUtil method regexException.

/**
 * Returns null if the argument is a syntactically valid regular expression with at least the
 * given number of groups. Otherwise returns a PatternSyntaxException describing why the
 * argument is not a regex.
 *
 * @param s string to check for being a regular expression
 * @param groups number of groups expected
 * @return null, or a PatternSyntaxException describing why the argument is not a regex
 */
// RegexUtil
@SuppressWarnings("regex")
@SideEffectFree
@Nullable
public static PatternSyntaxException regexException(String s, int groups) {
    try {
        Pattern p = Pattern.compile(s);
        int actualGroups = getGroupCount(p);
        if (actualGroups < groups) {
            return new PatternSyntaxException(regexErrorMessage(s, groups, actualGroups), s, -1);
        }
    } catch (PatternSyntaxException pse) {
        return pse;
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 59 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project pentaho-platform by pentaho.

the class ProxyTrustingFilter method isTrusted.

boolean isTrusted(final String addr) {
    if (trustedIpAddrs != null) {
        for (String element : trustedIpAddrs) {
            if (element.equals(addr)) {
                return (true);
            }
            // Reuse an pattern for this element
            Pattern pat = ipPatterns.get(element);
            if (pat == null) {
                // first one created, put it in the map for re-use
                try {
                    pat = Pattern.compile(element);
                    ipPatterns.put(element, pat);
                } catch (PatternSyntaxException ignored) {
                    continue;
                }
            }
            Matcher matcher = pat.matcher(addr);
            if (matcher.find()) {
                return (true);
            }
        }
    }
    return (false);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 60 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project acs-community-packaging by Alfresco.

the class HTTPRequestAuthenticationFilter method init.

public void init(FilterConfig config) throws ServletException {
    // Save the context
    this.context = config.getServletContext();
    // Setup the authentication context
    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    authComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authenticationService = (AuthenticationService) ctx.getBean("AuthenticationService");
    httpServletRequestAuthHeaderName = config.getInitParameter("httpServletRequestAuthHeaderName");
    if (httpServletRequestAuthHeaderName == null) {
        httpServletRequestAuthHeaderName = "x-user";
    }
    this.authPatternString = config.getInitParameter("authPatternString");
    if (this.authPatternString != null) {
        try {
            authPattern = Pattern.compile(this.authPatternString);
        } catch (PatternSyntaxException e) {
            logger.warn("Invalid pattern: " + this.authPatternString, e);
            authPattern = null;
        }
    }
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext) 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