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.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientUtil.java

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

    if (rps.isEnabled()) {
        logger(logger).info("... proxy setup with host '{}'", rps.getHostname());

        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(logger).warn("Invalid non proxy host regex: {}", nonProxyHostRegex, e);
                }//  w  w  w  .  java  2  s  .  c om
            }
            httpClient.setRoutePlanner(new NonProxyHostsAwareHttpRoutePlanner(
                    httpClient.getConnectionManager().getSchemeRegistry(), nonProxyHostPatterns));

        }

        configureAuthentication(httpClient, ctxPrefix, ctx, rps.getProxyAuthentication(), logger, "proxy ");

        if (rps.getProxyAuthentication() != null) {
            if (ctx.getRemoteAuthenticationSettings() != null
                    && (ctx.getRemoteAuthenticationSettings() instanceof NtlmRemoteAuthenticationSettings)) {
                logger(logger).warn("... Apache Commons HttpClient 3.x is unable to use NTLM auth scheme\n"
                        + " for BOTH server side and proxy side authentication!\n"
                        + " You MUST reconfigure server side auth and use BASIC/DIGEST scheme\n"
                        + " if you have to use NTLM proxy, otherwise it will not work!\n"
                        + " *** SERVER SIDE AUTH OVERRIDDEN");
            }

        }
    }
}

From source file:com.doculibre.constellio.services.ACLServicesImpl.java

private boolean matches(Record record, PolicyACLEntry entry, Collection<ConstellioGroup> groups,
        Collection<ConstellioUser> users) {
    boolean match = false;

    IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices();
    IndexField indexField = entry.getIndexField();
    String regexp = entry.getMatchRegexp();

    List<Object> fieldValues = indexFieldServices.extractFieldValues(record, indexField);
    for (Object fieldValue : fieldValues) {
        Pattern pattern = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(fieldValue.toString());
        if (matcher.find()) {
            if (groups != null || users != null) {
                if (groups != null && CollectionUtils.containsAny(entry.getGroups(), groups)) {
                    match = true;/*from  w w  w .j  a  va 2s  .  c o m*/
                    break;
                } else if (users != null && CollectionUtils.containsAny(entry.getUsers(), users)) {
                    match = true;
                    break;
                }
            } else {
                match = true;
                break;
            }
        }
    }
    return match;
}

From source file:org.opencron.common.utils.StringUtils.java

public static String HtmlToTextGb2312(String inputString) {
    if (inputString == null || "".equals(inputString)) {
        return "";
    }//  w  w  w .  j av  a 2 s .c  o  m
    String htmlStr = inputString; // ?html
    String textStr = "";
    Pattern p_script;
    Matcher m_script;
    Pattern p_style;
    Matcher m_style;
    Pattern p_html;
    Matcher m_html;
    Pattern p_houhtml;
    Matcher m_houhtml;
    Pattern p_spe;
    Matcher m_spe;
    Pattern p_blank;
    Matcher m_blank;
    Pattern p_table;
    Matcher m_table;
    Pattern p_enter;
    Matcher m_enter;

    try {
        String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?/[\\s]*?script[\\s]*?>";
        // script?.
        String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?/[\\s]*?style[\\s]*?>";
        // style?.
        String regEx_html = "<[^>]+>";
        // HTML?
        String regEx_houhtml = "/[^>]+>";
        // HTML?
        String regEx_spe = "\\&[^;]+;";
        // ??
        String regEx_blank = " +";
        // ?
        String regEx_table = "\t+";
        // ?
        String regEx_enter = "\n+";
        // ?

        p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
        m_script = p_script.matcher(htmlStr);
        htmlStr = m_script.replaceAll(""); // script

        p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
        m_style = p_style.matcher(htmlStr);
        htmlStr = m_style.replaceAll(""); // style

        p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
        m_html = p_html.matcher(htmlStr);
        htmlStr = m_html.replaceAll(""); // html

        p_houhtml = Pattern.compile(regEx_houhtml, Pattern.CASE_INSENSITIVE);
        m_houhtml = p_houhtml.matcher(htmlStr);
        htmlStr = m_houhtml.replaceAll(""); // html

        p_spe = Pattern.compile(regEx_spe, Pattern.CASE_INSENSITIVE);
        m_spe = p_spe.matcher(htmlStr);
        htmlStr = m_spe.replaceAll(""); // ?

        p_blank = Pattern.compile(regEx_blank, Pattern.CASE_INSENSITIVE);
        m_blank = p_blank.matcher(htmlStr);
        htmlStr = m_blank.replaceAll(" "); // 

        p_table = Pattern.compile(regEx_table, Pattern.CASE_INSENSITIVE);
        m_table = p_table.matcher(htmlStr);
        htmlStr = m_table.replaceAll(" "); // 

        p_enter = Pattern.compile(regEx_enter, Pattern.CASE_INSENSITIVE);
        m_enter = p_enter.matcher(htmlStr);
        htmlStr = m_enter.replaceAll(" "); // 

        textStr = htmlStr;

    } catch (Exception e) {
        System.err.println("Html2Text: " + e.getMessage());
    }

    return textStr;// 
}

