List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:com.google.enterprise.connector.util.filter.AclPropertyFilter.java
/** * Sets the domain for users for ACL Principals. * //from w w w.ja v a2 s . com * @param userDomain the domain name to set for user principals. * @since 3.0.8 */ public void setUserDomain(String userDomain) { this.userDomain = Strings.emptyToNull(userDomain); }
From source file:org.apache.jackrabbit.oak.security.authorization.permission.PermissionStoreEditor.java
PermissionStoreEditor(@Nonnull String aclPath, @Nonnull String name, @Nonnull NodeState node, @Nonnull NodeBuilder permissionRoot, @Nonnull TypePredicate isACE, @Nonnull TypePredicate isGrantACE, @Nonnull PrivilegeBitsProvider bitsProvider, @Nonnull RestrictionProvider restrictionProvider) { this.permissionRoot = permissionRoot; if (name.equals(REP_REPO_POLICY)) { accessControlledPath = ""; } else {// w ww . j a v a2s.c o m accessControlledPath = aclPath.isEmpty() ? "/" : aclPath; } nodeName = PermissionUtil.getEntryName(accessControlledPath); Set<String> orderedChildNames = newLinkedHashSet(node.getNames(OAK_CHILD_ORDER)); long n = orderedChildNames.size(); if (node.getChildNodeCount(n + 1) > n) { addAll(orderedChildNames, node.getChildNodeNames()); } PrivilegeBits jcrAll = bitsProvider.getBits(PrivilegeConstants.JCR_ALL); int index = 0; for (String childName : orderedChildNames) { NodeState ace = node.getChildNode(childName); if (isACE.apply(ace)) { boolean isAllow = isGrantACE.apply(ace); PrivilegeBits privilegeBits = bitsProvider.getBits(ace.getNames(REP_PRIVILEGES)); Set<Restriction> restrictions = restrictionProvider.readRestrictions( Strings.emptyToNull(accessControlledPath), TreeFactory.createReadOnlyTree(ace)); AcEntry entry = (privilegeBits.equals(jcrAll)) ? new JcrAllAcEntry(ace, accessControlledPath, index, isAllow, privilegeBits, restrictions) : new AcEntry(ace, accessControlledPath, index, isAllow, privilegeBits, restrictions); List<AcEntry> list = entries.get(entry.principalName); if (list == null) { list = new ArrayList<AcEntry>(); entries.put(entry.principalName, list); } list.add(entry); index++; } } }
From source file:com.facebook.buck.parser.AndroidBinaryBuildRuleFactory.java
@Override protected void amendBuilder(AbstractBuildRuleBuilder abstractBuilder, BuildRuleFactoryParams params) throws NoSuchBuildTargetException { AndroidBinaryRule.Builder builder = ((AndroidBinaryRule.Builder) abstractBuilder); // manifest//from w w w . ja v a2 s. co m String manifestAttribute = params.getRequiredStringAttribute("manifest"); String manifestPath = params.resolveFilePathRelativeToBuildFileDirectory(manifestAttribute); builder.setManifest(manifestPath); // target String target = params.getRequiredStringAttribute("target"); builder.setTarget(target); // keystore_properties String keystoreProperties = params.getRequiredStringAttribute("keystore_properties"); String keystorePropertiesPath = params.resolveFilePathRelativeToBuildFileDirectory(keystoreProperties); builder.setKeystorePropertiesPath(keystorePropertiesPath); // package_type // Note that it is not required for the user to supply this attribute, but buck.py should // supply 'debug' if the user has not supplied a value. String packageType = params.getRequiredStringAttribute("package_type"); builder.setPackageType(packageType); // no_dx ParseContext buildFileParseContext = ParseContext.forBaseName(params.target.getBaseName()); for (String noDx : params.getOptionalListAttribute("no_dx")) { BuildTarget buildTarget = params.buildTargetParser.parse(noDx, buildFileParseContext); builder.addBuildRuleToExcludeFromDex(buildTarget.getFullyQualifiedName()); } // use_split_dex boolean useSplitDex = params.getBooleanAttribute("use_split_dex"); ZipSplitter.DexSplitStrategy dexSplitStrategy = params.getBooleanAttribute("minimize_primary_dex_size") ? ZipSplitter.DexSplitStrategy.MINIMIZE_PRIMARY_DEX_SIZE : ZipSplitter.DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE; builder.setDexSplitMode(new AndroidBinaryRule.DexSplitMode(useSplitDex, dexSplitStrategy)); // use_android_proguard_config_with_optimizations boolean useAndroidProguardConfigWithOptimizations = params .getBooleanAttribute("use_android_proguard_config_with_optimizations"); builder.setUseAndroidProguardConfigWithOptimizations(useAndroidProguardConfigWithOptimizations); // proguard_config Optional<String> proguardConfig = params.getOptionalStringAttribute("proguard_config"); if (proguardConfig.isPresent()) { String proguardConfigPath = params.resolveFilePathRelativeToBuildFileDirectory(proguardConfig.get()); builder.setProguardConfig(proguardConfigPath); } // compress_resources boolean compressResources = params.getBooleanAttribute("compress_resources"); builder.setCompressResources(compressResources); // primary_dex_substrings List<String> primaryDexSubstrings = params.getOptionalListAttribute("primary_dex_substrings"); builder.addPrimaryDexSubstrings(primaryDexSubstrings); // resource_filter Optional<String> resourceFilter = params.getOptionalStringAttribute("resource_filter"); if (resourceFilter.isPresent()) { builder.setResourceFilter(Strings.emptyToNull(resourceFilter.get().trim())); } }
From source file:io.druid.server.lookup.PollingLookup.java
@Override public String apply(@NotNull String key) { final CacheRefKeeper cacheRefKeeper = refOfCacheKeeper.get(); if (cacheRefKeeper == null) { throw new ISE("Cache reference is null WTF"); }/*from w w w. ja v a 2 s .c om*/ final PollingCache cache = cacheRefKeeper.getAndIncrementRef(); try { if (cache == null) { // it must've been closed after swapping while I was getting it. Try again. return this.apply(key); } return Strings.emptyToNull((String) cache.get(key)); } finally { if (cacheRefKeeper != null && cache != null) { cacheRefKeeper.doneWithIt(); } } }
From source file:org.zanata.service.impl.ProjectServiceImpl.java
@Transactional @Override/*ww w . j ava 2 s. c om*/ public boolean updateWebhook(HProject project, Long webhookId, String url, String secret, String name, Set<WebhookType> types) { if (types.isEmpty()) { return false; } if (project == null) { return false; } WebHook webHook = webHookDAO.findById(webhookId); if (webHook == null) { return false; } secret = StringUtils.isBlank(secret) ? null : secret; webHook.update(url, Strings.emptyToNull(name), types, secret); webHookDAO.makePersistent(webHook); return true; }
From source file:org.dcache.restful.providers.billing.DoorTransferRecord.java
public DoorTransferRecord(TransferRecord record) { super(record); this.pool = record.getCellName(); this.door = record.getInitiator(); this.mappedGID = record.getMappedgid(); this.mappedUID = record.getMappedUid(); this.owner = record.getOwner(); this.fqan = Strings.emptyToNull(record.getFqan()); }
From source file:ru.org.linux.user.EditRegisterController.java
@RequestMapping(method = RequestMethod.POST) public ModelAndView edit(HttpServletRequest request, HttpServletResponse response, @Valid @ModelAttribute("form") EditRegisterRequest form, Errors errors) throws Exception { Template tmpl = Template.getTemplate(request); if (!tmpl.isSessionAuthorized()) { throw new AccessViolationException("Not authorized"); }//from ww w . jav a 2s . co m String nick = tmpl.getNick(); String password = Strings.emptyToNull(form.getPassword()); if (password != null && password.equalsIgnoreCase(nick)) { errors.reject(null, " ? ? "); } InternetAddress mail = null; if (!Strings.isNullOrEmpty(form.getEmail())) { try { mail = new InternetAddress(form.getEmail()); } catch (AddressException e) { errors.rejectValue("email", null, "? e-mail: " + e.getMessage()); } } String url = null; if (!Strings.isNullOrEmpty(form.getUrl())) { url = URLUtil.fixURL(form.getUrl()); } String name = Strings.emptyToNull(form.getName()); if (name != null) { name = StringUtil.escapeHtml(name); } String town = null; if (!Strings.isNullOrEmpty(form.getTown())) { town = StringUtil.escapeHtml(form.getTown()); } String info = null; if (!Strings.isNullOrEmpty(form.getInfo())) { info = StringUtil.escapeHtml(form.getInfo()); } ipBlockDao.checkBlockIP(request.getRemoteAddr(), errors, tmpl.getCurrentUser()); boolean emailChanged = false; User user = userService.getUser(nick); if (Strings.isNullOrEmpty(form.getOldpass())) { errors.rejectValue("oldpass", null, "? ? ? "); } else if (!user.matchPassword(form.getOldpass())) { errors.rejectValue("oldpass", null, "? "); } user.checkAnonymous(); String newEmail = null; if (mail != null) { if (user.getEmail() != null && user.getEmail().equals(form.getEmail())) { newEmail = null; } else { if (userDao.getByEmail(mail.getAddress().toLowerCase(), false) != null) { errors.rejectValue("email", null, " email ???"); } newEmail = mail.getAddress().toLowerCase(); emailChanged = true; } } if (!errors.hasErrors()) { userDao.updateUser(user, name, url, newEmail, town, password, info); // token- ? ? ? if (password != null) { try { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( user.getNick(), password); UserDetailsImpl details = (UserDetailsImpl) userDetailsService .loadUserByUsername(user.getNick()); token.setDetails(details); Authentication auth = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(auth); rememberMeServices.loginSuccess(request, response, auth); } catch (Exception ex) { logger.error( " ? ? ? ?. ", ex); } } if (emailChanged) { emailService.sendEmail(user.getNick(), newEmail, false); } } else { return new ModelAndView("edit-reg"); } if (emailChanged) { String msg = " ? ?. " + " ? " + StringUtil.escapeHtml(newEmail) + " ? ? email."; return new ModelAndView("action-done", "message", msg); } else { return new ModelAndView(new RedirectView("/people/" + tmpl.getNick() + "/profile")); } }
From source file:org.obm.icalendar.ical4jwrapper.ICalendarEvent.java
public String location() { Location location = vEvent.getLocation(); if (location != null) { return Strings.emptyToNull(location.getValue()); }/*from www . j ava2 s .c om*/ return null; }
From source file:com.google.gerrit.httpd.auth.become.BecomeAnyAccountLoginServlet.java
@Override protected void doPost(final HttpServletRequest req, final HttpServletResponse rsp) throws IOException, ServletException { CacheHeaders.setNotCacheable(rsp);// ww w .j av a 2s .c o m final AuthResult res; if ("create_account".equals(req.getParameter("action"))) { res = create(); } else if (req.getParameter("user_name") != null) { res = byUserName(rsp, req.getParameter("user_name")); } else if (req.getParameter("preferred_email") != null) { res = byPreferredEmail(rsp, req.getParameter("preferred_email")); } else if (req.getParameter("account_id") != null) { res = byAccountId(rsp, req.getParameter("account_id")); } else { byte[] raw; try { raw = prepareHtmlOutput(); } catch (OrmException e) { throw new ServletException(e); } rsp.setContentType("text/html"); rsp.setCharacterEncoding(HtmlDomUtil.ENC); rsp.setContentLength(raw.length); final OutputStream out = rsp.getOutputStream(); try { out.write(raw); } finally { out.close(); } return; } if (res != null) { webSession.get().login(res, false); final StringBuilder rdr = new StringBuilder(); rdr.append(Objects.firstNonNull(Strings.emptyToNull(req.getContextPath()), "/")); if (IS_DEV && req.getParameter("gwt.codesvr") != null) { if (rdr.indexOf("?") < 0) { rdr.append("?"); } else { rdr.append("&"); } rdr.append("gwt.codesvr=").append(req.getParameter("gwt.codesvr")); } rdr.append('#'); if (res.isNew()) { rdr.append(PageLinks.REGISTER); } rdr.append(PageLinks.MINE); rsp.sendRedirect(rdr.toString()); } else { rsp.setContentType("text/html"); rsp.setCharacterEncoding(HtmlDomUtil.ENC); final Writer out = rsp.getWriter(); out.write("<html>"); out.write("<body>"); out.write("<h1>Account Not Found</h1>"); out.write("</body>"); out.write("</html>"); out.close(); } }
From source file:ratpack.server.internal.DefaultPublicAddress.java
private HostAndPort getForwardedHostData(Context context) { Headers headers = context.getRequest().getHeaders(); String forwardedHostHeader = Strings.emptyToNull(headers.get(X_FORWARDED_HOST.toString())); String hostPortString = forwardedHostHeader != null ? Iterables.getFirst(FORWARDED_HOST_SPLITTER.split(forwardedHostHeader), null) : null;//from w w w . j a v a2 s. com return hostPortString != null ? HostAndPort.fromString(hostPortString) : null; }