Example usage for org.springframework.util StringUtils hasText

List of usage examples for org.springframework.util StringUtils hasText

Introduction

In this page you can find the example usage for org.springframework.util StringUtils hasText.

Prototype

public static boolean hasText(@Nullable String str) 

Source Link

Document

Check whether the given String contains actual text.

Usage

From source file:com.seajas.search.profiler.validator.FeedValidator.java

/**
 * Validate the given command object./*from   w  w w  .  j a  v a2s  . com*/
 * 
 * @param command
 * @param errors
 */
@Override
public void validate(final Object command, final Errors errors) {
    FeedCommand feed = (FeedCommand) command;

    if (feed.getAction().equals("add") || feed.getAction().equals("edit")) {
        if (!StringUtils.hasText(feed.getName()))
            errors.rejectValue("name", "feeds.errors.no.name");

        if (!StringUtils.hasText(feed.getCollection()))
            errors.rejectValue("collection", "feeds.errors.no.collection");
        else if (!profilerService.getJobNames().containsKey(feed.getCollection()))
            errors.rejectValue("collection", "feeds.errors.invalid.collection");

        if (StringUtils.hasText(feed.getFeedEncodingOverride())
                && !Charset.isSupported(feed.getFeedEncodingOverride()))
            errors.rejectValue("feedEncodingOverride", "feeds.errors.invalid.feed.encoding.override");
        if (StringUtils.hasText(feed.getResultEncodingOverride())
                && !Charset.isSupported(feed.getResultEncodingOverride()))
            errors.rejectValue("resultEncodingOverride", "feeds.errors.invalid.result.encoding.override");

        if (StringUtils.hasText(feed.getLanguage())
                && !profilerService.getAvailableSearchLanguages().contains(feed.getLanguage()))
            errors.rejectValue("language", "feeds.errors.invalid.language");

        for (String feedUrl : feed.getFeedUrls())
            try {
                if (StringUtils.hasText(feedUrl))
                    new URI(feedUrl);
            } catch (URISyntaxException e) {
                errors.rejectValue("feedUrls", "feeds.errors.invalid.feed.urls");

                break;
            }

        if (StringUtils.hasText(feed.getQueue())
                && !taskService.getFeedInjectionTriggers().containsKey(feed.getQueue()))
            errors.rejectValue("queue", "feeds.errors.invalid.queue");
        if (StringUtils.hasText(feed.getStrategy())
                && !profilerService.getAuthenticationStrategies().containsKey(feed.getStrategy()))
            errors.rejectValue("strategy", "feeds.errors.invalid.strategy");

        if (feed.getFeedParameterKeys() != null && feed.getFeedParameterKeys().size() > 0) {
            if (feed.getFeedParameterValues() == null
                    || feed.getFeedParameterKeys().size() != feed.getFeedParameterValues().size())
                errors.rejectValue("feedParameterKeys", "feeds.errors.invalid.feed.parameters");
            else {
                for (String feedParameterKey : feed.getFeedParameterKeys())
                    if (!StringUtils.hasText(feedParameterKey))
                        errors.rejectValue("feedParameterKeys", "feeds.errors.invalid.feed.parameters");

                for (String feedParameterValue : feed.getFeedParameterValues())
                    if (!StringUtils.hasText(feedParameterValue))
                        errors.rejectValue("feedParameterKeys", "feeds.errors.invalid.feed.parameters");
            }
        }
    }
}

From source file:org.synyx.hades.extensions.beans.DomainClassPropertyEditor.java

@Override
public void setAsText(String idAsString) throws IllegalArgumentException {

    if (!StringUtils.hasText(idAsString)) {
        setValue(null);/*from  w  w  w  .  j av  a  2s  . c  o  m*/
        return;
    }

    setValue(dao.readByPrimaryKey(getId(idAsString)));
}

From source file:com.mine.cassandra.CassandraConfiguration.java

@Override
protected AuthProvider getAuthProvider() {
    if (StringUtils.hasText(this.cassandraProperties.getUsername())) {
        return new PlainTextAuthProvider(this.cassandraProperties.getUsername(),
                this.cassandraProperties.getPassword());
    } else {//from www .  ja  va  2  s  .c om
        return null;
    }
}

From source file:com.oembedler.moon.graphql.engine.StereotypeUtils.java

private static <T extends Annotation> String getAnnotationValue(AnnotatedElement accessibleObject,
        Class<T> annotationClass, String defaultValue) {
    Assert.noNullElements(new Object[] { accessibleObject, annotationClass, defaultValue },
            "input parameters must not be null");

    String result = defaultValue;
    T annotation = accessibleObject.getAnnotation(annotationClass);
    if (annotation != null && StringUtils.hasText((String) AnnotationUtils.getValue(annotation)))
        result = (String) AnnotationUtils.getValue(annotation);

    return result;
}

From source file:ch.sdi.core.impl.data.filter.FilterFactory.java

/**
 * Instantiates the filter described by the given param.
 * <p>/*from w w w. j av a2 s  .  co m*/
 * The param is expected to be:
 * <pre>
 *     &lt;filterName>:&lt;fieldname>[:additionalParams]
 * </pre>
 * The number of additional parameters is dependant of the particular filter type.
 * <p>
 * @param aParams
 * @return the initialized filter
 * @throws SdiException on any problem
 */
