Example usage for java.util.regex Pattern CASE_INSENSITIVE

List of usage examples for java.util.regex Pattern CASE_INSENSITIVE

Introduction

In this page you can find the example usage for java.util.regex Pattern CASE_INSENSITIVE.

Prototype

int CASE_INSENSITIVE

To view the source code for java.util.regex Pattern CASE_INSENSITIVE.

Click Source Link

Document

Enables case-insensitive matching.

Usage

From source file:me.ryandowling.allmightybot.data.Spam.java

public boolean shouldTakeAction(MessageEvent event) {
    String message = StringEscapeUtils.escapeJava(event.getMessage());

    if (this.pattern == null) {
        this.pattern = Pattern.compile(Pattern.quote(this.search), Pattern.CASE_INSENSITIVE);
    }//  ww  w .  j a va 2 s .com

    return this.pattern.matcher(message).find();
}

From source file:com.seajas.search.contender.service.modifier.ModifierFilterProcessor.java

/**
 * Process the given reader using this filter.
 * //from  ww w .  jav a2s .  com
 * @param filter
 * @param reader
 * @return Reader
 * @throws IOException
 */
public Reader process(final ModifierFilter filter, final Reader reader) throws IOException {
    StringBuffer stringBuffer = new StringBuffer();

    for (int c; (c = reader.read()) != -1;)
        stringBuffer.append((char) c);

    reader.close();

    if (!filter.getIsExpression()) {
        Pattern pattern = Pattern.compile(
                Pattern.quote(filter.getFragmentStart()) + ".*" + Pattern.quote(filter.getFragmentEnd()),
                Pattern.DOTALL | Pattern.CASE_INSENSITIVE);

        return new StringReader(
                pattern.matcher(stringBuffer).replaceAll(filter.getFragmentStart() + filter.getFragmentEnd()));
    } else {
        Matcher startMatcher = Pattern.compile(filter.getFragmentStart(), Pattern.CASE_INSENSITIVE)
                .matcher(stringBuffer),
                endMatcher = Pattern.compile(filter.getFragmentEnd(), Pattern.CASE_INSENSITIVE)
                        .matcher(stringBuffer);

        while (startMatcher.find() && endMatcher.find(startMatcher.end()))
            if (startMatcher.end() != endMatcher.start()) {
                stringBuffer.delete(startMatcher.end(), endMatcher.start());

                startMatcher.reset();
                endMatcher.reset();
            }

        // Store the result

        return new StringReader(stringBuffer.toString());
    }
}

From source file:de.berlios.jhelpdesk.web.tools.UserValidator.java

public void validate(Object user, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "errors.hduser.firstName");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "errors.hduser.lastName");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "login", "errors.hduser.login");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "errors.hduser.password");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "errors.hduser.email");

    User u = (User) user;// w  w  w  . ja  va 2  s . c  om
    String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
    CharSequence inputStr = u.getEmail();
    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (!matcher.matches()) {
        errors.rejectValue("email", "errors.hduser.email.invalid");
    }
    if (u.getUserRole() == null) {
        errors.rejectValue("userRole", "errors.hduser.userRole.notset");
    }
}

From source file:at.gv.egovernment.moa.id.protocols.oauth20.OAuth20Util.java

public static boolean isValidStateValue(String state) {
    Pattern urlPattern = Pattern.compile("javascript|<|>|&|;", Pattern.CASE_INSENSITIVE);
    Matcher matcher = urlPattern.matcher(state);
    return !matcher.find();
}

From source file:dev.maisentito.suca.commands.FourChanCommandHandler.java

private void searchCommand(MessageEvent event, String[] args) throws IOException {
    String seq = StringUtils.join(args, ' ', 2, args.length);
    Pattern pattern;//  ww  w .j a  v  a  2  s . c  om
    try {
        pattern = Pattern.compile(seq, Pattern.CASE_INSENSITIVE);
    } catch (PatternSyntaxException e) {
        pattern = null;
    }

    for (FourChan.Catalog.Page page : FourChan.getCatalog(args[1]).pages) {
        for (FourChan.Catalog.ThreadPreview thread : page.threads) {
            if ((thread == null) || (thread.com == null)) {
                continue;
            }

            thread.com = Jsoup.parseBodyFragment(thread.com).text();

            if (pattern != null) {
                if (pattern.matcher(thread.com).find()) {
                    event.respond("match found: " + threadUrl(args[1], thread.no));
                    return;
                }
            } else {
                if (thread.com.contains(seq)) {
                    event.respond("match found: " + threadUrl(args[1], thread.no));
                    return;
                }
            }
        }
    }

    event.respond("no matches found");
}

From source file:com.doculibre.constellio.feedprotocol.model.impl.FeedImpl.java

