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:org.onehippo.cms7.brokenlinks.CheckExternalBrokenLinksConfig.java

public Pattern[] getUrlExcludePatterns() {
    if (urlExcludes == null) {
        return EMPTY_PATTERN_ARRAY;
    }/* w  ww.  ja  va2 s .  c  o m*/

    if (urlExcludePatterns == null) {
        urlExcludePatterns = new Pattern[urlExcludes.length];

        GlobCompiler compiler = new GlobCompiler();

        for (int i = 0; i < urlExcludes.length; i++) {
            urlExcludePatterns[i] = compiler.compile(urlExcludes[i], Pattern.CASE_INSENSITIVE);
        }
    }

    return urlExcludePatterns;
}

From source file:org.sonatype.nexus.error.reporting.NexusPRConnector.java

private static void configureProxy(final DefaultHttpClient httpClient, final RemoteStorageContext ctx) {
    final RemoteProxySettings rps = ctx.getRemoteProxySettings();

    if (rps.isEnabled()) {
        final HttpHost proxy = new HttpHost(rps.getHostname(), rps.getPort());
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        // check if we have non-proxy hosts
        if (rps.getNonProxyHosts() != null && !rps.getNonProxyHosts().isEmpty()) {
            final Set<Pattern> nonProxyHostPatterns = new HashSet<Pattern>(rps.getNonProxyHosts().size());
            for (String nonProxyHostRegex : rps.getNonProxyHosts()) {
                try {
                    nonProxyHostPatterns.add(Pattern.compile(nonProxyHostRegex, Pattern.CASE_INSENSITIVE));
                } catch (PatternSyntaxException e) {
                    logger.warn("Invalid non proxy host regex: {}", nonProxyHostRegex, e);
                }/*from w  w w. j av  a  2s  .  co  m*/
            }
            httpClient.setRoutePlanner(new NonProxyHostsAwareHttpRoutePlanner(
                    httpClient.getConnectionManager().getSchemeRegistry(), nonProxyHostPatterns));
        }

        configureAuthentication(httpClient, rps.getHostname(), rps.getPort(), rps.getProxyAuthentication());
    }
}

From source file:org.motechproject.mobile.imp.serivce.oxd.FormDefinitionServiceImpl.java

private Integer extractFormId(String formDefinition) {
    Matcher matcher = Pattern.compile("<xf:xforms.*?id=\"(.*?)\"", Pattern.CASE_INSENSITIVE)
            .matcher(formDefinition);// w  ww. j  a  v a2s.  co m
    Integer formId = null;
    if (matcher.find()) {
        String formIdString = matcher.group(1);
        formId = Integer.valueOf(formIdString);
    }
    return formId;
}

From source file:apps.ParsedPost.java

private static String replace(String src, String pat, String repl, boolean bIgnoreCase) {
    Pattern p = bIgnoreCase/*from  w  ww  .  j  a  va2 s .  co m*/
            ? Pattern.compile(pat, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL)
            : Pattern.compile(pat, Pattern.MULTILINE | Pattern.DOTALL);
    Matcher m = p.matcher(src);

    return m.replaceAll(repl);
}

From source file:Main.java

/**
 * Converts the string flags to their pattern constants
 * @param flags/*from  w w w .j ava  2s .com*/
 * @return
 */
public static int convertFlagsToConstants(ArrayList<String> flags) {
    int ret = 0;
    for (String s : flags) {
        if (s.equals("i")) {
            ret |= Pattern.CASE_INSENSITIVE;
        } else if (s.equals("m")) {
            ret |= Pattern.MULTILINE;
        } else {
            ret |= Pattern.DOTALL;
        }
    }
    return ret;
}

From source file:eu.openanalytics.rsb.security.X509AuthenticationFilter.java

/**
 * Sets the regular expression which will by used to extract the user name from the
 * certificate's Subject DN./*from w  ww.  j a  v  a  2  s  . c o m*/
 * <p>
 * It should contain a single group; for example the default expression "CN=(.*?)(?:/|$)"
 * matches the common name field. So "CN=Jimi Hendrix/OU=..." will give a user name of
 * "Jimi Hendrix".
 * <p>
 * The matches are case insensitive. So "emailAddress=(.?)/" will match
 * "EMAILADDRESS=jimi@hendrix.org/CN=..." giving a user name "jimi@hendrix.org"
 * 
 * @param subjectDnRegex the regular expression to find in the subject
 */
public void setSubjectDnRegex(final String subjectDnRegex) {
    Assert.hasText(subjectDnRegex, "Regular expression may not be null or empty");
    subjectDnPattern = Pattern.compile(subjectDnRegex, Pattern.CASE_INSENSITIVE);
}

From source file:babel.content.pages.PageVersion.java

/**
 * Used to construct a page version from a set of nutch page related objects.
 * Should only be used by NutchPageExtractor.
 *//* w  w w  . j  a va 2  s . c o  m*/
