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, final String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is null , the value of defaultStr .

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

Usage

From source file:io.wcm.samples.handler.controller.common.PageTitle.java

/**
 * Build html title from page titles up to site root page.
 * @param page Page/*from   ww  w .  ja  v a 2 s.  c o  m*/
 * @return Html title
 */
private String getRecursivePageTitle(Page page) {
    if (siteHelper.isSiteRootPage(page)) {
        return StringUtils.defaultString(page.getPageTitle(), page.getTitle());
    } else if (AppTemplate.isTemplate(page, AppTemplate.FRAMEWORK_STRUCTURE_ELEMENT)) {
        return getRecursivePageTitle(page.getParent());
    } else {
        return StringUtils.defaultString(page.getPageTitle(), page.getTitle()) + " - "
                + getRecursivePageTitle(page.getParent());
    }
}

From source file:io.redlink.solrlib.standalone.test.StandaloneSolrServer.java

public StandaloneSolrServer(int port, String context) {
    final JettyConfig.Builder builder = JettyConfig.builder()
            .setContext(StringUtils.defaultString(context, "/solr"));
    if (port > 0)
        builder.setPort(port);/*ww  w  .jav a 2  s .  com*/
    jettyConfig = builder.build();
}

From source file:io.wcm.handler.link.markup.DummyLinkMarkupBuilder.java

@Override
public Anchor build(Link link) {
    // build anchor
    String url = StringUtils.defaultString(link.getLinkRequest().getLinkArgs().getDummyLinkUrl(),
            LinkHandler.INVALID_LINK);/*w ww  .j a va  2  s. co m*/
    return new Anchor(url);
}

From source file:com.cognifide.aet.job.common.comparators.accessibility.report.AccessibilityReportConfiguration.java

public AccessibilityReportConfiguration(Map<String, String> params) {
    if (params.containsKey(PARAM_SHOW_EXCLUDED)) {
        showExcluded = BooleanUtils.toBoolean(params.get(PARAM_SHOW_EXCLUDED));
    }/*w ww.j a  v  a  2  s . c om*/

    if (params.containsKey(PARAM_IGNORE_NOTICE)) {
        ignoreNotice = BooleanUtils.toBoolean(params.get(PARAM_IGNORE_NOTICE));
    }

    String reportLevelString = StringUtils.defaultString(params.get(PARAM_REPORT_LEVEL), DEFAULT_REPORT_LEVEL);
    if (!ignoreNotice) {
        reportLevelString = IssueType.NOTICE.toString();
    }

    IssueType reportLevel;
    reportLevel = IssueType.valueOf(reportLevelString.toUpperCase());

    showNotice = IssueType.NOTICE.compareTo(reportLevel) <= 0;
    showWarning = IssueType.WARN.compareTo(reportLevel) <= 0;
}

From source file:com.navercorp.pinpoint.web.vo.AgentActiveThreadCountList.java

public List<AgentActiveThreadCount> getAgentActiveThreadRepository() {
    // sort agentId
    agentActiveThreadRepository.sort(new Comparator<AgentActiveThreadCount>() {
        @Override/*  w w  w .  j av  a 2s  .co  m*/
        public int compare(AgentActiveThreadCount o1, AgentActiveThreadCount o2) {
            final String agentId1 = StringUtils.defaultString(o1.getAgentId(), "");
            final String agentId2 = StringUtils.defaultString(o2.getAgentId(), "");
            return agentId1.compareTo(agentId2);
        }
    });
    return agentActiveThreadRepository;
}

From source file:com.sap.data.core.utils.PropertiesLoader.java

/**
 * ?PropertySystemProperty.NullDefault./*from   ww w  . ja  va2s  . c  o m*/
 */
public String getProperty(String key, String defaultValue) {
    String result = getProperty(key);
    return StringUtils.defaultString(result, defaultValue);
}

From source file:com.ejisto.modules.vertx.handler.Boilerplate.java

public static void writeError(HttpServerRequest req, Throwable e) {
    req.response().setStatusCode(INTERNAL_SERVER_ERROR.code())
            .setStatusMessage(StringUtils.defaultString(e.getMessage(), "exception")).end();
}

From source file:cop.maven.plugins.RamlMojoIT.java

@SuppressWarnings("CallToSystemGetenv")
private static String getMavenHome() {
    return StringUtils.defaultString(System.getenv("MAVEN_HOME"), System.getenv("M2_HOME"));
}

From source file:com.mgmtp.jfunk.common.cli.LoggingStreamConsumer.java

/**
 * @param loggerName/*from   w ww  . j  a v  a2  s .  c o  m*/
 *            the name of the logger to use (passed to {@link LoggerFactory#getLogger(String)});
 *            if {@code null} this class' name is used
 * @param logMessagePrefix
 *            if non-{@code null} consumed lines are prefix with this string
 * @param error
 *            specifies whether info or error level is used for logging
 */
public LoggingStreamConsumer(final String loggerName, final String logMessagePrefix, final boolean error) {
    this.logger = LoggerFactory.getLogger(StringUtils.defaultString(loggerName, getClass().getName()));
    this.logMessagePrefix = logMessagePrefix;
    this.error = error;
}

From source file:de.knightsoftnet.validators.server.security.CsrfCookieHandler.java

/**
 * set csrf/xsrf cookie./* w w w. j av a  2 s .  c  o  m*/
 */
public void setCookie(final HttpServletRequest prequest, final HttpServletResponse presponse)
        throws IOException {
    final CsrfToken csrf = (CsrfToken) prequest.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(prequest, ResourcePaths.XSRF_COOKIE);
        final String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie(ResourcePaths.XSRF_COOKIE, token);
            cookie.setPath(StringUtils.defaultString(StringUtils.trimToNull(prequest.getContextPath()), "/"));
            presponse.addCookie(cookie);
        }
    }
}