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

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

Introduction

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

Prototype

public static String capitalize(String str) 

Source Link

Document

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

Usage

From source file:ch.entwine.weblounge.common.impl.content.page.ScriptImpl.java

/**
 * Initializes this script include from an XML node that was generated using
 * {@link #toXml()}.//from   ww  w  . ja  v  a  2 s. co m
 * 
 * @param config
 *          the script node
 * @param xpathProcessor
 *          xpath processor to use
 * @throws IllegalStateException
 *           if the configuration cannot be parsed
 * @see #toXml()
 */
public static ScriptImpl fromXml(Node config, XPath xpathProcessor) throws IllegalStateException {

    String href = XPathHelper.valueOf(config, "@src", xpathProcessor);
    if (href == null)
        throw new ConfigurationException("Source path of script definition is mandatory!");

    ScriptImpl script = new ScriptImpl(href);
    script.setType(XPathHelper.valueOf(config, "@type", xpathProcessor));
    script.setCharset(XPathHelper.valueOf(config, "@charset", xpathProcessor));
    script.setJQuery(XPathHelper.valueOf(config, "@jquery", xpathProcessor));
    script.setDeferred("true".equalsIgnoreCase(XPathHelper.valueOf(config, "@defer", xpathProcessor)));

    String use = XPathHelper.valueOf(config, "@use", xpathProcessor);
    if (StringUtils.isNotBlank(use)) {
        script.setUse(Use.valueOf(StringUtils.capitalize(use)));
    }

    return script;
}

From source file:ca.uhn.hl7v2.sourcegen.SourceGenerator.java

public static String makeAlternateAccessorName(String fieldDesc, String parentName, int index) {
    StringBuffer aName = new StringBuffer();

    aName.append(StringUtils.capitalize(parentName.toLowerCase())).append(index).append("_");

    char[] chars = fieldDesc.toCharArray();
    boolean lastCharWasNotLetter = true;
    int inBrackets = 0;
    StringBuffer bracketContents = new StringBuffer();
    for (int i = 0; i < chars.length; i++) {
        if (chars[i] == '(')
            inBrackets++;//ww w. ja va2  s.  c om
        if (chars[i] == ')')
            inBrackets--;

        if (Character.isLetterOrDigit(chars[i])) {
            if (inBrackets > 0) {
                //buffer everthing in brackets
                bracketContents.append(chars[i]);
            } else {
                //add capitalized bracketed text if appropriate 
                if (bracketContents.length() > 0) {
                    aName.append(capitalize(filterBracketedText(bracketContents.toString())));
                    bracketContents = new StringBuffer();
                }
                if (lastCharWasNotLetter) {
                    //first letter of each word is upper-case
                    aName.append(Character.toUpperCase(chars[i]));
                } else {
                    aName.append(chars[i]);
                }
                lastCharWasNotLetter = false;
            }
        } else {
            lastCharWasNotLetter = true;
        }
    }
    aName.append(capitalize(filterBracketedText(bracketContents.toString())));
    String retVal = aName.toString();

    return retVal;
}

From source file:com.manydesigns.elements.fields.search.SelectSearchField.java

private void valueToXhtmlDropDown(XhtmlBuffer xb) {
    xb.writeLabel(StringUtils.capitalize(label), id, ATTR_NAME_HTML_CLASS);

    xb.openElement("div");
    xb.addAttribute("class", "controls");
    Object[] values = getValues();
    Map<Object, SelectionModel.Option> options = selectionModel.getOptions(selectionModelIndex);
    xb.openElement("select");
    xb.addAttribute("id", id);
    xb.addAttribute("name", inputName);

    boolean selected = (values == null && !notSet);
    if (!options.isEmpty()) {
        xb.writeOption("", selected, comboLabel);
        if (!required) {
            xb.writeOption(VALUE_NOT_SET, notSet, notSetLabel);
        }//from   w  ww  .jav a2 s  .c o  m
    }

    for (Map.Entry<Object, SelectionModel.Option> option : options.entrySet()) {
        //#1318 include inactive options, because they must be searchable.
        Object optionValue = option.getKey();
        String optionStringValue = OgnlUtils.convertValueToString(optionValue);
        String optionLabel = option.getValue().label;
        selected = ArrayUtils.contains(values, optionValue);
        xb.writeOption(optionStringValue, selected, optionLabel);
    }
    xb.closeElement("select");

    if (nextSelectField != null) {
        String js = composeDropDownJs();
        xb.writeJavaScript(js);
    }

    xb.closeElement("div");
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.AbstractTableLoader.java

protected void addDynamicAttributes(Table component, Datasource ds, List<Table.Column> availableColumns) {
    if (metadataTools.isPersistent(ds.getMetaClass())) {
        Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools
                .getAttributesToShowOnTheScreen(ds.getMetaClass(), context.getFullFrameId(), component.getId());
        if (CollectionUtils.isNotEmpty(attributesToShow)) {
            ds.setLoadDynamicAttributes(true);
            for (CategoryAttribute attribute : attributesToShow) {
                final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils
                        .getMetaPropertyPath(ds.getMetaClass(), attribute);

                Object columnWithSameId = IterableUtils.find(availableColumns,
                        o -> o.getId().equals(metaPropertyPath));

                if (columnWithSameId != null) {
                    continue;
                }//  ww  w .ja v a 2s.  c o  m

                final Table.Column column = new Table.Column(metaPropertyPath);

                column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames())
                        ? attribute.getLocaleName()
                        : StringUtils.capitalize(attribute.getName()));

                if (attribute.getDataType().equals(PropertyType.STRING)) {
                    column.setMaxTextLength(clientConfig.getDynamicAttributesTableColumnMaxTextLength());
                }

                if (attribute.getDataType().equals(PropertyType.ENUMERATION)) {
                    column.setFormatter(value -> LocaleHelper.getEnumLocalizedValue((String) value,
                            attribute.getEnumerationLocales()));
                }
                component.addColumn(column);
            }
        }

        dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
    }
}

