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:com.manydesigns.portofino.pageactions.text.TextAction.java

protected String processAttachmentUrls(String content) {
    String baseUrl = StringEscapeUtils.escapeHtml(generateViewAttachmentUrl("").replace("?", "\\?"));
    String patternString = "([^\\s\"]+)\\s*=\\s*\"\\s*" + baseUrl + "([^\"]+)\"";
    Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(content);
    int lastEnd = 0;
    StringBuilder sb = new StringBuilder();
    while (matcher.find()) {
        String hrefAttribute = matcher.group(1);
        String attachmentId = matcher.group(2);
        sb.append(content.substring(lastEnd, matcher.start()));
        sb.append("portofino:attachment=\"").append(attachmentId).append("\" ");
        sb.append("portofino:hrefAttribute=\"").append(hrefAttribute).append("\"");
        lastEnd = matcher.end();//from  ww w .j  av a  2s.c o  m
    }
    sb.append(content.substring(lastEnd));
    return sb.toString();
}

From source file:net.pms.encoders.VideoLanVideoStreaming.java

@Override
public @Nullable ExecutableInfo testExecutable(@Nonnull ExecutableInfo executableInfo) {
    executableInfo = testExecutableFile(executableInfo);
    if (Boolean.FALSE.equals(executableInfo.getAvailable())) {
        return executableInfo;
    }//w ww.  j a  va  2s . com
    ExecutableInfoBuilder result = executableInfo.modify();
    if (Platform.isWindows()) {
        if (executableInfo.getPath().isAbsolute()
                && executableInfo.getPath().equals(BasicSystemUtils.INSTANCE.getVlcPath())) {
            result.version(BasicSystemUtils.INSTANCE.getVlcVersion());
        }
        result.available(Boolean.TRUE);
    } else {
        final String arg = "--version";
        try {
            ListProcessWrapperResult output = SimpleProcessWrapper.runProcessListOutput(30000, 1000,
                    executableInfo.getPath().toString(), arg);
            if (output.getError() != null) {
                result.errorType(ExecutableErrorType.GENERAL);
                result.errorText(String.format(Messages.getString("Engine.Error"), this) + " \n"
                        + output.getError().getMessage());
                result.available(Boolean.FALSE);
                LOGGER.debug("\"{} {}\" failed with error: {}", executableInfo.getPath(), arg,
                        output.getError().getMessage());
                return result.build();
            }
            if (output.getExitCode() == 0) {
                if (output.getOutput() != null && output.getOutput().size() > 0) {
                    Pattern pattern = Pattern.compile("VLC version\\s+[^\\(]*\\(([^\\)]*)",
                            Pattern.CASE_INSENSITIVE);
                    Matcher matcher = pattern.matcher(output.getOutput().get(0));
                    if (matcher.find() && isNotBlank(matcher.group(1))) {
                        result.version(new Version(matcher.group(1)));
                    }
                }
                result.available(Boolean.TRUE);
            } else {
                result.errorType(ExecutableErrorType.GENERAL);
                result.errorText(
                        String.format(Messages.getString("Engine.ExitCode"), this, output.getExitCode()));
                result.available(Boolean.FALSE);
            }
        } catch (InterruptedException e) {
            return null;
        }
    }
    if (result.version() != null) {
        Version requiredVersion = new Version("2.0.2");
        if (result.version().compareTo(requiredVersion) <= 0) {
            result.errorType(ExecutableErrorType.GENERAL);
            result.errorText(String.format(Messages.getString("Engine.VersionTooLow"), requiredVersion, this));
            result.available(Boolean.FALSE);
            LOGGER.warn(String.format(Messages.getRootString("Engine.VersionTooLow"), requiredVersion, this));
        }
    } else if (result.available() != null && result.available().booleanValue()) {
        LOGGER.warn("Could not parse VLC version, the version might be too low (< 2.0.2)");
    }
    return result.build();
}

From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.RemoteStorageContextCustomizer.java

