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.syncope.console.commons.PreferenceManager.java

private Map<String, String> getPrefs(final String value) {

    HashMap<String, String> prefs;

    try {//from  w  w  w.j a va  2  s .c  o  m

        if (StringUtils.hasText(value)) {
            prefs = mapper.readValue(value, MAP_TYPE_REF);
        } else {
            throw new Exception("Invalid cookie value '" + value + "'");
        }

    } catch (Exception e) {
        LOG.debug("No preferences found", e);
        prefs = new HashMap<String, String>();
    }

    return prefs;
}

From source file:org.synyx.hera.si.config.DynamicServiceActivatorParser.java

@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {

    Object source = parserContext.extractSource(element);

    String pluginType = element.getAttribute("plugin-type");
    String method = element.getAttribute("method");

    BeanDefinitionBuilder builder = BeanDefinitionBuilder
            .rootBeanDefinition(PluginRegistryAwareMessageHandler.class);
    builder.addConstructorArgValue(getRegistryBeanDefinition(pluginType, source));
    builder.addConstructorArgValue(pluginType);
    builder.addConstructorArgValue(method);

    String delimiter = element.getAttribute("delimiter");

    if (StringUtils.hasText(delimiter)) {
        builder.addPropertyValue("delimiterExpression", delimiter);
    }/*from   www.  j  av  a2  s  .  c o  m*/

    String invocationArguments = element.getAttribute("invocation-arguments");

    if (StringUtils.hasText(invocationArguments)) {
        builder.addPropertyValue("invocationArgumentsExpression", invocationArguments);
    }

    AbstractBeanDefinition definition = builder.getBeanDefinition();
    definition.setSource(source);

    return builder;
}

From source file:org.jdal.dao.hibernate.AbstractCriteriaBuilder.java

/**
 * Add a ilike Restriction adding wrapping value on '%' and replacing '*'
 * for '%'/*from www  .j  a va2 s . co m*/
 * @param criteria Criteria to add restriction
 * @param property property path
 * @param value text for the ilike restriction
 */
protected void like(Criteria criteria, String property, String value) {
    if (StringUtils.hasText(value)) {
        String toMatch = ((String) value).trim();
        toMatch = toMatch.replace('*', '%');
        toMatch = "%" + toMatch + "%";
        criteria.add(Restrictions.ilike(property, toMatch));
    }
}

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

/**
 * Each concrete filter is responsible for initializing itself
 * <p>//from w  ww.ja v a  2 s.c o m
 *
 * @param aFieldname the field which is examined when applying this filter
 * @param aParameters optional additional parameters. May be <code>null</code>
 * @return the initialized filter (fluent API)
 * @throws SdiException if the initialization fails
 */
public CollectFilter<T> init(String aFieldname, String aParameters) throws SdiException {
    if (!StringUtils.hasText(aFieldname)) {
        throw new SdiException("Fieldname expected for this filter", SdiException.EXIT_CODE_CONFIG_ERROR);
    }

    myFieldName = aFieldname;

    return this;
}

From source file:org.tdmx.lib.control.job.TestJobExecutorImpl.java

@Override
public void execute(Long id, TestTask task) {
    if (StringUtils.hasText(task.getExceptionMessage())) {
        log.info("FAILURE task " + id + " with " + task.getProcessTimeMs() + "ms delay - "
                + task.getExceptionMessage());
    } else {// ww w .  j  a  v  a  2s  .co m
        log.info("SUCCESS task " + id + " with " + task.getProcessTimeMs() + "ms delay");
    }
    if (task.getProcessTimeMs() > 0) {
        try {
            Thread.sleep(task.getProcessTimeMs());
        } catch (InterruptedException e) {
            // ignore ie.
        }
    }
    task.setProcessMessage("" + id);
    if (StringUtils.hasText(task.getExceptionMessage())) {
        // usually the problem comes from deeper in the service layer.
        Exception causingException = new Exception(task.getExceptionMessage());
        causingException.fillInStackTrace();
        throw new RuntimeException("Some Problem Occured.", causingException);
    }
}

From source file:com.benfante.taglib.frontend.tags.PasswordInputTag.java

