List of usage examples for org.springframework.util StringUtils capitalize
public static String capitalize(String str)
From source file:com.phoenixnap.oss.ramlapisync.data.ApiMappingMetadata.java
private void parseResponse() { if (action.getResponses() != null && !action.getResponses().isEmpty()) { for (Entry<String, Response> responses : action.getResponses().entrySet()) { Response response = responses.getValue(); if ("200".equals(responses.getKey()) && response.getBody() != null && !response.getBody().isEmpty()) { for (Entry<String, MimeType> body : response.getBody().entrySet()) { if (body.getKey().toLowerCase().contains("json")) { // Continue here! String schema = body.getValue().getSchema(); if (StringUtils.hasText(schema)) { ApiBodyMetadata responseBody = SchemaHelper.mapSchemaToPojo(parent.getDocument(), schema, parent.getBasePackage() + ".model", StringUtils.capitalize(getName()) + "Response"); if (responseBody != null) { this.responseBody.put(body.getKey(), responseBody); }//w w w. j ava 2 s.co m } } } } } } }
From source file:com.phoenixnap.oss.ramlapisync.data.ApiActionMetadata.java
private void collectBodyParams(Entry<String, RamlMimeType> mime) { if (mime.getKey().equals(MediaType.MULTIPART_FORM_DATA_VALUE) && ResourceParser.doesActionTypeSupportMultipartMime(actionType)) { collectRequestParamsForMime(action.getBody().get(MediaType.MULTIPART_FORM_DATA_VALUE)); } else if (mime.getKey().equals(MediaType.APPLICATION_FORM_URLENCODED_VALUE) && ResourceParser.doesActionTypeSupportMultipartMime(actionType)) { collectRequestParamsForMime(action.getBody().get(MediaType.APPLICATION_FORM_URLENCODED_VALUE)); }//w w w .j a v a 2s .c o m if (ResourceParser.doesActionTypeSupportRequestBody(actionType) && mime.getKey().toLowerCase().contains("json")) { // Continue here! String schema = mime.getValue().getSchema(); if (StringUtils.hasText(schema)) { ApiBodyMetadata requestBody = SchemaHelper.mapSchemaToPojo(parent.getDocument(), schema, parent.getBasePackage() + NamingHelper.getDefaultModelPackage(), StringUtils.capitalize(getName()) + "Request", null); if (requestBody != null) { setRequestBody(requestBody, mime.getKey()); } } } }
From source file:org.vaadin.spring.i18n.Translator.java
private static void setPropertyValue(Object target, String propertyName, String value) { final String setterMethodName = "set" + StringUtils.capitalize(propertyName); try {// w w w. j a v a 2 s . c o m final Method setterMethod = target.getClass().getMethod(setterMethodName, String.class); setterMethod.invoke(target, value); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("No public setter method found for property " + propertyName); } catch (InvocationTargetException e) { throw new RuntimeException("Could not invoke setter method for property " + propertyName, e); } catch (IllegalAccessException e) { throw new RuntimeException("Could not access setter method for property " + propertyName); } }
From source file:org.easyj.orm.jpa.JPAEntityService.java
protected <T> Map<String, Object> fillUKParams(T entity) { String query = getNamedQuery(entity.getClass().getSimpleName() + ".findByUK", entity.getClass()); if (query == null) { return null; }/*w w w.jav a2 s. c o m*/ Pattern pattern = Pattern.compile("\\S+\\s*=\\s*:\\S+"); Matcher matcher = pattern.matcher(query); Matcher param; pattern = Pattern.compile(":\\S+"); String[] props; String group; Object paramValue; Map<String, Object> ukParams = new HashMap<String, Object>(); while (matcher.find()) { group = matcher.group(); props = group.split("=")[0].trim().split("\\."); paramValue = entity; for (String prop : props) { try { paramValue = paramValue.getClass().getMethod("get" + StringUtils.capitalize(prop)) .invoke(paramValue); } catch (Exception silent) { } } param = pattern.matcher(group); if (param.find()) { ukParams.put(param.group().replace(":", "").trim(), paramValue); } } return ukParams; }
From source file:ch.rasc.extclassgenerator.association.AbstractAssociation.java
public static AbstractAssociation createAssociation(ModelAssociation associationAnnotation) { ModelAssociationType type = associationAnnotation.value(); String name = associationAnnotation.propertyName(); if (!StringUtils.hasText(name)) { return null; }//from w w w .j ava 2s . com Class<?> associationClass = associationAnnotation.model(); if (associationClass == Object.class) { return null; } AbstractAssociation association; if (type == ModelAssociationType.HAS_MANY) { association = new HasManyAssociation(associationClass); } else if (type == ModelAssociationType.BELONGS_TO) { association = new BelongsToAssociation(associationClass); } else { association = new HasOneAssociation(associationClass); } association.setAssociationKey(name); if (StringUtils.hasText(associationAnnotation.foreignKey())) { association.setForeignKey(associationAnnotation.foreignKey()); } if (StringUtils.hasText(associationAnnotation.primaryKey())) { association.setPrimaryKey(associationAnnotation.primaryKey()); } else if (type == ModelAssociationType.BELONGS_TO || type == ModelAssociationType.HAS_ONE) { Model associationModelAnnotation = associationClass.getAnnotation(Model.class); if (associationModelAnnotation != null && StringUtils.hasText(associationModelAnnotation.idProperty()) && !associationModelAnnotation.idProperty().equals("id")) { association.setPrimaryKey(associationModelAnnotation.idProperty()); } } if (type == ModelAssociationType.HAS_MANY) { HasManyAssociation hasManyAssociation = (HasManyAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(null, name, association.getType(), "setterName")); } if (StringUtils.hasText(associationAnnotation.getterName())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(null, name, association.getType(), "getterName")); } if (associationAnnotation.autoLoad()) { hasManyAssociation.setAutoLoad(Boolean.TRUE); } if (StringUtils.hasText(associationAnnotation.name())) { hasManyAssociation.setName(associationAnnotation.name()); } else { hasManyAssociation.setName(name); } } else if (type == ModelAssociationType.BELONGS_TO) { BelongsToAssociation belongsToAssociation = (BelongsToAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { belongsToAssociation.setSetterName(associationAnnotation.setterName()); } else { belongsToAssociation.setSetterName("set" + StringUtils.capitalize(name)); } if (StringUtils.hasText(associationAnnotation.getterName())) { belongsToAssociation.setGetterName(associationAnnotation.getterName()); } else { belongsToAssociation.setGetterName("get" + StringUtils.capitalize(name)); } if (associationAnnotation.autoLoad()) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(null, name, association.getType(), "autoLoad")); } if (StringUtils.hasText(associationAnnotation.name())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(null, name, association.getType(), "name")); } } else { HasOneAssociation hasOneAssociation = (HasOneAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { hasOneAssociation.setSetterName(associationAnnotation.setterName()); } else { hasOneAssociation.setSetterName("set" + StringUtils.capitalize(name)); } if (StringUtils.hasText(associationAnnotation.getterName())) { hasOneAssociation.setGetterName(associationAnnotation.getterName()); } else { hasOneAssociation.setGetterName("get" + StringUtils.capitalize(name)); } if (associationAnnotation.autoLoad()) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(null, name, association.getType(), "autoLoad")); } if (StringUtils.hasText(associationAnnotation.name())) { hasOneAssociation.setName(associationAnnotation.name()); } } if (StringUtils.hasText(associationAnnotation.instanceName())) { association.setInstanceName(associationAnnotation.instanceName()); } return association; }
From source file:ch.ralscha.extdirectspring.generator.association.AbstractAssociation.java
public static AbstractAssociation createAssociation(ModelAssociation associationAnnotation, ModelBean model, Field field) {//from ww w . j a v a2 s .com ModelAssociationType type = associationAnnotation.value(); Class<?> associationClass = associationAnnotation.model(); if (associationClass == Object.class) { associationClass = field.getType(); } AbstractAssociation association; if (type == ModelAssociationType.HAS_MANY) { association = new HasManyAssociation(associationClass); } else if (type == ModelAssociationType.BELONGS_TO) { association = new BelongsToAssociation(associationClass); } else { association = new HasOneAssociation(associationClass); } association.setAssociationKey(field.getName()); if (StringUtils.hasText(associationAnnotation.foreignKey())) { association.setForeignKey(associationAnnotation.foreignKey()); } else if (type == ModelAssociationType.HAS_MANY) { association.setForeignKey(StringUtils.uncapitalize(field.getDeclaringClass().getSimpleName()) + "_id"); } else if (type == ModelAssociationType.BELONGS_TO || type == ModelAssociationType.HAS_ONE) { association.setForeignKey(StringUtils.uncapitalize(associationClass.getSimpleName()) + "_id"); } if (StringUtils.hasText(associationAnnotation.primaryKey())) { association.setPrimaryKey(associationAnnotation.primaryKey()); } else if (type == ModelAssociationType.HAS_MANY && StringUtils.hasText(model.getIdProperty()) && !model.getIdProperty().equals("id")) { association.setPrimaryKey(model.getIdProperty()); } else if (type == ModelAssociationType.BELONGS_TO || type == ModelAssociationType.HAS_ONE) { Model associationModelAnnotation = associationClass.getAnnotation(Model.class); if (associationModelAnnotation != null && StringUtils.hasText(associationModelAnnotation.idProperty()) && !associationModelAnnotation.idProperty().equals("id")) { association.setPrimaryKey(associationModelAnnotation.idProperty()); } } if (type == ModelAssociationType.HAS_MANY) { HasManyAssociation hasManyAssociation = (HasManyAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(field, association.getType(), "setterName")); } if (StringUtils.hasText(associationAnnotation.getterName())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(field, association.getType(), "getterName")); } if (associationAnnotation.autoLoad()) { hasManyAssociation.setAutoLoad(true); } if (StringUtils.hasText(associationAnnotation.name())) { hasManyAssociation.setName(associationAnnotation.name()); } else { hasManyAssociation.setName(field.getName()); } } else if (type == ModelAssociationType.BELONGS_TO) { BelongsToAssociation belongsToAssociation = (BelongsToAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { belongsToAssociation.setSetterName(associationAnnotation.setterName()); } else { belongsToAssociation.setSetterName("set" + StringUtils.capitalize(field.getName())); } if (StringUtils.hasText(associationAnnotation.getterName())) { belongsToAssociation.setGetterName(associationAnnotation.getterName()); } else { belongsToAssociation.setGetterName("get" + StringUtils.capitalize(field.getName())); } if (associationAnnotation.autoLoad()) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(field, association.getType(), "autoLoad")); } if (StringUtils.hasText(associationAnnotation.name())) { LogFactory.getLog(ModelGenerator.class).warn(getWarningText(field, association.getType(), "name")); } } else { HasOneAssociation hasOneAssociation = (HasOneAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { hasOneAssociation.setSetterName(associationAnnotation.setterName()); } else { hasOneAssociation.setSetterName("set" + StringUtils.capitalize(field.getName())); } if (StringUtils.hasText(associationAnnotation.getterName())) { hasOneAssociation.setGetterName(associationAnnotation.getterName()); } else { hasOneAssociation.setGetterName("get" + StringUtils.capitalize(field.getName())); } if (associationAnnotation.autoLoad()) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(field, association.getType(), "autoLoad")); } if (StringUtils.hasText(associationAnnotation.name())) { LogFactory.getLog(ModelGenerator.class).warn(getWarningText(field, association.getType(), "name")); } } return association; }
From source file:org.shept.persistence.provider.DaoUtils.java
private static Serializable getIdValue_old(DaoSupport dao, Object model) { checkProvider(dao);//from www.j a v a 2 s . c om String idStr = getIdentifierPropertyName_old(dao, model); if (!(StringUtils.hasText(idStr))) { return null; } Method idMth = ReflectionUtils.findMethod(model.getClass(), "get" + StringUtils.capitalize(idStr)); Serializable idxObj = (Serializable) ReflectionUtils.invokeMethod(idMth, model); return idxObj; }
From source file:com.phoenixnap.oss.ramlapisync.data.ApiActionMetadata.java
private void parseResponse(String responseContentTypeFilter) { RamlResponse response = RamlHelper.getSuccessfulResponse(action); if (response != null && response.getBody() != null && !response.getBody().isEmpty()) { for (Entry<String, RamlMimeType> body : response.getBody().entrySet()) { if (responseContentTypeFilter == null || body.getKey().equals(responseContentTypeFilter)) { if (body.getKey().toLowerCase().contains("json")) { //if we have a json type we need to return an object // Continue here! String schema = body.getValue().getSchema(); if (StringUtils.hasText(schema)) { ApiBodyMetadata responseBody = SchemaHelper.mapSchemaToPojo(parent.getDocument(), schema, parent.getBasePackage() + NamingHelper.getDefaultModelPackage(), StringUtils.capitalize(getName()) + "Response", null); if (responseBody != null) { this.responseBody.put(body.getKey(), responseBody); }//w w w. ja v a2s . c o m } } } } } }