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.reactivetechnologies.analytics.lucene.TextInstanceFilter.java

/**
 * Converts String attributes into a set of attributes representing word occurrence information from the text contained in the strings. 
 * The set of words (attributes) is determined by the first batch filtered (typically training data). Uses a Lucene analyzer to tokenize
 * the string. NOTE: The text string should either be the first or last attribute
 * @param dataRaw/*from www  . j  a  va 2s.co m*/
 * @param opts
 * @param isLast - whether last attribute is the text to be filtered, else first
 * @return
 * @throws Exception
 * @see {@linkplain StringToWordVector}
 */
public static Instances filter(Instances dataRaw, String opts, boolean isLast) throws Exception {
    TextInstanceFilter filter = new TextInstanceFilter();
    if (StringUtils.hasText(opts)) {
        filter.setOptions(Utils.splitOptions(opts));
    }
    filter.setTokenizer(new InstanceTokenizer());
    filter.setUseStoplist(false);//ignore any other stop list
    filter.setStemmer(new NullStemmer());//ignore any other stemmer
    filter.setInputFormat(dataRaw);
    filter.setAttributeIndices(isLast ? "last" : "first");
    filter.setDoNotOperateOnPerClassBasis(true);
    filter.setWordsToKeep(10000);
    return useFilter(dataRaw, filter);
}

From source file:com.artivisi.biller.simulator.service.impl.BillerSimulatorServiceImpl.java

@Override
public void delete(Bank bank) {
    if (bank == null || !StringUtils.hasText(bank.getId())) {
        return;//ww w.j a  v  a 2 s .c om
    }

    sessionFactory.getCurrentSession().delete(bank);
}

From source file:com.helpinput.propertyeditors.GLClassEditor.java

@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text)) {
        Class<?> result;// w ww .ja v a 2 s  . co  m
        try {
            result = ClassUtils.resolveClassName(text.trim(), this.classLoader);
        } catch (IllegalArgumentException e) {
            //for sessionFactory annotatedClasses
            result = ClassUtils.resolveClassName(text.trim(), ClassLoaderHolder.gcl);
            try {
                throw new Exception();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        setValue(result);
    } else {
        setValue(null);
    }
}

From source file:com.consol.citrus.selenium.action.PageAction.java

@SuppressWarnings("unchecked")
@Override/*ww w  .  j  ava2  s . c o  m*/
public void doExecute(TestContext context) {
    super.doExecute(context);

    if (StringUtils.hasText(pageName)) {
        WebPage pageObj;
        try {
            logger.debug("Initializing the page object {}", pageName);
            Class pageClass = Class.forName(pageName);
            pageObj = webClient.createPage(pageClass);
            logger.debug("page object {} is succesfully created.", pageName);
            webClient.verifyPage(pageObj);

            if (StringUtils.hasText(pageAction)) {
                logger.debug("running the action {} on the page object {}", pageAction, pageName);
                logger.info("Invoking method '" + pageAction + "' on instance '" + pageClass + "'");
                Method actionMethod;
                if (actionParameters == null || actionParameters.isEmpty()) {
                    actionMethod = pageObj.getClass().getMethod(pageAction);
                    actionMethod.invoke(pageObj);
                } else {
                    actionMethod = getMethod(pageClass, new Class<?>[] { Map.class });
                    Map<String, String> methodArgs = new HashMap<>();
                    for (String parameterName : actionParameters.keySet()) {
                        String parameterValue = context
                                .replaceDynamicContentInString(actionParameters.get(parameterName));
                        methodArgs.put(parameterName, parameterValue);
                    }
                    actionMethod.invoke(pageObj, methodArgs);
                }
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            throw new CitrusRuntimeException(ex);
        }
    }
}

From source file:com.frank.search.solr.core.query.CurrencyFunction.java

/**
 * Create new {@link CurrencyFunction} using ISO-4217 currencyCode representing
 * {@code currency(fieldname,currencyCode)}
 * /*from  ww w.ja v  a 2 s  . c  o m*/
 * @param fieldname
 * @param currencyCode
 * @return
 */
public static CurrencyFunction currency(String fieldname, String currencyCode) {
    Assert.hasText(fieldname, "Fieldname for currency function must not be 'empty'.");

    CurrencyFunction function = new CurrencyFunction(fieldname);
    if (StringUtils.hasText(currencyCode)) {
        function.addArgument(currencyCode);
    }
    return function;
}

From source file:io.spring.initializr.service.info.CloudFoundryInfoContributor.java

@Override
public void contribute(Info.Builder builder) {
    String applicationName = this.environment.getProperty("vcap.application.name");
    if (StringUtils.hasText(applicationName)) {
        Map<String, String> details = new LinkedHashMap<>();
        details.put("name", applicationName);
        builder.withDetail("app", details);
    }/*from ww  w . j  a v  a 2 s. c o m*/
}

From source file:biz.c24.io.spring.integration.config.UnmarshallingTransformerParser.java

@Override
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    String modelRef = element.getAttribute("model-ref");
    modelRef = StringUtils.hasText(modelRef) ? modelRef : C24ModelBeanDefinitionParser.DEFAULT_BEAN_NAME;
    builder.addConstructorArgReference(modelRef);

    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "source-factory-ref",
            "sourceFactory");

    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "unwrap-document-root",
            "unwrapDocumentRoot");

}

From source file:csns.web.editor.CalendarPropertyEditor.java

public void setAsText(String text) throws IllegalArgumentException {
    if (!StringUtils.hasText(text)) {
        setValue(null);//w  w w .jav  a 2  s  .c om
        return;
    }

    try {
        Calendar value = Calendar.getInstance();
        value.setTime(dateFormat.parse(text));
        setValue(value);
    } catch (ParseException ex) {
        logger.warn("Cannot parse date: " + text);
        throw new IllegalArgumentException("Cannot parse date: " + text);
    }
}

From source file:org.openmrs.module.htmlwidgets.web.handler.DateHandler.java

/** 
 * @see WidgetHandler#parse(String, Class<?>)
 */// ww  w .  j  a  v a 2s .  c  om
@Override
public Object parse(String input, Class<?> type) {
    if (StringUtils.hasText(input)) {
        try {
            return Context.getDateFormat().parse(input);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Unable to parse input <" + input + "> to a Date");
        }
    }
    return null;
}

From source file:org.openmrs.propertyeditor.ObsEditor.java

/**
 * @should set using id/*from www.  j  ava  2  s .  c o m*/
 * @should set using uuid
 * @should throw illegal argument exception for obs not found
 * @should return null for empty text
 * 
 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
 */
public void setAsText(String text) throws IllegalArgumentException {
    ObsService obsService = Context.getObsService();
    if (StringUtils.hasText(text)) {
        try {
            setValue(obsService.getObs(Integer.valueOf(text)));
        } catch (Exception exception) {
            Obs Obs = obsService.getObsByUuid(text);
            setValue(Obs);
            if (Obs == null) {
                log.error("Error setting text: " + text, exception);
                throw new IllegalArgumentException("Obs not found: " + exception.getMessage());
            }
        }
    } else {
        setValue(null);
    }
}