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:org.openmrs.module.drughistory.web.propertyeditor.ConceptListEditor.java

/**
 * loops over the textbox assigned to this property. The textbox is assumed to be a string of
 * conceptIds^drugIds separated by spaces.
 *
 * @param text list of conceptIds (not conceptAnswerIds)
 * @should set the sort weights with the least possible changes
 *//*from w  w  w.jav a2s  . c  o  m*/
public void setAsText(String text) throws IllegalArgumentException {

    if (StringUtils.hasText(text)) {
        ConceptService cs = Context.getConceptService();
        String[] conceptIds = text.split(" ");
        List<String> requestConceptIds = new Vector<String>();
        //set up parameter answer Set for easier add/delete functions and removal of duplicates
        for (String id : conceptIds) {
            id = id.trim();
            if (!id.equals("") && !requestConceptIds.contains(id)) //remove whitespace, blank lines, and duplicates
                requestConceptIds.add(id);
        }

        Collection<Concept> deletedConcepts = new HashSet<Concept>();

        // loop over original concept answers to find any deleted answers
        for (Concept concept : originalConcepts) {
            boolean conceptDeleted = true;
            for (String conceptId : requestConceptIds) {
                Integer id = getConceptId(conceptId);
                if (id.equals(concept.getConceptId())) {
                    conceptDeleted = false;
                }
            }
            if (conceptDeleted)
                deletedConcepts.add(concept);
        }

        // loop over those deleted answers to delete them
        for (Concept concept : deletedConcepts) {
            originalConcepts.remove(concept);
        }

        // loop over concept ids in the request to add any that are new
        for (String conceptId : requestConceptIds) {
            Integer id = getConceptId(conceptId);
            boolean newConcept = true;
            for (Concept originalConcept : originalConcepts) {
                if (id.equals(originalConcept.getConceptId())) {
                    newConcept = false;
                }
            }
            // if the current request answer is new, add it to the originals
            if (newConcept) {
                Concept concept = cs.getConcept(id);
                originalConcepts.add(concept);
            }
        }

        log.debug("originalConcepts.getConceptId(): ");
        for (Concept a : originalConcepts)
            log.debug("id: " + a.getConceptId());

        log.debug("requestConceptIds: ");
        for (String i : requestConceptIds)
            log.debug("id: " + i);
    } else {
        originalConcepts.clear();
    }

    setValue(originalConcepts);
}

From source file:com.consol.citrus.admin.service.executor.maven.MavenCommand.java

/**
 * Build the execute command./*  w w  w.j  ava  2 s . com*/
 * @return
 */
protected String buildCommand() {
    StringBuilder builder = new StringBuilder();
    if (StringUtils.hasText(buildConfiguration.getMavenHome())) {
        builder.append(buildConfiguration.getMavenHome() + System.getProperty("file.separator") + "bin"
                + System.getProperty("file.separator") + MVN);
    } else {
        builder.append(MVN);
    }

    builder.append(getLifeCycleCommand());

    for (BuildProperty propertyEntry : getSystemProperties()) {
        builder.append(String.format("-D%s=%s ", propertyEntry.getName(), propertyEntry.getValue()));
    }

    if (StringUtils.hasText(getActiveProfiles())) {
        builder.append(String.format("-P%s ", getActiveProfiles()));
    }

    log.debug("Using Maven command: " + builder.toString());

    return builder.toString();
}

From source file:com.ewcms.common.query.mongo.PropertyConvert.java

/**
 * ?{@link RuntimeException}//from  www.  j ava2 s  . co m
 * 
 * @param name  ???{@literal null}
 * @return {@value Class<?>}
 */
public Class<?> getPropertyType(String propertyName) {
    if (!StringUtils.hasText(propertyName)) {
        throw new IllegalArgumentException("Property's name must not null or empty!");
    }

    String[] names = StringUtils.tokenizeToStringArray(propertyName, NESTED);
    Class<?> type = beanClass;
    PropertyDescriptor pd = null;
    for (String name : names) {
        pd = BeanUtils.getPropertyDescriptor(type, name);
        if (pd == null) {
            logger.error("\"{}\" property isn't exist.", propertyName);
            throw new RuntimeException(propertyName + " property isn't exist.");
        }
        type = pd.getPropertyType();
    }

    if (type.isArray()) {
        return type.getComponentType();
    }

    if (Collection.class.isAssignableFrom(type)) {
        Method method = pd.getReadMethod();
        if (method == null) {
            logger.error("\"{}\" property is not read method.", propertyName);
            throw new RuntimeException(propertyName + " property is not read method.");
        }
        ParameterizedType returnType = (ParameterizedType) method.getGenericReturnType();
        if (returnType.getActualTypeArguments().length > 0) {
            return (Class<?>) returnType.getActualTypeArguments()[0];
        }
        logger.error("\"{}\" property is collection,but it's not generic.", propertyName);
        throw new RuntimeException(propertyName + " property is collection,but it's not generic.");
    }

    return type;
}

From source file:org.shept.util.FtpFileCopy.java