@VisibleForTesting
public void applyProxyConfig(final Builder builder, final RemoteProxySettings remoteProxySettings) {
    if (remoteProxySettings != null && remoteProxySettings.getHttpProxySettings() != null
            && remoteProxySettings.getHttpProxySettings().isEnabled()) {
        final Map<String, HttpHost> proxies = Maps.newHashMap();

        final HttpHost httpProxy = new HttpHost(remoteProxySettings.getHttpProxySettings().getHostname(),
                remoteProxySettings.getHttpProxySettings().getPort());
        applyAuthenticationConfig(builder, remoteProxySettings.getHttpProxySettings().getProxyAuthentication(),
                httpProxy);/*from www .jav  a2s. c  o  m*/

        log.debug("http proxy setup with host '{}'", remoteProxySettings.getHttpProxySettings().getHostname());
        proxies.put("http", httpProxy);
        proxies.put("https", httpProxy);

        if (remoteProxySettings.getHttpsProxySettings() != null
                && remoteProxySettings.getHttpsProxySettings().isEnabled()) {
            final HttpHost httpsProxy = new HttpHost(remoteProxySettings.getHttpsProxySettings().getHostname(),
                    remoteProxySettings.getHttpsProxySettings().getPort());
            applyAuthenticationConfig(builder,
                    remoteProxySettings.getHttpsProxySettings().getProxyAuthentication(), httpsProxy);
            log.debug("https proxy setup with host '{}'",
                    remoteProxySettings.getHttpsProxySettings().getHostname());
            proxies.put("https", httpsProxy);
        }

        final Set<Pattern> nonProxyHostPatterns = Sets.newHashSet();
        if (remoteProxySettings.getNonProxyHosts() != null
                && !remoteProxySettings.getNonProxyHosts().isEmpty()) {
            for (String nonProxyHostRegex : remoteProxySettings.getNonProxyHosts()) {
                try {
                    nonProxyHostPatterns.add(Pattern.compile(nonProxyHostRegex, Pattern.CASE_INSENSITIVE));
                } catch (PatternSyntaxException e) {
                    log.warn("Invalid non proxy host regex: {}", nonProxyHostRegex, e);
                }
            }
        }

        builder.getHttpClientBuilder().setRoutePlanner(
                new NexusHttpRoutePlanner(proxies, nonProxyHostPatterns, DefaultSchemePortResolver.INSTANCE));
    }
}

From source file:com.frostwire.search.youtube.jd.Request.java

