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:gov.nih.nci.cabig.caaers.domain.expeditedfields.ExpeditedReportTree.java

/**
 * Creates the person block.//from   w  w w. ja v a2s .  com
 *
 * @param person the person
 * @return the tree node
 */
private TreeNode createPersonBlock(String person) {
    TreeNode t = property(person, StringUtils.capitalize(person) + " details",
            property("title", getMessage("LBL_aeReport." + person + ".title", "Position title")),
            property("firstName", getMessage("LBL_aeReport." + person + ".firstName", "First name")),
            property("middleName", getMessage("LBL_aeReport." + person + ".middleName", "Middle name")),
            property("lastName", getMessage("LBL_aeReport." + person + ".lastName", "Last name")),
            contactField(ReportPerson.EMAIL,
                    getMessage("LBL_aeReport." + person + ".contactMechanisms[e-mail]", "E-mail address")),
            contactField(ReportPerson.PHONE,
                    getMessage("LBL_aeReport." + person + ".contactMechanisms[phone]", "Phone")),
            contactField(ReportPerson.FAX,
                    getMessage("LBL_aeReport." + person + ".contactMechanisms[fax]", "Fax")),
            property("address", getMessage("LBL_aeReport." + person + ".address", "Address"),
                    property("street", getMessage("LBL_aeReport." + person + ".address.street", "Street")),
                    property("city", getMessage("LBL_aeReport." + person + ".address.city", "City")),
                    property("state", getMessage("LBL_aeReport." + person + ".address.state", "State")),
                    property("zip", getMessage("LBL_aeReport." + person + ".address.zip", "Zip"))));
    if (person.equals("reporter")) {
        t.add(contactField(ReportPerson.ALT_EMAIL,
                getMessage("LBL_aeReport." + person + ".alternateEmail", "Alternate Email")));
    }

    return t;
}

From source file:ml.shifu.shifu.fs.PathFinder.java

public String getEncodeDataPath(EvalConfig evalConfig) {
    if (evalConfig == null) {
        return getPathBySourceType(new Path(Constants.TMP, Constants.TRAIN_DATA_ENCODE_PATH), SourceType.HDFS);
    } else {//from  w  w  w  . j  a  va  2s . c o  m
        return getPathBySourceType(
                new Path(Constants.TMP,
                        Constants.EVAL_DATA_ENCODE_PREFIX + StringUtils.capitalize(evalConfig.getName())),
                SourceType.HDFS);
    }
}

From source file:com.doculibre.constellio.services.IndexFieldServicesImpl.java

@Override
public Map<String, String> getDefaultLabelledValues(IndexField indexField, Locale locale) {
    Map<String, String> labels = new HashMap<String, String>();
    String indexFieldName = indexField.getName();
    if (IndexField.COLLECTION_ID_FIELD.equals(indexFieldName)) {
        RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
        for (RecordCollection collection : collectionServices.list()) {
            Locale displayLocale = collection.getDisplayLocale(locale);
            labels.put("" + collection.getId(), collection.getTitle(displayLocale));
        }/*from  www. jav  a 2 s  . co m*/
    } else if (IndexField.CONNECTOR_INSTANCE_ID_FIELD.equals(indexFieldName)) {
        ConnectorInstanceServices connectorInstanceServices = ConstellioSpringUtils
                .getConnectorInstanceServices();
        for (ConnectorInstance connectorInstance : connectorInstanceServices.list()) {
            labels.put("" + connectorInstance.getId(), connectorInstance.getDisplayName());
        }
    } else if (IndexField.CONNECTOR_TYPE_ID_FIELD.equals(indexFieldName)) {
        ConnectorTypeServices connectorTypeServices = ConstellioSpringUtils.getConnectorTypeServices();
        for (ConnectorType connectorType : connectorTypeServices.list()) {
            labels.put("" + connectorType.getId(), connectorType.getName());
        }
    } else if (IndexField.LANGUAGE_FIELD.equals(indexFieldName)) {
        for (Locale availableLocale : Locale.getAvailableLocales()) {
            labels.put(availableLocale.getLanguage(),
                    StringUtils.capitalize(availableLocale.getDisplayLanguage(locale)));
        }
    } else if (IndexField.MIME_TYPE_FIELD.equals(indexFieldName)) {
        // Source : http://www.w3schools.com/media/media_mimeref.asp
        String prefix = "mimeType.";
        Set<String> mimeTypeResourceKeys = ResourceBundleUtils.getKeys(prefix, ApplicationResources.class);
        for (String mimeTypeResourceKey : mimeTypeResourceKeys) {
            String mimeType = mimeTypeResourceKey.substring(prefix.length());
            String mimeTypeLabel = ResourceBundleUtils.getString(mimeTypeResourceKey, locale,
                    ApplicationResources.class);
            labels.put(mimeType, mimeTypeLabel);
        }
    }
    return labels;
}