From source file:com.google.gdt.eclipse.designer.gxt.databinding.wizards.autobindings.GxtDatabindingProvider.java

public String performSubstitutions(String code, ImportsManager imports) throws Exception {
    // bean class, field, name, field access
    String beanClassName = m_beanClass.getName().replace('$', '.');
    String beanClassShortName = ClassUtils.getShortClassName(beanClassName);
    String fieldPrefix = JavaCore.getOption(JavaCore.CODEASSIST_FIELD_PREFIXES);
    String fieldName = fieldPrefix + StringUtils.uncapitalize(beanClassShortName);
    ////www . j  a v a2s. c  om
    Collection<String> importList = Sets.newHashSet();
    //
    final List<PropertyAdapter> properties = Lists.newArrayList();
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            m_packageName = m_firstPage.getPackageFragment().getElementName();
            CollectionUtils.addAll(properties, m_propertiesViewer.getCheckedElements());
        }
    });
    //
    if (!ClassUtils.getPackageName(beanClassName).equals(m_packageName)) {
        importList.add(beanClassName);
    }
    beanClassName = beanClassShortName;
    //
    code = StringUtils.replace(code, "%BeanClass%", beanClassName);
    //
    if (ReflectionUtils.getConstructorBySignature(m_beanClass, "<init>()") == null) {
        code = StringUtils.replace(code, "%BeanField%", fieldName);
    } else {
        code = StringUtils.replace(code, "%BeanField%", fieldName + " = new " + beanClassName + "()");
    }
    //
    IPreferenceStore preferences = ToolkitProvider.DESCRIPTION.getPreferences();
    String accessPrefix = preferences.getBoolean(FieldUniqueVariableSupport.P_PREFIX_THIS) ? "this." : "";
    String beanFieldAccess = accessPrefix + fieldName;
    //
    code = StringUtils.replace(code, "%BeanFieldAccess%", beanFieldAccess);
    code = StringUtils.replace(code, "%BeanName%", StringUtils.capitalize(beanClassShortName));
    //
    boolean useGenerics = CoreUtils.useGenerics(m_javaProject);
    //
    StringBuffer fieldsCode = new StringBuffer();
    StringBuffer widgetsCode = new StringBuffer();
    StringBuffer bindingsCode = new StringBuffer();
    //
    for (Iterator<PropertyAdapter> I = properties.iterator(); I.hasNext();) {
        PropertyAdapter property = I.next();
        Object[] editorData = m_propertyToEditor.get(property);
        GxtWidgetDescriptor widgetDescriptor = (GxtWidgetDescriptor) editorData[0];
        //
        String propertyName = property.getName();
        String widgetClassName = ClassUtils.getShortClassName(widgetDescriptor.getWidgetClass());
        String widgetFieldName = fieldPrefix + propertyName + widgetClassName;
        String widgetFieldAccess = accessPrefix + widgetFieldName;
        //
        if (useGenerics && widgetDescriptor.isGeneric()) {
            widgetClassName += "<" + convertTypes(property.getType().getName()) + ">";
        }
        //
        fieldsCode.append("\r\nfield\r\n\tprivate " + widgetClassName + " " + widgetFieldName + ";");
        //
        widgetsCode.append("\t\t" + widgetFieldName + " = new " + widgetClassName + "();\r\n");
        widgetsCode.append("\t\t" + widgetFieldAccess + ".setFieldLabel(\""
                + StringUtils.capitalize(propertyName) + "\");\r\n");
        widgetsCode.append("\t\t" + accessPrefix + "m_formPanel.add(" + widgetFieldAccess
                + ", new FormData(\"100%\"));\r\n");
        widgetsCode.append("\t\t//");
        //
        importList.add(widgetDescriptor.getBindingClass());
        bindingsCode.append("\t\tm_formBinding.addFieldBinding(new "
                + ClassUtils.getShortClassName(widgetDescriptor.getBindingClass()) + "(" + widgetFieldAccess
                + ",\"" + propertyName + "\"));\r\n");
        //
        importList.add(widgetDescriptor.getWidgetClass());
        //
        if (I.hasNext()) {
            fieldsCode.append("\r\n");
            widgetsCode.append("\r\n");
        }
    }
    //
    bindingsCode.append("\t\t//\r\n");
    bindingsCode.append("\t\tm_formBinding.bind(" + beanFieldAccess + ");");
    // replace template patterns
    code = StringUtils.replace(code, "%WidgetFields%", fieldsCode.toString());
    code = StringUtils.replace(code, "%Widgets%", widgetsCode.toString());
    code = StringUtils.replace(code, "%Bindings%", bindingsCode.toString());
    // add imports
    for (String qualifiedTypeName : importList) {
        imports.addImport(qualifiedTypeName);
    }
    //
    return code;
}

