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:com.haulmont.cuba.gui.xml.layout.loaders.AbstractTableLoader.java

protected Table.Column loadColumn(Element element, Datasource ds) {
    String id = element.attributeValue("id");

    MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class)
            .resolveMetaPropertyPath(ds.getMetaClass(), id);

    Table.Column column = new Table.Column(metaPropertyPath != null ? metaPropertyPath : id);

    String editable = element.attributeValue("editable");
    if (StringUtils.isNotEmpty(editable)) {
        column.setEditable(Boolean.parseBoolean(editable));
    }/*from   w  ww  .  j  a  v a 2  s  .c o m*/

    String collapsed = element.attributeValue("collapsed");
    if (StringUtils.isNotEmpty(collapsed)) {
        column.setCollapsed(Boolean.parseBoolean(collapsed));
    }

    String groupAllowed = element.attributeValue("groupAllowed");
    if (StringUtils.isNotEmpty(groupAllowed)) {
        column.setGroupAllowed(Boolean.parseBoolean(groupAllowed));
    }

    String sortable = element.attributeValue("sortable");
    if (StringUtils.isNotEmpty(sortable)) {
        column.setSortable(Boolean.parseBoolean(sortable));
    }

    loadCaption(column, element);
    loadDescription(column, element);

    if (column.getCaption() == null) {
        String columnCaption;
        if (column.getId() instanceof MetaPropertyPath) {
            MetaPropertyPath mpp = (MetaPropertyPath) column.getId();
            MetaProperty metaProperty = mpp.getMetaProperty();
            String propertyName = metaProperty.getName();

            if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
                CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);

                columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())
                        ? categoryAttribute.getLocaleName()
                        : StringUtils.capitalize(categoryAttribute.getName());
            } else {
                MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(mpp);
                columnCaption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
            }
        } else {
            Class<?> declaringClass = ds.getMetaClass().getJavaClass();
            String className = declaringClass.getName();
            int i = className.lastIndexOf('.');
            if (i > -1)
                className = className.substring(i + 1);
            columnCaption = messages.getMessage(declaringClass, className + "." + id);
        }
        column.setCaption(columnCaption);
    }

    column.setXmlDescriptor(element);
    if (metaPropertyPath != null)
        column.setType(metaPropertyPath.getRangeJavaClass());

    String width = loadThemeString(element.attributeValue("width"));
    if (!StringUtils.isBlank(width)) {
        if (StringUtils.endsWith(width, "px")) {
            width = StringUtils.substring(width, 0, width.length() - 2);
        }
        try {
            column.setWidth(Integer.parseInt(width));
        } catch (NumberFormatException e) {
            throw new GuiDevelopmentException("Property 'width' must contain only numeric value",
                    context.getCurrentFrameId(), "width", element.attributeValue("width"));
        }
    }
    String align = element.attributeValue("align");
    if (StringUtils.isNotBlank(align)) {
        column.setAlignment(Table.ColumnAlignment.valueOf(align));
    }

    column.setFormatter(loadFormatter(element));

    loadAggregation(column, element);
    loadCalculatable(column, element);
    loadMaxTextLength(column, element);

    return column;
}

From source file:com.bibisco.servlet.BibiscoServlet.java

public void thumbnailAction(HttpServletRequest pRequest, HttpServletResponse pResponse) {

    mLog.debug("Start thumbnailAction(HttpServletRequest, HttpServletResponse)");

    String lStrThumbnailAction = pRequest.getParameter("thumbnailAction");
    String lStrFamily = pRequest.getParameter("family");
    String lStrId = pRequest.getParameter("id");
    String lStrPosition = pRequest.getParameter("position");

    mLog.debug("thumbnailAction=", lStrThumbnailAction, " family=", lStrFamily, " id= ", lStrId, " position=",
            lStrPosition);/*  w  w w. java2 s  .  co m*/

    try {
        Method lMethod = BibiscoServlet.class.getMethod(
                lStrThumbnailAction + StringUtils.capitalize(lStrFamily), HttpServletRequest.class,
                HttpServletResponse.class);
        lMethod.invoke(this, pRequest, pResponse);
    } catch (Exception e) {
        mLog.error(e);
        throw new BibiscoException(BibiscoException.REFLECTION_EXCEPTION);
    }

    mLog.debug("End thumbnailAction(HttpServletRequest, HttpServletResponse)");
}

