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.eucalyptus.simplequeue.common.policy.SimpleQueueResourceName.java

@Override
public String toString() {
    return new StringBuilder().append(ARN_PREFIX).append(getService()).append(':')
            .append(Strings.nullToEmpty(getRegion())).append(':').append(Strings.nullToEmpty(getAccount()))
            .append(':').append(getType().equals(SimpleQueuePolicySpec.RESOURCE_TYPE) ? "" : getType() + "/")
            .append(getResourceName()).toString();

}

From source file:com.google.testing.security.firingrange.tests.tags.Multiline.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String query = Strings.nullToEmpty(request.getParameter("q"));
    Matcher matcher = TAG_FILTER.matcher(query);
    if (matcher.matches()) {
        String error = "Invalid input, contains tags.";
        response.sendError(400, error);/*  w w  w .  j av a2  s .  com*/
        return;
    }
    String body = String.format("<html><body>%s</body></html>", query);
    Responses.sendXssed(response, body);
}

From source file:org.iplantc.de.desktop.client.views.widgets.TaskButton.java

TaskButton(Window win, TaskButtonCell cell) {
    super(cell);/* w w  w.  ja  va 2  s .c o m*/
    setText(Strings.nullToEmpty(win.getHeader().getText()));
    setIcon(getCell().getAppearance().getIcon());
    setHeight(getCell().getAppearance().getHeight());
    this.win = win;
    setValue(true);
    win.addMinimizeHandler(this);
    win.addMaximizeHandler(this);
    win.addShowHandler(this);
}

From source file:com.google.testing.security.firingrange.tests.redirect.Meta.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM));
    if (echoedParam.isEmpty()) {
        Responses.sendError(response, "Empty required parameter", 400);
        return;/*www. jav  a 2s. c om*/
    }
    URI uri;
    try {
        uri = URI.create(echoedParam);
    } catch (IllegalArgumentException e) {
        Responses.sendError(response, "Invalid echoed parameter", 400);
        return;
    }
    String template = Templates.getTemplate("meta.tmpl", this.getClass());
    Responses.sendXssed(response, Templates.replacePayload(template, uri.toString()));
}

From source file:de.bund.bfr.knime.ui.StringTextField.java

public void setValue(String value) {
    setTextWithoutListener(Strings.nullToEmpty(value));
    textChanged();
}

From source file:br.com.objectos.jabuticava.debs.DataParser.java

public LocalDate get() {
    LocalDate res = null;//from   w ww .jav  a 2  s. c  o  m

    try {
        CharSource charSource = CharSource.wrap(text);
        String line = charSource.readFirstLine();
        line = Strings.nullToEmpty(line);
        Matcher matcher = REGEX.matcher(line);
        if (matcher.find()) {
            String data = matcher.group(0);
            res = new LocalDateCsvConverter("dd/MM/yyyy").convert(data);
        }
    } catch (IOException e) {
    }

    return res;
}

From source file:com.google.testing.security.firingrange.tests.redirect.Parameter.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM));
    String pathInfo = Strings.nullToEmpty(request.getPathInfo());
    if (pathInfo.startsWith("/url/")) {
        // /redirect/parameter/url/a/b/c?x=y  gets redirected to /a/b/c?x=y
        // on the same host and port
        String target = pathInfo.substring(4);
        if (request.getQueryString() != null) {
            target += "?" + request.getQueryString();
        }/*from   ww w  .j  av a 2  s  .  c  o  m*/
        Responses.sendRedirect(response, target);
    } else if (!echoedParam.isEmpty()) {
        // /redirect/parameter?url=......  gets redirected to the specified
        // url, which can either be relative or absolute
        Check check = pathInfo.isEmpty() ? Check.NONE : Check.valueOf(pathInfo.toUpperCase().substring(1));
        switch (check) {
        case NONE:
            Responses.sendRedirect(response, echoedParam);
            break;
        case NOSTARTSWITHJS:
            handleNoStartWithJs(echoedParam, response);
            break;
        }
    } else {
        Responses.sendError(response, "Provide target url via url parameter", 400);
    }
}

From source file:io.macgyver.core.okhttp3.SoftPropertyConfig.java

public static OkHttpClientConfigurer basicAuthConfig(Properties props) {

    if (props == null) {
        return nullOkHttpClientConfigurer();
    }//from  w  w w . j av a2  s.c  o m

    String username = Strings.nullToEmpty(props.getProperty("username")).trim();
    String password = Strings.nullToEmpty(props.getProperty("password")).trim();

    if (Strings.isNullOrEmpty(username) && Strings.isNullOrEmpty(password)) {
        logger.warn("both username and password were empty");
        return nullOkHttpClientConfigurer();
    }

    // there are legitimate use-cases for either the username or password to be empty

    OkHttpClientConfigurer b = new OkHttpClientConfigurer() {

        @Override
        public void accept(Builder t) {
            if (username != null && password != null) {
                t.addInterceptor(new BasicAuthInterceptor(username, password));
            }
        }
    };
    return b;
}

From source file:com.google.testing.security.firingrange.tests.reflected.Substrings.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM));
    String template = Templates.getTemplate(request, getClass());
    String restrictionModifier = Splitter.on('/').splitToList(request.getPathInfo()).get(2);
    String restrictedString = Splitter.on('/').splitToList(request.getPathInfo()).get(3);

    switch (restrictionModifier) {
    case "caseSensitive":
        if (containsSubstrings(echoedParam, restrictedString)) {
            Responses.sendError(response, "Invalid param.", 400);
            return;
        }/*from   www . j av a  2  s. co  m*/
        break;
    case "caseInsensitive":
        if (containsSubstrings(echoedParam.toLowerCase(), restrictedString.toLowerCase())) {
            Responses.sendError(response, "Invalid param.", 400);
            return;
        }
        break;
    default:
        Responses.sendError(response, "Invalid restriction.", 400);
        return;
    }
    Responses.sendXssed(response, Templates.replacePayload(template, echoedParam));
}

From source file:com.google.enterprise.connector.spi.MockConnectorType.java

public MockConnectorType(String typeName) {
    this.typeName = Strings.nullToEmpty(typeName);
}