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:org.jahia.services.usermanager.ldap.JahiaLDAPConfig.java

private String transformPropKeyToBeanAttr(String key) {
    Iterable<String> upperStrings = Iterables.transform(Arrays.asList(StringUtils.split(key, '.')),
            new Function<String, String>() {
                public String apply(String input) {
                    return (input == null) ? null : StringUtils.capitalize(input);
                }//from ww w  .  j a  va 2s .com
            });
    return StringUtils.uncapitalize(StringUtils.join(upperStrings.iterator(), ""));
}

From source file:org.jahia.services.usermanager.mongo.JahiaMongoConfig.java

/**
 *
 * @param key/*from  w ww.j a  va2  s. c  om*/
 * @return
 */
private String transformPropKeyToBeanAttr(final String key) {
    final Iterable<String> upperStrings = Iterables.transform(Arrays.asList(StringUtils.split(key, '.')),
            new Function<String, String>() {
                public String apply(String input) {
                    return (input == null) ? null : StringUtils.capitalize(input);
                }
            });
    return StringUtils.uncapitalize(StringUtils.join(upperStrings.iterator(), ""));
}

From source file:org.jamwiki.parser.jflex.ParserFunctionUtil.java

/**
 * Parse the {{lcfirst:}} parser function.
 */// w ww .  j av  a  2s. c o  m
private static String parseLowerCaseFirst(ParserInput parserInput, String[] parserFunctionArgumentArray) {
    return StringUtils.uncapitalize(parserFunctionArgumentArray[0]);
}

From source file:org.jannocessor.bootstrap.processor.DomainProxyGeneratorHelper.java

public String fieldName(JavaMethod method) {
    String name = method.getName().getText();
    if (name.startsWith("get")) {
        return StringUtils.uncapitalize(name.substring(3));
    } else {//from  w  w w  .j ava  2s . c  om
        return "_" + name;
    }
}

From source file:org.jboss.loom.utils.Utils.java

/**
 *  Extracts all String getters properties to a map.
 *  @see also @Property.Utils.convert*()
 *//*from   w w  w .jav  a2  s  .  co  m*/
public static Map<String, String> describeBean(IConfigFragment bean) {

    Map<String, String> ret = new LinkedHashMap();

    Method[] methods = bean.getClass().getMethods();
    for (Method method : methods) {
        boolean get = false;
        String name = method.getName();

        // Only use getters which return String.
        if (method.getParameterTypes().length != 0)
            continue;
        if (!method.getReturnType().equals(String.class))
            continue;
        if (name.startsWith("get"))
            get = true;
        if (!(get || name.startsWith("is")))
            continue;

        // Remove "get" or "is".
        name = name.substring(get ? 3 : 2);
        // Uncapitalize, unless it's getDLQJNDIName.
        if (name.length() > 1 && !Character.isUpperCase(name.charAt(2)))
            name = StringUtils.uncapitalize(name);

        try {
            ret.put(name, (String) method.invoke(bean));
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            log.warn("Failed extracting property from " + bean.getClass().getSimpleName() + ":\n    "
                    + ex.getMessage(), ex);
        }
    }
    return ret;
}

From source file:org.jboss.tools.openshift.express.internal.ui.filters.SimplePropertyActionFilter.java

private boolean isAccessorFor(String property, String accessorName) {
    Matcher matcher = simpleAccessorPattern.matcher(accessorName);
    if (matcher.lookingAt()) {
        return property.equals(StringUtils.uncapitalize(matcher.group(NAME_CAPTURE_GROUP)));
    }/* ww w . j  av  a2s.c  o  m*/
    return false;
}

From source file:org.jdal.beans.ServiceBeanDefinitionParser.java

/**
 * {@inheritDoc}//from w  w  w . j a v  a  2 s.  c o  m
 */
