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

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

Introduction

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

Prototype

public static int length(String str) 

Source Link

Document

Gets a String's length or 0 if the String is null.

Usage

From source file:net.ymate.platform.mvc.web.support.CookieHelper.java

/**
 * @return ?Cookie/*from   www. j ava  2  s  .  c o  m*/
 */
public Map<String, BlurObject> getCookies() {
    Map<String, BlurObject> _returnValue = new HashMap<String, BlurObject>();
    Cookie[] _cookies = __request.getCookies();
    if (_cookies != null) {
        String _cookiePre = WebMVC.getConfig().getCookiePrefix();
        int _preLength = StringUtils.length(_cookiePre);
        for (Cookie _cookie : _cookies) {
            String _name = _cookie.getName();
            if (_name.startsWith(_cookiePre)) {
                String _v = decodeValue(_cookie.getValue());
                _returnValue.put(_name.substring(_preLength), new BlurObject(_v));
            }
        }
    }
    return _returnValue;
}

From source file:net.ymate.platform.webmvc.util.CookieHelper.java

/**
 * @return ?Cookie//from w  w w .  j  ava 2  s .co m
 */
public Map<String, BlurObject> getCookies() {
    Map<String, BlurObject> _returnValue = new HashMap<String, BlurObject>();
    Cookie[] _cookies = WebContext.getRequest().getCookies();
    if (_cookies != null) {
        String _cookiePre = __owner.getModuleCfg().getCookiePrefix();
        int _preLength = StringUtils.length(_cookiePre);
        for (Cookie _cookie : _cookies) {
            String _name = _cookie.getName();
            if (_name.startsWith(_cookiePre)) {
                String _v = decodeValue(_cookie.getValue());
                _returnValue.put(_name.substring(_preLength), new BlurObject(_v));
            }
        }
    }
    return _returnValue;
}

From source file:nl.knaw.huygens.security.client.filters.SecurityResourceFilter.java

protected SecurityContext createSecurityContext(ContainerRequest request) {
    SecurityInformation securityInformation;
    String token = getToken(request);

    LOG.info("token: {} length: {}", token, StringUtils.length(token));

    try {//w  w w  .  ja va  2  s . c  o  m
        securityInformation = authenticationHandler.getSecurityInformation(token);
    } catch (UnauthorizedException e) {
        throw new WebApplicationException(Status.UNAUTHORIZED);
    }

    return securityContextCreator.createSecurityContext(securityInformation);
}

From source file:nl.surfnet.coin.teams.util.TokenUtil.java

public static void checkTokens(String sessionToken, String token, SessionStatus status) {
    if (StringUtils.length(sessionToken) != TOKEN_LENGTH || !(sessionToken.equals(token))) {
        status.setComplete();//from www  .j ava 2 s . c o  m
        throw new SecurityException("Token does not match");
    }
}

From source file:org.adl.datamodels.datatypes.InteractionTrunc.java

/**
 * Truncates all parts of an interaction datatype to their SPMs
 * /*from www  .j  a va 2  s .c o m*/
 * @param iValue The value being truncated
 * @param iType  The type of the value being truncated
 * 
 * @return Returns the Truncated value
 */