From source file:com.blackbear.flatworm.ConfigurationReader.java

private void validateSegmentConfiguration(SegmentElement segment) throws FlatwormConfigurationValueException {
    StringBuilder errors = new StringBuilder();
    if (StringUtils.isBlank(segment.getBeanRef())) {
        if (!StringUtils.isBlank(segment.getName())) {
            segment.setBeanRef(segment.getName());
        } else {/*from   w w  w .  j a  va  2  s  .c o m*/
            errors.append("Must specify the beanref to be used, or a segment name that matches a bean name.\n");
        }
    }
    if (StringUtils.isBlank(segment.getParentBeanRef())) {
        errors.append("Must specify the beanref for the parent onject.");
    }
    if (StringUtils.isBlank(segment.getAddMethod())) {
        if (errors.length() == 0) {
            segment.setAddMethod("add" + StringUtils.capitalize(
                    StringUtils.isBlank(segment.getName()) ? segment.getBeanRef() : segment.getName()));
        }
    }
    if (segment.getFieldIdentMatchStrings().size() == 0) {
        errors.append("Must specify the segment identifier.\n");
    }
    if (errors.length() > 0) {
        throw new FlatwormConfigurationValueException(errors.toString());
    }
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.exporter.EObjectCreatorImpl.java

/**
 * Returns the captialized String for the given attributeName used to concatenate method-names
 * (e.g. "get" + capitalize(attributeName))
 * //  ww w . j  a  v a  2s  .  c  o m
 * @param attributeName
 *          a string
 * @return the capitalized String
 */
private String capitalize(String attributeName) {
    return StringUtils.capitalize(attributeName);
}

From source file:com.google.gdt.eclipse.designer.builders.GwtBuilder.java

/**
 * @return the {@link Type} that extends {@link Object}, even if given is primitive.
 *///w  w w .j  a  va2 s . com
private static Type getObjectType(Type type) {
    if (type.isPrimitiveType()) {
        String identifier = ((PrimitiveType) type).getPrimitiveTypeCode().toString();
        if (identifier.equals("int")) {
            identifier = "Integer";
        } else {
            identifier = StringUtils.capitalize(identifier);
        }
        SimpleName typeName = type.getAST().newSimpleName(identifier);
        return type.getAST().newSimpleType(typeName);
    } else {
        return type;
    }
}

From source file:com.doculibre.constellio.wicket.panels.search.SearchFormPanel.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public SearchFormPanel(String id, final IModel simpleSearchModel) {
    super(id);/*from  ww w.  j a v a 2 s  .c  o m*/

    searchForm = new WebMarkupContainer("searchForm", new CompoundPropertyModel(simpleSearchModel));

    simpleSearchFormDiv = new WebMarkupContainer("simpleSearchFormDiv") {
        @Override
        public boolean isVisible() {
            SimpleSearch search = (SimpleSearch) simpleSearchModel.getObject();
            return search.getAdvancedSearchRule() == null;
        }
    };
    advancedSearchFormDiv = new WebMarkupContainer("advancedSearchFormDiv") {
        @Override
        public boolean isVisible() {
            SimpleSearch search = (SimpleSearch) simpleSearchModel.getObject();
            return search.getAdvancedSearchRule() != null;
        }
    };

    advancedSearchPanel = new AdvancedSearchPanel("advanceForm", simpleSearchModel);

    searchForm.add(new AttributeModifier("action", new LoadableDetachableModel() {
        @Override
        protected Object load() {
            PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
            return urlFor(pageFactoryPlugin.getSearchResultsPage(), new PageParameters());
        }
    }));

    hiddenFields = new ListView("hiddenFields", new LoadableDetachableModel() {
        @Override
        protected Object load() {
            List<SimpleParam> hiddenParams = new ArrayList<SimpleParam>();
            HiddenSearchFormParamsPlugin hiddenSearchFormParamsPlugin = PluginFactory
                    .getPlugin(HiddenSearchFormParamsPlugin.class);

            if (hiddenSearchFormParamsPlugin != null) {
                WebRequestCycle webRequestCycle = (WebRequestCycle) RequestCycle.get();
                HttpServletRequest request = webRequestCycle.getWebRequest().getHttpServletRequest();
                SimpleParams hiddenSimpleParams = hiddenSearchFormParamsPlugin.getHiddenParams(request);
                for (String paramName : hiddenSimpleParams.keySet()) {
                    for (String paramValue : hiddenSimpleParams.getList(paramName)) {
                        hiddenParams.add(new SimpleParam(paramName, paramValue));
                    }
                }
            }

            SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject();
            SimpleSearch clone = simpleSearch.clone();

            SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils
                    .getSearchInterfaceConfigServices();
            SearchInterfaceConfig config = searchInterfaceConfigServices.get();
            if (!config.isKeepFacetsNewSearch()) {
                // Will be true if we just clicked on a delete link
                // on the CurrentSearchPanel
                if (!clone.isRefinedSearch()) {
                    clone.getSearchedFacets().clear();
                    clone.setCloudKeyword(null);
                }
                // We must click on a delete link on
                // CurrentSearchPanel so that it is considered
                // again as refined
                clone.setRefinedSearch(false);
            }

            clone.initFacetPages();

            List<String> ignoredParamNames = Arrays.asList("query", "searchType", "page", "singleSearchLocale");
            SimpleParams searchParams = clone.toSimpleParams();
            for (String paramName : searchParams.keySet()) {
                if (!ignoredParamNames.contains(paramName) && !paramName.contains(SearchRule.ROOT_PREFIX)) {
                    List<String> paramValues = searchParams.getList(paramName);
                    for (String paramValue : paramValues) {
                        SimpleParam hiddenParam = new SimpleParam(paramName, paramValue);
                        hiddenParams.add(hiddenParam);
                    }
                }
            }
            return hiddenParams;
        }
    }) {
        @Override
        protected void populateItem(ListItem item) {
            SimpleParam hiddenParam = (SimpleParam) item.getModelObject();
            if (hiddenParam.value != null) {
                item.add(new SimpleAttributeModifier("name", hiddenParam.name));
                item.add(new SimpleAttributeModifier("value", hiddenParam.value));
            } else {
                item.setVisible(false);
            }
        }
    };

    SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils
            .getSearchInterfaceConfigServices();
    SearchInterfaceConfig config = searchInterfaceConfigServices.get();

    if (config.isSimpleSearchAutocompletion()
            && ((SimpleSearch) simpleSearchModel.getObject()).getAdvancedSearchRule() == null) {
        AutoCompleteSettings settings = new AutoCompleteSettings();
        settings.setCssClassName("simpleSearchAutoCompleteChoices");
        IModel model = new Model(((SimpleSearch) simpleSearchModel.getObject()).getQuery());

        WordsAndValueAutoCompleteRenderer render = new WordsAndValueAutoCompleteRenderer() {
            @Override
            protected String getTextValue(String word, Object value) {
                return word;
            }
        };

        queryField = new TextAndValueAutoCompleteTextField("query", model, String.class, settings, render) {
            @Override
            public String getInputName() {
                return super.getId();
            }

            @Override
            protected Iterator getChoicesForWord(String word) {
                SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject();
                String collectionName = simpleSearch.getCollectionName();
                AutocompleteServices autocompleteServices = ConstellioSpringUtils.getAutocompleteServices();
                RecordCollectionServices collectionServices = ConstellioSpringUtils
                        .getRecordCollectionServices();
                RecordCollection collection = collectionServices.get(collectionName);
                List<String> suggestions = autocompleteServices.suggestSimpleSearch(word, collection,
                        getLocale());
                return suggestions.iterator();
            }

            @Override
            protected boolean supportMultipleWords() {
                return false;
            }
        };
    } else {
        queryField = new TextField("query") {
            @Override
            public String getInputName() {
                return super.getId();
            }
        };
    }

    searchTypeField = new RadioGroup("searchType") {
        @Override
        public String getInputName() {
            return super.getId();
        }
    };

    IModel languages = new LoadableDetachableModel() {
        protected Object load() {
            Set<String> localeCodes = new HashSet<String>();
            SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject();
            RecordCollectionServices recordCollectionServices = ConstellioSpringUtils
                    .getRecordCollectionServices();
            RecordCollection collection = recordCollectionServices.get(simpleSearch.getCollectionName());
            List<Locale> searchableLocales = ConstellioSpringUtils.getSearchableLocales();
            if (!collection.isOpenSearch()) {
                localeCodes.add("");
                if (!searchableLocales.isEmpty()) {
                    for (Locale searchableLocale : searchableLocales) {
                        localeCodes.add(searchableLocale.getLanguage());
                    }
                } else {
                    IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices();
                    IndexField languageField = indexFieldServices.get(IndexField.LANGUAGE_FIELD, collection);
                    for (String localeCode : indexFieldServices.suggestValues(languageField)) {
                        localeCodes.add(localeCode);
                    }
                }
            } else {
                localeCodes.add("");
                if (!searchableLocales.isEmpty()) {
                    for (Locale searchableLocale : searchableLocales) {
                        localeCodes.add(searchableLocale.getLanguage());
                    }
                } else {
                    for (Locale availableLocale : Locale.getAvailableLocales()) {
                        localeCodes.add(availableLocale.getLanguage());
                    }
                }
            }
            List<Locale> locales = new ArrayList<Locale>();
            for (String localeCode : localeCodes) {
                locales.add(new Locale(localeCode));
            }
            Collections.sort(locales, new Comparator<Locale>() {
                @Override
                public int compare(Locale locale1, Locale locale2) {
                    Locale locale1Display;
                    Locale locale2Display;
                    SearchInterfaceConfig config = ConstellioSpringUtils.getSearchInterfaceConfigServices()
                            .get();
                    if (config.isTranslateLanguageNames()) {
                        locale1Display = locale2Display = getLocale();
                    } else {
                        locale1Display = locale1;
                        locale2Display = locale2;
                    }

                    List<Locale> searchableLocales = ConstellioSpringUtils.getSearchableLocales();
                    if (searchableLocales.isEmpty()) {
                        searchableLocales = ConstellioSpringUtils.getSupportedLocales();
                    }

                    Integer indexOfLocale1;
                    Integer indexOfLocale2;
                    if (locale1.getLanguage().equals(getLocale().getLanguage())) {
                        indexOfLocale1 = Integer.MIN_VALUE;
                    } else {
                        indexOfLocale1 = searchableLocales.indexOf(locale1);
                    }
                    if (locale2.getLanguage().equals(getLocale().getLanguage())) {
                        indexOfLocale2 = Integer.MIN_VALUE;
                    } else {
                        indexOfLocale2 = searchableLocales.indexOf(locale2);
                    }

                    if (indexOfLocale1 == -1) {
                        indexOfLocale1 = Integer.MAX_VALUE;
                    }
                    if (indexOfLocale2 == -1) {
                        indexOfLocale2 = Integer.MAX_VALUE;
                    }
                    if (!indexOfLocale1.equals(Integer.MAX_VALUE)
                            || !indexOfLocale2.equals(Integer.MAX_VALUE)) {
                        return indexOfLocale1.compareTo(indexOfLocale2);
                    } else if (StringUtils.isBlank(locale1.getLanguage())) {
                        return Integer.MIN_VALUE;
                    } else {
                        return locale1.getDisplayLanguage(locale1Display)
                                .compareTo(locale2.getDisplayLanguage(locale2Display));
                    }
                }
            });
            return locales;
        }
    };

    IChoiceRenderer languageRenderer = new ChoiceRenderer() {
        @Override
        public Object getDisplayValue(Object object) {
            Locale locale = (Locale) object;
            String text;
            if (locale.getLanguage().isEmpty()) {
                text = (String) new StringResourceModel("all", SearchFormPanel.this, null).getObject();
            } else {
                Locale localeDisplay;
                SearchInterfaceConfig config = ConstellioSpringUtils.getSearchInterfaceConfigServices().get();
                if (config.isTranslateLanguageNames()) {
                    localeDisplay = getLocale();
                } else {
                    localeDisplay = locale;
                }
                text = StringUtils.capitalize(locale.getDisplayLanguage(localeDisplay));
            }
            return text;
        }

        @Override
        public String getIdValue(Object object, int index) {
            return ((Locale) object).getLanguage();
        }
    };

    IModel languageModel = new Model() {
        @Override
        public Object getObject() {
            SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject();
            Locale singleSearchLocale = simpleSearch.getSingleSearchLocale();
            if (singleSearchLocale == null) {
                SearchedFacet facet = simpleSearch.getSearchedFacet(IndexField.LANGUAGE_FIELD);
                List<String> values = facet == null ? new ArrayList<String>() : facet.getIncludedValues();
                singleSearchLocale = values.isEmpty() ? null : new Locale(values.get(0));
            }
            if (singleSearchLocale == null) {
                singleSearchLocale = getLocale();
            }
            return singleSearchLocale;
        }

        @Override
        public void setObject(Object object) {
            Locale singleSearchLocale = (Locale) object;
            SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject();
            simpleSearch.setSingleSearchLocale(singleSearchLocale);
        }
    };

    languageDropDown = new DropDownChoice("singleSearchLocale", languageModel, languages, languageRenderer) {
        @Override
        public String getInputName() {
            return "singleSearchLocale";
        }

        @Override
        public boolean isVisible() {
            SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils
                    .getSearchInterfaceConfigServices();
            SearchInterfaceConfig config = searchInterfaceConfigServices.get();
            return config.isLanguageInSearchForm();
        }

        @Override
        protected CharSequence getDefaultChoice(Object selected) {
            return "";
        };
    };

    searchButton = new Button("searchButton") {
        @Override
        public String getMarkupId() {
            return super.getId();
        }

        @Override
        public String getInputName() {
            return super.getId();
        }
    };

    String submitImgUrl = "" + urlFor(new ResourceReference(BaseConstellioPage.class, "images/ico_loupe.png"));

    add(searchForm);
    searchForm.add(simpleSearchFormDiv);
    searchForm.add(advancedSearchFormDiv);
    searchForm.add(hiddenFields);

    queryField.add(new SetFocusBehavior(queryField));

    addChoice(SimpleSearch.ALL_WORDS);
    addChoice(SimpleSearch.AT_LEAST_ONE_WORD);
    addChoice(SimpleSearch.EXACT_EXPRESSION);
    simpleSearchFormDiv.add(queryField);
    simpleSearchFormDiv.add(searchTypeField);
    simpleSearchFormDiv.add(languageDropDown);
    simpleSearchFormDiv.add(searchButton);
    advancedSearchFormDiv.add(advancedSearchPanel);
    searchButton.add(new SimpleAttributeModifier("src", submitImgUrl));
}

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

protected void addDynamicAttributes(DataGrid component, Datasource ds, List<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, column -> {
                    MetaPropertyPath propertyPath = column.getPropertyPath();
                    return propertyPath != null && propertyPath.equals(metaPropertyPath);
                });//  ww w . j  av a  2s . c o  m

                if (columnWithSameId != null) {
                    continue;
                }

                final Column column = component.addColumn(metaPropertyPath.getMetaProperty().getName(),
                        metaPropertyPath);

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

        dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
    }
}

From source file:info.magnolia.templating.elements.AreaElement.java

private String resolveLabel() {
    return label != null ? label
            : (areaDefinition != null && StringUtils.isNotBlank(areaDefinition.getTitle())
                    ? areaDefinition.getTitle()
                    : StringUtils.capitalize(name));
}

From source file:de.unioninvestment.eai.portal.support.scripting.ConfigurationScriptsCompiler.java

private boolean compileScripts(List<ScriptConfig> scripts, String location) {
    boolean hasMainScript = false;
    for (ScriptConfig config : scripts) {
        if (config.getProperty() == null) {
            hasMainScript = true;//from  w w w .  ja  va 2s  .  com
        }

        String scriptName;
        if (config.getSrc() != null) {
            scriptName = new File(config.getSrc()).getName();
        } else {
            String name = config.getProperty();
            if (name == null) {
                name = "main";
            }
            scriptName = StringUtils.capitalize(name) + "PortletScript.groovy";
        }
        compileScript(scriptName, config.getValue(), location);
    }
    return hasMainScript;
}

From source file:adalid.core.wrappers.ArtifactWrapper.java

public String getJavaCapitalizedName() {
    return StringUtils.capitalize(getJavaName());
}