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:de.hybris.platform.acceleratorstorefrontcommons.forms.validation.RegistrationValidator.java

protected void validateName(final Errors errors, final String name, final String propertyName,
        String property) {// www .  ja  v a2  s. c o m
    if (StringUtils.isBlank(name)) {
        errors.rejectValue(propertyName, property);
    } else if (StringUtils.length(name) > 255) {
        errors.rejectValue(propertyName, property);
    }
}

From source file:com.google.ie.common.validation.CommentValidator.java

public void validateProjectComments(Object object, Errors errors) {

    ProjectComment projectComment = (ProjectComment) object;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, PROJECT_KEY,
            IdeaExchangeConstants.Messages.REQUIRED_FIELD);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, TEXT, IdeaExchangeConstants.Messages.REQUIRED_FIELD);
    if (StringUtils.length(projectComment.getText()) > COMMENT_LENGTH) {
        errors.rejectValue(TEXT, IdeaExchangeErrorCodes.COMMENT_LENGTH_EXCEEDS,
                IdeaExchangeConstants.Messages.COMMENT_LENGTH_EXCEEDS);
    }/*from   w ww.jav a2s.  com*/

    if (log.isDebugEnabled()) {
        if (errors.hasErrors()) {
            log.debug("Validator found " + errors.getErrorCount() + " errors");
            for (Iterator<FieldError> iterator = errors.getFieldErrors().iterator(); iterator.hasNext();) {
                FieldError fieldError = iterator.next();
                log.debug("Error found in field: " + fieldError.getField() + " Message :"
                        + fieldError.getDefaultMessage());
            }
        } else {
            log.debug("Validator found no errors");
        }

    }
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.forms.validation.RegistrationValidator.java

protected void validateTitleCode(final Errors errors, final String titleCode) {
    if (StringUtils.isEmpty(titleCode)) {
        errors.rejectValue("titleCode", "register.title.invalid");
    } else if (StringUtils.length(titleCode) > 255) {
        errors.rejectValue("titleCode", "register.title.invalid");
    }//from  w w  w.j a  v  a 2  s  . c  o m
}

From source file:io.seldon.api.state.PredictionAlgorithmStore.java

@Override
public void configUpdated(String configKey, String configValue) {
    configValue = StringUtils.strip(configValue);
    logger.info("KEY WAS " + configKey);
    logger.info("Received new default strategy: " + configValue);

    if (StringUtils.length(configValue) == 0) {
        logger.warn("*WARNING* no default strategy is set!");
    } else {/*from www.jav  a2s . c o m*/
        try {
            ObjectMapper mapper = new ObjectMapper();
            List<PredictionAlgorithmStrategy> strategies = new ArrayList<>();
            AlgorithmConfig config = mapper.readValue(configValue, AlgorithmConfig.class);
            for (Algorithm algorithm : config.algorithms) {
                PredictionAlgorithmStrategy strategy = toAlgorithmStrategy(algorithm);
                strategies.add(strategy);
            }
            List<FeatureTransformerStrategy> featureTransformerStrategies = new ArrayList<>();
            for (Transformer transformer : config.transformers) {
                FeatureTransformerStrategy strategy = toFeatureTransformerStrategy(transformer);
                featureTransformerStrategies.add(strategy);
            }
            defaultStrategy = new SimplePredictionStrategy(PredictionStrategy.DEFAULT_NAME,
                    Collections.unmodifiableList(featureTransformerStrategies),
                    Collections.unmodifiableList(strategies));
            logger.info("Successfully added new default prediction strategy");
        } catch (IOException | BeansException e) {
            logger.error("Couldn't update default prediction strategy", e);
        }
    }
}

From source file:com.mmj.app.lucene.analyzer.AbstractWordAnalyzer.java

