List of usage examples for com.google.common.base Strings nullToEmpty
public static String nullToEmpty(@Nullable String string)
From source file:com.google.testing.security.firingrange.tests.reverseclickjacking.UniversalReverseClickjackingMultiPage.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String headerOptions, parameterLocation, template; try {//from w w w. java 2 s . c o m parameterLocation = Splitter.on('/').splitToList(request.getPathInfo()).get(2); headerOptions = Splitter.on('/').splitToList(request.getPathInfo()).get(3); } catch (IndexOutOfBoundsException e) { // Either the parameter location or the X-Frame-Options is not set. Responses.sendError(response, "Please specify the location of the vulnerable parameter and the preference for the" + " X-Frame-Option header.", 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("jsonly_in_query.tmpl", getClass()); template = Templates.replacePayload(template, vulnerableParameter); break; case "ParameterInFragment": template = Templates.getTemplate("jsonly_in_fragment.tmpl", getClass()); break; default: Responses.sendError(response, "Invalid location of the vulnerable parameter.", 400); return; } switch (headerOptions) { case "WithXFO": response.setHeader(HttpHeaders.X_FRAME_OPTIONS, "DENY"); break; case "WithoutXFO": break; default: Responses.sendError(response, "Invalid preference for the X-Frame-Option header.", 400); return; } Responses.sendXssed(response, template); }
From source file:fr.da2i.lup1.entity.formation.Member.java
public String getEmail() { return Strings.nullToEmpty(email); }
From source file:de.m0ep.canvas.AbstractEndpoint.java
@Override public void setParentEndpointPath(String parentEndpointPath) { this.parentEndpointPath = Strings.nullToEmpty(parentEndpointPath); }
From source file:com.zimbra.cs.redolog.op.CreateFolder.java
public CreateFolder(int mailboxId, String name, int parentId, Folder.FolderOptions fopt) { this();// w w w.j a v a 2 s. com setMailboxId(mailboxId); this.name = name == null ? "" : name; this.parentId = parentId; this.attrs = fopt.getAttributes(); this.defaultView = fopt.getDefaultView(); this.flags = fopt.getFlags(); this.color = fopt.getColor().getValue(); this.url = Strings.nullToEmpty(fopt.getUrl()); this.date = fopt.getDate(); this.custom = fopt.getCustomMetadata(); }
From source file:org.glowroot.agent.plugin.servlet.HttpSessions.java
private static void captureAllSessionAttributes(HttpSession session, Map<String, String> captureMap) { Enumeration<? extends /*@Nullable*/Object> e = session.getAttributeNames(); if (e == null) { return;/*from w ww. ja v a 2 s. c o m*/ } while (e.hasMoreElements()) { String attributeName = (String) e.nextElement(); if (attributeName == null) { continue; } String valueString; if (attributeName.equals(ServletPluginProperties.HTTP_SESSION_ID_ATTR)) { valueString = Strings.nullToEmpty(session.getId()); } else { Object value = session.getAttribute(attributeName); // value shouldn't be null, but its (remotely) possible that a concurrent // request for the same session just removed the attribute valueString = value == null ? "" : value.toString(); } // taking no chances on value.toString() possibly returning null captureMap.put(attributeName, Strings.nullToEmpty(valueString)); } }
From source file:org.sonar.core.issue.tracking.LineHashSequence.java
/** * Hash of the given line, which starts with 1. Return empty string * is the line does not exist.//from www . java 2 s . c om */ public String getHashForLine(int line) { if (line > 0 && line <= hashes.size()) { return Strings.nullToEmpty(hashes.get(line - 1)); } return ""; }
From source file:com.arcbees.website.server.LocaleExtractor.java
private String getLocaleFromPath() { String path = Strings.nullToEmpty(request.getRequestURI()); Matcher matcher = EXTRACT_LOCALE_PATTERN.matcher(path); String locale = null;/*from w w w .j ava2 s. c o m*/ if (matcher.find()) { locale = matcher.group(1).toLowerCase(); } return locale; }
From source file:com.zimbra.doc.soap.XmlAttributeDescription.java
public String getFieldTag() { return Strings.nullToEmpty(fieldTag); }
From source file:com.b2international.commons.exceptions.Exceptions.java
/** * Tries to extract the expected cause from the commit exception and returns with it. May return with {@code null} * if the expected exception cannot be extracted from the wrapper commit exception. * @param t the throwable possible wrapping the original cause of a failure commit. * @param classLoader class loader for resolving the excepted cause. May be {@code null}. * @param expectedCauseType the expected case type. * @return the wrapped cause or {@code null} if cannot be extracted. *///from w w w . ja va 2s . c o m public static <T extends Throwable> T extractCause(final Throwable t, final ClassLoader classLoader, final Class<? extends T> expectedCauseType) { Preconditions.checkNotNull(t, "Exception argument cannot be null."); Preconditions.checkNotNull(expectedCauseType, "Expected cause type class argument cannot be null."); @SuppressWarnings("rawtypes") final Pair<Class, String> cause = extractCause0(t, classLoader, expectedCauseType); if (null != cause && expectedCauseType.isAssignableFrom(cause.getA())) { try { final T $ = expectedCauseType.newInstance(); ReflectionUtils.setField(Throwable.class, $, THROWABLE_DETAILED_MESSAGE, Strings.nullToEmpty(cause.getB())); return $; } catch (final InstantiationException e1) { LOGGER.error("Cannot instantiate " + cause.getA().getSimpleName() + " instance as the cause of " + t + "."); } catch (final IllegalAccessException e1) { LOGGER.error("Cannot instantiate " + cause.getA().getSimpleName() + " instance as the cause of " + t + "."); } } return null; }
From source file:org.apache.hadoop.hbase.ipc.RpcExecutor.java
public RpcExecutor(final String name, final int handlerCount) { this.handlers = new ArrayList<Thread>(handlerCount); this.handlerCount = handlerCount; this.name = Strings.nullToEmpty(name); }