Example usage for com.google.common.base Strings nullToEmpty

List of usage examples for com.google.common.base Strings nullToEmpty

Introduction

In this page you can find the example usage for com.google.common.base Strings nullToEmpty.

Prototype

public static String nullToEmpty(@Nullable String string) 

Source Link

Document

Returns the given string if it is non-null; the empty string otherwise.

Usage

From source file:org.killbill.billing.plugin.notification.generator.formatters.DefaultInvoiceItemFormatter.java

@Override
public String getDescription() {
    return Strings.nullToEmpty(item.getDescription());
}

From source file:de.faustedition.tei.WhitespaceUtil.java

private static void formatLineElement(Element element) {
    final String prefix = Strings.nullToEmpty(element.getAttribute("rend")).contains("inline") ? " " : "\n";

    final Node firstChild = element.getFirstChild();
    if (firstChild != null && firstChild.getNodeType() == Node.TEXT_NODE) {
        firstChild.setTextContent(prefix + firstChild.getTextContent().replaceAll("^\\s+", ""));
    } else {// www  .  j  ava  2 s.c o  m
        element.insertBefore(element.getOwnerDocument().createTextNode(prefix), firstChild);
    }

    final Node lastChild = element.getLastChild();
    if (lastChild.getNodeType() == Node.TEXT_NODE && !lastChild.isSameNode(element.getFirstChild())) {
        lastChild.setTextContent(lastChild.getTextContent().replaceAll("\\s+$", ""));
    }
}

From source file:com.b2international.snowowl.server.console.CommandLineAuthenticator.java

@Override
public String toString() {
    return Strings.nullToEmpty(username);
}

From source file:com.zimbra.doc.soap.Command.java

public String getDeprecation() {
    return Strings.nullToEmpty(this.deprecation);
}

From source file:org.smartplatforms.oauth2.SmartClientUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException {

    try {/* w w w  . j a  v  a  2s.  co m*/
        ClientDetailsEntity client = clientDetailsService.loadClientByClientId(clientId);

        if (client != null) {

            String password = Strings.nullToEmpty(client.getClientSecret());

            if (client.getTokenEndpointAuthMethod() != null
                    && (client.getTokenEndpointAuthMethod().equals(AuthMethod.PRIVATE_KEY)
                            || client.getTokenEndpointAuthMethod().equals(AuthMethod.SECRET_JWT))) {

                // Issue a random password each time to prevent password auth from being used (or skipped)
                // for private key or shared key clients, see #715

                password = new BigInteger(512, new SecureRandom()).toString(16);
            }

            boolean enabled = true;
            boolean accountNonExpired = true;
            boolean credentialsNonExpired = true;
            boolean accountNonLocked = true;
            Collection<GrantedAuthority> authorities = new HashSet<GrantedAuthority>(client.getAuthorities());
            authorities.add(ROLE_CLIENT);

            if (adminClients.contains(client.getClientId())) {
                GrantedAuthority roleClient = new SimpleGrantedAuthority("ROLE_ADMIN");
                authorities.add(roleClient);
            }

            return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired,
                    accountNonLocked, authorities);
        } else {
            throw new UsernameNotFoundException("Client not found: " + clientId);
        }
    } catch (InvalidClientException e) {
        throw new UsernameNotFoundException("Client not found: " + clientId);
    }

}

From source file:com.google.cloud.tools.intellij.appengine.cloud.AppEngineStandardRunTask.java

@Override
public void execute(ProcessStartListener startListener) {
    CloudSdkService sdkService = CloudSdkService.getInstance();

    CloudSdk sdk = new CloudSdk.Builder().sdkPath(sdkService.getSdkHomePath()).async(true)
            .startListener(startListener).build();

    try {// w  ww  .  j  a va 2s.co m
        sdk.validateAppEngineJavaComponents();
    } catch (AppEngineJavaComponentsNotInstalledException ex) {
        return;
    }

    CloudSdkAppEngineDevServer devServer = new CloudSdkAppEngineDevServer(sdk);
    devServer.run(runConfig);

    UsageTrackerProvider.getInstance().trackEvent(GctTracking.APP_ENGINE_RUN)
            .withLabel(Strings.nullToEmpty(runnerId)).ping();

}

From source file:uk.org.ngo.squeezer.model.MusicFolderItem.java

public MusicFolderItem(Map<String, String> record) {
    setId(record.get("id"));
    name = record.get("filename");
    type = record.get("type");
    url = Uri.parse(Strings.nullToEmpty(record.get("url")));
    mDownloadUrl = Uri.parse(Strings.nullToEmpty(record.get("download_url")));
}

From source file:com.qcadoo.mes.cmmsMachineParts.hooks.PlannedEventHooks.java

public void onSave(final DataDefinition eventDD, final Entity event) {
    Entity owner = event.getBelongsToField(PlannedEventFields.OWNER);
    if (owner != null) {
        String person = Strings.nullToEmpty(owner.getStringField(StaffFields.NAME)) + " "
                + Strings.nullToEmpty(owner.getStringField(StaffFields.SURNAME));
        event.setField(PlannedEventFields.OWNER_NAME, person);
    } else {//from  w  w  w .ja va 2 s .c  om
        event.setField(PlannedEventFields.OWNER_NAME, StringUtils.EMPTY);
    }
    clearHiddenFields(event);
}

From source file:com.cloudbees.demo.beesshop.service.MailService.java

public void sendProductEmail(Product product, String recipient, String cocktailPageUrl)
        throws MessagingException {

    Message msg = new MimeMessage(mailSession);

    msg.setFrom(fromAddress);//  w ww.  j  av a2 s.c  o m
    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient));

    msg.setSubject("[BeesShop] Check this product: " + product.getName());
    String message = product.getName() + "\n" //
            + "--------------------\n" //
            + "\n" //
            + Strings.nullToEmpty(product.getDescription()) + "\n" //
            + "\n" //
            + cocktailPageUrl;
    msg.setContent(message, "text/plain");

    mailSession.getTransport().send(msg);
    auditLogger.info("Sent to {} product '{}'", recipient, product.getName());
    sentEmailCounter.incrementAndGet();
}

From source file:org.mitre.jwt.model.Jwt.java

/**
 * Return the canonical encoded string of this JWT, the header in Base64, a period ".", the claims in Base64, a period ".", and the signature in Base64.
 *///from  w w w.  j av  a 2  s .  co m
public String toString() {
    return getSignatureBase() + "." + Strings.nullToEmpty(this.signature);
}