/**
 * @param/*w  ww .  ja  v  a 2s .c  o  m*/
 * @return
 *
 * @param config
 * @param ftpC
 * @throws SocketException
 * @throws IOException
 */
private boolean configSetup(FtpConfig config, FTPClient ftpC) throws IOException {
    boolean rc;
    ftpC.connect(config.getHostAddress(), config.getPort());
    rc = ftpC.login(config.getUserName(), config.getPassword());
    if (!rc) {
        logger.error("Ftp could not log to remote server with " + config.getUserName());
        return false;
    }
    if (StringUtils.hasText(config.getServerPath())) {
        int cwdCode = ftpC.cwd(config.getServerPath());
        if (!FTPReply.isPositiveCompletion(cwdCode)) {
            logger.error("Ftp could not change working dir to " + config.getServerPath()
                    + " - Server returned Code " + cwdCode);
            return false;
        }
    }
    rc = ftpC.setFileType(config.getFileType());
    if (!rc) {
        logger.error("Ftp could not change FileType for transmission");
        return false;
    }
    return true;
}

From source file:it.cosenonjaviste.alfresco.annotations.processors.runtime.WebScriptConfigurer.java

@Override
protected void processBeanDefinition(ConfigurableListableBeanFactory beanFactory, BeanDefinition bd,
        String beanClassName, String definitionName) throws FatalBeanException {
    if (beanFactory instanceof DefaultListableBeanFactory) {
        DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory;
        try {//from ww  w. j  a  v  a 2 s.c  om
            final WebScript webScript = AnnotationUtils.findAnnotation(Class.forName(beanClassName),
                    WebScript.class);
            if (webScript != null) {
                String beanName = webScript.value();
                if (StringUtils.hasText(beanName)) {
                    final String webScriptName = "webscript." + beanName + "."
                            + webScript.method().toString().toLowerCase();
                    factory.removeBeanDefinition(definitionName);
                    factory.registerBeanDefinition(webScriptName, bd);
                } else {
                    throw new FatalBeanException(
                            String.format("%s is @WebScript annotated, but no value set.", beanClassName));
                }
            }
        } catch (ClassNotFoundException e) {
            logger.warn(String.format(
                    "ClassNotFoundException while searching for ChildOf annotation on bean name '%s' of type '%s'. This error is expected on Alfresco Community 4.2.c. for some classes in package 'org.alfresco.repo'",
                    definitionName, beanClassName));
        }
    } else {
        logger.error(String.format(
                "Unable to register '%s' as webscript because beanFactory is not instance of 'DefaultListableBeanFactory'",
                definitionName));
    }
}

From source file:com.oembedler.moon.graphql.engine.dfs.GraphQLFieldDefinitionWrapper.java

public GraphQLFieldDefinitionWrapper(GraphQLFieldDefinition graphQLFieldDefinition,
        String complexitySpelExpressionString) {
    this.graphQLFieldDefinition = graphQLFieldDefinition;
    this.complexitySpelExpressionString = complexitySpelExpressionString;
    this.complexitySpelExpression = StringUtils.hasText(this.complexitySpelExpressionString)
            ? SPEL_EXPRESSION_PARSER.parseExpression(this.complexitySpelExpressionString)
            : null;//ww w. j ava  2s  .co m
}

From source file:org.vbossica.springbox.jmx.MetadataNamingOverridingStrategy.java

@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
    ObjectName objectName = super.getObjectName(managedBean, beanKey);
    String finalName = resolver.resolve(objectName.getCanonicalName());

    if (finalName != null && StringUtils.hasText(finalName)) {
        logger.info("replacing " + objectName + " by " + finalName);
        return ObjectNameManager.getInstance(finalName);
    }/*from   w  ww . j  av  a 2s .com*/
    return objectName;
}

From source file:grails.plugin.cache.web.filter.CacheOperationContext.java

protected boolean isConditionPassing() {
    if (StringUtils.hasText(operation.getCondition())) {
        return evaluator.condition(operation.getCondition(), method, evalContext);
    }/*ww  w. ja  v  a2  s.  co  m*/
    return true;
}

From source file:egovframework.rte.itl.integration.type.support.PrimitiveTypeFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    if (id == null) {
        id = beanName;// ww  w  .  j a  v  a  2  s  .  com
    }
    if (StringUtils.hasText(id) == false) {
        throw new IllegalArgumentException();
    }
}

From source file:nl.surfnet.coin.api.client.domain.Name.java

@Override
public String toString() {
    /*//w ww  . j  a  v  a 2 s  .  c  o  m
     * "name":{"formatted":"Winny Smits","familyName":"Smits","givenName":"Winny"
     */
    if (StringUtils.hasText(formatted)) {
        return formatted;
    }
    boolean givenNameText = StringUtils.hasText(givenName);
    boolean familyNameText = StringUtils.hasText(familyName);
    if (givenNameText && familyNameText) {
        return givenName + " " + familyName;
    }
    if (familyNameText) {
        return familyName;
    }
    if (givenNameText) {
        return givenName;
    }
    return "";
}