Example usage for org.springframework.util StringUtils uncapitalize

List of usage examples for org.springframework.util StringUtils uncapitalize

Introduction

In this page you can find the example usage for org.springframework.util StringUtils uncapitalize.

Prototype

public static String uncapitalize(String str) 

Source Link

Document

Uncapitalize a String , changing the first letter to lower case as per Character#toLowerCase(char) .

Usage

From source file:org.web4thejob.util.L10nUtil.java

public static MessageSource getMessageSource() {
    if (source == null) {
        source = ContextUtil.getBean(StringUtils.uncapitalize(MessageSource.class.getSimpleName()),
                MessageSource.class);
        try {//from   w  w w .  j  av  a 2  s . c o  m
            source.getMessage("just_to_initialize_message_source_properly", null, CoreUtil.getUserLocale());
        } catch (NoSuchMessageException ignore) {
        }
    }

    return source;
}

From source file:com.xybase.spring.CompScanNameGenerator.java

public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry) {
    String className = beanDefinition.getBeanClassName();
    if (className.endsWith("Impl")) {
        className = className.substring(className.lastIndexOf(".") + 1, className.indexOf("Impl"));
    }/*from   ww  w  .  j a v a 2s .  c o  m*/
    return StringUtils.uncapitalize(className);
}

From source file:org.focusns.common.validation.ValidationHelper.java

/**
 * ? bean class ?  ?? ?// www.j  a v  a  2s  .  c om
 * 
 * @param validatorFactory
 * @param clazz
 * @param groups
 * @return
 */
public static ValidatedBean createForClass(ValidatorFactory validatorFactory, Class<?> clazz,
        Class<?>... groups) {
    Class<?> beanType = clazz;
    String beanName = StringUtils.uncapitalize(clazz.getSimpleName());
    //
    ValidatedBean validatedBean = new ValidatedBean(beanName, beanType);
    //
    Validator validator = validatorFactory.getValidator();
    MessageInterpolator messageInterpolator = validatorFactory.getMessageInterpolator();
    //
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(beanType);
    Set<PropertyDescriptor> propertyDescriptors = beanDescriptor.getConstrainedProperties();
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        String propertyName = propertyDescriptor.getPropertyName();
        ValidatedProperty validatedProperty = new ValidatedProperty(propertyName);
        //
        Set<ConstraintDescriptor<?>> constraintDesctipors = propertyDescriptor.getConstraintDescriptors();
        for (final ConstraintDescriptor<?> constraintDescriptor : constraintDesctipors) {
            // groups checks
            if (isOutOfGroup(constraintDescriptor, groups)) {
                continue;
            }
            //
            String constraintName = getConstraintName(constraintDescriptor);
            List<String> constraintParams = getConstraintParams(constraintDescriptor);
            ValidatedConstraint validatedConstraint = new ValidatedConstraint(constraintName, constraintParams);
            //
            String messageTemplate = (String) constraintDescriptor.getAttributes().get("message");
            MessageInterpolator.Context context = new MessageInterpolatorContext(constraintDescriptor);
            String message = messageInterpolator.interpolate(messageTemplate, context);
            //
            validatedConstraint.setMessage(message);
            //
            validatedProperty.addValidatedConstraint(validatedConstraint);
        }
        //
        if (!validatedProperty.getValidatedConstraints().isEmpty()) {
            //
            validatedBean.addValidatedProperty(validatedProperty);
        }
    }
    //
    return validatedBean;
}

From source file:org.synyx.hades.dao.config.DaoContext.java

/**
 * Creates a {@link DaoContext} from the given DAO interface name. Derives
 * DAO id, as well as the package name to use from the given interface.
 * //from  www  .j a v  a 2s .co  m
 * @param interfaceName
 * @param parent
 * @return
 */
public static DaoContext fromInterfaceName(String interfaceName, DaoConfigContext parent) {

    String shortName = ClassUtils.getShortName(interfaceName);

    String id = StringUtils.uncapitalize(shortName);

    final String packageName = interfaceName.substring(0, interfaceName.lastIndexOf(shortName) - 1);

    return new DaoContext(id, parent) {

        /*
         * (non-Javadoc)
         * 
         * @see org.synyx.hades.dao.config.DaoContext#getDaoPackageName()
         */
        @Override
        protected String getDaoBasePackageName() {

            return packageName;
        }
    };
}

From source file:org.easyj.rest.controller.AbstractController.java

protected <E> BindingResult createBindingResult(Class<E> klazz) {
    return new BeanPropertyBindingResult(klazz, StringUtils.uncapitalize(klazz.getSimpleName()));
}

From source file:net.nan21.dnet.core.presenter.converter.AbstractDsConverter.java

@Override
public List<M> entitiesToModels(List<E> entities, EntityManager em, List<String> fieldNames) throws Exception {
    List<M> result = new ArrayList<M>();
    Method[] methods = this.getModelClass().getMethods();
    int l = methods.length;
    Map<String, Method> setters = new HashMap<String, Method>();
    for (int i = 0; i < l; i++) {
        Method method = methods[i];
        if (method.getName().startsWith("set") && !method.getName().equals("set__clientRecordId__")) {
            String fieldName = StringUtils.uncapitalize(method.getName().substring(3));
            if (fieldNames == null || fieldNames.contains(fieldName)) {
                setters.put(fieldName, method);
            }/* w  w  w. j  av a 2 s .  c o  m*/
        }
    }
    Map<String, String> refpaths = this.descriptor.getE2mConv();
    for (E e : entities) {
        M m = modelClass.newInstance();
        this.entityToModel_(e, m, em, setters, refpaths);
        result.add(m);
    }
    return result;
}

