List of usage examples for org.springframework.util StringUtils uncapitalize
public static String uncapitalize(String str)
From source file:com.springinpractice.ch11.web.sitemap.Sitemap.java
/** * @param entityClass entity class/*w ww.j a v a2 s. c o m*/ * @return node ID */ public String getEntityListViewId(Class<?> entityClass) { return StringUtils.uncapitalize(entityClass.getSimpleName()) + "List"; }
From source file:org.javelin.sws.ext.bind.internal.metadata.PropertyCallback.java
/** * Like {@link MethodCallback#doWith(Method)}, but for two methods. * // ww w .j av a2s .co m * @see org.springframework.util.ReflectionUtils.MethodCallback#doWith(java.lang.reflect.Method) */ @Override public void doWith(Method getter) throws IllegalArgumentException, IllegalAccessException { Method setter = ReflectionUtils.findMethod(clazz, getter.getName().replaceFirst("^get", "set"), getter.getReturnType()); if (log.isTraceEnabled()) { if (setter != null) { log.trace(" - Analyzing pair of methods: {}.{}/{}.{}", getter.getDeclaringClass().getSimpleName(), getter.getName(), setter.getDeclaringClass().getSimpleName(), setter.getName()); } else { // we have java.util.Collection log.trace(" - Analyzing method: {}.{}", getter.getDeclaringClass().getSimpleName(), getter.getName()); } } // TODO: properly handle class hierarchies String propertyName = StringUtils.uncapitalize(getter.getName().substring(3)); // metadata for getter/setter PropertyMetadata<T, ?> metadata = PropertyMetadata.newPropertyMetadata(this.clazz, getter.getReturnType(), propertyName, getter, setter, PropertyKind.BEAN); this.doWithPropertySafe(metadata); }
From source file:com.springinpractice.ch11.web.sitemap.Sitemap.java
/** * @param entityClass entity class/* w ww.j a v a 2s. c o m*/ * @return node ID */ public String getCiDetailsViewId(Class<?> entityClass) { return StringUtils.uncapitalize(entityClass.getSimpleName()) + "Details"; }
From source file:ch.rasc.extclassgenerator.association.AbstractAssociation.java
public static AbstractAssociation createAssociation(ModelAssociation associationAnnotation, ModelBean model, Class<?> typeOfFieldOrReturnValue, Class<?> declaringClass, String name) { ModelAssociationType type = associationAnnotation.value(); Class<?> associationClass = associationAnnotation.model(); if (associationClass == Object.class) { associationClass = typeOfFieldOrReturnValue; }// w w w .j av a2 s .co m final 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()); } else if (type == ModelAssociationType.HAS_MANY) { association.setForeignKey(StringUtils.uncapitalize(declaringClass.getSimpleName()) + "_id"); } else if (type == ModelAssociationType.BELONGS_TO || type == ModelAssociationType.HAS_ONE) { association.setForeignKey(name + "_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()); } ReflectionUtils.doWithFields(associationClass, new FieldCallback() { @Override public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { if (field.getAnnotation(ModelId.class) != null && !"id".equals(field.getName())) { association.setPrimaryKey(field.getName()); } } }); } if (type == ModelAssociationType.HAS_MANY) { HasManyAssociation hasManyAssociation = (HasManyAssociation) association; if (StringUtils.hasText(associationAnnotation.setterName())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(declaringClass, name, association.getType(), "setterName")); } if (StringUtils.hasText(associationAnnotation.getterName())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(declaringClass, 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(declaringClass, name, association.getType(), "autoLoad")); } if (StringUtils.hasText(associationAnnotation.name())) { LogFactory.getLog(ModelGenerator.class) .warn(getWarningText(declaringClass, 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(declaringClass, 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:org.shredzone.commons.taglib.processor.TaglibProcessor.java
/** * Computes the name of a tag. If there was a name given in the annotation, it will be * used. Otherwise, a name is derived from the class name of the tag class, with a * "Tag" suffix removed./*from w w w . jav a 2 s .com*/ * * @param annotation * Tag name, as given in the annotation * @param className * Name of the tag class * @return Name of the tag */ private String computeTagName(String annotation, String className) { String result = annotation; if (!StringUtils.hasText(result)) { result = StringUtils.unqualify(className); if (result.endsWith("Tag")) { result = result.substring(0, result.length() - 3); } result = StringUtils.uncapitalize(result); } return result; }
From source file:com.expedia.seiso.web.assembler.ResourceAssembler.java
/** * Assembles a resource from a global search result set. * //from www .j ava 2 s . com * @param apiVersion * API version * @param results * Global search result set * @return Resource for the result set */ public Resource toGlobalSearchResource(@NonNull ApiVersion apiVersion, @NonNull SearchResults results) { val resultsResource = new Resource(); val itemClasses = results.getItemClasses(); for (val itemClass : itemClasses) { val propName = StringUtils.uncapitalize(itemClass.getSimpleName()); val typedSerp = results.getTypedSerp(itemClass); // TODO Not sure we want flat projection here. Shouldn't we do the default collection projection? val typedSerpResourceList = toResourceList(apiVersion, typedSerp.getContent(), ProjectionNode.FLAT_PROJECTION_NODE); resultsResource.setProperty(propName, typedSerpResourceList); } return resultsResource; }
From source file:ch.rasc.extclassgenerator.ModelGenerator.java
private static void createModelBean(ModelBean model, AccessibleObject accessibleObject, OutputConfig outputConfig) {//from w ww . j a va 2s . c om Class<?> javaType = null; String name = null; Class<?> declaringClass = null; if (accessibleObject instanceof Field) { Field field = (Field) accessibleObject; javaType = field.getType(); name = field.getName(); declaringClass = field.getDeclaringClass(); } else if (accessibleObject instanceof Method) { Method method = (Method) accessibleObject; javaType = method.getReturnType(); if (javaType.equals(Void.TYPE)) { return; } if (method.getName().startsWith("get")) { name = StringUtils.uncapitalize(method.getName().substring(3)); } else if (method.getName().startsWith("is")) { name = StringUtils.uncapitalize(method.getName().substring(2)); } else { name = method.getName(); } declaringClass = method.getDeclaringClass(); } ModelType modelType = null; if (model.isAutodetectTypes()) { for (ModelType mt : ModelType.values()) { if (mt.supports(javaType)) { modelType = mt; break; } } } else { modelType = ModelType.AUTO; } ModelFieldBean modelFieldBean = null; ModelField modelFieldAnnotation = accessibleObject.getAnnotation(ModelField.class); if (modelFieldAnnotation != null) { if (StringUtils.hasText(modelFieldAnnotation.value())) { name = modelFieldAnnotation.value(); } if (StringUtils.hasText(modelFieldAnnotation.customType())) { modelFieldBean = new ModelFieldBean(name, modelFieldAnnotation.customType()); } else { ModelType type = null; if (modelFieldAnnotation.type() != ModelType.NOT_SPECIFIED) { type = modelFieldAnnotation.type(); } else { type = modelType; } modelFieldBean = new ModelFieldBean(name, type); } updateModelFieldBean(modelFieldBean, modelFieldAnnotation); model.addField(modelFieldBean); } else { if (modelType != null) { modelFieldBean = new ModelFieldBean(name, modelType); model.addField(modelFieldBean); } } ModelId modelIdAnnotation = accessibleObject.getAnnotation(ModelId.class); if (modelIdAnnotation != null) { model.setIdProperty(name); } ModelClientId modelClientId = accessibleObject.getAnnotation(ModelClientId.class); if (modelClientId != null) { model.setClientIdProperty(name); model.setClientIdPropertyAddToWriter(modelClientId.configureWriter()); } ModelVersion modelVersion = accessibleObject.getAnnotation(ModelVersion.class); if (modelVersion != null) { model.setVersionProperty(name); } ModelAssociation modelAssociationAnnotation = accessibleObject.getAnnotation(ModelAssociation.class); if (modelAssociationAnnotation != null) { model.addAssociation(AbstractAssociation.createAssociation(modelAssociationAnnotation, model, javaType, declaringClass, name)); } if (modelFieldBean != null && outputConfig.getIncludeValidation() != IncludeValidation.NONE) { Set<ModelValidation> modelValidationAnnotations = AnnotationUtils .getRepeatableAnnotation(accessibleObject, ModelValidations.class, ModelValidation.class); if (!modelValidationAnnotations.isEmpty()) { for (ModelValidation modelValidationAnnotation : modelValidationAnnotations) { AbstractValidation modelValidation = AbstractValidation.createValidation(name, modelValidationAnnotation, outputConfig.getIncludeValidation()); if (modelValidation != null) { model.addValidation(modelValidation); } } } else { Annotation[] fieldAnnotations = accessibleObject.getAnnotations(); for (Annotation fieldAnnotation : fieldAnnotations) { AbstractValidation.addValidationToModel(model, modelFieldBean, fieldAnnotation, outputConfig.getIncludeValidation()); } if (accessibleObject instanceof Field) { PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(declaringClass, name); if (pd != null && pd.getReadMethod() != null) { for (Annotation readMethodAnnotation : pd.getReadMethod().getAnnotations()) { AbstractValidation.addValidationToModel(model, modelFieldBean, readMethodAnnotation, outputConfig.getIncludeValidation()); } } } } } }
From source file:com.phoenixnap.oss.ramlapisync.naming.NamingHelper.java
/** * Converts the name of a parameter into a name suitable for a Java parameter * * @param name The name of a RAML query parameter or request header * @return A name suitable for a Java parameter *///from w w w. j a v a 2s .com public static String getParameterName(String name) { return StringUtils.uncapitalize(cleanNameForJava(name)); }
From source file:org.grails.core.util.ClassPropertyFetcher.java
private void init() { FieldCallback fieldCallback = new ReflectionUtils.FieldCallback() { public void doWith(Field field) { if (field.isSynthetic()) { return; }/*from w w w . j av a 2 s . c o m*/ final int modifiers = field.getModifiers(); if (!Modifier.isPublic(modifiers)) { return; } final String name = field.getName(); if (name.indexOf('$') == -1) { boolean staticField = Modifier.isStatic(modifiers); if (staticField) { staticFetchers.put(name, new FieldReaderFetcher(field, staticField)); } else { instanceFetchers.put(name, new FieldReaderFetcher(field, staticField)); } } } }; MethodCallback methodCallback = new ReflectionUtils.MethodCallback() { public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if (method.isSynthetic()) { return; } if (!Modifier.isPublic(method.getModifiers())) { return; } if (Modifier.isStatic(method.getModifiers()) && method.getReturnType() != Void.class) { if (method.getParameterTypes().length == 0) { String name = method.getName(); if (name.indexOf('$') == -1) { if (name.length() > 3 && name.startsWith("get") && Character.isUpperCase(name.charAt(3))) { name = name.substring(3); } else if (name.length() > 2 && name.startsWith("is") && Character.isUpperCase(name.charAt(2)) && (method.getReturnType() == Boolean.class || method.getReturnType() == boolean.class)) { name = name.substring(2); } PropertyFetcher fetcher = new GetterPropertyFetcher(method, true); staticFetchers.put(name, fetcher); staticFetchers.put(StringUtils.uncapitalize(name), fetcher); } } } } }; List<Class<?>> allClasses = resolveAllClasses(clazz); for (Class<?> c : allClasses) { Field[] fields = c.getDeclaredFields(); for (Field field : fields) { try { fieldCallback.doWith(field); } catch (IllegalAccessException ex) { throw new IllegalStateException( "Shouldn't be illegal to access field '" + field.getName() + "': " + ex); } } Method[] methods = c.getDeclaredMethods(); for (Method method : methods) { try { methodCallback.doWith(method); } catch (IllegalAccessException ex) { throw new IllegalStateException( "Shouldn't be illegal to access method '" + method.getName() + "': " + ex); } } } propertyDescriptors = BeanUtils.getPropertyDescriptors(clazz); for (PropertyDescriptor desc : propertyDescriptors) { Method readMethod = desc.getReadMethod(); if (readMethod != null) { boolean staticReadMethod = Modifier.isStatic(readMethod.getModifiers()); if (staticReadMethod) { staticFetchers.put(desc.getName(), new GetterPropertyFetcher(readMethod, staticReadMethod)); } else { instanceFetchers.put(desc.getName(), new GetterPropertyFetcher(readMethod, staticReadMethod)); } } } }