private void _wiselySplit(List<String> result, SegMode segMode, boolean wiselyCombineSingleWord, String input) {
    if (StringUtils.isBlank(input)) {
        return;/*from w ww  . j a va2 s  .c o  m*/
    }
    // ?4??
    int len = StringUtils.length(input);
    if (len <= 2 || (len == 3 && !WordUnionUtils.isContainSingleWord(input))) {
        result.add(input);
    } else {
        List<String> segWords = segWords(new StringReader(input), segMode, wiselyCombineSingleWord);
        if (segWords.size() > 0) {
            result.addAll(segWords);
        }
    }
}

From source file:mitm.common.util.SizeLimitedWriter.java

@Override
public void write(String str) throws IOException {
    if (!isLimitReached(StringUtils.length(str))) {
        delegate.write(str);/*  w ww  . j a v  a  2s  . c  om*/
    }
}

From source file:hydrograph.ui.dataviewer.actions.ExportAction.java

private void writeDataInFile(List<String[]> fileDataList, String filePath) {
    if (filePath != null) {
        if (StringUtils.length(ConvertHexValues.parseHex(delimiter)) == 1
                && StringUtils.length(ConvertHexValues.parseHex(quoteCharactor)) == 1) {
            try (FileWriter fileWriter = new FileWriter(filePath);
                    CSVWriter writer = new CSVWriter(fileWriter,
                            ConvertHexValues.parseHex(delimiter).toCharArray()[0],
                            ConvertHexValues.parseHex(quoteCharactor).toCharArray()[0])) {
                writer.writeAll(fileDataList, false);
                showMessage("Data exported to " + filePath + " successfully.", INFORMATION,
                        SWT.ICON_INFORMATION);
            } catch (IOException e1) {
                showMessage(Messages.ERROR_MESSAGE, ERROR, SWT.ICON_ERROR);
            }/*from   www .  j ava  2  s .  c om*/
        }
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebSearchField.java

protected void executeSearch(final String newFilter) {
    if (optionsDatasource == null)
        return;//from w ww.  jav a  2s.  c  o  m

    String filterForDs = newFilter;
    if (mode == Mode.LOWER_CASE) {
        filterForDs = StringUtils.lowerCase(newFilter);
    } else if (mode == Mode.UPPER_CASE) {
        filterForDs = StringUtils.upperCase(newFilter);
    }

    if (escapeValueForLike && StringUtils.isNotEmpty(filterForDs)) {
        filterForDs = QueryUtils.escapeForLike(filterForDs);
    }

    if (!isRequired() && StringUtils.isEmpty(filterForDs)) {
        setValue(null);
        if (optionsDatasource.getState() == State.VALID) {
            optionsDatasource.clear();
        }
        return;
    }

    if (StringUtils.length(filterForDs) >= minSearchStringLength) {
        optionsDatasource.refresh(Collections.singletonMap(SEARCH_STRING_PARAM, filterForDs));

        if (optionsDatasource.getState() == State.VALID) {
            if (optionsDatasource.size() == 0) {
                if (searchNotifications != null) {
                    searchNotifications.notFoundSuggestions(newFilter);
                }
            } else if (optionsDatasource.size() == 1) {
                setValue(optionsDatasource.getItems().iterator().next());
            }
        }
    } else {
        if (optionsDatasource.getState() == State.VALID) {
            optionsDatasource.clear();
        }

        if (searchNotifications != null && StringUtils.length(newFilter) > 0) {
            searchNotifications.needMinSearchStringLength(newFilter, minSearchStringLength);
        }
    }
}

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

static boolean isLongEnoughToCount(String word) {
    return StringUtils.length(word) > 3 && StringUtils.isAlphaSpace(word);
}

From source file:cn.quickj.utils.Assert.java

/**
 * Assert that the given String is not empty; that is,
 * it must not be <code>null</code> and not the empty String.
 * <pre class="code">Assert.hasLength(name, "Name must not be empty");</pre>
 * @param text the String to check/*from  w w w.  j a  v a 2s.  com*/
 * @param message the exception message to use if the assertion fails
 * @see StringUtils#hasLength
 */
public static void hasLength(String text, String message) {
    if (StringUtils.length(text) == 0) {
        throw new IllegalArgumentException(message);
    }
}