From source file:seava.j4e.presenter.converter.AbstractDsConverter.java

@Override
public List<M> entitiesToModels(List<E> entities, EntityManager em, List<String> fieldNames) throws Exception {
    List<M> result = new ArrayList<M>();
    Method[] methods = this.getModelClass().getMethods();
    int l = methods.length;
    Map<String, Method> setters = new HashMap<String, Method>();
    for (int i = 0; i < l; i++) {
        Method method = methods[i];
        if (method.getName().startsWith("set") && !method.getName().equals("set__clientRecordId__")) {
            String fieldName = StringUtils.uncapitalize(method.getName().substring(3));
            if (fieldNames == null || fieldNames.contains(fieldName)) {
                setters.put(fieldName, method);
            }/* w  w w.j a v a  2  s  . c o m*/
        }
    }
    Map<String, String> refpaths = this.descriptor.getE2mConv();
    for (E e : entities) {
        M m = modelClass.newInstance();
        if (m instanceof AbstractDsModel<?>) {
            ((AbstractDsModel) m)._setEntity_(e);
        }
        this.entityToModel_(e, m, em, setters, refpaths);
        result.add(m);
    }
    return result;
}

From source file:org.thingsplode.server.bus.ThingsplodeServiceLocator.java

public <SRV extends AbstractExecutor> SRV getService(Message<?> message, Class<SRV> type)
        throws SrvExecutionException {
    if (message == null || message.getPayload() == null) {
        throw new SrvExecutionException(ExecutionStatus.DECLINED, ResponseCode.INTERNAL_SYSTEM_ERROR,
                "the message or the message payload cannot be null.");
    }//from  ww  w  . ja v a 2  s  .c  om
    Object request = message.getPayload();
    if (request instanceof AbstractRequest) {
        AbstractRequest req = (AbstractRequest) request;
        if (req.getServiceProviderName() != null && !req.getServiceProviderName().isEmpty()) {
            try {
                return (SRV) ctx.getBean(req.getServiceProviderName(), type);
            } catch (BeansException ex) {
                throw new SrvExecutionException(((AbstractRequest) request).getMessageId(),
                        ExecutionStatus.DECLINED, ResponseCode.INTERNAL_SYSTEM_ERROR,
                        "Service of name: " + req.getServiceProviderName()
                                + " is not installed! Try to request a different service provider name. "
                                + ex.getMessage(),
                        ex);
            }
        } else {
            String requestBeanName = request.getClass().getSimpleName();
            requestBeanName = StringUtils.uncapitalize(requestBeanName);
            requestBeanName += "Executor";
            try {
                return (SRV) ctx.getBean(requestBeanName, type);
            } catch (BeansException ex) {
                throw new SrvExecutionException(((AbstractRequest) request).getMessageId(),
                        ExecutionStatus.DECLINED, ResponseCode.INTERNAL_SYSTEM_ERROR,
                        "Service of name: " + requestBeanName
                                + " is not installed! Try to request a different service provider name. "
                                + ex.getMessage(),
                        ex);
            }
        }
    } else {
        throw new SrvExecutionException(ExecutionStatus.DECLINED, ResponseCode.INTERNAL_SYSTEM_ERROR,
                "This locator does not support the request of type: " + request.getClass().getSimpleName());
    }
}

From source file:org.springmodules.validation.commons.DefaultPageBeanValidator.java

/**
 * If <code>useFullyQualifiedClassName</code> is false (default value), this function returns a
 * string containing the uncapitalized, short name for the given class
 * (e.g. myBean for the class com.domain.test.MyBean). Otherwise, it  returns the value
 * returned by <code>Class.getName()</code>.
 *
 * @param cls <code>Class</code> of the bean to be validated.
 * @return the bean name.//from   w w w  .  jav  a2s .c om
 */
protected String getFormName(Class cls) {
    return (this.useFullyQualifiedClassName) ? cls.getName()
            : StringUtils.uncapitalize(ClassUtils.getShortName(cls));
}

From source file:com.agileapes.couteau.context.spring.event.impl.GenericTranslationScheme.java

@Override
public ApplicationEvent translate(Event originalEvent) throws EventTranslationException {
    final Method[] methods = ReflectionUtils.getAllDeclaredMethods(originalEvent.getClass());
    final GenericApplicationEvent applicationEvent = new GenericApplicationEvent(originalEvent.getSource(),
            originalEvent);// w w  w . j  av a  2 s . c om
    for (Method method : methods) {
        if (!isGetter(method)) {
            continue;
        }
        final String propertyName = StringUtils
                .uncapitalize(method.getName().substring(method.getName().startsWith("get") ? 3 : 2));
        try {
            applicationEvent.setProperty(propertyName, method.invoke(originalEvent));
        } catch (Exception e) {
            throw new EventTranslationException("Failed to set property on translated event: " + propertyName);
        }
    }
    return applicationEvent;
}