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

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

Introduction

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

Prototype

public static String defaultString(String str) 

Source Link

Document

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

Usage

From source file:lti.oauth.OAuthUtil.java

public static String constructAuthorizationHeader(String realm, Map<String, String> parameters) {
    StringBuilder header = new StringBuilder();
    if (realm != null) {
        header.append(" realm=\"").append(OAuthUtil.percentEncode(realm)).append('"');
    }//from   www .j  a  va  2  s  . c o  m

    if (parameters != null && !parameters.isEmpty()) {
        for (Entry<String, String> entry : parameters.entrySet()) {
            String key = entry.getKey();
            if (key.startsWith("oauth_")) {
                String value = StringUtils.defaultString(entry.getValue());
                if (header.length() > 0)
                    header.append(",");
                header.append(" ");
                header.append(OAuthUtil.percentEncode(key)).append("=\"");
                header.append(OAuthUtil.percentEncode(value)).append('"');
            }
        }
    }

    return AUTH_SCHEME + header.toString();
}

From source file:com.cloudbees.plugins.credentials.oauth.OAuth2Token.java

@DataBoundConstructor
public OAuth2Token(@CheckForNull String id, @CheckForNull String description, @CheckForNull String clientId,
        @CheckForNull String name, @CheckForNull String token) {
    super(id, description);
    this.clientId = StringUtils.defaultString(clientId);
    this.name = Util.fixEmpty(name);
    this.token = StringUtils.isBlank(token) ? null : Secret.fromString(token);
}

From source file:com.redhat.rhn.frontend.xmlrpc.serializer.NetworkInterfaceSerializer.java

/** {@inheritDoc} */
protected void doSerialize(Object value, Writer output, XmlRpcSerializer serializer)
        throws XmlRpcException, IOException {
    NetworkInterface device = (NetworkInterface) value;
    SerializerHelper devMap = new SerializerHelper(serializer);
    ArrayList ipv6List = new ArrayList();

    for (ServerNetAddress6 addr : device.getIPv6Addresses()) {
        //            SerializerHelper m = new SerializerHelper(serializer);
        Map m = new HashMap();
        m.put("address", StringUtils.defaultString(addr.getAddress()));
        m.put("netmask", StringUtils.defaultString(addr.getNetmask()));
        m.put("scope", StringUtils.defaultString(addr.getScope()));
        ipv6List.add(m);/*w w  w .j  ava 2 s.  co  m*/
    }

    devMap.add("interface", StringUtils.defaultString(device.getName()));
    devMap.add("ipv6", ipv6List);
    devMap.add("ip", StringUtils.defaultString(device.getIpaddr()));
    devMap.add("netmask", StringUtils.defaultString(device.getNetmask()));
    devMap.add("broadcast", StringUtils.defaultString(device.getBroadcast()));
    devMap.add("hardware_address", StringUtils.defaultString(device.getHwaddr()));
    devMap.add("module", StringUtils.defaultString(device.getModule()));
    devMap.writeTo(output);
}

From source file:com.bitium.confluence.config.SAMLConfig.java

public String getIdpEntityId() {
    return StringUtils.defaultString((String) pluginSettings.get(ENTITY_ID_SETTING));
}

From source file:com.redhat.rhn.frontend.xmlrpc.serializer.ChannelSerializer.java

/**
 * {@inheritDoc}// w ww  .  j a  va  2 s . c om
 */
