public static String getAppUrl() { return EnvUtils.findProperty("app.couch.url", "http://localhost:5984"); } }
public ApiException toBadRequestException() { String msg = StringUtils.toDelineatedString("\n", this); return ApiException.badRequest(msg); } }
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) {
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) ); } }
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); }
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> map, InputStream stream) throws IOException, WebApplicationException { String json = IoUtils.toString(stream); return objectMapper.readValue(json, type); }
public static void requireNull(RequestErrors errors, Object value, String errorMessage) { if (value instanceof Integer) { if (((Integer)value) != 0) { errors.add(errorMessage); } } else if (value instanceof Long) { if (((Long)value) != 0) { errors.add(errorMessage); } } else if (StringUtils.isNotBlank(value)) { errors.add(errorMessage); } }
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); } }
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 static LqNotificationPush newPush(String topic, String summary, String trackingId, Throwable throwable, Collection<LqAttachment> attachments, String callbackUrl, String...traits) { return newPush(topic, summary, trackingId, throwable, attachments, callbackUrl, BeanUtils.toMap(traits)); }
public String shortenUnencodedUrl(String longUrl) throws IOException { longUrl = StringUtils.encodeUrl(longUrl); return shortenEncodedUrl(longUrl); }
private String clean(String value) { if (value == null) { return null; } else if ("null".equalsIgnoreCase(value)) { return null; } else { return StringUtils.emptyToNull(value); } }
@Override public T fromString(String value) { return (value == null) ? null : rawType.cast(DateUtils.toLocalDate(value)); } @Override public String toString(T value) { return (value == null) ? "" : value.toString(); }
@Override public T fromString(String value) { return (value == null) ? null : rawType.cast(DateUtils.toLocalDateTime(value)); } @Override public String toString(T value) { return (value == null) ? "" : value.toString(); }
@Override public T fromString(String value) { return (value == null) ? null : rawType.cast(DateUtils.toLocalTime(value)); } @Override public String toString(T value) { return (value == null) ? "" : value.toString(); }
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 T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> map, InputStream stream) throws IOException, WebApplicationException { String json = IoUtils.toString(stream); return objectMapper.readValue(json, type); }
public static void requireValue(RequestErrors errors, Object value, String errorMessage) { if (value instanceof Integer) { if (((Integer)value) == 0) { errors.add(errorMessage); } } else if (value instanceof Long) { if (((Long)value) == 0) { errors.add(errorMessage); } } else if (StringUtils.isBlank(value)) { errors.add(errorMessage); } }
public static String getAppUserName() { return EnvUtils.findProperty("app.couch.userName", "app-user"); }
public static String getAppPassword() { String userName = getAppUserName(); return EnvUtils.findProperty("app.couch.password", userName); }