From source file:gov.nih.nci.cabig.caaers.domain.expeditedfields.ExpeditedReportTree.java

/**
 * Participant measure.//from  www  . jav  a  2  s  . c  o m
 *
 * @param baseName the base name
 * @return the tree node
 */
private TreeNode participantMeasure(String baseName) {
    return property(baseName, StringUtils.capitalize(baseName),
            property("quantity",
                    getMessage("LBL_aeReport.participantHistory." + baseName + ".quantity", "Quantity")),
            property("unit", getMessage("LBL_aeReport.participantHistory.measure.units", "Units")));
}

From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java

@Override
public void setDatasource(final CollectionDatasource datasource) {
    Preconditions.checkNotNullArgument(datasource, "datasource is null");

    if (this.datasource != null) {
        if (!this.datasource.getMetaClass().equals(datasource.getMetaClass())) {
            throw new IllegalArgumentException("The new datasource must correspond to the same MetaClass");
        }/*from   w  w w . j ava 2s  .  co  m*/

        if (fieldDatasources != null) {
            fieldDatasources.clear();
        }

        if (collectionDsListenersWrapper != null) {
            collectionDsListenersWrapper.unbind(this.datasource);
            if (containerDatasource != null) {
                containerDatasource.unsubscribe();
                containerDatasource = null;
            }
        }
    }

    MessageTools messageTools = AppBeans.get(MessageTools.NAME);

    final Collection<Object> columns;
    if (this.columns.isEmpty()) {
        Collection<MetaPropertyPath> paths = datasource.getView() != null ?
        // if a view is specified - use view properties
                metadataTools.getViewPropertyPaths(datasource.getView(), datasource.getMetaClass()) :
                // otherwise use all properties from meta-class
                metadataTools.getPropertyPaths(datasource.getMetaClass());
        for (MetaPropertyPath metaPropertyPath : paths) {
            MetaProperty property = metaPropertyPath.getMetaProperty();
            if (!property.getRange().getCardinality().isMany() && !metadataTools.isSystem(property)) {
                Table.Column column = new Table.Column(metaPropertyPath);

                String propertyName = property.getName();
                MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);

                column.setCaption(messageTools.getPropertyCaption(propertyMetaClass, propertyName));
                column.setType(metaPropertyPath.getRangeJavaClass());

                Element element = DocumentHelper.createElement("column");
                column.setXmlDescriptor(element);

                addColumn(column);
            }
        }
    }
    columns = this.columns.keySet();

    this.datasource = datasource;

    if (collectionDsListenersWrapper == null) {
        collectionDsListenersWrapper = createCollectionDsListenersWrapper();
    }

    containerDatasource = createContainerDatasource(datasource, getPropertyColumns(),
            collectionDsListenersWrapper);

    component.setContainerDataSource(containerDatasource);

    List<MetaPropertyPath> editableColumns = null;
    if (isEditable()) {
        editableColumns = new LinkedList<>();
    }

    MetaClass metaClass = datasource.getMetaClass();
    for (final Object columnId : columns) {
        final Table.Column column = this.columns.get(columnId);

        final String caption;
        if (column != null) {
            caption = getColumnCaption(columnId, column);
        } else {
            caption = StringUtils.capitalize(getColumnCaption(columnId));
        }

        setColumnHeader(columnId, caption);

        if (column != null) {
            if (editableColumns != null && column.isEditable() && (columnId instanceof MetaPropertyPath)) {
                MetaPropertyPath propertyPath = ((MetaPropertyPath) columnId);
                if (security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString())) {
                    editableColumns.add(propertyPath);
                }
            }

            if (column.isCollapsed() && component.isColumnCollapsingAllowed()) {
                if (!(columnId instanceof MetaPropertyPath)
                        || security.isEntityAttrReadPermitted(metaClass, columnId.toString())) {
                    component.setColumnCollapsed(column.getId(), true);
                }
            }

            if (column.getAggregation() != null && isAggregatable()) {
                checkAggregation(column.getAggregation());

                component.addContainerPropertyAggregation(column.getId(),
                        WebComponentsHelper.convertAggregationType(column.getAggregation().getType()));
            }
        }
    }

    if (editableColumns != null && !editableColumns.isEmpty()) {
        setEditableColumns(editableColumns);
    }

    createColumns(containerDatasource);

    for (Table.Column column : this.columnsOrder) {
        if (editable && column.getAggregation() != null
                && (BooleanUtils.isTrue(column.isEditable()) || BooleanUtils.isTrue(column.isCalculatable()))) {
            addAggregationCell(column);
        }
    }

    createStubsForGeneratedColumns();

    setVisibleColumns(getInitialVisibleColumns());

    if (security.isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION)) {
        ShowInfoAction action = (ShowInfoAction) getAction(ShowInfoAction.ACTION_ID);
        if (action == null) {
            action = new ShowInfoAction();
            addAction(action);
        }
        action.setDatasource(datasource);
    }

    if (rowsCount != null) {
        rowsCount.setDatasource(datasource);
    }

    collectionDsListenersWrapper.bind(datasource);

    for (Action action : getActions()) {
        action.refreshState();
    }

    if (!canBeSorted(datasource))
        setSortable(false);

    assignAutoDebugId();
}