public String getHtmlCode() throws CharacterCodingException {
    final String ct = this.httpConnection.getContentType();
    /* check for image content type */
    if (ct != null && Pattern.compile("images?/\\w*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(ct)
            .matches()) {//from   w  w  w  . ja  v  a2 s  .  c  o m
        throw new IllegalStateException("Content-Type: " + ct);
    }
    if (this.htmlCode == null && this.byteArray != null) {
        /* use custom charset or charset from httpconnection */
        String useCS = this.customCharset == null ? this.httpConnection.getCharset() : this.customCharset;
        if (useCS == null) {
            useCS = this.getCharsetFromMetaTags();
        }
        try {
            try {
                try {
                    if (useCS != null) {
                        /* try to use wanted charset */
                        this.htmlCode = new String(this.byteArray, useCS.toUpperCase());
                        return this.htmlCode;
                    }
                } catch (final Exception e) {
                }
                this.htmlCode = new String(this.byteArray, "ISO-8859-1");
                return this.htmlCode;
            } catch (final Exception e) {
                //System.out.println("could neither charset: " + useCS + " nor default charset");
                /* fallback to default charset in error case */
                this.htmlCode = new String(this.byteArray);
                return this.htmlCode;
            }
        } catch (final Exception e) {
            /* in case of error we do not reset byteArray */
        }
    }
    return this.htmlCode;
}

From source file:gtu._work.ui.RenameUI.java

private void usePatternNewNameBtnActionPerformed() {
    try {/* w ww .  j a  va2s.  c  o m*/
        String findFileRegex = Validate.notBlank(findFileRegexText.getText(), "??Regex");
        String renameRegex = Validate.notBlank(renameRegexText.getText(), "??");
        Pattern renameRegexPattern = Pattern.compile("\\#(\\w+)\\#");
        Matcher matcher2 = null;

        Pattern findFileRegexPattern = Pattern.compile(findFileRegex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = null;
        DefaultTableModel model = JTableUtil.createModel(false, "??", "??", "");

        int ind = 1;
        for (XFile f : fileList) {
            matcher = findFileRegexPattern.matcher(f.fileName);
            if (matcher.matches()) {
                StringBuffer sb = new StringBuffer();
                matcher2 = renameRegexPattern.matcher(renameRegex);
                while (matcher2.find()) {
                    String val = matcher2.group(1);
                    if (val.matches("\\d+L")) {
                        int index = Integer.parseInt(val.substring(0, val.length() - 1));
                        matcher2.appendReplacement(sb, DateFormatUtils
                                .format(Long.parseLong(matcher.group(index)), "yyyyMMdd_HHmmss"));
                    } else if (val.equalsIgnoreCase("date")) {
                        matcher2.appendReplacement(sb,
                                DateFormatUtils.format(f.file.lastModified(), "yyyyMMdd_HHmmss"));
                    } else if (val.equalsIgnoreCase("serial")) {
                        matcher2.appendReplacement(sb, String.valueOf(ind++));
                    } else if (StringUtils.isNumeric(val)) {
                        int index = Integer.parseInt(val);
                        matcher2.appendReplacement(sb, matcher.group(index));
                    }
                }
                matcher2.appendTail(sb);
                model.addRow(this.getXFile(f, sb.toString()));
            }
        }
        renameTable.setModel(model);
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

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

public static boolean validateImgFormat(String fileName) {
    String imgType = Defines.IMAGETYPE_REGEXP;// 
    Pattern pattern = Pattern.compile(imgType, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(fileName);
    boolean result = matcher.find();
    return result;
}

From source file:de.iteratec.iteraplan.persistence.MySQLScriptCaseSensitiveTablesTest.java

private Pattern createTableNamesPattern(Set<String> tableNames) {
    String patternString = "(?<=^|[` ,\\(\\)])(" + Joiner.on('|').join(tableNames) + ")(?=[` ,\\(\\)\\.;]|$)";
    return Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
}

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

/**
 * ??//from  w  w  w  .ja  v a2 s .  com
 * 
 * @param srcStr
 * @param regexp
 * @param ignoreCase
 *            ??
 * @return
 */
public static int lastIndexOf(String srcStr, String regexp, boolean ignoreCase) {

    Pattern p = null;
    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();

    }
    return end;
    // sql3.regionMatches(ignoreCase, toffset, other, ooffset, len)
    // log.info(m.matches());
}

From source file:io.fabric8.maven.core.util.kubernetes.KubernetesResourceUtil.java

private static Map<String, Object> readAndEnrichFragment(ResourceVersioning apiVersions, File file,
        String appName) throws IOException {
    Pattern pattern = Pattern.compile(FILENAME_PATTERN, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(file.getName());
    if (!matcher.matches()) {
        throw new IllegalArgumentException(
                String.format("Resource file name '%s' does not match pattern <name>-<type>.(yaml|yml|json)",
                        file.getName()));
    }//from   ww  w. j a  v a 2 s  .  c o m
    String name = matcher.group("name");
    String type = matcher.group("type");
    String ext = matcher.group("ext").toLowerCase();
    String kind;

    Map<String, Object> fragment = readFragment(file, ext);

    if (type != null) {
        kind = getAndValidateKindFromType(file, type);
    } else {
        // Try name as type
        kind = FILENAME_TO_KIND_MAPPER.get(name.toLowerCase());
        if (kind != null) {
            // Name is in fact the type, so lets erase the name.
            name = null;
        }
    }

    addKind(fragment, kind, file.getName());

    String apiVersion = apiVersions.getCoreVersion();
    if (Objects.equals(kind, "Deployment") || Objects.equals(kind, "Ingress")) {
        apiVersion = apiVersions.getExtensionsVersion();
    } else if (Objects.equals(kind, "StatefulSet")) {
        apiVersion = apiVersions.getAppsVersion();
    } else if (Objects.equals(kind, "Job")) {
        apiVersion = apiVersions.getJobVersion();
    }
    addIfNotExistent(fragment, "apiVersion", apiVersion);

    Map<String, Object> metaMap = getMetadata(fragment);
    // No name means: generated app name should be taken as resource name
    addIfNotExistent(metaMap, "name", StringUtils.isNotBlank(name) ? name : appName);

    return fragment;
}

From source file:com.github.thorqin.webapi.mail.MailService.java

public static Mail createHtmlMailFromTemplate(String templatePath, Map<String, String> replaced) {
    Mail mail = new Mail();
    try (InputStream in = MailService.class.getClassLoader().getResourceAsStream(templatePath)) {
        InputStreamReader reader = new InputStreamReader(in, "utf-8");
        char[] buffer = new char[1024];
        StringBuilder builder = new StringBuilder();
        while (reader.read(buffer) != -1)
            builder.append(buffer);//from  w  w  w  .  ja v a 2 s  . c  om
        String mailBody = builder.toString();
        builder.setLength(0);
        Pattern pattern = Pattern.compile("<%\\s*(.+?)\\s*%>", Pattern.MULTILINE);
        Matcher matcher = pattern.matcher(mailBody);
        int scanPos = 0;
        while (matcher.find()) {
            builder.append(mailBody.substring(scanPos, matcher.start()));
            scanPos = matcher.end();
            String key = matcher.group(1);
            if (replaced != null) {
                String value = replaced.get(key);
                if (value != null) {
                    builder.append(value);
                }
            }
        }
        builder.append(mailBody.substring(scanPos, mailBody.length()));
        mail.htmlBody = builder.toString();
        pattern = Pattern.compile("<title>(.*)</title>",
                Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
        matcher = pattern.matcher(mail.htmlBody);
        if (matcher.find()) {
            mail.subject = matcher.group(1);
        }
    } catch (IOException ex) {
        logger.log(Level.SEVERE, "Create mail from template error: {0}, {1}",
                new Object[] { templatePath, ex });
    }
    return mail;
}