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

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

Introduction

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

Prototype

public static boolean startsWith(String str, String prefix) 

Source Link

Document

Check if a String starts with a specified prefix.

Usage

From source file:eu.annocultor.analyzers.SolrPropertyHitsAnalyzer.java

/**
 * @param args/*from  w ww .  j  av  a  2 s .  c o m*/
 */
public static void main(String[] args) throws Exception {

    String solrUrl = args[0];
    SolrServer solr = new CommonsHttpSolrServer(solrUrl);

    String prefixOne = args[1];
    String prefixTwo = args[2];

    long prefixOneCount = 0;
    long prefixTwoCount = 0;

    long totalPassedCount = 0;

    for (File logLocation : FileUtils.listFiles(new File(args[3]), null, true)) {
        System.out.println("Parsing " + logLocation);

        for (String line : FileUtils.readLines(logLocation)) {
            if (StringUtils.contains(line, "FULL_RESULT_HMTL")) {
                line = StringUtils.substringAfter(line, "europeana_uri=");
                String solrDocumentId = StringUtils.substringBefore(line, ",");
                String query = extractQuery(line);
                if (StringUtils.startsWith(solrDocumentId, "http://") && isLongEnoughToCount(query)) {

                    SolrQuery solrQuery = new SolrQuery("europeana_uri:\"" + solrDocumentId + "\"");
                    QueryResponse response = solr.query(solrQuery);
                    SolrDocumentList sourceDocs = response.getResults();
                    if (sourceDocs.isEmpty()) {
                        System.out.println("Could not find object " + solrDocumentId);
                    } else {
                        SolrDocument document = sourceDocs.get(0);

                        if (hasWord(document, prefixOne, query)) {
                            prefixOneCount++;
                        } else {
                            if (hasWord(document, prefixTwo, query)) {
                                prefixTwoCount++;
                            }
                        }
                    }
                }
                totalPassedCount++;
            }
        }
        System.out.println(prefixOne + " : " + prefixOneCount + " " + prefixTwo + " : " + prefixTwoCount
                + " of total passed entries " + totalPassedCount);
    }
}

From source file:com.enonic.cms.business.core.content.ContentNameValidator.java

public static void validate(String contentName) {
    if (StringUtils.isEmpty(contentName)) {
        throw new ContentNameValidatorException("Content name cannot be empty");
    }/*from   w  w w. j  a v a  2s .c o  m*/

    if (StringUtils.startsWith(contentName, " ") || StringUtils.endsWith(contentName, " ")) {
        throw new ContentNameValidatorException("Content name cannot start or end with whitespace");
    }

    if (StringUtils.containsAny(contentName, FORBIDDEN_CHARS)) {
        throw new ContentNameValidatorException(
                "Content name cannot contain any of these characters: " + FORBIDDEN_CHARS);
    }

    if (contentName.length() > CONTENT_NAME_MAX_LENGTH) {
        throw new ContentNameValidatorException("Content name is too long: " + contentName.length()
                + " . Maximum length is " + CONTENT_NAME_MAX_LENGTH + " characters.");
    }
}

From source file:com.hangum.tadpole.mongodb.erd.core.utils.MongodbUtils.java

/**
 * Is mongodb reference key//from   w w  w.  j  av a2 s.  c  o m
 * 
 * @param type
 * @param field
 * @return
 */
public static boolean isReferenceKey(String type, String field) {
    if ("ObjectId".equals(type) && !StringUtils.startsWith(field, "_id")
            && StringUtils.endsWith(field, "_id")) {
        return true;
    }

    return false;
}

From source file:com.enonic.cms.core.search.query.QueryFieldFactory.java

private static void detectAttachmentField(final String field, final QueryField queryField) {
    if (StringUtils.startsWith(field, ATTACHMENT_FIELDNAME)) {
        queryField.setRenderAsHasChildQuery(true).setIndexType(IndexType.Binaries).setAttachmentField(true);
    } else {//w w  w.j  ava 2 s . c om
        queryField.setIndexType(IndexType.Content);
    }
}

From source file:io.kamax.mxisd.config.threepid.medium.GenericTemplateConfig.java

protected static String getName(String path) {
    if (StringUtils.startsWith(path, classpathPrefix)) {
        return "Built-in (" + path.substring(classpathPrefix.length()) + ")";
    }//ww  w.  ja  va 2  s  . c  o m

    return path;
}

From source file:com.enonic.cms.core.search.query.QueryFieldNameResolver.java

private static String doNormalizeQueryFieldName(final String fieldName) {
    String normalizedFieldName = IndexFieldnameNormalizer.normalizeFieldName(fieldName);

    if (StringUtils.startsWith(normalizedFieldName, CONTENTDATA_PREFIX_ALIAS_FOR_BW_COMPATABILITY)) {
        normalizedFieldName = StringUtils.replaceOnce(normalizedFieldName,
                CONTENTDATA_PREFIX_ALIAS_FOR_BW_COMPATABILITY, CONTENTDATA_PREFIX);
    }/*from   w  w  w . j av  a2  s.  com*/

    if (StringUtils.startsWith(normalizedFieldName, ATTACHMENT_ALIAS_FOR_BW_COMPATABILITY)) {
        normalizedFieldName = StringUtils.replaceOnce(normalizedFieldName,
                ATTACHMENT_ALIAS_FOR_BW_COMPATABILITY, ATTACHMENT_FIELDNAME);
    }

    return normalizedFieldName;
}

From source file:com.adobe.acs.commons.rewriter.impl.SaxElementUtils.java

public static boolean isCss(final String elementName, final Attributes attrs) {
    final String type = attrs.getValue("", "type");
    final String href = attrs.getValue("", "href");

    if (StringUtils.equals("link", elementName) && StringUtils.equals(type, CSS_TYPE)
            && StringUtils.startsWith(href, "/") && !StringUtils.startsWith(href, "//")
            && StringUtils.endsWith(href, LibraryType.CSS.extension)) {
        return true;
    }/*w  w w .j a v  a2  s  .  c om*/

    return false;
}

From source file:com.intel.cosbench.driver.generator.ConstantIntGenerator.java

public static ConstantIntGenerator parse(String pattern) {
    if (!StringUtils.startsWith(pattern, "c("))
        return null;
    try {//from  www.  ja v a  2  s  .  c  om
        return tryParse(pattern);
    } catch (Exception e) {
    }
    String msg = "illegal constant distribution pattern: " + pattern;
    throw new ConfigException(msg);
}

From source file:com.ewcms.web.util.EwcmsContextUtil.java

private static Collection<String> getGrantedAuthorities(String perfix) {

    List<String> names = new ArrayList<String>();

    UserDetails user = getUserDetails();
    if (user == null) {
        return names;
    }/*from ww  w  .  j  a va  2 s  .co  m*/

    Collection<GrantedAuthority> authorites = user.getAuthorities();
    for (GrantedAuthority auth : authorites) {
        if (StringUtils.startsWith(auth.getAuthority(), perfix)) {
            names.add(auth.getAuthority());
        }
    }

    return names;
}

From source file:com.intel.cosbench.driver.generator.BimodalIntGenerator.java

public static BimodalIntGenerator parse(String pattern) {
    if (!StringUtils.startsWith(pattern, "b("))
        return null;
    try {// ww  w. j a v  a  2 s .c  o m
        return tryParse(pattern);
    } catch (Exception e) {
    }
    String msg = "illegal uniform distribution pattern: " + pattern;
    throw new ConfigException(msg);
}