List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:org.ambraproject.wombat.service.CitationDownloadServiceImpl.java
private static StringBuilder appendRisCitationLine(StringBuilder builder, String key, String value) { return builder.append(Objects.requireNonNull(key)).append(" - ").append(Strings.nullToEmpty(value)) .append('\n'); }
From source file:com.google.testing.security.firingrange.tests.reflected.Charsets.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 restrictedCharsets = Splitter.on('/').splitToList(request.getPathInfo()).get(2); switch (restrictedCharsets) { case "SpaceDoubleQuoteSlashEquals": if (containsChars(echoedParam, '=', '\\', '"', ' ')) { Responses.sendError(response, "Invalid param.", 400); return; }//from w ww .j av a 2s.co m break; case "DoubleQuoteSinglequote": if (containsChars(echoedParam, '"', '\'')) { Responses.sendError(response, "Invalid param.", 400); return; } break; default: Responses.sendError(response, "Invalid charset.", 400); return; } Responses.sendXssed(response, Templates.replacePayload(template, echoedParam)); }
From source file:org.openqa.selenium.environment.webserver.GeneratedJsTestServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String symbol = Strings.nullToEmpty(req.getPathInfo()).replace("../", "").replace("/", "$"); byte[] data = ("<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta http-equiv=\"X-UA-Compatible\" content=\"IE-Edge\">\n" + "<!-- File generated by " + getClass().getName() + " -->\n" + "<title>" + req.getPathInfo() + "</title>\n" + "<script src=\"/third_party/closure/goog/base.js\"></script>\n" + "<script src=\"/javascript/deps.js\"></script>\n" + "<script>\n" + " (function() {\n" + " var path = '../../.." + req.getPathInfo() + "';\n" + " goog.addDependency(path, ['" + symbol + "'],\n" + " goog.dependencies_.requires['../../.." + req.getPathInfo() + "'] || [],\n" + " !!goog.dependencies_.pathIsModule[path]);\n" + " goog.require('" + symbol + "');\n" + " })()\n" + "</script></head><body></body></html>").getBytes(Charsets.UTF_8); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(MediaType.HTML_UTF_8.toString()); resp.setContentLength(data.length);// w w w.j a v a 2 s .co m OutputStream stream = resp.getOutputStream(); stream.write(data); stream.flush(); stream.close(); }
From source file:org.attribyte.api.http.AuthScheme.java
/** * Creates an authentication scheme.//from w w w. ja v a 2s . c o m * <p> * Must not contain the quote character. * </p> * @param scheme The scheme name. * @param realm The realm. * @throws java.lang.UnsupportedOperationException if the realm contains the quote character. */ protected AuthScheme(final String scheme, final String realm) { if (realm.contains("\"")) { throw new UnsupportedOperationException("The 'realm' must not contain the quote character"); } this.scheme = scheme.intern(); this.realm = Strings.nullToEmpty(realm); this.authenticateResponseHeader = this.scheme + " realm=\"" + this.realm + "\""; }
From source file:io.macgyver.plugin.metrics.RegexMetricFilter.java
public RegexMetricFilter excludes(String s) { Splitter.on(CharMatcher.anyOf(" \n\t\r,;|")).omitEmptyStrings().splitToList(Strings.nullToEmpty(s)) .forEach(it -> {//from ww w . j a v a 2 s . c o m exclude(Pattern.compile(it)); }); return this; }
From source file:net.anyflow.lannister.httphandler.Topics.java
@Override public String service() { String filter = Strings.nullToEmpty(httpRequest().parameter("filter")); switch (filter) { case "": case "all": return allString(); default://w ww.ja v a2 s . co m return null; } }
From source file:org.apache.jackrabbit.oak.security.authorization.permission.PermissionUtil.java
@Nonnull public static String getEntryName(@Nullable String accessControlledPath) { String path = Strings.nullToEmpty(accessControlledPath); return String.valueOf(path.hashCode()); }
From source file:org.dcache.xrootd.protocol.messages.ErrorResponse.java
public ErrorResponse(T request, int errnum, String errmsg) { super(request, XrootdProtocol.kXR_error); this.errnum = errnum; this.errmsg = Strings.nullToEmpty(errmsg); LOGGER.info("Xrootd-Error-Response: ErrorNr={} ErrorMsg={}", errnum, errmsg); }
From source file:it.reply.orchestrator.validator.DeploymentRequestValidator.java
@Override public void validate(Object target, Errors errors) { if (target == null) { errors.reject("request.null", "Deployment request is null"); return;/*from ww w . java2 s .c o m*/ } DeploymentRequest deploymentRequest = (DeploymentRequest) target; String callbackUrl = deploymentRequest.getCallback(); if (callbackUrl != null) { if (Strings.nullToEmpty(callbackUrl).trim().isEmpty()) { errors.rejectValue("callback", "callback.blank", "Callback URL is blank"); } else { try { URI.create(callbackUrl).toURL(); } catch (Exception ex) { errors.rejectValue("callback", "callback.malformed", "Callback URL is malformed"); } } } }
From source file:org.attribyte.api.pubsub.HTTPUtil.java
/** * Returns true if string is null, or empty after trimmed. * @param str The string./* ww w .j a v a 2s .co m*/ * @return Is the string null or empty? */ private static boolean isTrimmedEmpty(final String str) { return Strings.nullToEmpty(str).trim().isEmpty(); }