Example usage for org.apache.commons.lang3 StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang3 StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils defaultIfBlank.

Prototype

public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr) 

Source Link

Document

Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null , the value of defaultStr .

 StringUtils.defaultIfBlank(null, "NULL")  = "NULL" StringUtils.defaultIfBlank("", "NULL")    = "NULL" StringUtils.defaultIfBlank(" ", "NULL")   = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null)      = null 

Usage

From source file:com.thinkbiganalytics.metadata.sla.config.EmailServiceLevelAgreementSpringConfiguration.java

@Bean(name = "slaEmailSender")
public JavaMailSender javaMailSender(
        @Qualifier("slaEmailConfiguration") EmailConfiguration emailConfiguration) {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();

    Properties mailProperties = mailSender.getJavaMailProperties();
    mailProperties.put("mail.smtp.auth", StringUtils.defaultIfBlank(emailConfiguration.getSmtpAuth(), "false"));
    mailProperties.put("mail.smtp.starttls.enable",
            StringUtils.defaultIfBlank(emailConfiguration.getStarttls(), "false"));

    if (StringUtils.isNotBlank(emailConfiguration.getStarttlsRequired())) {
        mailProperties.put("mail.smtp.starttls.required", emailConfiguration.getStarttlsRequired());
    }//from   w w w  .j  av a 2  s  .c om
    if (StringUtils.isNotBlank(emailConfiguration.getSmptAuthNtmlDomain())) {
        mailProperties.put("mail.smtp.auth.ntlm.domain", emailConfiguration.getSmptAuthNtmlDomain());
    }

    mailProperties.put("mail.smtp.connectiontimeout",
            StringUtils.defaultIfBlank(emailConfiguration.getSmtpConnectionTimeout(), "5000"));
    mailProperties.put("mail.smtp.timeout",
            StringUtils.defaultIfBlank(emailConfiguration.getSmtpTimeout(), "5000"));
    mailProperties.put("mail.smtp.writetimeout",
            StringUtils.defaultIfBlank(emailConfiguration.getSmtpWriteTimeout(), "5000"));

    if (StringUtils.isNotBlank(emailConfiguration.getSslEnable())) {
        mailProperties.put("mail.smtp.ssl.enable", emailConfiguration.getSslEnable());
    }
    if (StringUtils.isNotBlank(emailConfiguration.getDebug())) {
        mailProperties.put("mail.debug", emailConfiguration.getDebug());
    }

    mailSender.setHost(emailConfiguration.getHost());
    mailSender.setPort(emailConfiguration.getPort());
    mailSender.setProtocol(emailConfiguration.getProtocol());
    mailSender.setUsername(emailConfiguration.getUsername());
    mailSender.setPassword(emailConfiguration.getPassword());

    return mailSender;
}

From source file:com.ericsson.eiffel.remrem.publish.helper.PublishUtils.java

/**
 * Method returns the routing key from the messaging service based on the json event type.
 * @param msgService the Messaging service.
 * @param json the eiffel event/*from  w w w  .  ja  v a 2 s. c om*/
 * @param userDomainSuffix is optional parameter, If user provide this it will add to the domainId.
 * @param tag is optional parameter, If user provide this it will add to the tag if routingKey is not specified by the user.
 * @param routingKey is optional parameter, If user provide this it will add to the routingKey otherwise generate routingKey based on message type.
 * @return routing key or returns "" if host, exchange and domainId not available.
*/
public static String getRoutingKey(MsgService msgService, JsonObject json, RMQHelper rmqHelper,
        String userDomainSuffix, String tag, String routingKey) {
    String protocol = msgService.getServiceName();
    Boolean cliMode = Boolean.getBoolean(PropertiesConfig.CLI_MODE);
    RabbitMqProperties rabbitMqProperties = rmqHelper.rabbitMqPropertiesMap.get(protocol);
    String domainId = rabbitMqProperties.getDomainId();
    if (rabbitMqProperties != null && rabbitMqProperties.getExchangeName() != null
            && rabbitMqProperties.getHost() != null
            && (cliMode || (!cliMode && StringUtils.isNotBlank(domainId)))) {
        return StringUtils.defaultIfBlank(routingKey,
                msgService.generateRoutingKey(json, tag, domainId, userDomainSuffix));
    }
    return "";
}

From source file:com.sonicle.webtop.core.app.sms.SmsHosting.java

public SmsHosting(Locale locale, String baseUrl) {
    super(locale, StringUtils.defaultIfBlank(baseUrl, BASE_URL));
}