@Override
protected int writeTagContent(TagWriter tagWriter) throws JspException {
    tagWriter.startTag("div");
    if (this.getBindStatus().isError()) {
        tagWriter.writeAttribute("class", "control-group error");
    } else {//w  w w  .j a  v a 2  s . co  m
        tagWriter.writeAttribute("class", "control-group");
    }
    writeLabelTagContent(tagWriter);
    tagWriter.startTag("div");
    tagWriter.writeAttribute("class", "controls");
    String cssClasses = BootstrapTagHelper.prependAppendCssClasses(prefix, suffix);
    if (StringUtils.hasText(cssClasses)) {
        tagWriter.startTag("div");
        tagWriter.writeAttribute("class", cssClasses);
        BootstrapTagHelper.writeInputTagDecorator(tagWriter, prefix);
    }
    super.writeTagContent(tagWriter);
    if (StringUtils.hasText(cssClasses)) {
        BootstrapTagHelper.writeInputTagDecorator(tagWriter, suffix);
        tagWriter.endTag();
    }
    if (this.getBindStatus().isError()) {
        tagWriter.startTag("span");
        tagWriter.writeAttribute("id", autogenerateErrorId());
        tagWriter.writeAttribute("class", "help-inline");
        // writeDefaultAttributes(tagWriter);
        String delimiter = "<br/>";
        String[] errorMessages = getBindStatus().getErrorMessages();
        for (int i = 0; i < errorMessages.length; i++) {
            String errorMessage = errorMessages[i];
            if (i > 0) {
                tagWriter.appendValue(delimiter);
            }
            tagWriter.appendValue(getDisplayString(errorMessage));
        }
        tagWriter.endTag();
    }
    BootstrapTagHelper.writeInputTagHelpBlock(tagWriter, help);
    tagWriter.endTag();
    tagWriter.endTag();
    return SKIP_BODY;
}

From source file:com.boxedfolder.carrot.config.security.filter.XAuthTokenFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    try {/*from  w w w.  ja va  2  s.  c  o  m*/
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String authToken = httpServletRequest.getHeader("x-auth-token");

        if (StringUtils.hasText(authToken)) {
            String username = tokenUtils.getUserNameFromToken(authToken);
            UserDetails details = detailsService.loadUserByUsername(username);

            if (tokenUtils.validateToken(authToken, details)) {
                UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(details,
                        details.getPassword(), details.getAuthorities());
                SecurityContextHolder.getContext().setAuthentication(token);
            }
        }
        filterChain.doFilter(request, response);
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
}

From source file:com.devnexus.ting.core.service.integration.PrepareMailToSpeakerTransformer.java

@Transformer
public GenericEmail prepareMailToSpeaker(CfpSubmission cfpSubmission) {

    final String templateHtml = SystemInformationUtils.getCfpHtmlEmailTemplate();
    final String templateText = SystemInformationUtils.getCfpTextEmailTemplate();

    final String renderedHtmlTemplate = applyMustacheTemplate(cfpSubmission, templateHtml);
    final String renderedTextTemplate = applyMustacheTemplate(cfpSubmission, templateText);

    final GenericEmail email = new GenericEmail();

    email.setText(renderedTextTemplate).setHtml(renderedHtmlTemplate).setFrom(fromUser)
            .setSubject("DevNexus 2017 - CFP - " + cfpSubmission.getSpeakersAsString(false));

    for (CfpSubmissionSpeaker submissionSpeaker : cfpSubmission.getCfpSubmissionSpeakers()) {
        email.addTo(submissionSpeaker.getEmail());
    }//  w  w w  .  j av a  2 s.  co  m

    if (StringUtils.hasText(this.ccUser)) {
        email.setCc(this.ccUser);
    }

    return email;
}

From source file:org.zalando.stups.oauth2.spring.server.AbstractAuthenticationExtractor.java

protected Set<String> validateUidScope(final Set<String> scopes, final Map<String, Object> map) {
    Set<String> result = new HashSet<String>(scopes);
    String uidValue = (String) map.get(UID_SCOPE);

    if (StringUtils.hasText(uidValue)) {
        result.add(UID_SCOPE);/*  w  w  w. j  a va2 s.c o  m*/
    } else {
        if (isThrowExceptionOnEmptyUid()) {
            throw new InvalidTokenException("'uid' in accessToken should never be empty!");
        }
    }

    return result;
}