From source file:com.dragoniade.deviantart.deviation.SearchStream.java

public List<Collection> getCollections() {
    List<Collection> collections = new ArrayList<Collection>();

    if (search.getCollection() == null) {
        collections.add(null);//from   w w  w  . j  av  a2 s  .co  m
        return collections;
    }

    String queryString = "http://" + user + ".deviantart.com/" + search.getCollection() + "/";
    GetMethod method = new GetMethod(queryString);

    try {
        int sc = -1;
        do {
            sc = client.executeMethod(method);
            if (sc != 200) {
                LoggableException ex = new LoggableException(method.getResponseBodyAsString());
                Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex);

                int res = DialogHelper.showConfirmDialog(owner,
                        "An error has occured when contacting deviantART : error " + sc + ". Try again?",
                        "Continue?", JOptionPane.YES_NO_OPTION);
                if (res == JOptionPane.NO_OPTION) {
                    return null;
                }
            }
        } while (sc != 200);

        InputStream is = method.getResponseBodyAsStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte[] buffer = new byte[4096];
        int read = -1;
        while ((read = is.read(buffer)) > -1) {
            baos.write(buffer, 0, read);
        }
        String charsetName = method.getResponseCharSet();
        String body = baos.toString(charsetName);
        String regex = user + ".deviantart.com/" + search.getCollection() + "/([0-9]+)\"[^>]*>([^<]+)<";
        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(body);
        while (matcher.find()) {
            String id = matcher.group(1);
            String name = matcher.group(2);
            Collection c = new Collection(Long.parseLong(id), name);
            collections.add(c);
        }
    } catch (IOException e) {
    } finally {
        method.releaseConnection();
    }
    collections.add(null);
    return collections;
}

From source file:com.eryansky.common.utils.StringUtils.java

/**
 * hrefinnerHtml/*from  w w w. j a  v a  2  s . c  o  m*/
 * 
 * @param href href
 * @return hrefinnerHtml
 *         <ul>
 *         <li>""</li>
 *         <li>???</li>
 *         <li>???innerHtml</li>
 *         </ul>
 * @see
 * <pre>
 *      getHrefInnerHtml(null)                                  = ""
 *      getHrefInnerHtml("")                                    = ""
 *      getHrefInnerHtml("mp3")                                 = "mp3";
 *      getHrefInnerHtml("&lt;a innerHtml&lt;/a&gt;")                    = "&lt;a innerHtml&lt;/a&gt;";
 *      getHrefInnerHtml("&lt;a&gt;innerHtml&lt;/a&gt;")                    = "innerHtml";
 *      getHrefInnerHtml("&lt;a&lt;a&gt;innerHtml&lt;/a&gt;")                    = "innerHtml";
 *      getHrefInnerHtml("&lt;a href="baidu.com"&gt;innerHtml&lt;/a&gt;")               = "innerHtml";
 *      getHrefInnerHtml("&lt;a href="baidu.com" title="baidu"&gt;innerHtml&lt;/a&gt;") = "innerHtml";
 *      getHrefInnerHtml("   &lt;a&gt;innerHtml&lt;/a&gt;  ")                           = "innerHtml";
 *      getHrefInnerHtml("&lt;a&gt;innerHtml&lt;/a&gt;&lt;/a&gt;")                      = "innerHtml";
 *      getHrefInnerHtml("jack&lt;a&gt;innerHtml&lt;/a&gt;&lt;/a&gt;")                  = "innerHtml";
 *      getHrefInnerHtml("&lt;a&gt;innerHtml1&lt;/a&gt;&lt;a&gt;innerHtml2&lt;/a&gt;")        = "innerHtml2";
 * </pre>
 */
public static String getHrefInnerHtml(String href) {
    if (isEmpty(href)) {
        return "";
    }
    // String hrefReg = "[^(<a)]*<[\\s]*a[\\s]*[^(a>)]*>(.+?)<[\\s]*/a[\\s]*>.*";
    String hrefReg = ".*<[\\s]*a[\\s]*.*>(.+?)<[\\s]*/a[\\s]*>.*";
    Pattern hrefPattern = Pattern.compile(hrefReg, Pattern.CASE_INSENSITIVE);
    Matcher hrefMatcher = hrefPattern.matcher(href);
    if (hrefMatcher.matches()) {
        return hrefMatcher.group(1);
    }
    return href;
}

From source file:com.clustercontrol.process.factory.RunMonitorProcess.java

/**
 * ?????????<BR>/*  www.  jav  a2 s .co m*/
 * ?????? preCollect ?????
 * 
 * @param facilityId ID
 * @return ???????true
 */
