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.google.testing.security.firingrange.tests.reverseclickjacking.UniversalReverseClickjackingSinglePage.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String parameterLocation, template;

    try {//from  w  w  w.  j a v  a2s .c om
        parameterLocation = Splitter.on('/').splitToList(request.getPathInfo()).get(2);
    } catch (IndexOutOfBoundsException e) {
        // The parameter location is not set. Return 400 later.
        Responses.sendError(response, "Please specify the location of the vulnerable parameter.", 400);
        return;
    }

    String vulnerableParameter = Strings.nullToEmpty(request.getParameter(VULNERABLE_PARAMETER));
    // Encode URL to prevent XSS
    vulnerableParameter = urlFormParameterEscaper().escape(vulnerableParameter);

    switch (parameterLocation) {
    case "ParameterInQuery":
        template = Templates.getTemplate("parameter_in_query.tmpl", getClass());
        template = Templates.replacePayload(template, vulnerableParameter);
        break;
    case "ParameterInFragment":
        template = Templates.getTemplate("parameter_in_fragment.tmpl", getClass());
        break;
    default:
        Responses.sendError(response, "Invalid location of the vulnerable parameter.", 400);
        return;
    }

    Responses.sendXssed(response, template);
}

From source file:com.b2international.snowowl.snomed.datastore.internal.id.reservations.ReservationRangeImpl.java

public ReservationRangeImpl(long itemIdMin, long itemIdMax, String namespace,
        Collection<ComponentCategory> components) {
    checkArgument(components.size() >= 1, "At least one ComponentNature must be defined");
    final int minItemIdMin = Strings.isNullOrEmpty(namespace) ? 100 : 1;
    checkArgument(itemIdMin >= minItemIdMin, "ItemIdMin should be greater than or equal to %s", minItemIdMin);
    checkArgument(itemIdMax >= itemIdMin, "ItemIdMax should be greater than or equal to ItemIdMin");
    this.itemIdRange = Range.closed(itemIdMin, itemIdMax);
    this.namespace = Strings.nullToEmpty(namespace);
    this.components = components;
}

From source file:org.sosy_lab.cpachecker.util.predicates.mathsat5.Mathsat5AbstractProver.java

public boolean isUnsat() throws InterruptedException, SolverException {
    Preconditions.checkState(curEnv != 0);
    try {//  w w  w  . ja  v  a  2 s  .com
        return !msat_check_sat(curEnv);
    } catch (IllegalStateException e) {
        String msg = Strings.nullToEmpty(e.getMessage());
        if (msg.contains("too many iterations")
                || msg.contains("impossible to build a suitable congruence graph!")
                || msg.contains("can't produce proofs")) {
            // This is not a bug in CPAchecker, but a problem of MathSAT which happens during interpolation
            throw new SolverException(e.getMessage(), e);
        }
        throw e;
    }
}

From source file:org.apache.sqoop.submission.spark.SqoopSparkClientManager.java

private void addJars(String addedJars) {
    for (String addedJar : CSV_SPLITTER.split(Strings.nullToEmpty(addedJars))) {
        if (!localJars.contains(addedJar)) {
            localJars.add(addedJar);/*from www. j  av a2  s.  c  o  m*/
            context.addJar(addedJar);
        }
    }
}

From source file:org.apache.sentry.policy.db.DBWildcardPrivilege.java

public DBWildcardPrivilege(String wildcardString) {
    wildcardString = Strings.nullToEmpty(wildcardString).trim();
    if (wildcardString.isEmpty()) {
        throw new IllegalArgumentException("Wildcard string cannot be null or empty.");
    }//from   w  ww .  ja  v  a  2 s  .com
    List<KeyValue> parts = Lists.newArrayList();
    for (String authorizable : ProviderConstants.AUTHORIZABLE_SPLITTER.trimResults().split(wildcardString)) {
        if (authorizable.isEmpty()) {
            throw new IllegalArgumentException("Privilege '" + wildcardString + "' has an empty section");
        }
        parts.add(new KeyValue(authorizable));
    }
    if (parts.isEmpty()) {
        throw new AssertionError("Should never occur: " + wildcardString);
    }
    this.parts = ImmutableList.copyOf(parts);
}

