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

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

Introduction

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

Prototype

public static int length(final CharSequence cs) 

Source Link

Document

Gets a CharSequence length or 0 if the CharSequence is null .

Usage

From source file:org.sakaiproject.gradebookng.business.importExport.CommentValidator.java

/**
 * Test the given comment string for validity (character length).
 * Max length is defined by sakai.property 'gradebookng.maxCommentLength'; defaults to 20,000
 *
 * @param comment the comment string to test
 * @return true if the given comment is invalid; false otherwise
 *//*  w  ww .j av  a 2  s . c  om*/
public static boolean isCommentInvalid(String comment, ServerConfigurationService serverConfigService) {
    return StringUtils.length(comment) > getMaxCommentLength(serverConfigService);
}

From source file:org.sparkcommerce.openadmin.server.service.persistence.validation.FieldLengthValidator.java

@Override
public PropertyValidationResult validate(Entity entity, Serializable instance,
        Map<String, FieldMetadata> entityFieldMetadata, BasicFieldMetadata propertyMetadata,
        String propertyName, String value) {
    boolean valid = true;
    String errorMessage = "";
    if (propertyMetadata.getLength() != null) {
        valid = StringUtils.length(value) <= propertyMetadata.getLength();
    }//from  ww w  .j av  a 2  s  . c o m

    if (!valid) {
        SparkRequestContext context = SparkRequestContext.getSparkRequestContext();
        MessageSource messages = context.getMessageSource();
        errorMessage = messages.getMessage("fieldLengthValidationFailure",
                new Object[] { propertyMetadata.getLength(), StringUtils.length(value) },
                context.getJavaLocale());
    }

    return new PropertyValidationResult(valid, errorMessage);
}

From source file:org.zanata.dao.GlossaryDAO.java

/**
 * Perform lucene search in HGlossaryTerm in srcLocale
 * Object[0] - Float score/*from  w  ww.j  a  va 2 s.c om*/
 * Object[1] - HGlossaryTerm srcTerm
 */
public List<Object[]> getSearchResult(String searchText, SearchType searchType, LocaleId srcLocale,
        final int maxResult, String qualifiedName) throws ParseException {
    if (StringUtils.length(searchText) > LuceneQuery.QUERY_MAX_LENGTH) {
        throw new RuntimeException("Query string exceed max length: " + LuceneQuery.QUERY_MAX_LENGTH + "='"
                + StringUtils.left(searchText, 80) + "'");
    }

    String queryText;

    switch (searchType) {
    case RAW:
        queryText = searchText;
        break;
    case FUZZY:
        // search by N-grams
        queryText = QueryParser.escape(searchText);
        break;
    case EXACT:
        queryText = "\"" + QueryParser.escape(searchText) + "\"";
        break;
    default:
        throw new RuntimeException("Unknown query type: " + searchType);
    }
    if (StringUtils.isEmpty(queryText)) {
        return Lists.newArrayList();
    }
    QueryParser parser = new QueryParser("content", new StandardAnalyzer());
    org.apache.lucene.search.Query textQuery = parser.parse(queryText);

    TermQuery qualifiedNameQuery = new TermQuery(
            new Term(IndexFieldLabels.GLOSSARY_QUALIFIED_NAME, qualifiedName));

    BooleanQuery booleanQuery = new BooleanQuery.Builder().add(textQuery, BooleanClause.Occur.MUST)
            .add(qualifiedNameQuery, BooleanClause.Occur.MUST).build();

    FullTextQuery ftQuery = entityManager.createFullTextQuery(booleanQuery, HGlossaryTerm.class);
    ftQuery.enableFullTextFilter("glossaryLocaleFilter").setParameter("locale", srcLocale);
    ftQuery.setProjection(FullTextQuery.SCORE, FullTextQuery.THIS);
    @SuppressWarnings("unchecked")
    List<Object[]> matches = ftQuery.setMaxResults(maxResult).getResultList();
    return matches;
}

From source file:org.zanata.rest.review.ReviewService.java

/**
 * Validate DTO in service due to missing hibernate validator in gwt-shared
 * DTO./* w  w  w. ja v  a  2  s .  co  m*/
 *
 * TODO: move validation to DTO
 *
 * @param criteria
 */
private Optional<Response> validateReviewCriteria(TransReviewCriteria criteria) {
    String description = criteria.getDescription();
    if (StringUtils.isBlank(description) || StringUtils.length(description) > DESCRIPTION_MAX_LENGTH) {
        return Optional.of(Response.status(Response.Status.BAD_REQUEST).build());
    }
    return Optional.empty();
}

From source file:org.zanata.service.impl.GlossaryFileServiceImpl.java

/**
 * Return error message when//from w  w w  .  j  ava  2  s  . c o  m
 *
 * @param entry#description
 *            length not over {@link #MAX_LENGTH_CHAR}
 * @param entry#pos
 *            length not over {@link #MAX_LENGTH_CHAR} Source term content
 *            not empty
 */
private Optional<String> validateGlossaryEntry(GlossaryEntry entry) {
    if (StringUtils.length(entry.getDescription()) > MAX_LENGTH_CHAR) {
        return Optional.of("Glossary description too long, maximum " + MAX_LENGTH_CHAR + " character");
    }
    if (StringUtils.length(entry.getPos()) > MAX_LENGTH_CHAR) {
        return Optional.of("Glossary part of speech too long, maximum " + MAX_LENGTH_CHAR + " character");
    }
    Optional<GlossaryTerm> srcTerm = getSourceTerm(entry);
    if (!srcTerm.isPresent()) {
        return Optional.of("No source term (" + entry.getSrcLang() + ") found in Glossary entry.");
    }
    if (StringUtils.isBlank(srcTerm.get().getContent())) {
        return Optional.of("Source term content cannot be empty.");
    }
    return Optional.empty();
}

From source file:org.zanata.service.impl.TranslationMemoryServiceImpl.java

private void validateQueryLength(String query) {
    if (StringUtils.length(query) > LuceneQuery.QUERY_MAX_LENGTH) {
        throw new RuntimeException("Query string exceed max length: " + LuceneQuery.QUERY_MAX_LENGTH + "=\'"
                + StringUtils.left(query, 80) + "\'");
    }//from  w w w .  jav  a2  s. c o m
}

From source file:pl.hycom.pip.messanger.handler.processor.ExtractKeywordsFromMessageProcessor.java

protected Set<String> processKeywords(@NonNull String[] keywords) {
    return Arrays.stream(keywords).filter(s -> StringUtils.length(s) > 2).collect(Collectors.toSet());
}

From source file:reconf.server.domain.security.Client.java

public Client(Client request) {
    this.username = request.getUsername();
    this.password = StringUtils.repeat("*", StringUtils.length(request.getPassword()));
}

From source file:therian.operator.size.SizeOfCharSequence.java

@Override
public boolean perform(TherianContext context, Size<CharSequence> operation) {
    operation.setResult(StringUtils.length(operation.getPosition().getValue()));
    return true;//from   w ww.jav  a2s  . c om
}

From source file:us.fatehi.schemacrawler.webapp.service.storage.FileSystemStorageService.java

/**
 * Prevent malicious injection attacks./*  w  ww.  jav a2  s .co  m*/
 *
 * @param filenameKey
 *        Filename key
 * @throws Exception
 *         On a badly constructed filename key.
 */
private void validateFilenameKey(final String filenameKey) throws Exception {
    if (StringUtils.length(filenameKey) != 12 || !StringUtils.isAlphanumeric(filenameKey)) {
        throw new Exception(String.format("Invalid filename key \"%s\"", filenameKey));
    }
}