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:com.epam.ta.reportportal.database.dao.TestItemRepositoryCustomImpl.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/*w w w .j a v a2  s. c  o m*/
public List<String> findDistinctValues(String launchId, String containsValue, String distinctBy) {
    Aggregation aggregation = newAggregation(match(where(LAUNCH_REFERENCE).is(launchId)), unwind(distinctBy),
            match(where(distinctBy).regex("(?i).*" + Pattern.quote(containsValue) + ".*")), group(distinctBy));
    AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, TestItem.class, Map.class);
    return result.getMappedResults().stream().map(entry -> entry.get("_id").toString()).collect(toList());
}

From source file:com.graphiq.kettle.steps.uniquelist.UniqueListStep.java

public String dedupe(String source, String sourceDelim, String outputDelim, boolean removeBlanks) {
    if (source == null) {
        return null;
    }/*w ww  .  ja  v a2 s.c  om*/
    String[] items = source.split(Pattern.quote(sourceDelim));
    LinkedHashSet<String> uniques = new LinkedHashSet<String>();
    Collections.addAll(uniques, items);
    if (removeBlanks) {
        uniques.remove("");
    }
    return StringUtils.join(uniques, outputDelim);
}

From source file:at.ofai.gate.virtualcorpus.JDBCCorpus.java

@Override
/**// w  ww. j av a  2s  .c  o m
 * Initializes the JDBCCorpus LR
 */
public Resource init() throws ResourceInstantiationException {
    if (getTableName() == null || getTableName().equals("")) {
        throw new ResourceInstantiationException("tableName must not be empty");
    }
    if (getDocumentNameField() == null || getDocumentNameField().equals("")) {
        throw new ResourceInstantiationException("documentNameField must not be empty");
    }
    if (getDocumentContentField() == null || getDocumentContentField().equals("")) {
        throw new ResourceInstantiationException("documentContentField must not be empty");
    }
    if (getSelectSQL() == null || getSelectSQL().equals("")) {
        throw new ResourceInstantiationException("selectSQL must not be empty");
    }
    String query = getSelectSQL(); // this contains the ${tableName} and ${documentNameField} vars
    query = query.replaceAll(Pattern.quote("${tableName}"), getTableName());
    query = query.replaceAll(Pattern.quote("${documentNameField}"), getDocumentNameField());
    String expandedUrl = "";
    try {
        Class.forName(getJdbcDriver());
        String dbdirectory = "";
        if (getDbDirectoryUrl().getProtocol().equals("file")) {
            dbdirectory = getDbDirectoryUrl().getPath();
            dbdirectory = new File(dbdirectory).getAbsolutePath();
        } else {
            throw new GateRuntimeException("The database directory URL is not a file URL");
        }
        Map<String, String> dbdirectoryMap = new HashMap<String, String>();
        dbdirectoryMap.put("dbdirectory", dbdirectory);

        expandedUrl = gate.Utils.replaceVariablesInString(jdbcUrl, dbdirectoryMap, this);
        String expandedUser = gate.Utils.replaceVariablesInString(jdbcUser, dbdirectoryMap, this);
        String expandedPassword = gate.Utils.replaceVariablesInString(jdbcPassword, dbdirectoryMap, this);

        System.out.println("Using JDBC URL: " + expandedUrl);
        dbConnection = DriverManager.getConnection(expandedUrl, expandedUser, expandedPassword);
    } catch (Exception ex) {
        throw new ResourceInstantiationException("Could not get driver/connection", ex);
    }
    Statement stmt = null;
    try {
        stmt = dbConnection.createStatement();
        ResultSet rs = null;
        rs = stmt.executeQuery(query);
        int i = 0;
        while (rs.next()) {
            String docName = rs.getString(getDocumentNameField());
            documentNames.add(docName);
            isLoadeds.add(false);
            documentIndexes.put(docName, i);
            i++;
        }
    } catch (SQLException ex) {
        throw new ResourceInstantiationException("Problem accessing database", ex);
    }
    try {
        PersistenceManager.registerPersistentEquivalent(at.ofai.gate.virtualcorpus.JDBCCorpus.class,
                at.ofai.gate.virtualcorpus.JDBCCorpusPersistence.class);
    } catch (PersistenceException e) {
        throw new ResourceInstantiationException("Could not register persistence", e);
    }
    try {
        // TODO: use more fields or a hash to make this unique?
        ourDS = (DummyDataStore4JDBCCorp) Factory.createDataStore(
                "at.ofai.gate.virtualcorpus.DummyDataStore4JDBCCorp", expandedUrl + "//" + getTableName());
        ourDS.setName("DummyDS4_" + this.getName());
        ourDS.setComment("Dummy DataStore for JDBCCorpus " + this.getName());
        ourDS.setCorpus(this);
        //System.err.println("Created dummy corpus: "+ourDS+" with name "+ourDS.getName());
    } catch (Exception ex) {
        throw new ResourceInstantiationException("Could not create dummy data store", ex);
    }
    Gate.getCreoleRegister().addCreoleListener(this);

    // create all the prepared statements we need for accessing stuff in the db
    try {
        query = "SELECT " + getDocumentContentField() + " FROM " + getTableName() + " WHERE "
                + getDocumentNameField() + " = ?";
        System.out.println("Preparing get document statement: " + query);
        getContentStatement = dbConnection.prepareStatement(query);
        String outfield = getDocumentContentField();

    } catch (SQLException ex) {
        throw new ResourceInstantiationException("Could not prepare statement", ex);
    }

    return this;
}

From source file:com.vmware.identity.saml.impl.TokenValidatorImpl.java