public static String trunc(String iValue, int iType) {
    StringBuilder trunc = new StringBuilder();

    // SCORM defined separators
    String comma = "\\[,\\]";

    int idx = -1;

    // Swith on the interaction type
    switch (iType) {
    case InteractionValidator.MULTIPLE_CHOICE: {
        // Check for an empty set
        if (StringUtils.isBlank(iValue)) {
            // Value OK
            break;
        }

        String choices[] = iValue.split(comma);
        trunc = new StringBuilder();

        // Check to determine if each choice is within the SPM range  
        for (int i = 0; i < 36; i++) {
            if (choices[i].length() > 250) {
                trunc.append(choices[i].substring(0, 250));
            } else {
                trunc.append(choices[i]);
            }

            if (i != 35) {
                trunc.append("[,]");
            }
        }

        break;
    }
    case InteractionValidator.FILL_IN: {
        // Extract each part of the match_text
        String matchText[] = iValue.split(comma);
        trunc = new StringBuilder();

        for (int i = 0; i < 10; i++) {
            String matchString = null;
            String langString = null;

            // Look for the 'lang' delimiter
            if (matchText[i].startsWith("{lang=")) {
                // Find the closing '}'
                idx = matchText[i].indexOf('}');
                if (idx != -1) {
                    matchString = matchText[i].substring(idx + 1);
                    langString = matchText[i].substring(6, idx);
                } else {
                    matchString = matchText[i];
                }
            } else {
                matchString = matchText[i];
            }

            if (StringUtils.length(langString) > 250) {
                trunc.append("{lang=" + langString.substring(0, 250) + "}");
            } else {
                trunc.append("{lang=" + langString + "}");
            }

            if (matchString.length() > 250) {
                trunc.append(matchString.substring(0, 250));
            } else {
                trunc.append(matchString);
            }

            if (i != 9) {
                trunc.append("[,]");
            }
        }

        break;
    }
    case InteractionValidator.LONG_FILL_IN: {
        if (iValue.length() > 4000) {
            trunc = new StringBuilder(iValue.substring(0, 4000));
        } else {
            trunc = new StringBuilder(iValue);
        }

        break;
    }
    case InteractionValidator.LIKERT: {
        if (iValue.length() > 250) {
            trunc = new StringBuilder(iValue.substring(0, 250));
        }

        break;
    }
    case InteractionValidator.MATCHING: {
        if (StringUtils.isBlank(iValue)) {
            // Value OK
            break;
        }

        String commas[] = iValue.split(comma);
        trunc = new StringBuilder();

        for (int i = 0; i < 36; i++) {
            idx = commas[i].indexOf("[.]");

            String target = commas[i].substring(0, idx);
            String source = commas[i].substring(idx + 3, commas[i].length());

            if (target.length() > 250) {
                trunc.append(target.substring(0, 250));
            } else {
                trunc.append(target);
            }

            trunc.append("[.]");

            if (source.length() > 250) {
                trunc.append(source.substring(0, 250));
            } else {
                trunc.append(source);
            }

            if (i != 35) {
                trunc.append("[,]");
            }
        }

        break;
    }
    case InteractionValidator.PERFORMANCE: {
        String commaCheck[] = iValue.split(comma);
        trunc = new StringBuilder();

        for (int i = 0; i < 125; i++) {
            idx = commaCheck[i].indexOf("[.]");

            String sn = commaCheck[i].substring(0, idx);
            String sa = commaCheck[i].substring(idx + 3, commaCheck[i].length());

            if (sn.length() > 250) {
                trunc.append(sn.substring(0, 250));
            } else {
                trunc.append(sn);
            }

            trunc.append("[.]");

            if (sa.length() > 250) {
                trunc.append(sa.substring(0, 250));
            } else {
                trunc.append(sa);
            }

            if (i != 124) {
                trunc.append("[,]");
            }
        }

        break;
    }
    case InteractionValidator.SEQUENCING: {
        String array[] = iValue.split(comma);
        trunc = new StringBuilder();

        for (int i = 0; i < 36; i++) {

            if (array[i].length() > 250) {
                trunc.append(array[i].substring(0, 250));
            } else {
                trunc = new StringBuilder(array[i]);
            }

            if (i != 35) {
                trunc.append("[,]");
            }
        }

        break;
    }
    case InteractionValidator.NUMERIC: {
        trunc = new StringBuilder(iValue);

        break;
    }
    default: {
        break;
    }
    }

    return trunc.toString();
}

From source file:org.apache.archiva.metadata.repository.cassandra.CassandraMetadataRepository.java

@Override
public Collection<String> getNamespaces(final String repoId, final String namespaceId)
        throws MetadataResolutionException {

    QueryResult<OrderedRows<String, String, String>> result = HFactory //
            .createRangeSlicesQuery(keyspace, ss, ss, ss) //
            .setColumnFamily(cassandraArchivaManager.getNamespaceFamilyName()) //
            .setColumnNames(NAME.toString()) //
            .addEqualsExpression(REPOSITORY_NAME.toString(), repoId) //
            .execute();// w  ww  .j  av  a 2  s  . c  o m

    List<String> namespaces = new ArrayList<>(result.get().getCount());

    for (Row<String, String, String> row : result.get()) {
        String currentNamespace = getStringValue(row.getColumnSlice(), NAME.toString());
        if (StringUtils.startsWith(currentNamespace, namespaceId) //
                && (StringUtils.length(currentNamespace) > StringUtils.length(namespaceId))) {
            // store after namespaceId '.' but before next '.'
            // call org namespace org.apache.maven.shared -> stored apache

            String calledNamespace = StringUtils.endsWith(namespaceId, ".") ? namespaceId : namespaceId + ".";
            String storedNamespace = StringUtils.substringAfter(currentNamespace, calledNamespace);

            storedNamespace = StringUtils.substringBefore(storedNamespace, ".");

            namespaces.add(storedNamespace);
        }
    }

    return namespaces;

}

From source file:org.artifactory.rest.resource.search.types.ChecksumSearchResource.java

/**
 * check if checksum length match sha 256 length
 *
 * @return - true if match sha256/*from  w w w  .  ja  v a 2 s  .  c om*/
 */