public FeedImpl(String datasource, String feedtype, List<FeedGroup> groups) throws ParseFeedException {
    if (StringUtils.isBlank(datasource)) {
        throw new ParseFeedException("Blank datasource");
    }/*from  w  w w  .  j a v  a2s  . c  om*/
    Matcher matcher = Pattern.compile(REGEX_VALIDATION, Pattern.CASE_INSENSITIVE).matcher(datasource);
    if (!matcher.find()) {
        throw new ParseFeedException("Invalid name format (" + REGEX_VALIDATION + ") for datasource");
    }
    this.datasource = datasource;

    if (StringUtils.isBlank(feedtype)) {
        throw new ParseFeedException("Blank feedType");
    } else if (feedtype.equals(FULL)) {
        this.feedtype = FEEDTYPE.FULL;
    } else if (feedtype.equals(INCREMENTAL)) {
        this.feedtype = FEEDTYPE.INCREMENTAL;
    } else if (feedtype.equals(METADATA_AND_URL)) {
        this.feedtype = FEEDTYPE.METADATA_AND_URL;
    } else {
        throw new ParseFeedException("Invalid feedType: " + feedtype);
    }

    if (CollectionUtils.isEmpty(groups)) {
        throw new ParseFeedException("Groups is empty");
    }
    List<FeedGroup> groupsTemp = new ArrayList<FeedGroup>();
    groupsTemp.addAll(groups);
    this.groups = Collections.unmodifiableList(groupsTemp);
}

From source file:com.redhat.lightblue.eval.RegexEvaluator.java

/**
 * Constructs evaluator for {field op value} style comparison
 *
 * @param expr The expression//w w w  .j a va2 s .  com
 * @param md Entity metadata
 * @param context The path relative to which the expression will be
 * evaluated
 */
public RegexEvaluator(RegexMatchExpression expr, FieldTreeNode context) {
    this.relativePath = expr.getField();
    fieldMd = context.resolve(relativePath);
    if (fieldMd == null) {
        throw new EvaluationError(expr, CrudConstants.ERR_FIELD_NOT_THERE + relativePath);
    }
    int flags = 0;
    if (expr.isCaseInsensitive()) {
        flags |= Pattern.CASE_INSENSITIVE;
    }
    if (expr.isMultiline()) {
        flags |= Pattern.MULTILINE;
    }
    if (expr.isExtended()) {
        flags |= Pattern.COMMENTS;
    }
    if (expr.isDotAll()) {
        flags |= Pattern.DOTALL;
    }
    regex = Pattern.compile(expr.getRegex(), flags);
    LOGGER.debug("ctor {} {}", relativePath, regex);
}

From source file:org.energyos.espi.thirdparty.web.filter.CORSFilter.java

public void init(FilterConfig cfg) throws ServletException {

    // Process origin parameters
    String regex = cfg.getInitParameter("allow.origin.regex");
    if (regex != null) {
        allowOriginRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    } else {//from  ww  w . j  a  va  2s.  co  m
        allowOrigin = cfg.getInitParameter("allow.origin");
        if (allowOrigin != null) {
            optionsHeaders.put("Access-Control-Allow-Origin", allowOrigin);
        }
    }

    // Process optional header parameters
    for (Enumeration<String> i = cfg.getInitParameterNames(); i.hasMoreElements();) {
        String name = i.nextElement();
        if (name.startsWith("header:")) {
            optionsHeaders.put(name.substring(7), cfg.getInitParameter(name));
        }
    }

    // Process Credential support parameter
    allowCredentials = cfg.getInitParameter("allow.credentials");

    // Process Expose header parameter
    exposeHeaders = cfg.getInitParameter("expose.headers");

    // Initialize default header values
    optionsHeaders.put("Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type");
    optionsHeaders.put("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    optionsHeaders.put("Access-Control-Max-Age", "1800");

}

From source file:Main.java

public static Pattern compilePattern(String key, boolean ignoreCase) {
    StringTokenizer stk = new StringTokenizer(key, "*?", true);
    StringBuilder regex = new StringBuilder();
    while (stk.hasMoreTokens()) {
        String tk = stk.nextToken();
        char ch1 = tk.charAt(0);
        if (ch1 == '*') {
            regex.append(".*");
        } else if (ch1 == '?') {
            regex.append(".");
        } else {/* w w  w  . j  a va  2 s. c o m*/
            regex.append("\\Q").append(tk).append("\\E");
        }
    }
    return Pattern.compile(regex.toString(), ignoreCase ? Pattern.CASE_INSENSITIVE : 0);
}

From source file:com.redhat.utils.RegexFullPathnameFileFilter.java

public RegexFullPathnameFileFilter(final String pattern, final IOCase caseSensitivity) {
    if (pattern == null) {
        throw new IllegalArgumentException("Pattern is missing");
    }/*from  w  w  w  . ja v  a 2  s  . c om*/
    int flags = 0;
    if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) {
        flags = Pattern.CASE_INSENSITIVE;
    }
    this.pattern = Pattern.compile(pattern, flags);
}