public CollectFilter<?> getFilter(String aParams) throws SdiException {
    if (!StringUtils.hasText(aParams)) {
        throw new SdiException("Given param is empty!", SdiException.EXIT_CODE_CONFIG_ERROR);

    }

    String[] values = aParams.split(":", 3);

    if (values.length < 2) {
        throw new SdiException("Given param does not contain at least 2 parts: " + aParams,
                SdiException.EXIT_CODE_CONFIG_ERROR);
    }

    String filterName = values[0];
    String fieldName = values[1];
    String params = values.length == 3 ? values[2] : null;

    myLog.debug("Looking up filter " + filterName + " for field " + fieldName);

    Map<String, Object> beans = myAppCtxt.getBeansWithAnnotation(SdiFilter.class);

    myLog.trace("Found candidates for filters: " + beans.keySet());

    for (Object bean : beans.values()) {
        SdiFilter annotation = bean.getClass().getAnnotation(SdiFilter.class);
        String value = annotation.value();

        if (filterName.equals(value)) {
            if (!(bean instanceof CollectFilter)) {
                throw new SdiException(
                        "Found Bean annotated with @SdiFilter which is not a CollectFilter, but: "
                                + bean.getClass().getName(),
                        SdiException.EXIT_CODE_CONFIG_ERROR);
            }

            CollectFilter<?> filter = (CollectFilter<?>) bean;

            return filter.init(fieldName, params);
        }
    }

    throw new SdiException("No filter found for filtername " + filterName, SdiException.EXIT_CODE_CONFIG_ERROR);
}

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

/**
 * Get the team from the {@link String} teamId.
 *
 * @param teamId the {@link String} teamId
 * @return The {@link Team} team/*from   www. j  a va 2s .c o m*/
 * @throws RuntimeException if the team cannot be found
 */
public Team getTeamById(String teamId) {
    Team team = null;
    if (StringUtils.hasText(teamId)) {
        team = grouperTeamService.findTeamById(teamId);
    }
    if (team == null) {
        throw new RuntimeException("Team (" + teamId + ") not found");
    }
    return team;
}

From source file:io.fabric8.spring.cloud.kubernetes.archaius.ArchaiusConfigMapSourceRegistar.java

private String getSourceName(Map<String, Object> source) {
    if (source == null) {
        return null;
    }/*from  ww  w  .ja v  a2 s  .co m*/
    String value = (String) source.get(VALUE_ATTR);
    if (!StringUtils.hasText(value)) {
        value = (String) source.get(NAME_ATTR);
    }
    if (StringUtils.hasText(value)) {
        return value;
    }
    throw new IllegalStateException("Either 'name' or 'value' must be provided in @ConfigMapSource");
}

From source file:org.eclipse.virgo.ide.manifest.internal.core.validation.rules.ApplicationSymbolicNameRule.java

@Override
protected void validateHeader(BundleManifestHeader header, BundleManifestValidationContext context) {

    BundleManifestHeaderElement[] elements = header.getBundleManifestHeaderElements();
    String id = elements.length > 0 ? elements[0].getManifestElement().getValue() : null;
    if (id == null || id.length() == 0) {
        context.error("NO_SYMBOLIC_NAME", BundleManifestCoreMessages.BundleErrorReporter_NoSymbolicName,
                header.getLineNumber() + 1);
    }//from   w  w  w  .j  av a 2 s  .co m

    if (StringUtils.hasText(id) && !IdUtil.isValidCompositeID3_0(id)) {
        context.error("ILLAGEL_SYMBOLIC_NAME",
                BundleManifestCoreMessages.BundleErrorReporter_InvalidSymbolicName,
                BundleManifestUtils.getLineNumber(context.getBundleManifest().getDocument(), header, id));
    }

}

From source file:org.jellycastle.build.JellyBuild.java

private void loadBuildInformation(Project project) {
    org.jellycastle.annotation.Build build = configuration
            .getAnnotation(org.jellycastle.annotation.Build.class);

    project.setModelVersion(build.modelVersion());

    project.setGroupId(build.groupId());
    project.setArtifactId(build.artifactId());
    project.setVersion(build.version());

    if (StringUtils.hasText(build.description())) {
        project.setDescription(build.description());
    }//from w  ww. j  a v  a 2s.co  m

    if (build.modules().length > 0) {
        project.setPackaging("pom");
    } else if (configuration.getAnnotation(JavaBuild.class) != null) {
        project.setPackaging("jar");
    } else if (configuration.getAnnotation(WebBuild.class) != null) {
        project.setPackaging("web");
    }
}

From source file:com.googlecode.starflow.engine.xml.NodeUtil.java

/**
 * ?elementpathlong/*from  w w  w  .j  a  v  a  2  s . co  m*/
 * 
 * @param element
 * @param path
 * @return
 */
public static long getNodeLongValue(Element element, String path) {
    Node node = element.selectSingleNode(path);
    if (node != null) {
        if (StringUtils.hasText(node.getText()))
            return Long.parseLong(node.getText());
        else
            return 0l;
    } else
        return 0l;
}