Example usage for org.apache.commons.lang StringUtils contains

List of usage examples for org.apache.commons.lang StringUtils contains

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils contains.

Prototype

public static boolean contains(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String, handling null.

Usage

From source file:com.haulmont.cuba.gui.app.core.categories.AttributeEditor.java

protected List<Suggestion> requestHint(SourceCodeEditor sender, String text, int senderCursorPosition) {
    String joinStr = joinField.getValue();
    String whereStr = whereField.getValue();

    // CAUTION: the magic entity name!  The length is three character to match "{E}" length in query
    String entityAlias = "a39";

    int queryPosition = -1;
    Class javaClassForEntity = attribute.getJavaClassForEntity();
    if (javaClassForEntity == null)
        return new ArrayList<>();

    MetaClass metaClass = metadata.getClassNN(javaClassForEntity);
    String queryStart = "select " + entityAlias + " from " + metaClass.getName() + " " + entityAlias + " ";

    StringBuilder queryBuilder = new StringBuilder(queryStart);
    if (StringUtils.isNotEmpty(joinStr)) {
        if (sender == joinField) {
            queryPosition = queryBuilder.length() + senderCursorPosition - 1;
        }/*  w w  w.  j  a va  2 s.  c  om*/
        if (!StringUtils.containsIgnoreCase(joinStr, "join") && !StringUtils.contains(joinStr, ",")) {
            queryBuilder.append("join ").append(joinStr);
            queryPosition += "join ".length();
        } else {
            queryBuilder.append(joinStr);
        }
    }
    if (StringUtils.isNotEmpty(whereStr)) {
        if (sender == whereField) {
            queryPosition = queryBuilder.length() + WHERE.length() + senderCursorPosition - 1;
        }
        queryBuilder.append(WHERE).append(whereStr);
    }
    String query = queryBuilder.toString();
    query = query.replace("{E}", entityAlias);

    return JpqlSuggestionFactory.requestHint(query, queryPosition, sender.getAutoCompleteSupport(),
            senderCursorPosition);
}

From source file:edu.ku.brc.af.core.db.DBTableIdMgr.java

/**
 * //from  www.j a  v  a2 s.c om
 */
public void dumpTablesAsCSV() {
    boolean checkMM = true;
    try {
        PrintWriter pw = new PrintWriter("TablesAndField.csv");
        for (DBTableInfo ti : getTables()) {
            pw.write("\"" + ti.getName() + "\",,\"" + ti.getTitle() + "\",\"" + ti.getDescription() + "\","
                    + (checkMM ? "Mismatch" : "") + "\n");
            for (DBFieldInfo fi : ti.getFields()) {
                pw.write(",\"" + fi.getName() + "\",\"" + fi.getTitle() + "\",\""
                        + (StringUtils.isNotEmpty(fi.getDescription()) ? fi.getDescription() : "") + "\",\""
                        + fi.getType() + "\"");
                if (checkMM) {
                    if (fi.getColumn().startsWith("Number")) {
                        if (StringUtils.contains(fi.getType(), "Byte")
                                || StringUtils.contains(fi.getType(), "Short")
                                || StringUtils.contains(fi.getType(), "Integer")
                                || StringUtils.contains(fi.getType(), "Long")
                                || StringUtils.contains(fi.getType(), "Float")
                                || StringUtils.contains(fi.getType(), "Double")) {
                            //pw.write(", OK");
                        } else {
                            pw.write(",*");
                        }
                    } else if (fi.getColumn().startsWith("Text")) {
                        if (StringUtils.contains(fi.getType(), "String")) {
                            //pw.write(", OK");
                        } else {
                            pw.write(",*");
                        }
                    } else if (fi.getColumn().startsWith("Yes")) {
                        if (StringUtils.contains(fi.getType(), "Boolean")) {
                            //pw.write(", OK");
                        } else {
                            pw.write(",*");
                        }
                    } else if (fi.getColumn().startsWith("Remark")) {
                        if (StringUtils.contains(fi.getType(), "text")) {
                            //pw.write(", OK");
                        } else {
                            pw.write(",*");
                        }
                    }
                }
                pw.write("\n");
            }
            for (DBRelationshipInfo ri : ti.getRelationships()) {
                pw.write(",\"" + ri.getName() + "\",\"" + ri.getTitle() + "\",\""
                        + (StringUtils.isNotEmpty(ri.getDescription()) ? ri.getDescription() : "") + "\",\""
                        + ri.getType() + "\"\n");
            }
        }

        pw.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:gov.nih.nci.cabig.caaers.rules.business.service.CaaersRulesEngineService.java

private void replaceCommaSeperatedStringToList(Condition condition) {
    for (Column col : condition.getColumn()) {
        if (CollectionUtils.isEmpty(col.getFieldConstraint()))
            continue;
        FieldConstraint fc = col.getFieldConstraint().get(0);
        if (CollectionUtils.isEmpty(fc.getLiteralRestriction()))
            continue;
        LiteralRestriction lr = fc.getLiteralRestriction().get(0);
        if (CollectionUtils.isEmpty(lr.getValue()))
            continue;
        String value = lr.getValue().get(0);
        if (StringUtils.contains(value, ",")) {
            List<String> values = CaaersRuleUtil.charSeparatedStringToStringList(value, ",");
            col.getFieldConstraint().get(0).getLiteralRestriction().get(0).setValue(values);
        }/*from w ww  .j  a  va  2s.  c o m*/

    }
}

From source file:com.vmware.veei.qe.devcenter.SampleExchangeTest.java

/**
 * Returns a list of URLs of the My Sample links.
 *///from  w  w  w  .ja va 2 s .c o m
@DataProvider
public Object[][] getMySampleExchangeUrls() {
    List<Object[]> data = new ArrayList<Object[]>();
    // #action : Navigates to main Sample Exchange pages.
    driver.get(baseUrl + SAMPLE_CODE_URL);

    selectTab("My samples");

    // Gets all the links under Sample page span.
    List<WebElement> elements = driver
            .findElements(By.cssSelector("#search-results-list .title-list li .title"));

    // We have to put this in a temporary list, since any further action on the Web driver
    // will make the references to the WebElement unusable.
    for (WebElement element : elements) {
        if (!StringUtils.contains(element.getAttribute("href"), "/user?id")) {
            data.add(new Object[] { element.getAttribute("href").trim() });
        }
    }
    return data.toArray(new Object[][] {});
}

From source file:ips1ap101.lib.core.db.util.Reporter.java

private static String getParent(File file, Long usuario) {
    String sep = System.getProperties().getProperty("file.separator");
    String path = file.getPath();
    String substring = sep + "user-defined" + sep + Utils.getUserDir(usuario) + sep;
    return StringUtils.contains(path, substring) ? file.getParentFile().getParent() : file.getParent();
}

From source file:com.impetus.client.cassandra.query.CassQuery.java

/**
 * On condition./*  w  w w  . j  a v a2  s. c o  m*/
 * 
 * @param m
 *            the m
 * @param metaModel
 *            the meta model
 * @param keyObj
 *            the compound key
 * @param idColumn
 *            the id column
 * @param builder
 *            the builder
 * @param isPresent
 *            the is present
 * @param translator
 *            the translator
 * @param use
 *            the use
 * @return true, if successful
 */
private boolean onCondition(EntityMetadata m, MetamodelImpl metaModel, EmbeddableType keyObj, String idColumn,
        StringBuilder builder, boolean isPresent, CQLTranslator translator, boolean use) {
    String partitionKey = null;
    boolean allowFiltering = false;
    for (Object o : getKunderaQuery().getFilterClauseQueue()) {
        if (o instanceof FilterClause) {
            FilterClause clause = ((FilterClause) o);
            String fieldName = clause.getProperty();
            String condition = clause.getCondition();
            List<Object> value = clause.getValue();
            boolean useInClause = condition.trim().equalsIgnoreCase("IN");

            // if compound key field is given in where clause.
            isPresent = true;

            if (keyObj != null && idColumn.equals(fieldName)) {
                Field[] fields = m.getIdAttribute().getBindableJavaType().getDeclaredFields();

                Map<Attribute, List<Object>> columnValues = new HashMap<Attribute, List<Object>>();

                for (Field field : fields) {
                    if (!ReflectUtils.isTransientOrStatic(field)) {
                        extractCompositeKey(metaModel, keyObj, builder, translator, value, useInClause,
                                columnValues, field);
                    }
                }

                // Composite key always contains clusterKey.
                allowFiltering = true;
                if (useInClause) {
                    for (Attribute columnAttribute : columnValues.keySet()) {
                        isPresent = appendInClause(builder, translator, columnValues.get(columnAttribute),
                                ((AbstractAttribute) columnAttribute).getBindableJavaType(),
                                ((AbstractAttribute) columnAttribute).getJPAColumnName(), isPresent);
                    }
                }
            } else if (keyObj != null && metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType())
                    && StringUtils.contains(fieldName, '.')) {
                // Means it is a case of composite column.
                isPresent = getCompoundKeyColumn(metaModel, keyObj, builder, isPresent, translator, fieldName,
                        condition, value, useInClause);

                allowFiltering = true;
            } else if (idColumn.equals(fieldName)) {
                // dont use token for equals query on id column (#856)
                boolean useToken = use;
                if (condition.equals("=")) {
                    useToken = false;
                }
                isPresent = buildWhereClause(builder, isPresent, translator, condition, value, useInClause,
                        ((AbstractAttribute) m.getIdAttribute()),
                        CassandraUtilities.getIdColumnName(kunderaMetadata, m, externalProperties,
                                ((CassandraClientBase) persistenceDelegeator.getClient(m)).isCql3Enabled(m)),
                        useToken);
            } else {
                EntityType entity = metaModel.entity(m.getEntityClazz());
                // Metamodel metamodel =
                // KunderaMetadataManager.getMetamodel(kunderaMetadata,
                // m.getPersistenceUnit());
                String discriminatorColumn = ((AbstractManagedType) entity).getDiscriminatorColumn();
                if (fieldName.equals(discriminatorColumn)) {
                    translator.buildWhereClause(builder, String.class, fieldName,
                            value.isEmpty() ? null : value.get(0), condition, false);
                    isPresent = true;

                } else {
                    Metamodel metamodel = KunderaMetadataManager.getMetamodel(kunderaMetadata,
                            m.getPersistenceUnit());
                    Attribute attribute = ((MetamodelImpl) metamodel).getEntityAttribute(m.getEntityClazz(),
                            m.getFieldName(fieldName));

                    isPresent = buildWhereClause(builder, isPresent, translator, condition, value, useInClause,
                            ((AbstractAttribute) attribute), fieldName, false);
                }

                allowFiltering = true;
            }
        }
    }

    // Strip last AND clause.
    if (isPresent) {
        builder.delete(builder.lastIndexOf(CQLTranslator.AND_CLAUSE), builder.length());
    }

    // Append order by clause into query
    builder = appendOrderByClause(metaModel, m, keyObj, builder, translator);

    if (allowFiltering && use) {
        onLimit(builder);
        builder.append(" ");
        translator.buildFilteringClause(builder);
    } else if (use) {
        onLimit(builder);
    }

    return isPresent;
}

From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java

/**
 * @param inputText/* ww  w  .  j  a  v  a2 s  .c o  m*/
 */
protected String translate(final String inputText) {
    if (inputText.isEmpty())
        return "";
    //System.out.println("\n"+inputText);

    Translate.setHttpReferrer("http://www.specifysoftware.org");

    try {
        String text = inputText;

        boolean hasSpecialChars = false;
        while (StringUtils.contains(text, "%d") || StringUtils.contains(text, "%s")
                || StringUtils.contains(text, "\\n")) {
            text = StringUtils.replace(text, "%d", "99");
            text = StringUtils.replace(text, "%s", "88");
            text = StringUtils.replace(text, "\\n", " 77 ");
            hasSpecialChars = true;
        }

        Language lang = getLangFromCode(destLanguage.getCode());
        //System.out.println(text);
        String newText = Translate.execute(text, Language.ENGLISH, lang);

        if (hasSpecialChars) {
            while (StringUtils.contains(newText, "77") || StringUtils.contains(newText, "88")
                    || StringUtils.contains(newText, "99")) {
                newText = StringUtils.replace(newText, "99", "%d");
                newText = StringUtils.replace(newText, "88", "%s");
                newText = StringUtils.replace(newText, " 77 ", " \\n ");
                newText = StringUtils.replace(newText, "77 ", "\\n ");
                newText = StringUtils.replace(newText, " 77", " \\n");
            }
        }
        //System.out.println(newText);
        return newText;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.SwiftTagListBlock.java

/**
 * Returns the tags having the specified content as part of its value.<br />
 * For example the field :98A::XDTE//20090818 will be included for parameter XDTE
 *
 * @param value value of tags to find//from  w  w w  .j a v a2s  .c  om
 * @return an list of tags or an empty list if no tags are found
 *
 * @since 6.0
 */
public List<Tag> getTagsByContent(final String value) {
    final List<Tag> result = new ArrayList<Tag>();
    for (int i = 0; i < this.tags.size(); i++) {
        final Tag t = (Tag) this.tags.get(i);
        if (StringUtils.contains(t.getValue(), value)) {
            result.add(t);
        }
    }
    return result;
}

From source file:edu.ku.brc.dbsupport.MySQLDMBSUserMgr.java

/**
 * @param username/*from  ww w  . j  av  a2  s  . c om*/
 * @param serverName
 * @param dbName
 * @return
 */
public int getPermissionsUsingGrants(final String username, final String serverName, final String dbName) {
    try {
        if (connection != null) {
            //String sql = String.format("SHOW GRANTS FOR '%s'@'%s'", username, serverName);
            String uNameStr = String.format("'%s'@'", username);
            //log.debug(sql);
            Vector<Object[]> list = BasicSQLUtils.query(connection, "SHOW GRANTS");
            if (list != null) {
                int perms = PERM_NONE;
                for (Object[] row : list) {
                    String line = row[0].toString();
                    if (StringUtils.contains(line, uNameStr) && StringUtils.contains(line, dbName)) {
                        if (StringUtils.containsIgnoreCase(line, "GRANT ALL")) {
                            return PERM_ALL;
                        }

                        String pStr = line;
                        int eInx = pStr.indexOf(" ON ");
                        if (eInx > -1) {
                            pStr = pStr.substring(5, eInx).trim();
                            String[] tokens = StringUtils.split(pStr, ",");
                            for (String tok : tokens) {
                                perms = addPerm(tok.trim(), perms);
                            }
                        }
                    }
                }
                //log.debug("PERMS: "+perms);

                if (perms == 0 && username.equalsIgnoreCase("root")) {
                    perms = PERM_ALL;
                }
                return perms;
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return PERM_NONE;
}

From source file:com.vmware.veei.qe.devcenter.SampleExchangeTest.java

/**
 * Returns a list of URLs of the Sample Request links.
 *///from   w  w w  .j a  v  a  2 s.  c om
@DataProvider
public Object[][] getMyRequestUrls() {
    List<Object[]> data = new ArrayList<Object[]>();
    // #action : Navigates to main Sample Exchange pages.
    driver.get(baseUrl + SAMPLE_CODE_URL);

    selectTab("My Requests");

    // Gets all the links under Sample page span.
    List<WebElement> elements = driver
            .findElements(By.cssSelector("#search-results-list .title-list li div a"));
    // We have to put this in a temporary list, since any further action on the Web driver
    // will make the references to the WebElement unusable.
    for (WebElement element : elements) {
        if (StringUtils.contains(element.getAttribute("href"), "request&id=")) {
            data.add(new Object[] { element.getAttribute("href").trim() });
        }
    }
    return data.toArray(new Object[][] {});
}