Example usage for org.apache.commons.lang StringUtils uncapitalize

List of usage examples for org.apache.commons.lang StringUtils uncapitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils uncapitalize.

Prototype

public static String uncapitalize(String str) 

Source Link

Document

Uncapitalizes a String changing the first letter to title case as per Character#toLowerCase(char) .

Usage

From source file:com.p5solutions.core.utils.ReflectionUtility.java

/**
 * Builds the field name./*from   w  ww. j a  v  a2 s  .  com*/
 * 
 * @param method
 *          the method
 * @return the string
 */
public static String buildFieldName(Method method) {
    String fieldName = null;
    String methodName = method.getName();

    if (isGetter(method) || isSet(method)) {
        fieldName = methodName.substring(3);
    } else if (isIs(method)) {
        fieldName = methodName.substring(2);
    }

    fieldName = StringUtils.uncapitalize(fieldName);

    return fieldName;
}

From source file:net.servicefixture.util.ReflectionUtils.java

private static void setProperty(Object parent, String attributeName, Object source) throws Exception {
    Method[] methods = parent.getClass().getMethods();
    for (Method method : methods) {
        if (method.getName().startsWith("set") && method.getName().length() > 3
                && StringUtils.uncapitalize(method.getName().substring(3)).equals(attributeName)
                && method.getParameterTypes().length == 1
                && (source == null || method.getParameterTypes()[0].isAssignableFrom(source.getClass()))) {
            method.invoke(parent, source);
            return;
        }/*  w w w . ja v  a 2 s .  com*/
    }
    BeanUtils.setProperty(parent, attributeName, source);
}

From source file:com.zauberlabs.commons.mom.internal.AttributesMap.java

@Override
public Set<Entry<String, Object>> entrySet() {
    return Streams.cons(target.getClass().getMethods()).filter(NaiveProperties.argCount(0))
            .flatMap(new AbstractFunction.Soft<Method, Iterable<? extends Entry<String, Object>>>() {
                @Override/*from  w  ww. j  a  v  a2  s .  c om*/
                public Iterable<? extends java.util.Map.Entry<String, Object>> softApply(final Method arg)
                        throws Exception {
                    if (arg.getName().equals("getClass")) {
                        return Collections.emptyList();
                    }

                    Matcher m = GETTER_PATTERN.matcher(arg.getName());
                    if (!m.find()) {
                        return Collections.emptyList();
                    }
                    return Arrays
                            .asList(_(StringUtils.uncapitalize(m.group(2)), transform(arg.invoke(target))));
                }
            }).toSet();
}

From source file:CubaEnhancer.java

private void enhanceSetters(CtClass ctClass)
        throws NotFoundException, CannotCompileException, ClassNotFoundException {
    for (CtMethod ctMethod : ctClass.getDeclaredMethods()) {
        final String name = ctMethod.getName();
        if (Modifier.isAbstract(ctMethod.getModifiers()) || !name.startsWith("set")
                || ctMethod.getReturnType() != CtClass.voidType || ctMethod.getParameterTypes().length != 1)
            continue;

        String fieldName = StringUtils.uncapitalize(name.substring(3));

        // check if the setter is for a persistent or transient property
        CtMethod persistenceMethod = null;
        for (CtMethod method : ctClass.getDeclaredMethods()) {
            if (method.getName().equals("_persistence_set_" + fieldName)) {
                persistenceMethod = method;
                break;
            }//from   w w w. jav  a2  s .  com
        }
        if (persistenceMethod == null) {
            // can be a transient property
            CtField ctField = null;
            CtField[] declaredFields = ctClass.getDeclaredFields();
            for (CtField field : declaredFields) {
                if (field.getName().equals(fieldName)) {
                    ctField = field;
                    break;
                }
            }
            if (ctField == null)
                continue; // no field
            // check if the field is annotated with @MetaProperty
            // cannot use ctField.getAnnotation() because of problem with classpath in child projects
            AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctField.getFieldInfo()
                    .getAttribute(AnnotationsAttribute.visibleTag);
            if (annotationsAttribute == null
                    || annotationsAttribute.getAnnotation(METAPROPERTY_ANNOTATION) == null)
                continue;
        }

        CtClass setterParamType = ctMethod.getParameterTypes()[0];

        if (setterParamType.isPrimitive()) {
            throw new IllegalStateException(
                    String.format("Unable to enhance field %s.%s with primitive type %s. Use type %s.",
                            ctClass.getName(), fieldName, setterParamType.getSimpleName(),
                            StringUtils.capitalize(setterParamType.getSimpleName())));
        }

        ctMethod.addLocalVariable("__prev", setterParamType);

        ctMethod.insertBefore("__prev = this.get" + StringUtils.capitalize(fieldName) + "();");

        ctMethod.insertAfter(
                "if (!com.haulmont.chile.core.model.utils.InstanceUtils.propertyValueEquals(__prev, $1)) {"
                        + "  this.propertyChanged(\"" + fieldName + "\", __prev, $1);" + "}");
    }
}