private boolean matchToSha256Length(String sha256) {
    return StringUtils.length(sha256) == ChecksumType.sha256.length();
}

From source file:org.artifactory.webapp.wicket.page.search.checksum.ChecksumSearchPanel.java

@Override
protected void validateSearchControls() {
    // RTFACT-6211 - clearing old search query before running new query
    searchControls.clearChecksums();//w  w  w .  j a v  a 2 s  .  com
    if (StringUtils.isNotBlank(query)) {
        if (StringUtils.length(query) == ChecksumType.md5.length()) {
            searchControls.addChecksum(ChecksumType.md5, query);
        } else if (StringUtils.length(query) == ChecksumType.sha1.length()) {
            searchControls.addChecksum(ChecksumType.sha1, query);
        }
    }
    if (searchControls.isEmpty()) {
        throw new IllegalArgumentException("Please enter a valid checksum to search for");
    }
    if (searchControls.isWildcardsOnly()) {
        throw new IllegalArgumentException("Search term containing only wildcards is not permitted");
    }
}

From source file:org.b3log.solo.model.Tag.java

/**
 * Formats the specified tags./*from w  w w  .  j  av a 2s .  co  m*/
 * <ul>
 * <li>Trims every tag</li>
 * <li>Deduplication</li>
 * </ul>
 *
 * @param tagStr the specified tags
 * @return formatted tags string
 */
public static String formatTags(final String tagStr) {
    final String tagStr1 = tagStr.replaceAll("\\s+", "").replaceAll("", ",").replaceAll("?", ",")
            .replaceAll("", ",").replaceAll(";", ",");
    String[] tagTitles = tagStr1.split(",");

    tagTitles = Strings.trimAll(tagTitles);

    // deduplication
    final Set<String> titles = new LinkedHashSet<>();
    for (final String tagTitle : tagTitles) {
        if (!exists(titles, tagTitle)) {
            titles.add(tagTitle);
        }
    }

    tagTitles = titles.toArray(new String[0]);

    int count = 0;
    final StringBuilder tagsBuilder = new StringBuilder();
    for (final String tagTitle : tagTitles) {
        String title = tagTitle.trim();
        if (StringUtils.isBlank(title)) {
            continue;
        }

        if (StringUtils.length(title) > 12) {
            continue;
        }

        if (!TAG_TITLE_PATTERN.matcher(title).matches()) {
            continue;
        }

        tagsBuilder.append(title).append(",");
        count++;

        if (count >= MAX_TAG_COUNT) {
            break;
        }
    }
    if (tagsBuilder.length() > 0) {
        tagsBuilder.deleteCharAt(tagsBuilder.length() - 1);
    }

    return tagsBuilder.toString();
}

From source file:org.b3log.symphony.model.Tag.java

/**
 * Formats the specified tags.//from   w  ww . j  av  a 2  s.c o m
 *
 * <ul>
 * <li>Trims every tag</li>
 * <li>Deduplication</li>
 * </ul>
 *
 * @param tagStr the specified tags
 * @return formatted tags string
 */
public static String formatTags(final String tagStr) {
    final String tagStr1 = tagStr.replaceAll("\\s+", "").replaceAll("", ",").replaceAll("?", ",")
            .replaceAll("", ",").replaceAll(";", ",");
    String[] tagTitles = tagStr1.split(",");

    tagTitles = Strings.trimAll(tagTitles);

    // deduplication
    final Set<String> titles = new LinkedHashSet<>();
    for (final String tagTitle : tagTitles) {
        if (!exists(titles, tagTitle)) {
            titles.add(tagTitle);
        }
    }

    tagTitles = titles.toArray(new String[0]);

    int count = 0;
    final StringBuilder tagsBuilder = new StringBuilder();
    for (final String tagTitle : tagTitles) {
        String title = tagTitle.trim();
        if (StringUtils.isBlank(title)) {
            continue;
        }

        if (containsWhiteListTags(title)) {
            tagsBuilder.append(title).append(",");
            count++;

            if (count >= MAX_TAG_COUNT) {
                break;
            }

            continue;
        }

        if (StringUtils.length(title) > MAX_TAG_TITLE_LENGTH) {
            continue;
        }

        if (!TAG_TITLE_PATTERN.matcher(title).matches()) {
            continue;
        }

        title = normalize(title);
        tagsBuilder.append(title).append(",");
        count++;

        if (count >= MAX_TAG_COUNT) {
            break;
        }
    }
    if (tagsBuilder.length() > 0) {
        tagsBuilder.deleteCharAt(tagsBuilder.length() - 1);
    }

    return tagsBuilder.toString();
}