/**
 * @param value//from w  w w.j av a2  s  .com
 *           required
 * @param separator
 *           required
 * @return
 */
private String[] splitInTwo(String value, char separator) {

    Pattern splitter = Pattern.compile(Pattern.quote(String.valueOf(separator)));
    String split[] = splitter.split(value, 3);
    if (split.length != 2 || split[0].isEmpty() || split[1].isEmpty()) {
        throw new IllegalStateException(
                String.format("Invalid principal value: `%s' (incorrect number of fields)", value));
    }

    return split;
}

From source file:io.lavagna.service.SearchFilter.java

private static void addDateParams(SearchFilter sf, List<Object> params) {
    if (sf.value.type == ValueType.DATE_IDENTIFIER) {
        fromDateIdentifier(sf.value.value.toString(), params);
    } else {// ww  w  .j av a  2s.  c  o m
        Date from = null, to = null;
        try {
            String[] splitted = sf.value.value.toString().split(Pattern.quote(".."));
            String[] format = { "dd.MM.yyyy", "dd-MM-yyyy", "dd/MM/yyyy", "yyyy-MM-dd", "yyyy.MM.dd",
                    "yyyy/MM/dd" };
            if (splitted.length == 2) {
                from = truncate(parseDateStrictly(splitted[0], format), Calendar.DAY_OF_MONTH);
                to = addDays(truncate(parseDateStrictly(splitted[1], format), Calendar.DAY_OF_MONTH), 1);
            } else {
                from = truncate(parseDateStrictly(sf.value.value.toString(), format), Calendar.DAY_OF_MONTH);
                to = addDays(from, 1);
            }
        } catch (ParseException pe) {
            //
        }
        params.add(from);
        params.add(to);
    }
}

From source file:com.epam.ta.reportportal.database.dao.LaunchRepositoryCustomImpl.java

@SuppressWarnings({ "rawtypes" })
@Override//from   w ww .  j  a v a  2s.  c o m
public List<String> findValuesWithMode(String projectName, String containsValue, String distinctBy,
        String mode) {
    Aggregation aggregation = newAggregation(match(where(PROJECT_ID_REFERENCE).is(projectName)),
            match(where(MODE).is(mode)),
            match(where(distinctBy).regex("(?i).*" + Pattern.quote(containsValue) + ".*")), group(distinctBy),
            limit(AUTOCOMPLETE_LIMITATION));
    AggregationResults<Map> result = mongoTemplate.aggregate(aggregation, Launch.class, Map.class);
    return result.getMappedResults().stream().map(entry -> entry.get("_id").toString()).collect(toList());
}

From source file:org.openbaton.vnfm.utils.Utils.java

public static String replaceVariables(String userdataRaw, Map<String, String> variables) {
    String userdata = userdataRaw;
    for (String variable : variables.keySet()) {
        log.debug("Replace " + variable + " with value " + variables.get(variable));
        userdata = userdata.replaceAll(Pattern.quote(variable), variables.get(variable));
        log.debug("Replaced userdata: " + userdata);
    }//from  w ww.  j ava 2  s .  c om
    return userdata;
}

From source file:com.predic8.membrane.core.interceptor.authentication.session.LDAPUserDataProvider.java

private String searchUser(String login, HashMap<String, String> userAttrs, DirContext ctx)
        throws NamingException {
    String uid;/*from   ww  w .  j  a  va  2  s .c  om*/
    SearchControls ctls = new SearchControls();
    ctls.setReturningObjFlag(true);
    ctls.setSearchScope(searchScope);
    String search = searchPattern.replaceAll(Pattern.quote("%LOGIN%"), escapeLDAPSearchFilter(login));
    log.debug("Searching LDAP for " + search);
    NamingEnumeration<SearchResult> answer = ctx.search(base, search, ctls);
    try {
        if (!answer.hasMore())
            throw new NoSuchElementException();
        log.debug("LDAP returned >=1 record.");
        SearchResult result = answer.next();
        uid = result.getName();
        for (Map.Entry<String, String> e : attributeMap.entrySet()) {
            log.debug("found LDAP attribute: " + e.getKey());
            Attribute a = result.getAttributes().get(e.getKey());
            if (a != null)
                userAttrs.put(e.getValue(), a.get().toString());
        }
    } finally {
        answer.close();
    }
    return uid;
}

From source file:com.offbynull.coroutines.instrumenter.testhelpers.TestUtils.java

/**
 * Gets the system classpath and creates a list of {@link File} objects for each path.
 *
 * @return classpath as list of {@link File} objects
 * @throws IllegalStateException if the classpath doesn't exist or can't be split up
 *//*from ww w.jav a 2 s . co m*/
public static List<File> getClasspath() {
    String pathSeparator = System.getProperty("path.separator");
    Validate.validState(pathSeparator != null);

    String classpath = System.getProperty("java.class.path");
    Validate.validState(classpath != null);
    List<File> classPathFiles = Arrays.stream(classpath.split(Pattern.quote(pathSeparator)))
            .map(x -> new File(x)).filter(x -> x.exists()).collect(Collectors.toList());

    String bootClasspath = System.getProperty("sun.boot.class.path");
    Validate.validState(bootClasspath != null);
    List<File> bootClassPathFiles = Arrays.stream(bootClasspath.split(Pattern.quote(pathSeparator)))
            .map(x -> new File(x)).filter(x -> x.exists()).collect(Collectors.toList());

    ArrayList<File> ret = new ArrayList<>();
    ret.addAll(classPathFiles);
    ret.addAll(bootClassPathFiles);

    return ret;
}