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

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

Introduction

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

Prototype

public static String defaultString(final String str) 

Source Link

Document

Returns either the passed in String, or if the String is null , an empty String ("").

 StringUtils.defaultString(null)  = "" StringUtils.defaultString("")    = "" StringUtils.defaultString("bat") = "bat" 

Usage

From source file:ca.uhn.fhir.model.base.composite.BaseCodingDt.java

/**
 * {@inheritDoc}/*  ww w  .  j a v a  2s  . co  m*/
 */
@Override
public String getValueAsQueryToken(FhirContext theContext) {
    if (getSystemElement().getValueAsString() != null) {
        return ParameterUtil.escape(StringUtils.defaultString(getSystemElement().getValueAsString())) + '|'
                + ParameterUtil.escape(getCodeElement().getValueAsString());
    } else {
        return ParameterUtil.escape(getCodeElement().getValueAsString());
    }
}

From source file:ai.nitro.bot4j.integration.telegram.send.rules.impl.BubbleRuleImpl.java

protected String createTitle(final Bubble bubble) {
    String title = bubble.getTitle();
    final String text = bubble.getText();

    if (Strings.isBlank(title) && Strings.isBlank(text)) {
        title = "undefined title of bubble";
    }/*from   ww w  . ja v  a  2 s.co  m*/

    final String boldTitle = "*" + title + "*";

    final StringBuilder stringBuilder = new StringBuilder();
    final String result = stringBuilder.append(StringUtils.defaultString(boldTitle)).append(" ")
            .append(StringUtils.defaultString(text)).toString();
    return result;
}

From source file:com.sonicle.webtop.core.versioning.Whatsnew.java

public Whatsnew(String resourceName, HashMap<String, String> variables) {
    this.resourceName = resourceName;
    // Converts variables into regex patterns 
    for (String key : variables.keySet()) {
        patterns.put(Pattern.compile("\\{" + key + "\\}"), StringUtils.defaultString(variables.get(key)));
    }//w w  w. ja  v  a 2s. c  o  m
}

From source file:fr.gouv.culture.thesaurus.util.TextUtils.java

/**
 * Permet d'abbrger et de surligner une occurrence dans un texte. Le code
 * HTML  insrer autour de la partie  surligner ne le sera pas si la
 * partie  surligner est vide./*from  www .j av  a2s .  com*/
 * 
 * @param texte
 *            Texte  abbrger et contenant l'occurrence  surligner (peut
 *            tre <code>null</code>)
 * @param occurrenceStart
 *            Position de dbut de l'occurrence  surligner
 * @param occurrenceEnd
 *            Position de fin de l'occurrence  surligner (exclusif)
 * @param occurrenceMaxLength
 *            Taille max en nombre de caractres de l'occurrence
 * @param contextMaxLength
 *            Taille max en nombre de caractres du contexte (texte
 *            prcdant et suivant l'occurrence, chacun des deux constituant
 *            un contexte)
 * @param hlPreTag
 *            Code HTML  insrer avant l'occurrence (peut tre
 *            <code>null</code>)
 * @param hlPostTag
 *            Code HTML  insrer aprs l'occurrence (peut tre
 *            <code>null</code>)
 * @return Code HTML contenant le texte abbrg et l'occurrence surlign
 *         avec le code mentionn, ou <code>null</code> si le texte en
 *         entre tait <code>null</code>
 */
public static String htmlHighlightOccurrence(final String texte, final int occurrenceStart,
        final int occurrenceEnd, final int occurrenceMaxLength, final int contextMaxLength,
        final String hlPreTag, final String hlPostTag) {
    if (occurrenceStart > occurrenceEnd) {
        throw new IllegalArgumentException("Invalid occurrence position.");
    }

    String highlightedVersion;

    if (texte == null) {
        highlightedVersion = null;
    } else {
        final String preCode = StringUtils.defaultString(hlPreTag);
        final String postCode = StringUtils.defaultString(hlPostTag);

        // Partie du texte :
        // 0 : contexte prcdent
        // 1 : occurrence  surligner
        // 2 : contexte suivant
        final String[] parts = new String[3];

        parts[0] = texte.substring(0, occurrenceStart);
        parts[1] = texte.substring(occurrenceStart, occurrenceEnd);
        parts[2] = texte.substring(occurrenceEnd);

        // 1. Abbrviation des termes trouvs si besoin.
        if ((occurrenceEnd - occurrenceStart) > occurrenceMaxLength) {
            parts[1] = StringUtils.abbreviateMiddle(parts[1], ELLIPSIS, occurrenceMaxLength);
        }

        // 2. Abbrviation du contexte.
        parts[0] = rightAbbreviateOnWords(parts[0], contextMaxLength);
        parts[2] = leftAbbreviateOnWords(parts[2], contextMaxLength);

        // HTML.
        final StringBuilder highlightVersionBuilder = new StringBuilder(
                occurrenceMaxLength + contextMaxLength * 2 + preCode.length() + postCode.length());

        highlightVersionBuilder.append(StringEscapeUtils.escapeHtml4(parts[0]));

        if (StringUtils.isNotEmpty(parts[1])) {
            highlightVersionBuilder.append(preCode);
            highlightVersionBuilder.append(StringEscapeUtils.escapeHtml4(parts[1]));
            highlightVersionBuilder.append(postCode);
        }

        highlightVersionBuilder.append(StringEscapeUtils.escapeHtml4(parts[2]));

        highlightedVersion = highlightVersionBuilder.toString();
    }

    return highlightedVersion;
}