From source file:com.manydesigns.elements.fields.AbstractField.java

public void labelToXhtml(XhtmlBuffer xb) {
    if (StringUtils.isBlank(label)) {
        return;// w  w w  . j a v  a  2  s . c  o m
    }

    xb.openElement("label");
    if (!mode.isView(insertable, updatable)) {
        xb.addAttribute("for", id); //HTML5 validation
    }
    xb.addAttribute("class", FORM_LABEL_CLASS);
    if (mode.isBulk() && mode.isEdit() && !mode.isView(insertable, updatable)) {
        xb.writeInputCheckbox(null, bulkCheckboxName, "checked", bulkChecked, false, "pull-left");
    }
    String actualLabel;
    boolean capitalize = elementsConfiguration.getBoolean(ElementsProperties.FIELDS_LABEL_CAPITALIZE);
    if (capitalize) {
        actualLabel = StringUtils.capitalize(label);
    } else {
        actualLabel = label;
    }
    xb.write(actualLabel);
    xb.closeElement("label");
}

From source file:com.frameworkset.orm.engine.model.Column.java

/**
 * Get name to use in Java sources to build method names.
 *
 * @return the capitalised javaName//from   w  w w  . j  a  v  a2 s .  c  o  m
 */
public String getJavaName() {
    if (javaName == null) {
        List inputs = new ArrayList(2);
        inputs.add(name);
        inputs.add(javaNamingMethod);
        try {
            javaName = NameFactory.generateName(NameFactory.JAVA_GENERATOR, inputs, false);
        } catch (EngineException e) {
            log.error(e, e);
        }
    }
    return StringUtils.capitalize(javaName);
}

From source file:com.alibaba.jstorm.ui.model.pages.ComponentPage.java