@Override
public boolean collect(String facilityId) {

    if (m_log.isDebugEnabled())
        m_log.debug("collect() : start." + " facilityId = " + m_facilityId + ", monitorId = " + m_monitorId
                + ", monitorType = " + m_monitorTypeId);

    // ?,???
    int count = 0;

    // 
    if (m_now != null) {
        m_nodeDate = m_now.getTime();
    }
    m_value = 0;

    // 
    m_messageOrg = MessageConstant.COMMAND.getMessage() + " : " + m_command + ", "
            + MessageConstant.PARAM.getMessage() + " : " + m_param;

    // ???
    Pattern pCommand = null;
    Pattern pParam = null;
    try {
        // ?????
        if (m_process.getCaseSensitivityFlg()) {
            pCommand = Pattern.compile(m_command, Pattern.CASE_INSENSITIVE);
            pParam = Pattern.compile(m_param, Pattern.CASE_INSENSITIVE);
        }
        // ???
        else {
            pCommand = Pattern.compile(m_command);
            pParam = Pattern.compile(m_param);
        }
    } catch (PatternSyntaxException e) {
        m_log.info("collect() command, parameter PatternSyntax error : " + e.getClass().getSimpleName() + ", "
                + e.getMessage());
        m_message = MessageConstant.MESSAGE_PLEASE_SET_VALUE_WITH_REGEX.getMessage();
        return false;
    }

    @SuppressWarnings("unchecked")
    List<ProcessInfo> procList = (List<ProcessInfo>) preCollectData;

    if (procList == null) {
        // TODO nagatsumas ???OK
        // ??????????????
        return false;
    } else {
        // ??????????
        for (ProcessInfo procInfo : procList) {
            if (pCommand.matcher(procInfo.command).matches()) {
                if (pParam.matcher(procInfo.param).matches()) {
                    count++;
                    // ??
                    m_nodeDate = procInfo.time;
                    // ????
                    if (ProcessProperties.getProperties().isDetailedDisplay()) {
                        m_messageOrg = m_messageOrg + "\n";

                        if (procInfo.pid != null) {
                            // PID???????SNMP????
                            m_messageOrg = m_messageOrg + procInfo.pid + " : ";
                        }

                        m_messageOrg = m_messageOrg + procInfo.command + " " + procInfo.param;
                    }
                }
            }
        }
    }
    // 
    m_value = count;
    m_message = MessageConstant.PROCESS_NUMBER.getMessage() + " : "
            + NumberFormat.getNumberInstance().format(m_value);

    if (m_log.isDebugEnabled())
        m_log.debug("collect() : end." + " facilityId = " + m_facilityId + ", monitorId = " + m_monitorId
                + ", monitorType = " + m_monitorTypeId + ", count = " + count);

    return true;

    //      // ???????
    //      m_message = MessageConstant.MESSAGE_TIME_OUT.getMessage();
    //      return false;
}

From source file:de.mpg.mpdl.inge.syndication.feed.Feed.java

/**
 * Generate <code>UriMatcher</code> for the feed and list of the parameters <code>paramList</code>
 * according to the <code>uri</code>.
 * /*  w  w  w  .  j ava  2 s .  c om*/
 * @param uri
 */
public void generateUriMatcher(final String uri) {
    String result = new String(uri);

    result = escapeUri(result);

    // property regexp in uri
    String regexp = "(\\$\\{[\\w.]+?\\})";

    Matcher m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(uri);
    while (m.find()) {
        String param = m.group(1);
        paramList.add(param);
        result = result.replaceFirst(Utils.quoteReplacement(param), "\\(.+\\)?");
    }
    setUriMatcher(result);
}

From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java

/**
 * ()./* w w w  .  j  a  va2  s  .  c  om*/
 * 
 * @return
 * @author sunny
 * @create 2007-10-25 03:44:40
 */
public static String getAbsPathOfProject() {
    String url = CommonsFiend.class.getClassLoader().getResource("").toString();
    String reg = "file:(.+)WEB-INF";
    Matcher mat = Pattern.compile(reg, Pattern.CASE_INSENSITIVE).matcher(url);
    if (mat.find()) {
        String path = mat.group(1);
        path = path.replaceAll("/", "\\" + File.separator);
        if (File.separator.equals("\\"))// windows
            return path.substring(1);
        return path;
    }
    return null;
}

From source file:com.g3net.tool.StringUtils.java

public static int lastIndexOf(String srcStr, String regexp, boolean ignoreCase, TInteger endPos) {

    Pattern p = null;/*  w w  w.j  a  va2s.  c o  m*/
    if (ignoreCase) {
        p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
    } else {
        p = Pattern.compile(regexp);
    }
    Matcher m = p.matcher(srcStr);
    int end = -1;
    while (m.find()) {
        // log.info(m.group()+":"+m.start()+":"+m.end());
        end = m.start();
        endPos.setValue(m.end());
    }
    return end;
    // sql3.regionMatches(ignoreCase, toffset, other, ooffset, len)
    // log.info(m.matches());
}