From source file:hr.fer.zemris.vhdllab.platform.manager.editor.impl.DefaultEditorManagerFactory.java

private EditorManager configureManager(EditorManager manager) {
    String beanName = StringUtils.uncapitalize(manager.getClass().getSimpleName());
    context.getBeanFactory().configureBean(manager, beanName);
    return manager;
}

From source file:com.liferay.alloy.taglib.alloy_util.ComponentTag.java

private void _processEventAttribute(String key, String value, Map<String, String> afterEventOptionsMap,
        Map<String, String> onEventsOptionsMap) {

    if (key.startsWith(_AFTER)) {
        String event = StringUtils.uncapitalize(key.replaceFirst(_AFTER, StringPool.BLANK));

        afterEventOptionsMap.put(event, value);
    } else {/* w ww . j  a v  a  2 s .  c om*/
        String event = StringUtils.uncapitalize(key.replaceFirst(_ON, StringPool.BLANK));

        onEventsOptionsMap.put(event, value);
    }
}

From source file:com.phoenixnap.oss.ramlapisync.generation.rules.spring.SpringControllerDecoratorRule.java

@Override
public final JDefinedClass apply(ApiControllerMetadata metadata, JCodeModel generatableType) {

    JDefinedClass generatedInterface = new GenericJavaClassRule().setPackageRule(new PackageRule())
            .setClassCommentRule(new ClassCommentRule()).setClassRule(new ControllerInterfaceDeclarationRule())
            .setMethodCommentRule(new MethodCommentRule())
            .setMethodSignatureRule(//from w  ww. j  a  v a  2  s . c  om
                    new ControllerMethodSignatureRule(new SpringResponseEntityRule(), new MethodParamsRule()))
            .apply(metadata, generatableType);

    String delegateFieldName = StringUtils.uncapitalize(generatedInterface.name() + "Delegate");

    GenericJavaClassRule delegateGenerator = new GenericJavaClassRule().setPackageRule(new PackageRule())
            .setClassCommentRule(new ClassCommentRule()).addClassAnnotationRule(getControllerAnnotationRule())
            .addClassAnnotationRule(new SpringRequestMappingClassAnnotationRule())
            .setClassRule(new ControllerClassDeclarationRule("Decorator"))
            .setImplementsExtendsRule(new ImplementsControllerInterfaceRule(generatedInterface))
            .addFieldDeclarationRule(new SpringDelegateFieldDeclerationRule(delegateFieldName))
            .setMethodCommentRule(new MethodCommentRule())
            .addMethodAnnotationRule(new SpringRequestMappingMethodAnnotationRule())
            .addMethodAnnotationRule(getResponseBodyAnnotationRule())
            .setMethodSignatureRule(new ControllerMethodSignatureRule(new SpringResponseEntityRule(),
                    new SpringMethodParamsRule()))
            .setMethodBodyRule(new DelegatingMethodBodyRule(delegateFieldName));

    return delegateGenerator.apply(metadata, generatableType);
}

From source file:gDao.genericDao.GDaoImpl.java

public List<T> findWithFinder(Finder finder) {
    Session session = getSessionFactory().getCurrentSession();
    Criteria criteria = session.createCriteria(persistentClass,
            StringUtils.uncapitalize(persistentClass.getSimpleName()));
    finder.prepareCriteria(criteria, persistentClass);
    return criteria.list();
}

From source file:com.fengduo.bee.commons.util.ObjectUtils.java

/**
 * ????//from ww  w .j a v  a  2s  . co m
 * 
 * @param annotation
 * @param object
 */
public static void annotationToObject(Object annotation, Object object) {
    if (annotation != null) {
        Class<?> annotationClass = annotation.getClass();
        Class<?> objectClass = object.getClass();
        for (Method m : objectClass.getMethods()) {
            if (StringUtils.startsWith(m.getName(), "set")) {
                try {
                    String s = StringUtils.uncapitalize(StringUtils.substring(m.getName(), 3));
                    Object obj = annotationClass.getMethod(s).invoke(annotation);
                    if (obj != null && !"".equals(obj.toString())) {
                        if (object == null) {
                            object = objectClass.newInstance();
                        }
                        m.invoke(object, obj);
                    }
                } catch (Exception e) {
                    // 
                }
            }
        }
    }
}

From source file:de.extra.client.core.config.impl.ExtraProfileConfiguration.java

@Override
public String getFieldName(final String parentElement, final String childElement) {
    // Die Implementierung geht davon aus, dass Feldname des Elements dem
    // childElementName ohne Prefix entspricht.
    // TODO Den Profiler anschauen.
    final String childElementOhnePrefix = removePrefix(childElement);
    String childElementFieldName = StringUtils.uncapitalize(childElementOhnePrefix);
    // Noch ein Workaround Plugin -> PlugIn konvertieren
    childElementFieldName = convertPluginName(childElementFieldName);
    return childElementFieldName;
}