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:mobi.jenkinsci.server.core.net.ProxyUtil.java

private String resolveJs(final String userAgent, final String pluginName, final String url,
        final String resultString) throws IOException {
    log.debug("Resolving JavaScript for URL " + url);
    final StringBuilder outString = new StringBuilder();
    int currPos = 0;
    final Pattern linkPattern = Pattern.compile(
            "<script>?[^>]*src=[\"\\']([^>\"\\']*)[\"\\']([^>]*/>|[^>]*>[ \r\n]*</script>)",
            Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    final Matcher matcher = linkPattern.matcher(resultString);
    while (matcher.find(currPos)) {
        final int start = matcher.start();
        final int end = matcher.end();
        outString.append(resultString.substring(currPos, start));
        final String cssUrl = matcher.group(1);
        final String jsText = retrieveJs(userAgent, pluginName, url, cssUrl);
        outString.append(jsText);//  w w w . j  a  v  a2  s.c  o  m
        currPos = end;
    }

    outString.append(resultString.substring(currPos));
    log.debug(outString.length() + " JavaScript chars included for URL " + url);
    return outString.toString();
}

From source file:com.age.core.orm.hibernate.HibernateDao.java

private static String removeOrders(String hql) {
    Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(hql);/*from ww  w .ja  va2 s  . co  m*/
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:fedroot.dacs.examples.ExampleRunner.java

private static void getCookiesWithEmail() {
    //        Pattern name = Pattern.compile("(DACS:[:\\w]+)=([-\\w]+)");
    //        Matcher m = name.matcher(cookieHeader);
    //        while (m.find()) {
    //            String cookieName = m.group(1);
    //            String cookieValue = m.group(2);
    //        }//w  ww  .  j av  a  2  s .c  om

    //        String test = "DACS:NFIS::CA:roderick.oneil-morrison@fedroot.com";
    String test = "JSESSIONID=fec51a10f955a26756e4d15d6eb2; DACS:FEDROOT::METALOGIC:rmorriso@fedroot.com=mIIKA5vrtLJgMxTG3UsrS4FBbQopZk1gxG4lDmuOUCL2w53n3wYoX2vdPBiF1K1xKOaEsyw3arq0PBnrxWNDLW0IP_O1jVJGAO14gWUNgkIFaEpdGLY3vOnXdZmCjYDTKLqAdzTJDm8GSHBjzr-XZvfokf_yrOnkYpFrxpZQgACEgMnPamqO4BUMeZcbWqo1_4TjxmzM5gWLKu1y0KwltG8QVLqfc4cCWfnakQuIT9VNDRnoyi79lh-RhIMugJGRJcICwlTEi5nlusrucooAk7_PP0kCEh2FMGJb03GR3Cj-yf6Ayh87KZpOuSNYPCyrmxW030bVLbsVHIlBdeMyvpmz5xJkqu-jfAuINlgqmKdY1p6jYkxsijI2s2lTJetIpkZnocnbSvU_RQSMezhLQWeVQu02clhDusMvjv3bMWfwNU7CiDhowXq8cSly5mLH6GhKH7iyP0; DACS:FEDROOT::DSS:brachman=mIIKA5vrtLJgMxTG3UsrS4FBbQopZk1gxG4lDmuOUCL2w53n3wYoX2vdPBiF1K1xKOaEsyw3arq0PBnrxWNDLW0IP_O1jVJGAO14gWUNgkIFaEpdGLY3vOnXdZmCjYDTKLqAdzTJDm8GSHBjzr-XZvfokf_yrOnkYpFrxpZQgACEgMnPamqO4BUMeZcbWqo1_4TjxmzM5gWLKu1y0KwltG8QVLqfc4cCWfnakQuIT9VNDRnoyi79lh-RhIMugJGRJcICwlTEi5nlusrucooAk7_PP0kCEh2FMGJb03GR3Cj-yf6Ayh87KZpOuSNYPCyrmxW030bVLbsVHIlBdeMyvpmz5xJkqu-jfAuINlgqmKdY1p6jYkxsijI2s2lTJetIpkZnocnbSvU_RQSMezhLQWeVQu02clhDusMvjv3bMWfwNU7CiDhowXq8cSly5mLH6GhKH7iyP0; JSESSIONID=fec51a10f955a26756e4d15d6eb2";
    Pattern email = Pattern.compile(
            "(DACS:[:\\w]+[\\w][\\w\\-]*[\\.]{0,1}[\\w\\-]*[@[A-Za-z0-9-]+\\.+[A-Za-z]{2,4}]*)=([-\\w]+)",
            Pattern.CASE_INSENSITIVE);
    Matcher emailMatcher = email.matcher(test);
    while (emailMatcher.find()) {
        String group1 = emailMatcher.group(1);
        String group2 = emailMatcher.group(2);
    }
}

From source file:com.jubination.io.chatbot.service.ReligareService.java

private String emailValidate(String text) {
    String validatedText = null;/*w  w w .j  av a2 s  . c o  m*/
    Pattern re = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
    Matcher reMatcher = re.matcher(text.trim());
    if (reMatcher.find()) {
        validatedText = reMatcher.group();
    } else {
        return null;
    }

    return validatedText;
}

From source file:com.puppycrawl.tools.checkstyle.checks.coding.CustomDeclarationOrderCheck.java

/**
 * Set whether or not the match is case sensitive.
 *
 * @param aCaseInsensitive true if the match is case insensitive.
 *//*from   ww w  .  ja va  2 s .  c om*/
public void setIgnoreRegExCase(final boolean aCaseInsensitive) {
    if (aCaseInsensitive) {
        if (!mCustomOrderDeclaration.isEmpty()) {
            for (FormatMatcher currentRule : mCustomOrderDeclaration) {
                currentRule.setCompileFlags(Pattern.CASE_INSENSITIVE);
            }
        } else {
            mCompileFlags = Pattern.CASE_INSENSITIVE;
        }
    }
}

From source file:org.sonatype.nexus.httpclient.config.ConfigurationCustomizer.java

/**
 * Creates instance of {@link NexusHttpRoutePlanner} from passed in configuration, never {@code null}.
 *///from   w w  w  .j  a  va 2s . co  m
@VisibleForTesting
NexusHttpRoutePlanner createRoutePlanner(final ProxyConfiguration proxy) {
    Map<String, HttpHost> proxies = new HashMap<>(2);

    // HTTP proxy
    ProxyServerConfiguration http = proxy.getHttp();
    if (http != null && http.isEnabled()) {
        HttpHost host = new HttpHost(http.getHost(), http.getPort());
        proxies.put(HTTP, host);
        proxies.put(HTTPS, host);
    }

    // HTTPS proxy
    ProxyServerConfiguration https = proxy.getHttps();
    if (https != null && https.isEnabled()) {
        HttpHost host = new HttpHost(https.getHost(), https.getPort());
        proxies.put(HTTPS, host);
    }

    // Non-proxy hosts (Java http.nonProxyHosts formatted glob-like patterns converted to single Regexp expression)
    LinkedHashSet<String> patterns = new LinkedHashSet<>();
    if (proxy.getNonProxyHosts() != null) {
        patterns.addAll(Arrays.asList(proxy.getNonProxyHosts()));
    }
    String nonProxyPatternString = Joiner.on("|")
            .join(Iterables.transform(patterns, GLOB_STRING_TO_REGEXP_STRING));
    Pattern nonProxyPattern = null;
    if (!Strings2.isBlank(nonProxyPatternString)) {
        try {
            nonProxyPattern = Pattern.compile(nonProxyPatternString, Pattern.CASE_INSENSITIVE);
        } catch (PatternSyntaxException e) {
            log.warn("Invalid non-proxy host regex: {}, using defaults", nonProxyPatternString, e);
        }
    }
    return new NexusHttpRoutePlanner(proxies, nonProxyPattern);
}

From source file:cz.vity.freerapid.plugins.services.rapidshare_premium.RapidShareRunner.java

private void checkProblems() throws ServiceConnectionProblemException, YouHaveToWaitException {
    Matcher matcher;// w  w  w  .ja  v a 2  s.c  om
    final String contentAsString = client.getContentAsString();
    matcher = Pattern.compile("IP address (.*?) is already", Pattern.MULTILINE).matcher(contentAsString);
    if (matcher.find()) {
        final String ip = matcher.group(1);
        throw new ServiceConnectionProblemException(String.format(
                "<b>RapidShare error:</b><br>Your IP address %s is already downloading a file. <br>Please wait until the download is completed.",
                ip));
    }
    if (contentAsString.contains("Currently a lot of users")) {
        matcher = Pattern
                .compile("Please try again in ([0-9]+) minute", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE)
                .matcher(contentAsString);
        if (matcher.find()) {
            throw new YouHaveToWaitException("Currently a lot of users are downloading files.",
                    Integer.parseInt(matcher.group(1)) * 60 + 20);
        }
        throw new ServiceConnectionProblemException(
                String.format("<b>RapidShare error:</b><br>Currently a lot of users are downloading files."));
    }
    if (getContentAsString().contains("momentarily not available")
            || getContentAsString().contains("Server under repair")) {
        throw new ServiceConnectionProblemException("The server is momentarily not available.");
    }
}

From source file:com.clustercontrol.custom.factory.RunCustomString.java

/**
 * ????<br/>/*from  w w w.  j  a  v  a  2 s. co m*/
 * 
 * @throws HinemosUnknown
 *             ??????
 * @throws MonitorNotFound
 *             ??????
 * @throws CustomInvalid
 *             ??????
 */
@Override
public void monitor() throws HinemosUnknown, MonitorNotFound, CustomInvalid {
    // Local Variables
    MonitorInfo monitor = null;

    int priority = PriorityConstant.TYPE_UNKNOWN;
    String facilityPath = "";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat.setTimeZone(HinemosTime.getTimeZone());
    String msg = "";
    String msgOrig = "";

    boolean isMonitorJob = result.getRunInstructionInfo() != null;

    // MAIN
    try {
        monitor = new MonitorSettingControllerBean().getMonitor(result.getMonitorId());

        String executeDate = dateFormat.format(result.getExecuteDate());
        String exitDate = dateFormat.format(result.getExitDate());
        String collectDate = dateFormat.format(result.getCollectDate());

        facilityPath = new RepositoryControllerBean().getFacilityPath(result.getFacilityId(), null);
        if (result.getTimeout() || result.getStdout() == null || result.getStdout().isEmpty()
                || result.getResults() == null) {
            if (m_log.isDebugEnabled()) {
                m_log.debug("command monitoring : timeout or no stdout [" + result + "]");
            }
            // if command execution failed (timeout or no stdout)
            if (isMonitorJob || monitor.getMonitorFlg()) {
                msg = "FAILURE : command execution failed (timeout, no stdout or not unexecutable command)...";

                msgOrig = "FAILURE : command execution failed (timeout, no stdout or unexecutable command)...\n\n"
                        + "COMMAND : " + result.getCommand() + "\n" + "COLLECTION DATE : " + collectDate + "\n"
                        + "executed at " + executeDate + "\n" + "exited (or timeout) at " + exitDate + "\n"
                        + "EXIT CODE : " + (result.getExitCode() != null ? result.getExitCode() : "timeout")
                        + "\n\n" + "[STDOUT]\n" + result.getStdout() + "\n" + "[STDERR]\n" + result.getStderr()
                        + "\n";

                // 
                if (!isMonitorJob) {
                    notify(PriorityConstant.TYPE_UNKNOWN, monitor, result.getFacilityId(), facilityPath, null,
                            msg, msgOrig, HinemosModuleConstant.MONITOR_CUSTOM_S);
                } else {
                    // 
                    this.monitorJobEndNodeList.add(new MonitorJobEndNode(result.getRunInstructionInfo(),
                            HinemosModuleConstant.MONITOR_CUSTOM_S, makeJobOrgMessage(monitor, msgOrig), "",
                            RunStatusConstant.END, MonitorJobWorker.getReturnValue(
                                    result.getRunInstructionInfo(), PriorityConstant.TYPE_UNKNOWN)));
                }
            }
        } else {
            // if command stdout was returned Monitor
            msg = result.getStdout();
            // Stdout???
            Pattern patternMsg = Pattern.compile("\r\n$|\n$");
            Matcher matcherMsg = patternMsg.matcher(msg);
            msg = matcherMsg.replaceAll("");

            if (m_log.isDebugEnabled()) {
                m_log.debug("command monitoring : values [" + msg + "]");
            }

            // ?
            if (monitor.getCollectorFlg()) { // collector each value
                List<StringSample> sampleList = new ArrayList<StringSample>();
                StringSample sample = new StringSample(new Date(HinemosTime.currentTimeMillis()),
                        monitor.getMonitorId());
                // 
                sample.set(result.getFacilityId(), "custom", msg);

                sampleList.add(sample);
                if (!sampleList.isEmpty()) {
                    CollectStringDataUtil.store(sampleList);
                }
            }

            // 
            int orderNo = 0;
            if (isMonitorJob || monitor.getMonitorFlg()) { // monitor each value
                for (MonitorStringValueInfo stringValueInfo : monitor.getStringValueInfo()) {
                    ++orderNo;
                    if (m_log.isDebugEnabled()) {
                        m_log.info(String.format(
                                "monitoring (monitorId = %s, orderNo = %d, patten = %s, enabled = %s, casesensitive = %s)",
                                monitor.getMonitorId(), orderNo, stringValueInfo.getPattern(),
                                stringValueInfo.getValidFlg(), stringValueInfo.getCaseSensitivityFlg()));
                    }
                    if (!stringValueInfo.getValidFlg()) {
                        // ?????
                        continue;
                    }
                    // ?
                    if (m_log.isDebugEnabled()) {
                        m_log.debug(String.format("filtering customtrap (regex = %s, Msg = %s",
                                stringValueInfo.getPattern(), msg));
                    }
                    try {
                        Pattern pattern = null;
                        if (stringValueInfo.getCaseSensitivityFlg()) {
                            // ?????
                            pattern = Pattern.compile(stringValueInfo.getPattern(),
                                    Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
                        } else {
                            // ???
                            pattern = Pattern.compile(stringValueInfo.getPattern(), Pattern.DOTALL);
                        }
                        Matcher matcher = pattern.matcher(msg);
                        if (matcher.matches()) {
                            if (stringValueInfo.getProcessType()) {
                                msgOrig = MessageConstant.LOGFILE_PATTERN.getMessage() + "="
                                        + stringValueInfo.getPattern() + "\n"
                                        + MessageConstant.LOGFILE_LINE.getMessage() + "=" + msg + "\n\n"
                                        + "COMMAND : " + result.getCommand() + "\n" + "COLLECTION DATE : "
                                        + collectDate + "\n" + "executed at " + executeDate + "\n"
                                        + "exited (or timeout) at " + exitDate + "\n" + "EXIT CODE : "
                                        + (result.getExitCode() != null ? result.getExitCode() : "timeout")
                                        + "\n\n" + "[STDOUT]\n" + result.getStdout() + "\n\n" + "[STDERR]\n"
                                        + result.getStderr() + "\n";

                                msg = makeMsg(stringValueInfo, msg);

                                priority = stringValueInfo.getPriority();
                                if (!isMonitorJob) {
                                    // 
                                    notify(priority, monitor, result.getFacilityId(), facilityPath,
                                            stringValueInfo.getPattern(), msg, msgOrig,
                                            HinemosModuleConstant.MONITOR_CUSTOM_S);
                                } else {
                                    // 
                                    this.monitorJobEndNodeList
                                            .add(new MonitorJobEndNode(result.getRunInstructionInfo(),
                                                    HinemosModuleConstant.MONITOR_CUSTOM_S,
                                                    makeJobOrgMessage(monitor, msgOrig), "",
                                                    RunStatusConstant.END, MonitorJobWorker.getReturnValue(
                                                            result.getRunInstructionInfo(), priority)));
                                }
                            } else {
                                m_log.debug(String.format("not ProcessType (regex = %s, Msg = %s",
                                        stringValueInfo.getPattern(), result.getStdout()));
                            }
                            break;// Syslog??????
                        }
                    } catch (RuntimeException e) {
                        m_log.warn("filtering failure. (regex = " + stringValueInfo.getPattern() + ") . "
                                + e.getMessage(), e);
                    }
                }
            }
        }
    } catch (MonitorNotFound | CustomInvalid | HinemosUnknown e) {
        m_log.warn("unexpected internal failure occurred. [" + result + "]");
        throw e;
    } catch (Exception e) {
        m_log.warn("unexpected internal failure occurred. [" + result + "]", e);
        throw new HinemosUnknown("unexpected internal failure occurred. [" + result + "]", e);
    }
}

From source file:net.paissad.waqtsalat.utils.UncompressUtils.java

/**
 * Implements different methods used to uncompress a file.
 * //from   w w w  .  ja  v a 2 s.  com
 * @param method
 *            Method to use for uncompressing the file. Available methods
 *            are GUNZIP_METHOD, BUNZIP_METHOD.
 * @return File that has been created after the decompression process.
 * @throws IOException
 * @see #gunzip
 * @see #bunzip2
 */
private File uncompress(final String method) throws IOException {
    try {
        logger.info("Uncompressing file '{}' ...", source.getAbsolutePath());
        // We must set the destination filename, if not set before !
        if (this.dest == null) {
            logger.trace("'dest' file is null ...");
            Pattern pattern;
            String outputFileName;

            if (method.equals(BUNZIP_METHOD)) {
                pattern = Pattern.compile(REGEX_DEFAULT_EXTENSION_BZIP, Pattern.CASE_INSENSITIVE);
            }

            else if (method.equals(GUNZIP_METHOD)) {
                pattern = Pattern.compile(REGEX_DEFAULT_EXTENSION_GZIP, Pattern.CASE_INSENSITIVE);
            }

            else if (method.equals(TAR_METHOD)) {
                pattern = Pattern.compile(REGEX_DEFAULT_EXTENSION_TAR);
            }

            else {
                throw new RuntimeException("Unsupported method '" + method + "'.");
            }

            // Set output filename.
            Matcher matcher = pattern.matcher(source.getAbsolutePath());
            if (source.toString().toLowerCase().endsWith(".tgz")) {
                outputFileName = matcher.replaceFirst(".tar");
            } else {
                outputFileName = matcher.replaceFirst("");
            }

            dest = new File(outputFileName);
        }

        // GZIP and BZIP2 (decompression)
        if (method.equals(BUNZIP_METHOD) || method.equals(GUNZIP_METHOD)) {
            dest = inputstreamToFile(uncompressStream(method), dest, CLOSE_STREAM);
        }

        // TAR (decompression)
        else if (method.equals(TAR_METHOD)) {
            TarInputStream tis = (TarInputStream) uncompressStream(TAR_METHOD);
            try {

                TarEntry tarEntry = tis.getNextEntry();
                while (tarEntry != null) {
                    File destPath = new File(dest.getParent() + File.separatorChar + tarEntry.getName());

                    if (tarEntry.isDirectory()) {
                        destPath.mkdir();
                    } else {
                        if (!destPath.getParentFile().exists()) {
                            destPath.getParentFile().mkdirs();
                        }
                        logger.trace("untar: '{}'", destPath);
                        FileOutputStream fos = new FileOutputStream(destPath);
                        try {
                            tis.copyEntryContents(fos);
                        } finally {
                            fos.flush();
                            fos.close();
                        }
                    }
                    tarEntry = tis.getNextEntry();
                }
            } catch (IOException ioe) {
                ioe.printStackTrace();
                throw new IOException("Untar failed.");
            } finally {
                if (tis != null)
                    tis.close();
            }

        } // End of tar method.
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new IOException("Uncompressing file '" + source.getAbsolutePath() + "' failed.");
    }
    logger.info("Uncompressing file '{}' finished successfully.", source.getAbsolutePath());
    return dest;
}

From source file:com.nextep.designer.sqlgen.helpers.CaptureHelper.java

/**
 * Checks if the specified "CREATE...(columns_list) AS SELECT..." statement contains a columns
 * list clause./*from w  w  w.  j  a  v  a2 s  . c  o  m*/
 * 
 * @param stmt a <code>String</code> representing a "CREATE AS SELECT" statement
 * @return <code>true</code> if the specified statement contains a columns list clause,
 *         <code>false</code> otherwise
 */
public static boolean containsColumnsListClause(String stmt) {
    if (stmt != null) {
        Pattern p = Pattern.compile(".+?\\s*\\([^,]+(?:,[^,]+)*\\)\\s+AS\\s+SELECT\\s+.+", //$NON-NLS-1$
                Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(stmt);
        return m.find();
    }
    return false;
}