public static String parseUserFromAuth(String authentication) { if (StringUtils.isBlank(authentication)) { return null; } int pos = authentication.indexOf(":"); if (pos < 0) return authentication; String name = authentication.substring(0, pos); return StringUtils.isNotBlank(name) ? name : null; } public static String parsePassFromAuth(String authentication) {
protected EmailPush(@JsonProperty("toAddress") String toAddress, @JsonProperty("fromAddress") String fromAddress, @JsonProperty("emailSubject") String emailSubject, @JsonProperty("htmlContent") String htmlContent, @JsonProperty("callbackUrl") String callbackUrl, @JsonProperty("remoteHost") String remoteHost, @JsonProperty("remoteAddress") String remoteAddress, @JsonProperty("traits") Map<String, String> traits) { this.toAddress = toAddress; this.fromAddress = fromAddress; this.emailSubject = emailSubject; String content = StringUtils.getTagContents(htmlContent, "body", 0); this.htmlContent = StringUtils.isNotBlank(content) ? content : htmlContent; this.callbackUrl = callbackUrl; this.remoteHost = remoteHost; this.remoteAddress = remoteAddress; // Get a list of all the keys so that we can loop on the map // and remove anything without an actual value (purge nulls). if (traits != null) { this.traits.putAll(traits); } String[] keys = ReflectUtils.toArray(String.class, this.traits.keySet()); for (String key : keys) { if (StringUtils.isBlank(this.traits.get(key))) { this.traits.remove(key); } } }
private static void validSecurityField(RequestErrors errors, String value, String what) { ValidationUtils.requireValue(errors, value, String.format("The %s must be specified.", what)); if (StringUtils.isBlank(value)) return; for (String chr : invalidSecurityChr) { if (value.contains(chr)) { String list = StringUtils.toDelineatedString(" ", invalidSecurityChr); String msg = String.format("The %s cannot contain the following characters: %s", what, list); errors.add(msg); break; } } }
public static LatLng getLatLng(String address, String city, String state, String zip) throws IOException { String url = "https://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address="; url += encodeUrl(String.format("%s, %s, %s %s", address, city, state, zip)); URLConnection connection = new URL(url).openConnection(); String data = IoUtils.toString(connection.getInputStream()); data = getTagContents(data, "location", 0); return new LatLng( getTagContents(data, "lat", 0), getTagContents(data, "lng", 0) ); } }
@Override public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String roleType : permissions.getRoleTypes()) { if (StringUtils.isNotBlank(roleType)) { SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(roleType); authorities.add(grantedAuthority); } } return Collections.unmodifiableCollection(authorities); }
public static String emailToPhoneNumber(String address) { if (StringUtils.isBlank(address)) { return null; } int pos = address.indexOf("@"); if (pos < 0) return address; return address.substring(0, pos); }
public ApiException toBadRequestException() { String msg = StringUtils.toDelineatedString("\n", this); return ApiException.badRequest(msg); } }
@Override public String getAdminUi(PluginContext context, Domain domain) throws IOException { LqNotificationsConfig config = getConfig(context.getCouchServer(), domain); InputStream stream = getClass().getResourceAsStream("/com/cosmicpush/plugins/notifier/admin.html"); String content = IoUtils.toString(stream); content = content.replace("${legend-class}", nullToString(config == null ? "no-config" : "")); content = content.replace("${push-type}", nullToString(getPushType().getCode())); content = content.replace("${plugin-name}", nullToString(getPluginName())); content = content.replace("${domain-key}", nullToString(domain.getDomainKey())); content = content.replace("${push-server-base}", nullToString(context.getBaseURI())); content = content.replace("${config-user-name}", nullToString(config == null ? null : config.getUserName())); if (content.contains("${")) { String msg = String.format("The Notification admin UI still contains un-parsed elements."); throw new IllegalStateException(msg); } return content; } }
String data = wrapper.toString(); String htmlHead = StringUtils.getTagContents(data, "head", 0); String htmlTitle = StringUtils.getTagContents(htmlHead, "title", 0); request.setAttribute(PageAttribute.title, htmlTitle); String htmlBody = StringUtils.getTagContents(data, "body", 0); if (htmlBody != null) data = htmlBody;
public static UserAgentModel lookupUserAgent(String userAgentString) throws IOException { String encodedUserAgent = StringUtils.encodeUrl(userAgentString); String url = "http://www.useragentstring.com/?getJSON=all&uas=" + encodedUserAgent; URLConnection connection = new URL(url).openConnection(); String json = IoUtils.toString(connection.getInputStream()); return objectMapper.readValue(json, UserAgentModel.class); }
public static void requireInteger(RequestErrors errors, String value, String message) { if (StringUtils.isNotBlank(value)) { try { // noinspection ResultOfMethodCallIgnored Integer.valueOf(value); } catch (NumberFormatException e) { errors.add(message); } } } }
@JsonIgnore public String getAgent() { String retVal = ""; if (agentName != null) retVal = (retVal + " " + agentName).trim(); if (agentVersion != null) retVal = (retVal + " " + agentVersion).trim(); if (agentLanguage != null) retVal = (retVal + " " + agentLanguage).trim(); return StringUtils.isBlank(retVal) ? null : retVal; } }
protected String[] getSpringProfiles(ServletContext servletContext, WebApplicationContext appContext) { String environmentName = System.getProperty(getEnvironmentPropertyName(servletContext, appContext), "null"); String envProfileName = "env-"+environmentName; String defaultProfiles = StringUtils.toDelineatedString(",", "main", "live", envProfileName); String profilesString = System.getProperty(getProfilesPropertyName(servletContext, appContext), defaultProfiles); List<String> profiles = new ArrayList<>(); for (String profile : profilesString.split(",")) { profiles.add(profile.trim()); } return ReflectUtils.toArray(String.class, profiles); } }
@Override public String getAdminUi(PluginContext context, Domain domain) throws IOException { GoogleTalkConfig config = getConfig(context.getCouchServer(), domain); InputStream stream = getClass().getResourceAsStream("/com/cosmicpush/plugins/gtalk/admin.html"); String content = IoUtils.toString(stream); content = content.replace("${legend-class}", nullToString(config == null ? "no-config" : "")); content = content.replace("${push-type}", nullToString(getPushType().getCode())); content = content.replace("${plugin-name}", nullToString(getPluginName())); content = content.replace("${domain-key}", nullToString(domain.getDomainKey())); content = content.replace("${push-server-base}", nullToString(context.getBaseURI())); content = content.replace("${config-user-name}", nullToString(config == null ? null : config.getUserName())); content = content.replace("${config-password}", nullToString(config == null ? null : config.getPassword())); content = content.replace("${config-test-address}", nullToString(config == null ? null : config.getTestAddress())); content = content.replace("${config-recipient-override}", nullToString(config == null ? null : config.getRecipientOverride())); if (content.contains("${")) { String msg = String.format("The Google Talk admin UI still contains un-parsed elements."); throw new IllegalStateException(msg); } return content; } }
public String shortenUnencodedUrl(String longUrl) throws IOException { longUrl = StringUtils.encodeUrl(longUrl); return shortenEncodedUrl(longUrl); }
public static String parsePassFromAuth(String authentication) { if (StringUtils.isBlank(authentication)) { return null; } int pos = authentication.indexOf(":"); if (pos < 0) return null; String pass = authentication.substring(pos+1); return StringUtils.isNotBlank(pass) ? pass : null; }
@Override public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String roleType : permissions.getRoleTypes()) { if (StringUtils.isNotBlank(roleType)) { SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(roleType); authorities.add(grantedAuthority); } } return Collections.unmodifiableCollection(authorities); }
private SesEmailPush(@JsonProperty("toAddress") String toAddress, @JsonProperty("fromAddress") String fromAddress, @JsonProperty("emailSubject") String emailSubject, @JsonProperty("htmlContent") String htmlContent, @JsonProperty("callbackUrl") String callbackUrl, @JsonProperty("remoteHost") String remoteHost, @JsonProperty("remoteAddress") String remoteAddress, @JsonProperty("traits") Map<String, String> traits) { this.toAddress = toAddress; this.fromAddress = fromAddress; this.emailSubject = emailSubject; String content = StringUtils.getTagContents(htmlContent, "body", 0); this.htmlContent = StringUtils.isNotBlank(content) ? content : htmlContent; this.callbackUrl = callbackUrl; this.remoteHost = remoteHost; this.remoteAddress = remoteAddress; // Get a list of all the keys so that we can loop on the map // and remove anything without an actual value (purge nulls). if (traits != null) { this.traits.putAll(traits); } String[] keys = ReflectUtils.toArray(String.class, this.traits.keySet()); for (String key : keys) { if (StringUtils.isBlank(this.traits.get(key))) { this.traits.remove(key); } } }
@JsonIgnore public String getOs() { String retVal = ""; if (osName != null) retVal = (retVal + " " + osName).trim(); if (osVersionNumber != null) retVal = (retVal + " " + osVersionNumber).trim(); if (osVersionName != null) retVal = (retVal + " " + osVersionName).trim(); return StringUtils.isBlank(retVal) ? null : retVal; }
accountOperation.validate(errors); if (errors.isEmpty() == false) { String msg = StringUtils.toDelineatedString("\n", errors); throw ApiException.badRequest(msg);