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:com.zimbra.cs.db.HSQLDB.java

/**
 * Deletes all records from all tables.//  w  w w. ja v a  2 s  . c om
 * @param zimbraServerDir the directory that contains the ZimbraServer project
 * @throws Exception
 */
public static void clearDatabase(String zimbraServerDir) throws Exception {
    zimbraServerDir = Strings.nullToEmpty(zimbraServerDir);
    DbConnection conn = DbPool.getConnection();
    try {
        execute(conn, zimbraServerDir + "src/db/hsqldb/clear.sql");
    } finally {
        DbPool.quietClose(conn);
    }
}

From source file:com.arcbees.beestore.server.servlets.LocaleExtractor.java

public String getLocaleFromPath() {
    String path = Strings.nullToEmpty(request.getRequestURI());
    Matcher matcher = EXTRACT_LOCALE_PATTERN.matcher(path);

    String locale = null;//from   w w w  . j av a2 s .com
    if (matcher.find()) {
        locale = matcher.group(1).toLowerCase();
    }

    return locale;
}

From source file:org.sonatype.nexus.security.privilege.PrivilegeDescriptorSupport.java

/**
 * Helper to read a privilege property and return default-value if unset or empty.
 *//*from   w  ww  .ja  va2s  .  c  o m*/
protected String readProperty(final CPrivilege privilege, final String name, final String defaultValue) {
    String value = privilege.getProperty(name);
    if (Strings.nullToEmpty(value).isEmpty()) {
        value = defaultValue;
    }
    return value;
}

From source file:fr.da2i.lup1.entity.security.Credential.java

public String getPassword() {
    return Strings.nullToEmpty(password);
}

From source file:org.ambraproject.rhino.content.xml.AssetXml.java

@Override
public AssetMetadata build() throws XmlContentException {
    String doi = assetId.getName();
    String title = "";
    String description = "";

    if (xml.getLocalName().equalsIgnoreCase(DECISION_LETTER)) {
        title = Strings.nullToEmpty(readString("front-stub/title-group/article-title"));
        description = Strings.nullToEmpty(readString("@article-type"));
    } else {//from   w  w w.  ja  va 2 s.c  o  m
        title = Strings.nullToEmpty(readString("child::label"));
        Node captionNode = readNode("child::caption");
        description = Strings.nullToEmpty(getXmlFromNode(captionNode));
    }

    return new AssetMetadata(doi, title, description);
}

From source file:com.hp.printos.deviceapi.example.util.HttpClientFactoryBean.java

private HttpRoutePlanner getRoutePlanner() {
    proxyHostname = Strings.nullToEmpty(proxyHostname);
    if (proxyHostname.isEmpty()) {
        proxyEnabled = false;/*from  w  w  w. j  a  va  2  s.  co m*/
    }
    if (proxyEnabled) {
        HttpHost proxy = new HttpHost(proxyHostname, proxyPort, proxyScheme);

        HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy) {

            @Override
            public HttpRoute determineRoute(final HttpHost host, final HttpRequest request,
                    final HttpContext context) throws HttpException {
                String hostname = host.getHostName();
                if (hostname.equals("127.0.0.1") || hostname.equalsIgnoreCase("localhost")) {
                    // Return direct route
                    return new HttpRoute(host);
                }
                return super.determineRoute(host, request, context);
            }
        };
        return routePlanner;
    }
    return null;
}

From source file:com.bdenney.locl.activity.NearbyActivity.java

private String getSearchTerm() {
    String query = null;/*  ww w  .  j  a v  a  2s  .  c om*/
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        query = intent.getStringExtra(SearchManager.QUERY);
    }
    return Strings.nullToEmpty(query);
}

From source file:org.apache.sentry.tests.e2e.hive.hiveserver.AbstractHiveServer.java

protected static void waitForStartup(HiveServer hiveServer) throws Exception {
    int waitTime = 0;
    long startupTimeout = 1000L * 10L;
    do {/*ww  w  . j  ava2s.com*/
        Thread.sleep(500L);
        waitTime += 500L;
        if (waitTime > startupTimeout) {
            throw new TimeoutException("Couldn't access new HiveServer: " + hiveServer.getURL());
        }
        try {
            DriverManager.setLoginTimeout(30);
            Connection connection = DriverManager.getConnection(hiveServer.getURL(), "foo", "bar");
            connection.close();
            break;
        } catch (SQLException e) {
            String state = Strings.nullToEmpty(e.getSQLState()).trim();
            if (!state.equalsIgnoreCase(LINK_FAILURE_SQL_STATE)) {
                throw e;
            }
        }
    } while (true);
}

From source file:com.zimbra.cs.mailbox.MailboxTestUtil.java

/**
 * Initializes the provisioning./*  w  w w  .j a va2  s  . co  m*/
 *
 * @param zimbraServerDir the directory that contains the ZimbraServer project
 * @throws Exception
 */
public static void initProvisioning(String zimbraServerDir) throws Exception {
    String zimbraHome = "/opt/zimbra/";
    zimbraServerDir = Strings.nullToEmpty(zimbraServerDir);
    System.setProperty("log4j.configuration", "log4j-test.properties");
    // Don't load from /opt/zimbra/conf
    System.setProperty("zimbra.config", zimbraServerDir + "src/java-test/localconfig-test.xml");
    LC.reload();
    LC.zimbra_attrs_directory.setDefault(zimbraHome + "conf/attrs");
    LC.zimbra_rights_directory.setDefault(zimbraHome + "conf/rights");
    LC.timezone_file.setDefault(zimbraHome + "conf/timezones.ics");

    // default MIME handlers are now set up in MockProvisioning constructor
    Provisioning.setInstance(new MockProvisioning());
}

From source file:com.indeed.imhotep.metadata.FieldMetadata.java

public void toJSON(@Nonnull ObjectNode jsonNode) {
    jsonNode.put("name", getName());
    final String description = Strings.nullToEmpty(getDescription());
    jsonNode.put("description", description);
    jsonNode.put("type", getType().toString());
    if (getType() != getImhotepType()) {
        jsonNode.put("imhotepType", getImhotepType().toString());
    }/*from   w  ww .  jav a2 s . com*/
}