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.escape.ServersideEscape.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { String echoedParam = Strings.nullToEmpty(request.getParameter(ECHOED_PARAM)); String pathInfo = request.getPathInfo().substring(1); String[] path = pathInfo.split("/"); if (CharMatcher.is('/').countIn(pathInfo) != 1) { String errorMsg = String.format("Missing escaper :(." + "Got %d, expected 1", CharMatcher.is('/').countIn(pathInfo)); Responses.sendError(response, errorMsg, 400); return;//from ww w.j av a 2 s. c o m } String template; try { template = Templates.getTemplate(path[1] + ".tmpl", getClass()); } catch (IOException e) { logger.fine(e.toString()); Responses.sendError(response, e.getMessage(), 400); return; } if (path[0].equals("escapeHtml")) { Responses.sendXssed(response, Templates.replacePayload(template, htmlEscape(echoedParam))); } else if (path[0].equals("encodeUrl")) { Responses.sendXssed(response, Templates.replacePayload(template, encodeURL(echoedParam))); } else { Responses.sendError(response, "Unrecognized escaper", 400); } }
From source file:org.iplantc.de.client.desktop.widget.TaskButton.java
@Override public void setText(String text) { if (Strings.nullToEmpty(text).length() > MAX_TEXT_LENGTH) { setToolTip(text);//from w w w . j a v a 2 s. c o m } super.setText(Format.ellipse(text, MAX_TEXT_LENGTH)); }
From source file:org.ambraproject.wombat.util.BuildInfo.java
public BuildInfo(String version, String date, String user, String gitCommitIdAbbrev, Collection<String> enabledDevFeatures) { this.version = Strings.nullToEmpty(version); this.date = Strings.nullToEmpty(date); this.user = Strings.nullToEmpty(user); this.gitCommitIdAbbrev = Strings.nullToEmpty(gitCommitIdAbbrev); this.enabledDevFeatures = (enabledDevFeatures == null) ? ImmutableSet.<String>of() : ImmutableSet.copyOf(enabledDevFeatures); }
From source file:io.macgyver.plugin.git.GitRepository.java
public Git cloneInto(File dir, boolean isBare) throws GitAPIException { Preconditions.checkNotNull(dir);/*w ww . j a va 2 s. c om*/ Preconditions.checkArgument(dir.exists(), "dir does not exist: " + dir.getAbsolutePath()); CloneCommand cc = Git.cloneRepository().setURI(url).setBare(isBare).setDirectory(dir) .setCloneAllBranches(true); if ((!Strings.isNullOrEmpty(username)) || (!Strings.isNullOrEmpty(password))) { cc = cc.setCredentialsProvider(new UsernamePasswordCredentialsProvider(Strings.nullToEmpty(username), Strings.nullToEmpty(password))); } Git git = cc.call(); return git; }
From source file:com.googlesource.gerrit.plugins.hooks.workflow.action.AddStandardComment.java
private String getCommentChangeEvent(String Action, String prefix, Map<String, String> map) { String ret = ""; String changeNumber = Strings.nullToEmpty(map.get("change-number")); if (!changeNumber.isEmpty()) { changeNumber += " "; }// w w w .j a va 2s.co m ret += "Change " + changeNumber + Action; String submitter = formatPerson(prefix, map); if (!submitter.isEmpty()) { ret += " by " + submitter; } String subject = Strings.nullToEmpty(map.get("subject")); if (!subject.isEmpty()) { ret += ":\n" + subject; } String reason = Strings.nullToEmpty(map.get("reason")); if (!reason.isEmpty()) { ret += "\n\nReason:\n" + reason; } String url = Strings.nullToEmpty(map.get("change-url")); if (!url.isEmpty()) { ret += "\n\n" + its.createLinkForWebui(url, url); } return ret; }
From source file:com.hyperion.framework.app.ShowTextActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_text); // Get the message from the Intent. Intent intent = getIntent();//from w w w .ja v a2 s . c o m String message = Strings.nullToEmpty(intent.getStringExtra(KEY_EXTRA_MESSAGE)); // Show message. ((TextView) findViewById(R.id.show_text_view)).setText(message); }
From source file:net.anyflow.lannister.httphandler.Sessions.java
@Override public String service() { String filter = Strings.nullToEmpty(httpRequest().parameter("filter")); switch (filter) { case "": case "live": return liveString(); case "all": return allString(); default://from w w w . j a va2 s . c o m return null; } }
From source file:org.pentaho.caching.spi.AbstractCacheProvidingService.java
@Override public <K, V> CompleteConfiguration<K, V> createConfiguration(Class<K> keyType, Class<V> valueType, Map<String, String> properties) { MutableConfiguration<K, V> configuration = new MutableConfiguration<K, V>(); configuration.setTypes(keyType, valueType); if (properties.containsKey(CONFIG_TTL)) { Long ttl = Longs.tryParse(Strings.nullToEmpty(properties.get(CONFIG_TTL))); Preconditions.checkArgument(ttl != null, "Template config error", CONFIG_TTL); Optional<ExpiryFunction> expiryFunction; if (properties.containsKey(CONFIG_TTL_RESET)) { expiryFunction = Enums.getIfPresent(ExpiryFunction.class, properties.get(CONFIG_TTL_RESET)); } else {// w ww . j a va 2 s . c o m expiryFunction = Optional.of(CONFIG_TTL_RESET_DEFAULT); } Preconditions.checkArgument(expiryFunction.isPresent(), "Template config error", CONFIG_TTL_RESET); configuration.setExpiryPolicyFactory(expiryFunction.get().createFactory(ttl)); } if (properties.containsKey(CONFIG_STORE_BY_VALUE)) { configuration.setStoreByValue(Boolean.valueOf(properties.get(CONFIG_STORE_BY_VALUE))); } return configuration; }
From source file:org.radonix.moted.service.FileService.java
public void loadSource(final File file, final SourceEditor editor) { executeTask(new Task<String>() { @Override/*from www .j a v a2s . co m*/ public String atWorking() throws Exception { String source = null; if (file.exists() && file.isFile()) { String ext = Files.getFileExtension(file.getName()); if (Const.TEXT_FILE_EXTS.contains(ext)) { source = Files.toString(file, Charset.defaultCharset()); } else { // File type not supported. // TODO } } else { // Cannot find the file. // TODO } return Strings.nullToEmpty(source); } @Override public void onSuccess(String source) { editor.setSource(source); } @Override public void onFailure(Exception e) { Log.e(TAG, "Cannot read from " + file.getName(), e); } }); }
From source file:com.github.vbauer.yta.converter.TranslationConverter.java
/** * {@inheritDoc}// w w w .j av a2s . c om */ @Nonnull @Override protected Translation doForward(@Nonnull final TranslationInfo translationInfo) { final String text = Strings.nullToEmpty(Iterables.getFirst(translationInfo.text(), null)); final Direction direction = DirectionConverter.INSTANCE.convert(translationInfo.lang()); return Translation.of(direction, text); }