From source file:au.org.ala.biocache.web.WMSController.java

@RequestMapping(value = { "/ogc/getMetadata" }, method = RequestMethod.GET)
public String getMetadata(@RequestParam(value = "LAYER", required = false, defaultValue = "") String layer,
        @RequestParam(value = "q", required = false, defaultValue = "") String query,
        HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {

    //System.out.println("GETMETADATA: " + request.getQueryString());

    String taxonName = "";
    String rank = "";
    String q = "";
    if (StringUtils.trimToNull(layer) != null) {
        String[] parts = layer.split(":");
        taxonName = parts[parts.length - 1];
        if (parts.length > 1) {
            rank = parts[0];//from www  .j  ava 2 s  . c om
        }
        q = layer;
    } else if (StringUtils.trimToNull(query) != null) {
        String[] parts = query.split(":");
        taxonName = parts[parts.length - 1];
        if (parts.length > 1) {
            rank = parts[0];
        }
        q = query;
    } else {
        response.sendError(400);
    }

    //http://bie.ala.org.au/ws/guid/Carcharodon%20carcharias  - get the guid
    ObjectMapper om = new ObjectMapper();
    String guid = null;
    JsonNode guidLookupNode = om
            .readTree(new URL("http://bie.ala.org.au/ws/guid/" + URLEncoder.encode(taxonName, "UTF-8")));
    //NC: Fixed the ArraryOutOfBoundsException when the lookup fails to yield a result
    if (guidLookupNode.isArray() && guidLookupNode.size() > 0) {
        JsonNode idNode = guidLookupNode.get(0).get("acceptedIdentifier");//NC: changed to used the acceptedIdentifier because this will always hold the guid for the accepted taxon concept whether or not a synonym name is provided
        guid = idNode != null ? idNode.asText() : null;
    }
    String newQuery = "raw_name:" + taxonName;
    if (guid != null) {

        model.addAttribute("guid", guid);
        model.addAttribute("speciesPageUrl", "http://bie.ala.org.au/species/" + guid);
        JsonNode node = om.readTree(new URL("http://bie.ala.org.au/ws/species/info/" + guid + ".json"));
        JsonNode tc = node.get("taxonConcept");
        JsonNode imageNode = tc.get("smallImageUrl");
        String imageUrl = imageNode != null ? imageNode.asText() : null;
        if (imageUrl != null) {
            model.addAttribute("imageUrl", imageUrl);
            JsonNode imageMetadataNode = node.get("taxonConcept").get("imageMetadataUrl");
            String imageMetadataUrl = imageMetadataNode != null ? imageMetadataNode.asText() : null;

            //image metadata
            JsonNode imageMetadata = om.readTree(new URL(imageMetadataUrl));
            if (imageMetadata != null) {
                if (imageMetadata.get("http://purl.org/dc/elements/1.1/creator") != null)
                    model.addAttribute("imageCreator",
                            imageMetadata.get("http://purl.org/dc/elements/1.1/creator").asText());
                if (imageMetadata.get("http://purl.org/dc/elements/1.1/license") != null)
                    model.addAttribute("imageLicence",
                            imageMetadata.get("http://purl.org/dc/elements/1.1/license").asText());
                if (imageMetadata.get("http://purl.org/dc/elements/1.1/source") != null)
                    model.addAttribute("imageSource",
                            imageMetadata.get("http://purl.org/dc/elements/1.1/source").asText());
            }
        }

        JsonNode leftNode = tc.get("left");
        JsonNode rightNode = tc.get("right");
        newQuery = leftNode != null && rightNode != null
                ? "lft:[" + leftNode.asText() + " TO " + rightNode.asText() + "]"
                : "taxon_concept_lsid:" + guid;
        logger.debug("The new query : " + newQuery);

        //common name
        JsonNode commonNameNode = tc.get("commonNameSingle");
        if (commonNameNode != null) {
            model.addAttribute("commonName", commonNameNode.asText());
            logger.debug("retrieved name: " + commonNameNode.asText());
        }

        //name
        JsonNode nameNode = tc.get("nameComplete");
        if (nameNode != null) {
            model.addAttribute("name", nameNode.asText());
            logger.debug("retrieved name: " + nameNode.asText());
        }

        //authorship
        JsonNode authorshipNode = node.get("taxonConcept").get("author");
        if (authorshipNode != null)
            model.addAttribute("authorship", authorshipNode.asText());

        //taxonomic information
        JsonNode node2 = om.readTree(new URL("http://bie.ala.org.au/ws/species/" + guid + ".json"));
        JsonNode classificationNode = node2.get("classification");
        model.addAttribute("kingdom",
                StringUtils.capitalize(classificationNode.get("kingdom").asText().toLowerCase()));
        model.addAttribute("phylum",
                StringUtils.capitalize(classificationNode.get("phylum").asText().toLowerCase()));
        model.addAttribute("clazz",
                StringUtils.capitalize(classificationNode.get("clazz").asText().toLowerCase()));
        model.addAttribute("order",
                StringUtils.capitalize(classificationNode.get("order").asText().toLowerCase()));
        model.addAttribute("family",
                StringUtils.capitalize(classificationNode.get("family").asText().toLowerCase()));
        model.addAttribute("genus", classificationNode.get("genus").asText());

        JsonNode taxonNameNode = node2.get("taxonName");
        if (taxonNameNode != null && taxonNameNode.get("specificEpithet") != null) {
            model.addAttribute("specificEpithet", taxonNameNode.get("specificEpithet").asText());
        }
    }

    SpatialSearchRequestParams searchParams = new SpatialSearchRequestParams();
    searchParams.setQ(newQuery);
    searchParams.setFacets(new String[] { "data_resource" });
    searchParams.setPageSize(0);
    List<FacetResultDTO> facets = searchDAO.getFacetCounts(searchParams);
    model.addAttribute("query", newQuery); //need a facet on data providers
    model.addAttribute("dataProviders", facets.get(0).getFieldResult()); //need a facet on data providers
    return "metadata/mcp";
}

From source file:mrcg.MRCGInstance.java

private void createEnums() throws Exception {
    for (JavaClass jc : types.values()) {
        if (jc.isEnum()) {
            JavaEnum je = (JavaEnum) jc;
            jc.setPreExisting(!jc.getCompleteName().startsWith(basePackage));
            if (jc.isPreExisting())
                continue;
            jc.setPreExisting(getBoolean("enums." + je.getName() + ".preexisting", false));

            JavaField jf = new JavaField(JavaType.STRING, "name");
            jf.setType(JavaType.STRING);
            jf.setDbType(DBType.Varchar);
            je.addField(jf);/*from ww w.  j  av a2  s .  co  m*/
            je.addMethod(new JavaGetter(jf));

            JavaConstructor jcon = new JavaConstructor(je.getJavaType());
            jcon.setVisibility(Visibility.Private);
            jcon.addParameter(new JavaParameter(JavaType.STRING, "name"));
            jcon.setBody("\t\tthis.name = name;");
            je.addConstructor(jcon);

            JavaMethod getcode = new JavaMethod(JavaType.STRING, "getCode");
            getcode.setBody("\t\treturn toString();");
            je.addMethod(getcode);

            JavaMethod aci = new JavaMethod(JavaType.OBJECT, "getIdentifierLabel");
            aci.setBody("\t\treturn name;");
            je.addMethod(aci);

            int maxCodeLength = 0;
            int maxNameLength = 0;
            Object object = getValue("enums." + jc.getName());
            if (object instanceof Map) {
                Map<String, Object> map = getMap("enums." + jc.getName());
                for (String key : map.keySet()) {
                    if ("preexisting".equals(key))
                        continue;
                    maxCodeLength = Math.max(maxCodeLength, key.toString().length());
                    maxNameLength = Math.max(maxNameLength, map.get(key).toString().length());
                    je.addValue(new JavaEnumValue(key, map.get(key).toString()));
                }
            } else if (object instanceof List) {
                List<Object> values = getList("enums." + jc.getName());
                for (Object value : values) {
                    if (value instanceof String) {
                        if ("preexisting".equals(value.toString()))
                            continue;
                        maxCodeLength = Math.max(maxCodeLength, value.toString().length());
                        maxNameLength = Math.max(maxNameLength, value.toString().length());
                        je.addValue(new JavaEnumValue(value.toString(),
                                Utils.toSpacedCamelCase(StringUtils.capitalize(value.toString()))));
                    } else if (value instanceof Map) {
                        Map<String, Object> map = toMap(value);
                        for (String key : map.keySet()) {
                            if ("preexisting".equals(key))
                                continue;
                            maxCodeLength = Math.max(maxCodeLength, key.toString().length());
                            maxNameLength = Math.max(maxNameLength, map.get(key).toString().length());
                            je.addValue(new JavaEnumValue(key, map.get(key).toString()));
                        }
                    }
                }
            }

            je.setMaxCodeLength(maxCodeLength);
            jf.setMaxLength(maxNameLength);
        }
    }
}

From source file:it.eng.spagobi.meta.initializer.BusinessModelInitializer.java

public static String beutfyName(String name) {
    return StringUtils.capitalize(name.replace("_", " "));
}

From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java

protected String getColumnCaption(Object columnId, Column column) {
    String caption = column.getCaption();

    if (caption != null) {
        return caption;
    }/*from  www. j av  a  2 s. co m*/

    if (!(columnId instanceof MetaPropertyPath)) {
        return StringUtils.capitalize(getColumnCaption(columnId));
    }

    MetaPropertyPath mpp = (MetaPropertyPath) columnId;
    MetaProperty metaProperty = mpp.getMetaProperty();

    if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
        CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
        if (LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())) {
            return categoryAttribute.getLocaleName();
        }

        caption = StringUtils.capitalize(categoryAttribute.getName());
    } else {
        caption = StringUtils.capitalize(getColumnCaption(columnId));
    }

    return caption;
}