From source file:com.sonicle.webtop.core.app.util.EmailNotification.java

protected HashMap<String, String> buildTplStrings() {
    HashMap<String, String> map = new HashMap<>();

    // Colored message
    if (!StringUtils.isBlank(builder.redMessage)) {
        map.put("redMessage", builder.redMessage);
    } else if (!StringUtils.isBlank(builder.yellowMessage)) {
        map.put("yellowMessage", builder.yellowMessage);
    } else if (!StringUtils.isBlank(builder.greenMessage)) {
        map.put("greenMessage", builder.greenMessage);
    } else if (!StringUtils.isBlank(builder.greyMessage)) {
        map.put("greyMessage", builder.greyMessage);
    }/*from   w w w. j  a  va  2s  .  c  o  m*/

    // Body
    map.put("bodyHeader", StringUtils.defaultString(builder.bodyHeader));
    if (!StringUtils.isBlank(builder.bodyRaw)) {
        map.put("customBody", builder.bodyRaw);
    } else if (!StringUtils.isBlank(builder.bodyMessage)) {
        map.put("bodyMessage", builder.bodyMessage);
    }

    // Footer
    map.put("footerHeader", StringUtils.defaultString(builder.footerHeader));
    map.put("footerMessage", StringUtils.defaultString(builder.footerMessage));

    return map;
}

From source file:alfio.controller.AdminController.java

@RequestMapping("/events/{eventName}/export/badges.csv")
public void downloadBadgesCSV(@PathVariable("eventName") String eventName, Principal principal,
        HttpServletResponse response) throws IOException {
    downloadTicketsCSV(eventName, "badges", CSV_TICKETS_HEADER, principal, response, eventManager,
            t -> new String[] { t.getUuid(), t.getFullName(), StringUtils.defaultString(t.getCompany()) });
}

From source file:cz.lbenda.dataman.db.frm.DbConfigFrmController.java

public void loadDataFromSessionConfiguration(DbConfig dbConfig) {
    currentDriverClass = dbConfig.getJdbcConfiguration().getDriverClass();
    lvLibraries.getItems().clear();/*from  ww  w.j  av  a 2s . co m*/
    lvLibraries.getItems().addAll(dbConfig.getLibrariesPaths());

    tfName.setText(StringUtils.defaultString(dbConfig.getId()));
    tfUrl.setText(StringUtils.defaultString(dbConfig.getJdbcConfiguration().getUrl()));

    tfUsername.setText(StringUtils.defaultString(dbConfig.getJdbcConfiguration().getUsername()));
    pfPassword.setText(StringUtils.defaultString(dbConfig.getJdbcConfiguration().getPassword()));
    if (dbConfig.getConnectionTimeout() < 0) {
        tfTimeout.setText(
                dbConfig.getConnectionTimeout() < 0 ? "" : Integer.toString(dbConfig.getConnectionTimeout()));
    }

    tfExtendConfigPath.setText(StringUtils.defaultString(dbConfig.getExtConfFactory().getSrc()));
}

From source file:com.szmslab.quickjavamail.receive.MessageLoader.java

/**
 * Message-ID????//  w ww. j  av  a  2s .c  o  m
 *
 * @return Message-ID
 * @throws MessagingException
 */
public String getMessageId() throws MessagingException {
    return StringUtils.defaultString(StringUtils.join(message.getHeader("Message-ID"), ","));
}

From source file:com.mirth.connect.client.ui.attachments.IdentityAttachmentDialog.java

private void setProperties(AttachmentHandlerProperties attachmentHandlerProperties) {
    this.attachmentHandlerProperties = attachmentHandlerProperties;
    mimeTypeField.setText(//from   w ww  . j av  a 2s .  c o  m
            StringUtils.defaultString(attachmentHandlerProperties.getProperties().get("identity.mimetype")));
}

From source file:com.netsteadfast.greenstep.util.SystemSettingConfigureUtils.java

public static String getFirstLoadJavascriptValue() {
    SysCodeVO sysCode = getFirstLoadJavascript();
    return StringUtils.defaultString(sysCode.getParam1());
}