Example usage for java.util.regex Pattern quote

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

Introduction

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

Prototype

public static String quote(String s) 

Source Link

Document

Returns a literal pattern String for the specified String .

Usage

From source file:io.jeffrey.web.assemble.InMemoryAssembler.java

private static String getContentType(File source, String key) {
    String[] parts = key.split(Pattern.quote("."));
    if (parts.length > 0) {
        String ext = parts[parts.length - 1].toLowerCase();
        if ("png".equals(ext))
            return "image/png";
        if ("css".equals(ext))
            return "text/css";
    }/*from   ww  w.jav a  2s . com*/
    return new MimetypesFileTypeMap().getContentType(source);
}

From source file:Main.java

public static void addPattern(String emojiText, Object icon) {
    emoticons.put(Pattern.compile(Pattern.quote(emojiText)), icon);
}

From source file:com.sic.bb.jenkins.plugins.sicci_for_xcode.util.PluginUtils.java

public static String stringToPattern(String string) {
    return Pattern.quote(string);
}

From source file:com.predic8.membrane.core.interceptor.registration.SecurityUtils.java

public static boolean isHashedPassword(String postDataPassword) {
    // TODO do a better check here
    String[] split = postDataPassword.split(Pattern.quote("$"));
    return split.length == 4 && split[0].isEmpty() && split[3].length() >= 20;
}

From source file:Main.java

public static String getClientIdFromCertificate(X509Certificate certificate) {

    if (certificate == null) {
        throw new IllegalArgumentException("Certificate cannot be null");
    }/*from   w  ww .  j a  va  2  s. c om*/

    //subjectDN is of the form: "UID=<clientId>, DC=<some other value>" or "DC=<some other value>, UID=<clientId>"
    String clientId = null;

    String subjectDN = certificate.getSubjectDN().getName();
    String[] parts = subjectDN.split(Pattern.quote(","));
    for (String part : parts) {
        if (part.contains("UID=")) {
            String uid = part.substring(part.indexOf("UID="));
            clientId = uid.split(Pattern.quote("="))[1];
        }
    }

    return clientId;
}

From source file:Main.java

public static boolean renameDict(final File dictFile, final File newDictFile) {
    if (dictFile.isFile()) {
        return dictFile.renameTo(newDictFile);
    } else if (dictFile.isDirectory()) {
        final String dictName = dictFile.getName();
        final String newDictName = newDictFile.getName();
        if (newDictFile.exists()) {
            return false;
        }//  w w w  .  ja v  a2 s .  c o  m
        for (final File file : dictFile.listFiles()) {
            if (!file.isFile()) {
                continue;
            }
            final String fileName = file.getName();
            final String newFileName = fileName.replaceFirst(Pattern.quote(dictName),
                    Matcher.quoteReplacement(newDictName));
            if (!file.renameTo(new File(dictFile, newFileName))) {
                return false;
            }
        }
        return dictFile.renameTo(newDictFile);
    }
    return false;
}

From source file:Main.java

/**
 * Checks if string representation corresponds to the collection. Parts of an expected collection should not contain
 * delimiter./*from w  w  w. j  a va  2 s .  c  om*/
 */
public static boolean isStringPermutationOfCollection(String input, Collection<String> expected,
        String delimeter, int trimFromStart, int trimFromEnd) {
    input = input.substring(trimFromStart, input.length() - trimFromEnd);
    List<String> parts = new ArrayList<>(Arrays.asList(input.split(Pattern.quote(delimeter))));
    for (String part : expected) {
        if (parts.contains(part)) {
            parts.remove(part);
        }
    }
    return parts.isEmpty();
}

From source file:com.ejisto.util.ContainerUtils.java

public static String extractAgentJar(String classPath) {
    String systemProperty = System.getProperty("ejisto.agent.jar.path");
    if (StringUtils.isNotBlank(systemProperty)) {
        return systemProperty;
    }/*from ww  w.  j a  v  a 2 s.  c o  m*/

    final Optional<String> agentPath = Arrays.stream(classPath.split(Pattern.quote(File.pathSeparator)))
            .filter(e -> AGENT_JAR.matcher(e).matches()).findFirst();
    if (agentPath.isPresent()) {
        return Paths.get(System.getProperty("user.dir"), agentPath.get()).toString();
    }
    throw new IllegalStateException("unable to find agent jar");
}

From source file:com.ge.predix.uaa.token.lib.HttpServletRequestUtil.java

/**
 * @return empty string if requestHostname and baseDomain are identical, null if domain is not a sub-string of
 *         requestHostname//from   w  ww. j a  v  a  2s .co m
 */
static String getZoneNameFromRequestHostName(final String requestHostname, final String baseDomain) {

    if (requestHostname.equals(baseDomain)) {
        return "";
    }

    String regexPattern = "^(.*?)\\." + Pattern.quote(baseDomain) + "$";
    Pattern pattern = Pattern.compile(regexPattern);
    Matcher matcher = pattern.matcher(requestHostname);
    if (!matcher.matches()) {
        // There is no zone scope for this request. Return null
        return null;
    }

    String subdomain = matcher.group(1);

    return subdomain;
}

From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java

public static void createGraph(String name, String outputDir, GraphCSV csv, String htmlData)
        throws IOException {
    String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream("/graph-curved.html"));
    content = content.replaceAll(Pattern.quote("$CSVNAME$"), Matcher.quoteReplacement(name))
            .replaceAll(Pattern.quote("$HTML$"), Matcher.quoteReplacement(htmlData));

    FileUtils.writeStringToFile(Paths.get(outputDir + File.separator + name + ".html").toFile(), content);
    FileUtils.writeStringToFile(new File(outputDir + File.separator + name + ".csv"), csv.toString());
    TpaPersistorUtils.copyFromResourceToDir("d3.v3.js", outputDir);
}