public AbstractBeanDefinition parse(Element element, ParserContext parserContext) {

    // default dao and service classes
    String daoClassName = JPA_DAO_CLASS_NAME;
    String serviceClassName = PERSISTENT_SERVICE_CLASS_NAME;
    String name = null;
    boolean declareService = false;

    if (element.hasAttribute(DAO_CLASS))
        daoClassName = element.getAttribute(DAO_CLASS);

    if (element.hasAttribute(SERVICE_CLASS)) {
        serviceClassName = element.getAttribute(SERVICE_CLASS);
        declareService = true;
    }

    if (element.hasAttribute(NAME))
        name = element.getAttribute(NAME);

    if (element.hasAttribute(ENTITY)) {
        String className = element.getAttribute(ENTITY);
        if (name == null) {
            name = StringUtils
                    .uncapitalize(StringUtils.substringAfterLast(className, PropertyUtils.PROPERTY_SEPARATOR));
        }
        parserContext.pushContainingComponent(
                new CompositeComponentDefinition(name, parserContext.extractSource(element)));

        // Dao
        BeanDefinitionBuilder daoBuilder = BeanDefinitionBuilder.genericBeanDefinition(daoClassName);
        NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), CRITERIA);
        if (nl.getLength() > 0) {
            ManagedMap<String, BeanReference> builders = new ManagedMap<String, BeanReference>(nl.getLength());
            for (int i = 0; i < nl.getLength(); i++) {
                Element e = (Element) nl.item(i);
                builders.put(e.getAttribute(NAME), new RuntimeBeanReference(e.getAttribute(BUILDER)));
            }
            daoBuilder.addPropertyValue(CRITERIA_BUILDER_MAP, builders);
        }

        daoBuilder.addConstructorArgValue(ClassUtils.resolveClassName(className, null));
        daoBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        String daoBeanName;

        if (declareService) {
            // use dao suffix
            daoBeanName = name + DAO_SUFFIX;
            registerBeanDefinition(parserContext, daoBuilder, daoBeanName);

            // register service wrapper
            String serviceBeanName = name + SERVICE_SUFFIX;
            BeanDefinitionBuilder serviceBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(serviceClassName);
            serviceBuilder.addPropertyReference("dao", daoBeanName);
            registerBeanDefinition(parserContext, serviceBuilder, serviceBeanName);
        } else {
            // use service suffix for dao and declare an alias with dao suffix for compatibility with older api.
            daoBeanName = name + SERVICE_SUFFIX;
            String[] aliases = new String[] { name + DAO_SUFFIX };
            BeanComponentDefinition bcd = new BeanComponentDefinition(daoBuilder.getBeanDefinition(),
                    daoBeanName, aliases);
            parserContext.registerBeanComponent(bcd);
        }

        parserContext.popAndRegisterContainingComponent();
    }

    return null;
}

From source file:org.jdal.beans.TableBeanDefinitionParser.java

/**
 * {@inheritDoc}/* w w  w.  ja v a 2 s .c  o m*/
 */