From source file:com.sonicle.webtop.core.app.sms.Twilio.java

public Twilio(Locale locale, String baseUrl) {
    super(locale, StringUtils.defaultIfBlank(baseUrl, BASE_URL));
}

From source file:com.yqboots.web.thymeleaf.processor.element.AlertElementProcessor.java

/**
 * {@inheritDoc}/*from www .j  a  v a2  s .  c o m*/
 */
@Override
protected List<Node> getMarkupSubstitutes(final Arguments arguments, final Element element) {
    final List<Node> nodes = new ArrayList<>();

    final String levelAttrValue = StringUtils.defaultIfBlank(element.getAttributeValue(ATTR_LEVEL),
            DEFAULT_LEVEL);

    final VariablesMap<String, Object> variables = arguments.getContext().getVariables();
    variables.values().stream().filter(new Predicate<Object>() {
        @Override
        public boolean test(final Object o) {
            return BindingResult.class.isAssignableFrom(o.getClass());
        }
    }).forEach(new Consumer<Object>() {
        @Override
        public void accept(final Object value) {
            BindingResult bindingResult = (BindingResult) value;
            if (bindingResult.hasGlobalErrors()) {
                nodes.add(build(arguments, bindingResult.getGlobalErrors(), levelAttrValue));
            }
        }
    });

    return nodes;
}

From source file:controllers.SiteApp.java

/**
 * @param pageNum pager number//from   ww w  .j  a va 2s  .c  om
 * @param loginId loginId
 * @return the result
 * @see {@link User#findUsers(int, String)}
 */
public static Result userList(int pageNum, String query) {
    String state = StringUtils.defaultIfBlank(request().getQueryString("state"), UserState.ACTIVE.name());
    UserState userState = UserState.valueOf(state);
    Page<User> users = User.findUsers(pageNum - 1, query, userState);
    return ok(userList.render("title.siteSetting", users, userState, query));
}

From source file:ca.uhn.fhir.jaxrs.server.util.JaxRsResponse.java

@Override
public Response sendWriterResponse(int theStatus, String theContentType, String theCharset, Writer theWriter) {
    ResponseBuilder builder = buildResponse(theStatus);
    if (isNotBlank(theContentType)) {
        String charContentType = theContentType + "; charset="
                + StringUtils.defaultIfBlank(theCharset, Constants.CHARSET_NAME_UTF8);
        builder.header(Constants.HEADER_CONTENT_TYPE, charContentType);
    }/*w w  w.  j a v a  2 s .c o  m*/
    builder.entity(theWriter.toString());
    Response retVal = builder.build();
    return retVal;
}

From source file:io.github.lxgaming.teleportbow.commands.AbstractCommand.java

@Override
public final Optional<Text> getShortDescription(CommandSource commandSource) {
    if (StringUtils.length(getDescription()) > 53) {
        return Optional.of(Text.of(StringUtils.substring(getDescription(), 0, 50), "..."));
    }//from  ww w.j a va  2s.c o m

    return Optional.of(Text.of(StringUtils.defaultIfBlank(getDescription(), "No description provided")));
}

From source file:eu.ggnet.saft.runtime.HiddenMonitorDisplayTask.java

@Override
@SuppressWarnings("SleepWhileInLoop")
protected Void doInBackground() throws Exception {
    // Hint: the supplied Monitor has a length of 100;
    HiddenMonitor hm = lookup(ProgressObserver.class).getMonitor(key);
    while (hm != null && !hm.isFinished()) {
        int progress = 100 - hm.getAbsolutRemainingTicks();
        if (progress < 0)
            progress = 0;/*from w w w.jav a  2  s.co m*/
        if (progress > 100)
            progress = 100;
        publish(new Progress(progress, hm.getTitle() + ":" + StringUtils.defaultIfBlank(hm.getMessage(), "")));
        Thread.sleep(250);
        hm = lookup(ProgressObserver.class).getMonitor(key);
    }
    publish(new Progress(100, ""));
    keys.remove(key);
    return null;
}

From source file:com.cognifide.aet.job.common.modifiers.replacetext.ReplaceTextModifier.java

@Override
public void setParameters(Map<String, String> params) throws ParametersException {
    setElementParams(params);/*  w  w w. j  av a2s  .  c  o  m*/
    attributeName = StringUtils.defaultIfBlank(params.get(ATTRIBUTE_PARAM), "innerHTML");
    value = StringUtils.defaultIfBlank(params.get(VALUE_PARAM), "");
}