List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:org.obm.push.mail.SendEmail.java
public SendEmail(InternetAddress defaultFrom, Message message) throws MimeException { Preconditions.checkNotNull(Strings.emptyToNull(defaultFrom.getAddress())); this.from = defaultFrom; this.originalMessage = message; setMessage(message);// w ww . jav a 2 s. c om }
From source file:com.google.gerrit.server.account.PutHttpPassword.java
@Override public Response<String> apply(AccountResource rsrc, Input input) throws AuthException, ResourceNotFoundException, ResourceConflictException, OrmException, IOException, ConfigInvalidException {// www . j a va2 s . co m if (input == null) { input = new Input(); } input.httpPassword = Strings.emptyToNull(input.httpPassword); String newPassword; if (input.generate) { if (self.get() != rsrc.getUser() && !self.get().getCapabilities().canAdministrateServer()) { throw new AuthException("not allowed to generate HTTP password"); } newPassword = generate(); } else if (input.httpPassword == null) { if (self.get() != rsrc.getUser() && !self.get().getCapabilities().canAdministrateServer()) { throw new AuthException("not allowed to clear HTTP password"); } newPassword = null; } else { if (!self.get().getCapabilities().canAdministrateServer()) { throw new AuthException("not allowed to set HTTP password directly, " + "requires the Administrate Server permission"); } newPassword = input.httpPassword; } return apply(rsrc.getUser(), newPassword); }
From source file:org.spongepowered.asm.mixin.injection.points.BeforeNew.java
public BeforeNew(InjectionPointData data) { this.ordinal = data.getOrdinal(); this.className = Strings.emptyToNull(data.get("class", data.get("target", "")).replace('.', '/')); }
From source file:com.dowdandassociates.gentoo.bootstrap.DefaultTestSessionInformationProvider.java
private Optional<String> getHost() { if (null == instanceInfo) { return Optional.absent(); }//from ww w . jav a 2 s . c om Optional<Instance> instance = instanceInfo.getInstance(); if (instance.isPresent()) { return Optional.fromNullable(Strings.emptyToNull(instance.get().getPublicDnsName())); } else { return Optional.absent(); } }
From source file:fathom.realm.jdbc.JdbcRealm.java
@Override public void setup(Config config) { super.setup(config); if (config.hasPath("url")) { jdbcUrl = Strings.emptyToNull(config.getString("url")); }//from w w w.jav a 2 s . c o m Preconditions.checkNotNull(jdbcUrl, "You must specify 'url'"); if (config.hasPath("username")) { jdbcUsername = Strings.emptyToNull(config.getString("username")); } if (config.hasPath("password")) { jdbcPassword = Strings.emptyToNull(config.getString("password")); } if (config.hasPath("accountQuery")) { accountQuery = Strings.emptyToNull(config.getString("accountQuery")); } Preconditions.checkNotNull(accountQuery, "You must specify 'accountQuery'"); passwordMapping = "password"; if (config.hasPath("passwordMapping")) { passwordMapping = Strings.emptyToNull(config.getString("passwordMapping")); } Preconditions.checkNotNull(passwordMapping, "You must specify 'passwordMapping'"); if (config.hasPath("nameMapping")) { nameMapping = Strings.emptyToNull(config.getString("nameMapping")); } if (config.hasPath("emailMapping")) { emailMapping = Strings.emptyToNull(config.getString("emailMapping")); } if (config.hasPath("roleMapping")) { roleMapping = Strings.emptyToNull(config.getString("roleMapping")); } if (config.hasPath("permissionMapping")) { permissionMapping = Strings.emptyToNull(config.getString("permissionMapping")); } if (config.hasPath("accountRolesQuery")) { accountRolesQuery = Strings.emptyToNull(config.getString("accountRolesQuery")); } if (config.hasPath("accountPermissionsQuery")) { accountPermissionsQuery = Strings.emptyToNull(config.getString("accountPermissionsQuery")); } if (config.hasPath("definedRolesQuery")) { definedRolesQuery = Strings.emptyToNull(config.getString("definedRolesQuery")); } if (config.hasPath("startScript")) { startScript = Strings.emptyToNull(config.getString("startScript")); } if (config.hasPath("stopScript")) { stopScript = Strings.emptyToNull(config.getString("stopScript")); } if (config.hasPath("hikariCP")) { hikariCPConfig = config.getConfig("hikariCP"); } }
From source file:com.infobip.bitbucket.JiraVersionGeneratorHook.java
private Optional<String> getNonEmptySetting(RepositoryHookContext repositoryHookContext, String key) { String setting = Strings.emptyToNull(repositoryHookContext.getSettings().getString(key)); return Optional.ofNullable(setting); }
From source file:org.apache.ambari.server.topology.SecurityConfigurationFactory.java
/** * Creates and also validates SecurityConfiguration based on properties parsed from request Json. * * @param properties Security properties from Json parsed into a Map * @param persistEmbeddedDescriptor whether to save embedded descriptor or not * @return/*from www.java 2s .c o m*/ */ public SecurityConfiguration createSecurityConfigurationFromRequest(Map<String, Object> properties, boolean persistEmbeddedDescriptor) { SecurityConfiguration securityConfiguration = null; LOGGER.debug("Creating security configuration from properties: {}", properties); Map<String, Object> securityProperties = (Map<String, Object>) properties.get(SECURITY_PROPERTY_ID); if (securityProperties == null) { LOGGER.debug("No security information properties provided, returning null"); return securityConfiguration; } String securityTypeString = Strings.emptyToNull((String) securityProperties.get(TYPE_PROPERTY_ID)); if (securityTypeString == null) { LOGGER.error("Type is missing from security block."); throw new IllegalArgumentException("Type missing from security block."); } SecurityType securityType = Enums.getIfPresent(SecurityType.class, securityTypeString).orNull(); if (securityType == null) { LOGGER.error("Unsupported security type specified: {}", securityType); throw new IllegalArgumentException("Invalid security type specified: " + securityTypeString); } if (securityType == SecurityType.KERBEROS) { // get security information from the request propertie if any String descriptorReference = Strings .emptyToNull((String) securityProperties.get(KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID)); Object descriptorJsonMap = securityProperties.get(KERBEROS_DESCRIPTOR_PROPERTY_ID); if (descriptorReference != null && descriptorJsonMap != null) { LOGGER.error( "Both kerberos descriptor and kerberos descriptor reference are set in the security configuration!"); throw new IllegalArgumentException( "Usage of properties : " + KERBEROS_DESCRIPTOR_PROPERTY_ID + " and " + KERBEROS_DESCRIPTOR_REFERENCE_PROPERTY_ID + " at the same time, is not allowed."); } String descriptorText = null; if (descriptorJsonMap != null) { // this means the reference is null LOGGER.debug("Found embedded descriptor: {}", descriptorJsonMap); descriptorText = jsonSerializer.<Map<String, Object>>toJson(descriptorJsonMap, Map.class); if (persistEmbeddedDescriptor) { descriptorReference = persistKerberosDescriptor(descriptorText); } securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS, descriptorReference, descriptorText); } else if (descriptorReference != null) { // this means the reference is not null LOGGER.debug("Found descriptor reference: {}", descriptorReference); securityConfiguration = loadSecurityConfigurationByReference(descriptorReference); } else { LOGGER.debug("There is no security descriptor found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.KERBEROS); } } else { LOGGER.debug("There is no security configuration found in the request"); securityConfiguration = new SecurityConfiguration(SecurityType.NONE); } return securityConfiguration; }
From source file:org.n52.sos.util.Reference.java
public Reference setActuate(String actuate) { this.actuate = Optional.fromNullable(Strings.emptyToNull(actuate)); return this; }
From source file:org.n52.iceland.util.net.ProxyChain.java
/** * Creates a Proxy chain from the {@code X-Forwarded-For} HTTP header. * * @param header the {@code X-Forwarded-For} header * * @return a {@code ProxyChain} if the header is present, non empty and well * formed./*from ww w . ja va 2 s .c o m*/ */ public static Optional<ProxyChain> fromForwardedForHeader(String header) { try { if (Strings.emptyToNull(header) != null) { String[] split = header.split(","); List<IPAddress> chain = Lists.newArrayListWithExpectedSize(split.length); for (String splitted : split) { chain.add(getIPAddress(splitted)); } return Optional.of(new ProxyChain(chain)); } } catch (IllegalArgumentException e) { LOG.warn("Ignoring invalid IP address in X-Forwared-For header: " + header, e); } return Optional.absent(); }
From source file:io.github.bktlib.command.CommandBase.java
/** * @return A {@link Command#permission() permisso} desse commando *///from ww w . j a va2 s . co m public Optional<String> getPermission() { return Optional.ofNullable(Strings.emptyToNull(commandAnnotation.permission())); }