public PageVersion(String segmentId, List<NutchChunk> chunks, Page page) {
    this();

    Writable curVal;
    CrawlDatum curCD;
    Content curCT;
    ParseData curPD;
    ParseText curPT;

    // Store Segment ID
    m_verProps.set(PROP_SEGMENT_ID, segmentId);

    // Unwrap all of the page related information
    for (NutchChunk chunk : chunks) {
        curVal = chunk.get();

        if (curVal instanceof CrawlDatum) {
            // Get fetch information
            curCD = (CrawlDatum) curVal;

            if (curCD.getStatus() == CrawlDatum.STATUS_FETCH_SUCCESS) {
                m_verProps.set(PROP_FETCH_TIME, Long.toString(curCD.getFetchTime()));
                m_verProps.set(PROP_MODIFIED_TIME, Long.toString(curCD.getModifiedTime()));
            }
        } else if (curVal instanceof Content) {
            // Get the original unparsed content
            curCT = (Content) curVal;

            try {
                String str = new String(curCT.getContent(), DEFAULT_CHARSET);
                Matcher m = Pattern.compile("<html[^>]*>", Pattern.CASE_INSENSITIVE).matcher(str);

                if (m.find()) {
                    str = str.substring(m.start(), m.end());
                    m = Pattern.compile("\\slang\\s*=\\s*\"*([^\\s=\"]+)\"*", Pattern.CASE_INSENSITIVE)
                            .matcher(str);

                    if (m.find()) {
                        str = str.substring(m.start(1), m.end(1)).trim().toLowerCase();
                        if (str.length() > 0) {
                            page.setLanguage(Language.fromString(str));
                        }
                    }
                }
            } catch (Exception e) {
            }
        } else if (curVal instanceof ParseData) {
            // Get data extracted from page content
            curPD = (ParseData) curVal;
            if (curPD.getStatus().isSuccess()) {
                m_verProps.set(PROP_TITLE, curPD.getTitle());
                m_parseMeta.setAll(curPD.getParseMeta());
                m_contentMeta.setAll(curPD.getContentMeta());
                m_outLinks = curPD.getOutlinks();
            }
        } else if (curVal instanceof ParseText) {
            // Get parsed content
            curPT = (ParseText) curVal;
            m_content = setStr(curPT.getText());
        } else if (LOG.isWarnEnabled()) {
            LOG.warn("Unrecognized type: " + curVal.getClass());
        }
    }
}

From source file:org.freaknet.gtrends.api.GoogleAuthenticator.java

/**
 * Parse the login page for the GALX id.
 *
 * @return GALX id/*from  ww w  . ja va  2 s  . co m*/
 * @throws GoogleAuthenticatorException
 */
private String galx() throws GoogleAuthenticatorException {
    String galx = null;
    HttpGet get;
    try {
        DataConfiguration config = GoogleConfigurator.getConfiguration();

        Pattern pattern = Pattern.compile(config.getString("google.auth.reGalx"), Pattern.CASE_INSENSITIVE);
        get = new HttpGet(config.getString("google.auth.loginUrl"));

        HttpResponse response = _httpClient.execute(get);
        String html = GoogleUtils.toString(response.getEntity().getContent());
        get.releaseConnection();
        Matcher matcher = pattern.matcher(html);
        if (matcher.find()) {
            galx = matcher.group(1);
        }

        if (galx == null) {
            throw new GoogleAuthenticatorException("Cannot parse GALX!");
        }
    } catch (ConfigurationException ex) {
        throw new GoogleAuthenticatorException(ex);
    } catch (ClientProtocolException ex) {
        throw new GoogleAuthenticatorException(ex);
    } catch (IOException ex) {
        throw new GoogleAuthenticatorException(ex);
    }

    //printCookies();

    return galx;
}

From source file:org.codhaus.groovy.grails.validation.routines.RegexValidator.java

/**
 * Construct a validator that matches any one of the set of regular
 * expressions with the specified case sensitivity.
 *
 * @param regexs The set of regular expressions this validator will
 * validate against//from   w w  w.j a  va  2  s.co  m
 * @param caseSensitive when <code>true</code> matching is <i>case
 * sensitive</i>, otherwise matching is <i>case in-sensitive</i>
 */
public RegexValidator(String[] regexs, boolean caseSensitive) {
    Assert.isTrue(regexs != null && regexs.length > 0, "Regular expressions are missing");

    patterns = new Pattern[regexs.length];
    int flags = (caseSensitive ? 0 : Pattern.CASE_INSENSITIVE);
    for (int i = 0; i < regexs.length; i++) {
        if (regexs[i] == null || regexs[i].length() == 0) {
            throw new IllegalArgumentException("Regular expression[" + i + "] is missing");
        }
        patterns[i] = Pattern.compile(regexs[i], flags);
    }
}