@Override public <T> List<T> getBeans(Class<? super T> type, String qualifier) throws BeanException { qualifier = Strings.nullToEmpty(qualifier); String key = null == qualifier ? type.getName() : type.getName() + "$" + qualifier; return doGetBeans(type, key, true, qualifier); }
private static String replace(String text, String oldString, String newString, int max) { if (isEmpty(text) || isEmpty(oldString) || newString == null || max == 0) { return nullToEmpty(text); } int start = 0; int end = text.indexOf(oldString, start); if (end == -1) { return text; } int replLength = oldString.length(); int increase = newString.length() - replLength; increase = increase < 0 ? 0 : increase; increase *= max < 0 ? 16 : max > 64 ? 64 : max; StringBuilder buf = new StringBuilder(text.length() + increase); while (end != -1) { buf.append(text.substring(start, end)).append(newString); start = end + replLength; if (--max == 0) { break; } end = text.indexOf(oldString, start); } buf.append(text.substring(start)); return buf.toString(); }
private static String replaceIgnoreCase(String text, String oldString, String newString, int max) { if (isEmpty(text) || isEmpty(oldString) || newString == null || max == 0) { return nullToEmpty(text); } String lcText = text.toLowerCase(); String lcOldString = oldString.toLowerCase(); int start = 0; int end = lcText.indexOf(lcOldString, start); if (end == -1) { return lcText; } int replLength = lcOldString.length(); int increase = newString.length() - replLength; increase = increase < 0 ? 0 : increase; increase *= max < 0 ? 16 : max > 64 ? 64 : max; StringBuilder buf = new StringBuilder(lcText.length() + increase); while (end != -1) { buf.append(text.substring(start, end)).append(newString); start = end + replLength; if (--max == 0) { break; } end = lcText.indexOf(lcOldString, start); } buf.append(text.substring(start)); return buf.toString(); }
protected boolean validateMap(String name, Map map, Validation validation, int maxErrors) { TypeInfo typeInfo = null; for(Object item : map.entrySet()) { Map.Entry entry = (Map.Entry)item; Object value = entry.getValue(); if(null == value) { continue; } if(null == typeInfo) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "['" + entry.getKey().toString() + "']"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } } return true; }
protected boolean validateArray(String name, Object[] array, Validation validation, int maxErrors) { TypeInfo typeInfo = null; for(int i=0;i<array.length;i++) { Object value = array[i]; if(value == null) { continue; } if(typeInfo == null) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "[" + String.valueOf(i) + "]"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } } return true; }
protected boolean validateCollection(String name, Iterable iterable, Validation validation, int maxErrors) { int i=0; TypeInfo typeInfo = null; for(Object value : iterable) { if(value == null) { continue; } if(typeInfo == null) { typeInfo = Types.getTypeInfo(value.getClass()); } if(typeInfo.isComplexType() || typeInfo.isCollectionType()) { String fullName = Strings.nullToEmpty(name) + "[" + String.valueOf(i) + "]"; if(!validate(fullName, value, validation, maxErrors) ){ return false; } } else { return true; } i++; } return true; }
private void postReadApiInfo(Runtime runtime, MetaApi api) { String url = runtime.getServerUrl() + Strings.nullToEmpty(api.getBasePath()); runtime.setApiUrl(Paths.suffixWithoutSlash(url)); }
@Override public boolean authenticate(CredentialsAuthenticationContext context, Credentials credentials, Out<UserPrincipal> principal) throws AuthenticationException { if(credentials instanceof UsernamePasswordCredentials){ UsernamePasswordCredentials usernamePassword = (UsernamePasswordCredentials)credentials; UserDetails details = resolveUserDetails(context, usernamePassword.getUsername(), usernamePassword.getParameters()); if(null == details) { return true; } //Check password String rawPassword = Strings.nullToEmpty(usernamePassword.getPassword()); if(!sc.getPasswordEncoder().matches(rawPassword, details.getPassword())){ log.debug("Incorrect password of user '{}'",usernamePassword.getUsername()); context.validation().addError(UsernamePasswordCredentials.PASSWORD, INCORRECT_PASSWORD_MESSAGE_KEY,"Incorrect password"); }else{ principal.set(details); } return true; } return false; } }
public MetaDataSource createMetaDataSource(Map<String, Object> params) throws ValidationException { //check parameters for (Param param : getJdbcUrlParameters()) { if (Objects2.isEmpty(params.get(param.getName()))) { if (!Strings.isEmpty(param.getDefaultValue())) { params.put(param.getName(), param.getDefaultValue()); } else if (param.isRequired()) { throw new ValidationException("Parameter '" + param.getName() + "' is required by dbms ' " + name + "'"); } } } String url = STPL.render(getJdbcUrlTemplate(), params); MetaDataSource mds = new MetaDataSource(); mds.setDriverClassName(getDriverClassName()); mds.setJdbcUrl(url); mds.setUsername(Strings.nullToEmpty(Maps.getString(params, "username"))); mds.setPassword(Strings.nullToEmpty(Maps.getString(params, "password"))); mds.setMaxActive(Maps.getInteger(params, "maxActive")); mds.setMaxWait(Maps.getInteger(params, "maxWait")); mds.setMaxIdle(Maps.getInteger(params, "maxIdle")); mds.setMinIdle(Maps.getInteger(params, "minIdle")); mds.setParams(params); if(Strings.isEmpty(mds.getUsername()) && isUsernameRequired()) { throw new ValidationException("Username required!"); } return mds; }
w.property(DESCRIPTION, nullToEmpty(Strings.firstNotEmpty(r.getDescription(), r.getSummary()))); w.property(DESCRIPTION, nullToEmpty(header.getDescription())); writeType(context, m, w, header.getType()); w.endObject();
.property(DESCRIPTION, nullToEmpty(m.getDescription())) .propertyOptional(TERMS_OF_SERVICE, m.getTermsOfService()) .propertyOptional(CONTACT, m.getConcat()); .propertyOptional(BASE_PATH, sc.getContextPath() + Strings.nullToEmpty(m.getBasePath())) .propertyOptional(SCHEMES, m.getProtocols()) .propertyOptional(CONSUMES, m.getConsumes())
protected void writeParameter(WriteContext context, ApiMetadata m, JsonWriter w, MApiParameter p) { w.startObject(); w.property(NAME, p.getName()) .propertyOptional(SUMMARY, p.getSummary()) .property(DESCRIPTION, nullToEmpty(Strings.firstNotEmpty(p.getDescription(),p.getSummary(), p.getTitle()))) .property(IN, SwaggerMappings.in(p.getLocation())); w.propertyOptional(REQUIRED, p.getRequired()); writeExtension(w, p.getExtension()); try{ if(Location.BODY == p.getLocation()) { w.property(SCHEMA, () -> { w.startObject(); writeParameterType(context, m, w, p); w.endObject(); }); }else{ writeParameterType(context, m, w, p); } }catch(RuntimeException e) { throw e; } w.endObject(); }
w.property(DESCRIPTION, Strings.nullToEmpty(Strings.firstNotEmpty(p.getDescription(),p.getSummary()))); writeParameterType(context, m, w, p);
w.property(DESCRIPTION, nullToEmpty(o.getDescription()));