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));
}
}
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);
}
}
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;
}
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);
}
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;
}
}
}
Aggregations