public TableData getTaskSummary(ComponentSummary componentSummary, List<TaskSummary> tasks,
        Map<String, String> paramMap, String topologyId, Map<String, Object> nimbusConf,
        List<TaskSummary> showTasks) {
    TableData table = new TableData();
    List<String> headers = table.getHeaders();
    List<Map<String, ColumnData>> lines = table.getLines();
    table.setName("Tasks");

    headers.add(UIDef.HEADER_TASK_ID);/*from   w w w .java  2  s  .c  om*/
    headers.add(UIDef.HEADER_STATUS);
    headers.add(UIDef.HEADER_UPTIME);
    headers.add(StringUtils.capitalize(UIDef.HOST));
    headers.add(StringUtils.capitalize(UIDef.PORT));
    headers.add(UIDef.HEADER_LOG);
    headers.add(UIDef.HEADER_ERROR);

    List<Integer> taskIds = componentSummary.get_task_ids();
    Set<Integer> taskIdSet = new HashSet<Integer>();
    taskIdSet.addAll(taskIds);

    long pos = JStormUtils.parseLong(paramMap.get(UIDef.POS), 0);
    long index = 0;

    Collections.sort(tasks);
    for (TaskSummary task : tasks) {

        Integer taskId = task.get_task_id();
        if (taskIdSet.contains(taskId) == false) {
            continue;
        }

        if (index < pos) {
            index++;
            continue;
        } else if (pos <= index && index < pos + UIUtils.ONE_TABLE_PAGE_SIZE) {
            showTasks.add(task);
            taskIdSet.remove(taskId);
            index++;
        } else {
            break;
        }

    }

    int logPort = ConfigExtension.getSupervisorDeamonHttpserverPort(nimbusConf);
    for (TaskSummary task : showTasks) {
        Map<String, ColumnData> line = new HashMap<String, ColumnData>();
        lines.add(line);

        ColumnData taskIdColumn = new ColumnData();
        taskIdColumn.addText(String.valueOf(task.get_task_id()));
        line.put(UIDef.HEADER_TASK_ID, taskIdColumn);

        ColumnData statusColumn = new ColumnData();
        statusColumn.addText(task.get_status());
        line.put(UIDef.HEADER_STATUS, statusColumn);

        ColumnData uptimeColumn = new ColumnData();
        int uptime = task.get_uptime();
        uptimeColumn.addText(StatBuckets.prettyUptimeStr(uptime));
        line.put(UIDef.HEADER_UPTIME, uptimeColumn);

        ColumnData hostColumn = new ColumnData();
        LinkData linkData = new LinkData();
        hostColumn.addLinkData(linkData);
        line.put(StringUtils.capitalize(UIDef.HOST), hostColumn);

        linkData.setUrl(UIDef.LINK_TABLE_PAGE);
        linkData.setText(NetWorkUtils.ip2Host(task.get_host()));
        linkData.addParam(UIDef.CLUSTER, paramMap.get(UIDef.CLUSTER));
        linkData.addParam(UIDef.PAGE_TYPE, UIDef.PAGE_TYPE_SUPERVISOR);
        linkData.addParam(UIDef.HOST, task.get_host());

        ColumnData portColumn = new ColumnData();
        portColumn.addText(String.valueOf(task.get_port()));
        line.put(StringUtils.capitalize(UIDef.PORT), portColumn);

        ColumnData logColumn = new ColumnData();
        LinkData logLink = new LinkData();
        logColumn.addLinkData(logLink);
        line.put(UIDef.HEADER_LOG, logColumn);

        logLink.setUrl(UIDef.LINK_LOG);
        logLink.setText(UIDef.HEADER_LOG.toLowerCase());
        logLink.addParam(UIDef.CLUSTER, paramMap.get(UIDef.CLUSTER));
        logLink.addParam(UIDef.PAGE_TYPE, UIDef.PAGE_TYPE_LOG);
        logLink.addParam(UIDef.HOST, task.get_host());
        logLink.addParam(UIDef.TOPOLOGY, topologyId);
        logLink.addParam(UIDef.PORT, String.valueOf(task.get_port()));
        logLink.addParam(UIDef.LOG_SERVER_PORT, String.valueOf(logPort));

        ColumnData errColumn = new ColumnData();
        List<ErrorInfo> errList = task.get_errors();
        if (errList == null || errList.size() == 0) {
            errColumn.addText("");
        } else {
            for (ErrorInfo err : errList) {
                errColumn.addText(err.get_error() + "\r\n");
            }
        }
        line.put(UIDef.HEADER_ERROR, errColumn);
    }

    return table;

}

From source file:com.ecyrd.management.SimpleMBean.java

public void setAttribute(Attribute attr)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Method m;//from   ww w.ja v  a 2s  . c  o  m

    String mname = "set" + StringUtils.capitalize(attr.getName());
    m = findGetterSetter(getClass(), mname, attr.getValue().getClass());

    if (m == null)
        throw new AttributeNotFoundException(attr.getName());

    Object[] args = { attr.getValue() };

    try {
        m.invoke(this, args);
    } catch (IllegalArgumentException e) {
        throw new InvalidAttributeValueException("Faulty argument: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e, "Cannot access attribute " + e.getMessage());
    } catch (InvocationTargetException e) {
        throw new ReflectionException(e, "Cannot invoke attribute " + e.getMessage());
    }
}

From source file:com.aol.advertising.qiao.util.ContextUtils.java

/**
 * A simple call to invoke a class method.
 *
 * @param object//from ww  w .jav  a2s . c  om
 *            the target object to invoke the method on
 * @param fieldName
 *            the field whose set method to be invoked
 * @param param
 *            the invocation argument
 * @throws BeansException
 * @throws ClassNotFoundException
 */
public static void injectMethod(Object object, String fieldName, Object param)
        throws BeansException, ClassNotFoundException {
    String mth_name = "set" + StringUtils.capitalize(fieldName);

    Method mth = findMethod(object.getClass(), mth_name, param.getClass());

    if (mth != null) {
        ReflectionUtils.invokeMethod(mth, object, param);
    } else {
        String err = String.format(ERR_METHOD_NOTFOUND, mth_name, param.getClass().getSimpleName(),
                object.getClass().getSimpleName());
        logger.error(err);
        throw new MethodNotFoundException(err);
    }
}