protected void doSerialize(Object value, Writer output, XmlRpcSerializer serializer)
        throws XmlRpcException, IOException {
    SerializerHelper helper = new SerializerHelper(serializer);
    Channel c = (Channel) value;

    helper.add("id", c.getId());
    helper.add("label", c.getLabel());
    helper.add("name", c.getName());
    helper.add("arch_name", StringUtils.defaultString(c.getChannelArch().getName()));
    helper.add("arch_label", StringUtils.defaultString(c.getChannelArch().getLabel()));
    helper.add("summary", StringUtils.defaultString(c.getSummary()));
    helper.add("description", StringUtils.defaultString(c.getDescription()));
    helper.add("checksum_label", c.getChecksumTypeLabel());
    helper.add("last_modified", c.getLastModified());
    helper.add("maintainer_name", StringUtils.defaultString(c.getMaintainerName()));
    helper.add("maintainer_email", StringUtils.defaultString(c.getMaintainerEmail()));
    helper.add("maintainer_phone", StringUtils.defaultString(c.getMaintainerPhone()));
    helper.add("support_policy", StringUtils.defaultString(c.getSupportPolicy()));

    helper.add("gpg_key_url", StringUtils.defaultString(c.getGPGKeyUrl()));
    helper.add("gpg_key_id", StringUtils.defaultString(c.getGPGKeyId()));
    helper.add("gpg_key_fp", StringUtils.defaultString(c.getGPGKeyFp()));

    List<ContentSource> csList = new ArrayList<ContentSource>(c.getSources().size());
    if (!c.getSources().isEmpty()) {
        for (Iterator itr = c.getSources().iterator(); itr.hasNext();) {
            ContentSource cs = (ContentSource) itr.next();
            csList.add(cs);
        }
        helper.add("yumrepo_last_sync", c.getLastSynced());
    }
    helper.add("contentSources", csList);

    if (c.getEndOfLife() != null) {
        helper.add("end_of_life", c.getEndOfLife().toString());
    } else {
        helper.add("end_of_life", "");
    }

    Channel parent = c.getParentChannel();
    if (parent != null) {
        helper.add("parent_channel_label", parent.getLabel());
    } else {
        helper.add("parent_channel_label", "");
    }

    Channel orig = ChannelFactory.lookupOriginalChannel(c);
    if (orig != null) {
        helper.add("clone_original", orig.getLabel());
    } else {
        helper.add("clone_original", "");
    }

    helper.writeTo(output);
}

From source file:com.opengamma.web.region.WebRegionVersionResource.java

/**
 * Builds a URI for this resource./*from   www. j av  a  2 s  .co  m*/
 * @param data  the data, not null
 * @param overrideVersionId  the override version id, null uses information from data
 * @return the URI, not null
 */
public static URI uri(final WebRegionData data, final UniqueId overrideVersionId) {
    String regionId = data.getBestRegionUriId(null);
    String versionId = StringUtils
            .defaultString(overrideVersionId != null ? overrideVersionId.getVersion() : data.getUriVersionId());
    return data.getUriInfo().getBaseUriBuilder().path(WebRegionVersionResource.class).build(regionId,
            versionId);
}

From source file:mitm.djigzo.web.components.PortalLayout.java

@Cached
public String getLoggedInUser() {
    String name = null;/*  w  w  w. j  av a2 s .  com*/

    Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();

    if (currentUser != null) {
        name = currentUser.getName();
    }

    return StringUtils.defaultString(name);
}

From source file:mitm.common.util.UniqueIDGenerator.java

/**
 * Creates an instance of SecureUniqueIDCreator. The initial base value of the ID will be based on the 
 * current time in milliseconds. It's therefore advised to make sure that the system clock is in sync. The 
 * RandomGenerator should be a secure random generator and the number of random bytes should be long enough to
 * make guessing impossible.// w  ww  . ja  va  2 s . c o m
 * 
 * @param randomGenerator the generator for generating random nr's (make sure a secure random generator is used)
 * @param randomBytes the number of random bytes to generate
 * @param baseID the base ID. This can be helpful to distiguish multiple SecureUniqueIDCreator's instances. 
 */
public UniqueIDGenerator(RandomGenerator randomGenerator, int randomBytes, String baseID) {
    Check.notNull(randomGenerator, "randomGenerator");

    this.randomGenerator = randomGenerator;
    this.randomBytes = randomBytes;
    this.baseID = StringUtils.defaultString(baseID) + Long.toString(System.currentTimeMillis());
}

From source file:mitm.djigzo.web.services.LoginBanServiceImpl.java

private String getKey(String remoteAddress, String loginName) {
    return BASE_KEY + ":" + StringUtils.defaultString(remoteAddress) + ":"
            + StringUtils.defaultString(loginName);
}

From source file:mitm.common.extractor.impl.TextExtractorUtils.java

/**
 * Creates a name for an embedded document based on the parent name and the name of the 
 * embedded document (can be a word, excel, image etc.)
 *///from ww w .  j ava  2 s .  c  o  m
public static String createEmbeddedName(String parentName, String childName) {
    return StringUtils.isNotEmpty(parentName) ? parentName + "/" + StringUtils.defaultString(childName)
            : StringUtils.defaultString(childName);
}