@SuppressWarnings("rawtypes")
public BeanDefinition parse(Element element, ParserContext parserContext) {
    // Defaults
    String entity = null;

    if (element.hasAttribute(ENTITY))
        entity = element.getAttribute(ENTITY);

    String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, "."));

    if (element.hasAttribute(ID))
        name = element.getAttribute(ID);

    parserContext.pushContainingComponent(
            new CompositeComponentDefinition(name, parserContext.extractSource(element)));

    // Bean names
    String tableModelBeanName = name + LIST_TABLE_MODEL_SUFFIX;
    String tablePanelBeanName = name + TABLE_PANEL_SUFFIX;
    String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX;
    String dataSource = name + SERVICE_SUFFIX;
    String paginator = PAGINATOR_VIEW;
    String editor = name + EDITOR_SUFFIX;
    String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS;
    String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY;
    String scope = BeanDefinition.SCOPE_PROTOTYPE;

    if (element.hasAttribute(SERVICE_ATTRIBUTE))
        dataSource = element.getAttribute(SERVICE_ATTRIBUTE);

    if (element.hasAttribute(PAGINATOR))
        paginator = element.getAttribute(PAGINATOR);

    if (element.hasAttribute(ACTIONS))
        actions = element.getAttribute(ACTIONS);

    if (element.hasAttribute(GUI_FACTORY))
        guiFactory = element.getAttribute(GUI_FACTORY);

    if (element.hasAttribute(EDITOR))
        editor = element.getAttribute(EDITOR);

    if (element.hasAttribute(SCOPE))
        scope = element.getAttribute(SCOPE);

    // create ListTableModel
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListTableModel.class);
    bdb.setScope(scope);
    bdb.addPropertyValue("modelClass", entity);
    NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS);

    if (nl.getLength() > 0) {
        List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0),
                bdb.getRawBeanDefinition());
        bdb.addPropertyValue(COLUMNS, columns);
    }
    registerBeanDefinition(element, parserContext, tableModelBeanName, bdb);

    // create PageableTable
    bdb = BeanDefinitionBuilder.genericBeanDefinition(PageableTable.class);
    bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bdb.addPropertyReference(DATA_SOURCE, dataSource);
    bdb.addPropertyReference(PAGINATOR_VIEW, paginator);
    bdb.addPropertyReference(TABLE_MODEL, tableModelBeanName);
    bdb.addPropertyValue(NAME, pageableTableBeanName);

    if (element.hasAttribute(TABLE_SERVICE))
        bdb.addPropertyReference(Conventions.attributeNameToPropertyName(TABLE_SERVICE),
                element.getAttribute(TABLE_SERVICE));

    if (element.hasAttribute(FILTER))
        bdb.addPropertyReference(FILTER, element.getAttribute(FILTER));

    if (element.hasAttribute(SHOW_MENU))
        bdb.addPropertyValue(Conventions.attributeNameToPropertyName(SHOW_MENU),
                element.getAttribute(SHOW_MENU));

    if (element.hasAttribute(MESSAGE_SOURCE))
        bdb.addPropertyReference(MESSAGE_SOURCE, element.getAttribute(MESSAGE_SOURCE));

    registerBeanDefinition(element, parserContext, pageableTableBeanName, bdb);

    // create TablePanel
    String tablePanelClassName = "org.jdal.swing.table.TablePanel";
    if (element.hasAttribute(TABLE_PANEL_CLASS))
        tablePanelClassName = element.getAttribute(TABLE_PANEL_CLASS);

    bdb = BeanDefinitionBuilder.genericBeanDefinition(tablePanelClassName);
    bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bdb.addPropertyReference(TABLE, pageableTableBeanName);
    bdb.addPropertyReference(GUI_FACTORY, guiFactory);
    bdb.addPropertyValue(EDITOR_NAME, editor);
    bdb.addPropertyReference(PERSISTENT_SERVICE, dataSource);

    if (element.hasAttribute(FILTER_VIEW))
        bdb.addPropertyReference(Conventions.attributeNameToPropertyName(FILTER_VIEW),
                element.getAttribute(FILTER_VIEW));

    if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS)))
        bdb.addPropertyReference(ACTIONS, actions);

    registerBeanDefinition(element, parserContext, tablePanelBeanName, bdb);

    parserContext.popAndRegisterContainingComponent();

    return null;
}

From source file:org.jdal.dao.BeanFilter.java

public BeanFilter() {
    this.filterName = StringUtils.uncapitalize(this.getClass().getSimpleName());
    init();
}

From source file:org.jdal.vaadin.beans.TableBeanDefinitionParser.java

/**
 * {@inheritDoc}// w  w w  .j  a v a2s .c om
 */