From source file:com.smoketurner.dropwizard.consul.task.MaintenanceTask.java

@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {

    if (!parameters.containsKey("enable")) {
        throw new IllegalArgumentException("Parameter \"enable\" not found");
    }//from   w  ww. jav  a 2 s  .com

    final boolean enable = Boolean.parseBoolean(parameters.get("enable").asList().get(0));
    final String reason;
    if (parameters.containsKey("reason")) {
        reason = Strings.nullToEmpty(parameters.get("reason").asList().get(0));
    } else {
        reason = "";
    }

    if (enable) {
        if (!Strings.isNullOrEmpty(reason)) {
            LOGGER.warn("Enabling maintenance mode for service {} (reason: {})", serviceId, reason);
        } else {
            LOGGER.warn("Enabling maintenance mode for service {} (no reason given)", serviceId);
        }
    } else {
        LOGGER.warn("Disabling maintenance mode for service {}", serviceId);
    }

    consul.agentClient().toggleMaintenanceMode(serviceId, enable, reason);

    output.println("OK");
    output.flush();
}

From source file:edu.cmu.lti.oaqa.baseqa.providers.query.LuceneQueryStringConstructor.java

@Override
public String formatQueryConcept(String formatQueryField, String formatQueryText) {
    return Strings.nullToEmpty(formatQueryField) + formatQueryText;
}

From source file:io.druid.server.namespace.http.NamespacesCacheResource.java

@GET
@Produces({ MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE })
public Response getNamespaces() {
    try {/*from  www.  jav  a 2 s  .co m*/
        return Response.ok().entity(namespaceExtractionCacheManager.getKnownNamespaces()).build();
    } catch (Exception ex) {
        log.error("Can not get the list of known namespaces");
        return Response.serverError().entity(Strings.nullToEmpty(ex.getMessage())).build();
    }
}

From source file:org.haiku.haikudepotserver.dataobjects.PkgLocalization.java

@Override
protected void validateForSave(ValidationResult validationResult) {

    String titleTrimmed = Strings.emptyToNull(Strings.nullToEmpty(getTitle()).trim());
    String descriptionTrimmed = Strings.emptyToNull(Strings.nullToEmpty(getDescription()).trim());
    String summaryTrimmed = Strings.emptyToNull(Strings.nullToEmpty(getSummary()).trim());

    if (!Objects.equals(titleTrimmed, getTitle())) {
        setTitle(titleTrimmed);/* w  w  w .  j  av a 2s .c  o m*/
    }

    if (!Objects.equals(descriptionTrimmed, getDescription())) {
        setDescription(descriptionTrimmed);
    }

    if (!Objects.equals(summaryTrimmed, getSummary())) {
        setSummary(summaryTrimmed);
    }

    super.validateForSave(validationResult);

}

From source file:org.apache.sentry.policy.search.SearchWildcardPermission.java

public SearchWildcardPermission(String wildcardString) {
    wildcardString = Strings.nullToEmpty(wildcardString).trim();
    if (wildcardString.isEmpty()) {
        throw new IllegalArgumentException("Wildcard string cannot be null or empty.");
    }/*from   w w  w . ja  v  a  2  s.  co m*/
    List<KeyValue> parts = Lists.newArrayList();
    for (String authorizable : AUTHORIZABLE_SPLITTER.trimResults().split(wildcardString)) {
        if (authorizable.isEmpty()) {
            throw new IllegalArgumentException("Privilege '" + wildcardString + "' has an empty section");
        }
        parts.add(new KeyValue(authorizable));
    }
    if (parts.isEmpty()) {
        throw new AssertionError("Should never occur: " + wildcardString);
    }
    this.parts = ImmutableList.copyOf(parts);
}