From source file:com.doculibre.constellio.services.SolrServicesImpl.java

@SuppressWarnings("rawtypes")
private static void setProperty(Element element, String attributeName, ConstellioEntity entity) {
    try {/*from  ww w  . j a  va 2s .  c  o  m*/
        Method getter = findGetter(entity.getClass(), attributeName);
        Class returnType = getter.getReturnType();
        String setterName = "set" + StringUtils.capitalize(attributeName);
        Method setter = entity.getClass().getMethod(setterName, returnType);

        String attributeValue = element.attributeValue(attributeName);
        Object setterValue;
        if (StringUtils.isEmpty(attributeValue)) {
            if (boolean.class.equals(returnType)) {
                setterValue = false;
            } else if (int.class.equals(returnType)) {
                setterValue = 0;
            } else if (returnType.isPrimitive()) {
                throw new UnsupportedOperationException(setterName + "(" + returnType + ")");
            } else {
                setterValue = null;
            }
        } else if (boolean.class.equals(returnType) || Boolean.class.equals(returnType)) {
            setterValue = Boolean.valueOf(attributeValue);
        } else if (int.class.equals(returnType) || Integer.class.equals(returnType)) {
            setterValue = Integer.valueOf(attributeValue);
        } else if (String.class.equals(returnType)) {
            setterValue = attributeValue;
        } else {
            throw new UnsupportedOperationException(setterName + "(" + returnType + ")");
        }
        setter.invoke(entity, setterValue);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}