@SuppressWarnings("rawtypes")
public BeanDefinition parse(Element element, ParserContext parserContext) {
    // Defaults
    String entity = null;

    if (element.hasAttribute(ENTITY))
        entity = element.getAttribute(ENTITY);

    String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, "."));

    if (element.hasAttribute(ID))
        name = element.getAttribute(ID);

    parserContext.pushContainingComponent(
            new CompositeComponentDefinition(name, parserContext.extractSource(element)));

    // Bean names
    String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX;
    String tableBeanName = name + TABLE_SUFFIX;
    String dataSource = name + SERVICE_SUFFIX;
    String paginator = PAGINATOR_VIEW;
    String editor = name + EDITOR_SUFFIX;
    String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS;
    String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY;
    String scope = BeanDefinition.SCOPE_PROTOTYPE;
    String pageableTableClass = DEFAULT_PAGEABLE_TABLE_CLASS;
    String tableClass = DEFAULT_TABLE_CLASS;

    if (element.hasAttribute(DATA_SOURCE))
        dataSource = element.getAttribute(DATA_SOURCE);

    if (element.hasAttribute(PAGINATOR))
        paginator = element.getAttribute(PAGINATOR);

    if (element.hasAttribute(ACTIONS))
        actions = element.getAttribute(ACTIONS);

    if (element.hasAttribute(GUI_FACTORY))
        guiFactory = element.getAttribute(GUI_FACTORY);

    if (element.hasAttribute(EDITOR))
        editor = element.getAttribute(EDITOR);

    if (element.hasAttribute(SCOPE))
        scope = element.getAttribute(SCOPE);

    if (element.hasAttribute(PAGEABLE_TABLE_CLASS))
        pageableTableClass = element.getAttribute(PAGEABLE_TABLE_CLASS);

    if (element.hasAttribute(TABLE_CLASS))
        tableClass = element.getAttribute(TABLE_CLASS);

    // create PageableTable
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(pageableTableClass);
    bdb.setScope(scope);
    bdb.addPropertyReference(DATA_SOURCE, dataSource);
    bdb.addPropertyReference(PAGINATOR_VIEW, paginator);
    bdb.addPropertyValue(NAME, pageableTableBeanName);
    bdb.addPropertyReference(TABLE, tableBeanName);
    bdb.addPropertyReference(GUI_FACTORY, guiFactory);
    bdb.addPropertyValue(EDITOR_NAME, editor);
    bdb.addPropertyValue(ENTITY_CLASS, entity);

    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, TABLE_SERVICE);
    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER);
    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, MESSAGE_SOURCE);
    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER_FORM);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, SORT_PROPERTY);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, ORDER);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PAGE_SIZE);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, NATIVE_BUTTONS);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PROPAGATE_SERVICE);

    if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS)))
        bdb.addPropertyReference(ACTIONS, actions);

    parserContext.getDelegate().parseBeanDefinitionAttributes(element, pageableTableBeanName, null,
            bdb.getBeanDefinition());

    BeanDefinitionHolder holder = new BeanDefinitionHolder(bdb.getBeanDefinition(), pageableTableBeanName);

    // Test Decorators like aop:scoped-proxy
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node n = childNodes.item(i);
        if (Node.ELEMENT_NODE != n.getNodeType() || COLUMNS.equals(n.getLocalName()))
            continue;

        NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver()
                .resolve(n.getNamespaceURI());
        if (handler != null) {
            holder = handler.decorate(n, holder, parserContext);
        }
    }

    parserContext.registerBeanComponent(new BeanComponentDefinition(holder));

    // create ConfigurableTable
    bdb = BeanDefinitionBuilder.genericBeanDefinition(tableClass);
    bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);

    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FIELD_FACTORY);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, MULTISELECT);

    if (element.hasAttribute(SELECTABLE)) {
        bdb.addPropertyValue(SELECTABLE, element.getAttribute(SELECTABLE));
    } else {
        // set selectable by default
        bdb.addPropertyValue(SELECTABLE, true);
    }

    // parse columns
    NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS);

    if (nl.getLength() > 0) {
        List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0),
                bdb.getRawBeanDefinition());
        bdb.addPropertyValue(COLUMNS, columns);
    }

    registerBeanDefinition(element, parserContext, tableBeanName, bdb);

    parserContext.popAndRegisterContainingComponent();

    return null;
}