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.agimatec.validation.jsr303.NestedMetaProperty.java

private void resolveMetaBean() {
    if (metaProperty.getMetaBean() == null) {
        return;/*from  www.jav  a2  s  .c  o  m*/
    }

    if (getValue() != null) {
        metaBean = metaProperty.getMetaBean().resolveMetaBean(getValue());
    } else {
        Member member = null;
        try {
            member = metaBean.getBeanClass().getDeclaredField(metaProperty.getName());
        } catch (NoSuchFieldException e) {
            String getter = "get" + StringUtils.capitalize(metaProperty.getName());
            try {
                member = metaBean.getBeanClass().getDeclaredMethod(getter);
            } catch (NoSuchMethodException e1) {
                try {
                    member = metaBean.getBeanClass().getField(metaProperty.getName());
                } catch (NoSuchFieldException e2) {
                    try {
                        member = metaBean.getBeanClass().getMethod(getter);
                    } catch (NoSuchMethodException e3) {
                    }
                }
            }
        }
        if (member != null) {
            Type type = getIndexedType(typeOf(member));
            if (type != null) {
                metaBean = metaProperty.getMetaBean().resolveMetaBean(type);
            }
        }
    }
}

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

/**
 * Converts a database schema name to java object name. 
 * First, it removes all characters before the last occurence of 
 * .<code>SCHEMA_SEPARATOR_CHAR</code>. Then, in a second step, removes
 * <code>STD_SEPARATOR_CHAR</code>, capitilizes first letter of
 * name and each letter after the <code>STD_SEPERATOR</code>,
 * and converts the rest of the letters to lowercase.
 *
 * @param schemaName name to be converted.
 * @return converted name./*from w  ww.ja va 2s . com*/
 * @see com.frameworkset.orm.engine.model.NameGenerator
 * @see #underscoreOmitSchemaMethod(String)
 */
protected String underscoreOmitSchemaMethod(String schemaName, boolean IGNORE_FIRST_TOKEN) {
    // take only part after last dot
    int lastDotPos = schemaName.lastIndexOf(SCHEMA_SEPARATOR_CHAR);
    if (lastDotPos != -1) {
        schemaName = schemaName.substring(lastDotPos + 1);
    }
    StringBuffer name = new StringBuffer();
    StringTokenizer tok = new StringTokenizer(schemaName, String.valueOf(STD_SEPARATOR_CHAR));
    while (tok.hasMoreTokens()) {
        String namePart = ((String) tok.nextElement()).toLowerCase();
        name.append(StringUtils.capitalize(namePart));
    }
    return name.toString();
}

From source file:com.p5solutions.trackstate.utils.TrackStateUtility.java

/**
 * Similar to {@link #hasChanges(Object, Class)} the method will check if a
 * specified property had been changed./*ww w .  j a v a  2  s  . co  m*/
 * 
 * @param object
 *          The object instance in question.
 * @param property
 *          The object's property in question.
 * @param object
 *          The object instance in question.
 * @param forClazz
 *          The {@link Class} type to check for changes on.
 * 
 * @return <code>true</code>, if any value for the specific ?.class were
 *         changed, otherwise <code>false</code>
 */
public static Boolean hasChanges(Object object, String property, Class<?> forClazz) {

    // check object existence.
    if (object == null || StringUtils.isBlank(property)) {
        // throw exception if the object is null
        throw new NullPointerException("Object and property cannot be null/empty.");

    } else if (object instanceof TrackStateProxy) {
        // cast the proxy to a TrackStateProxy
        TrackStateProxy proxy = (TrackStateProxy) object;

        // get a track state laundry list for a given TrackState(clazz=?) type
        List<TrackStateLaundry> laundryList = proxy.getTrackStateLaundryListForClass(forClazz);
        // if the laundry list came back as not null then changes
        // were made to the proxy for a given class tracked class type.
        if (laundryList != null) {
            String propertyGetter = "get" + StringUtils.capitalize(property);
            for (TrackStateLaundry tsl : laundryList) {
                if (tsl.getMethod().equals(propertyGetter)) {
                    return tsl.isDirty();
                }
            }
        }
        // didn't find the property
        return false;
    }
    // since there is no proxy, return null
    else {
        return null;
    }
}

From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.AbstractExportGraphMLService.java

/**
 * Ajouter un tableau rcapitulatif du nombre de FDP par catgorie
 * /*from w  w  w . ja v  a2  s  .c o m*/
 * @param graph
 *            : l'lment graph
 * @param entiteDto
 *            : l'entit exporte
 */
protected void construitTableauStats(Element graph, EntiteDto entiteDto) {

    String listIdStatutFDP = StatutFichePoste.getListIdStatutActif();
    Map<String, Double> mapCategorieNombreETP = new LinkedHashMap<String, Double>();

    List<FichePosteDto> listeFichePosteDto = sirhWSConsumer.getFichePosteByIdEntite(entiteDto.getIdEntite(),
            listIdStatutFDP, true);
    Collections.sort(listeFichePosteDto, new ComparatorUtil.FichePosteCategorieComparator());

    int tailleLibelleMax = 0;
    for (FichePosteDto fichePosteDto : listeFichePosteDto) {
        Double nombreFdpCategorie = mapCategorieNombreETP.get(fichePosteDto.getLibelleGradeCategorie());
        // On ne met dans les stats que les rglementaires
        if (StringUtils.isNotBlank(fichePosteDto.getReglementaire())
                && !fichePosteDto.getReglementaire().toLowerCase().equals("non")) {
            if (nombreFdpCategorie == null) {
                nombreFdpCategorie = fichePosteDto.getTauxETP();
            } else {
                nombreFdpCategorie += fichePosteDto.getTauxETP();
            }

            String libelleGradeCategorie = fichePosteDto.getLibelleGradeCategorie();
            if (libelleGradeCategorie.length() > tailleLibelleMax) {
                tailleLibelleMax = libelleGradeCategorie.length();
            }

            mapCategorieNombreETP.put(libelleGradeCategorie, nombreFdpCategorie);
        }
    }

    List<String> listeResultat = new ArrayList<String>();
    Double total = new Double(0);

    for (Map.Entry<String, Double> entry : mapCategorieNombreETP.entrySet()) {
        total += entry.getValue();
    }

    DecimalFormat df = new DecimalFormat("#.##");
    int longueurChiffreTotal = df.format(total).toString().length();

    for (Map.Entry<String, Double> entry : mapCategorieNombreETP.entrySet()) {
        int longueurChiffreEntry = df.format(entry.getValue()).toString().length();
        int nombrePointAjoutFin = tailleLibelleMax + (longueurChiffreTotal - longueurChiffreEntry) + 1;
        listeResultat.add(StringUtils.capitalize(StringUtils.rightPad(entry.getKey(), nombrePointAjoutFin, "."))
                + df.format(entry.getValue()).toString());
    }

    listeResultat.add("");
    listeResultat.add(StringUtils.rightPad("Total", tailleLibelleMax + 1, ".") + df.format(total));

    String height = listeResultat.size() == 0 ? "20" : String.valueOf(listeResultat.size() * 20);
    String width = tailleLibelleMax == 0 ? "50" : String.valueOf(tailleLibelleMax * 10);

    Element elNodeCategorie = graph.addElement("node").addAttribute("id", "-1");
    Element elD6Categorie = elNodeCategorie.addElement("data").addAttribute("key", "d6");
    Element elGenericNodeCategorie = elD6Categorie.addElement("y:ShapeNode");
    elGenericNodeCategorie.addElement("y:Geometry").addAttribute("height", height).addAttribute("width", width);
    elGenericNodeCategorie.addElement("y:NodeLabel").addAttribute("alignment", "left")
            .addAttribute("fontFamily", "Courier New").setText(StringUtils.join(listeResultat, "\n"));
}

From source file:com.bluexml.side.deployer.alfresco.directcopy.AlfrescoAmpHotDeployer.java

private void reloadMessagesBundles() throws AuthenticationException, Exception {
    System.out.println("AlfrescoAmpHotDeployer.reloadMessagesBundles()");
    String regex = ".*WEB-INF/classes/(.*/module/[^/]*/[model|bpm])/.*properties";

    // search for messages
    List<String> list = new ArrayList<String>();
    // search for processDefinition files
    for (String string : deployedFiles) {

        boolean matches = string.matches(regex);

        if (matches) {
            list.add(string);/*from  w ww.jav a2  s  . c o  m*/
            System.out.println("model found :" + string);
        }
    }
    for (String filepath : list) {
        File model = new File(filepath);
        String classPath = getRegExG0(regex, filepath);
        // upload the file
        String prefix = getModuleName(filepath) + "_";
        String modelRepoName = prefix + model.getName();
        String[] split = modelRepoName.split("_");
        modelRepoName = "";
        for (String string : split) {
            modelRepoName += StringUtils.capitalize(string);
        }

        //         NamedValue[] props = new NamedValue[1];
        //         props[0] = new NamedValue("{http://www.alfresco.org/model/content/1.0}name", false, modelRepoName, null);
        //         ContentFormat format = new ContentFormat("text/plain", "UTF-8");
        //         uploadFile(model, modelRepoName, messagesRepoPath, props, format);

        // reload bundles
        String alfrescoURL = getGenerationParameters().get(CONFIGURATION_PARAMETER_ALFRESCO_URL)
                + SERVICE_SIDE_SERVICE_MESSAGES_DEPLOY + classPath;
        callReloadService(alfrescoURL);
    }
}

From source file:info.magnolia.jcr.util.PropertiesImportExport.java

protected Object convertPropertyStringToObject(String valueStr) {
    if (contains(valueStr, ':')) {
        final String type = StringUtils.substringBefore(valueStr, ":");
        final String value = StringUtils.substringAfter(valueStr, ":");

        // there is no beanUtils converter for Calendar
        if (type.equalsIgnoreCase("date")) {
            return ISO8601.parse(value);
        } else if (type.equalsIgnoreCase("binary")) {
            return new ByteArrayInputStream(value.getBytes());
        } else {/*  w w w  .  j a  v  a 2  s  .  c  o  m*/
            try {
                final Class<?> typeCl;
                if (type.equals("int")) {
                    typeCl = Integer.class;
                } else {
                    typeCl = Class.forName("java.lang." + StringUtils.capitalize(type));
                }
                return ConvertUtils.convert(value, typeCl);
            } catch (ClassNotFoundException e) {
                // possibly a stray :, let's ignore it for now
                return valueStr;
            }
        }
    }
    // no type specified, we assume it's a string, no conversion
    return valueStr;
}

From source file:be.idamediafoundry.sofa.livecycle.dsc.util.AbstractQDoxComponentInfoExtractor.java

/**
 * Generate an appropriate title for an element holding "title". The title
 * of an element is shown in the workbench as label for the operation,
 * configuration, input, output and fault elements. This method will make a
 * sentence of a camel cased string, transform it to lower case and finally
 * capitalize the first letter again.//w w  w .  j  a v a 2  s .c  om
 * 
 * @param base
 *            the camel cased string
 * @return the sentence
 */
final protected String generateTitle(final String base) {
    return StringUtils
            .capitalize(StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(base), ' ').toLowerCase());
}

From source file:edu.ku.brc.specify.datamodel.DataModelObjBase.java

/**
 * Sets a value into the current object.
 * @param clazz the class of the data being set
 * @param ref the value/*from   w  ww  .ja v  a 2s.c o m*/
 * @return true on success
 */
public static boolean setDataMember(final FormDataObjIFace dataObject, final String fieldName,
        final FormDataObjIFace ref) {
    String methodName = "";
    try {
        methodName = "set" + StringUtils.capitalize(fieldName);
        //System.out.println(dataObject.getClass().getSimpleName()+"."+methodName+"("+clazz.getSimpleName()+")");
        Method method = dataObject.getClass().getMethod(methodName, ref.getDataClass());
        if (method != null) {
            method.invoke(dataObject, ref);
            return true;
        }

    } catch (java.lang.NoSuchMethodException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex);
        log.error("Couldn't find method [" + methodName + "] on Class ["
                + dataObject.getDataClass().getSimpleName() + "] for arg[" + ref.getDataClass() + "]");
        log.error("For Class " + dataObject.getClass().getSimpleName());
        for (Method m : dataObject.getClass().getMethods()) {
            String mName = m.getName();
            if (mName.startsWith("set")) {
                log.error(mName + " " + mName.equals(methodName));
            }
        }
        ex.printStackTrace();

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex);
        ex.printStackTrace();

    }
    return false;
}

From source file:gov.nih.nci.cabig.caaers.web.ae.ReporterTab.java

private void createPersonGroup(AeInputFieldCreator creator, String person) {
    String base = person + '.';
    InputField title = InputFieldFactory.createTextField(base + "title", "Position Title", false);
    InputFieldAttributes.setSize(title, 50);
    InputField firstNameField = InputFieldFactory.createTextField(base + "firstName", "First name", false);
    InputField middleNameField = InputFieldFactory.createTextField(base + "middleName", "Middle name", false);
    InputField lastNameField = InputFieldFactory.createTextField(base + "lastName", "Last name", false);
    InputField emailField = createContactField(base, ReportPerson.EMAIL, "E-mail address", false);
    InputFieldAttributes.setSize(emailField, 50);

    InputField phoneField = createCustomPhoneTextField(base, ReportPerson.PHONE, false);
    InputFieldAttributes.setSize(phoneField, 21);

    InputField faxField = createCustomPhoneTextField(base, ReportPerson.FAX, false);
    InputFieldAttributes.setSize(faxField, 21);

    InputField streetField = InputFieldFactory.createTextField(base + "address.street", "Street");
    InputFieldAttributes.setColumns(streetField, 50);

    InputField cityField = InputFieldFactory.createTextField(base + "address.city", "City");
    InputFieldAttributes.setColumns(cityField, 50);

    InputField stateField = InputFieldFactory.createTextField(base + "address.state", "State");
    InputFieldAttributes.setColumns(stateField, 50);

    InputField zipField = InputFieldFactory.createZipCodeField(base + "address.zip", "Zip", false);
    InputFieldAttributes.setColumns(zipField, 5);

    if ("reporter".equals(person)) {
        InputField altEmailField = createContactField(base, ReportPerson.ALT_EMAIL, "Alternate e-mail", false);
        InputFieldAttributes.setSize(altEmailField, 50);

        creator.createFieldGroup(person, StringUtils.capitalize(person) + " details", title, firstNameField,
                middleNameField, lastNameField, emailField, phoneField, faxField, streetField, cityField,
                stateField, zipField, altEmailField);
    } else {/*from w  w  w .  ja v a  2s. c o m*/
        creator.createFieldGroup(person, StringUtils.capitalize(person) + " details", title, firstNameField,
                middleNameField, lastNameField, emailField, phoneField, faxField, streetField, cityField,
                stateField, zipField);
    }

}

From source file:com.google.gdt.eclipse.designer.model.widgets.panels.DockLayoutPanelInfo.java

public void setEdge(WidgetInfo widget, String edge) throws Exception {
    if (widget.getAssociation() instanceof InvocationChildAssociation) {
        InvocationChildAssociation association = (InvocationChildAssociation) widget.getAssociation();
        MethodInvocation invocation = association.getInvocation();
        // add/remove "size" argument
        String oldMethodName = invocation.getName().getIdentifier();
        if (!edge.equals("CENTER") && oldMethodName.equals("add")) {
            getEditor().addInvocationArgument(invocation, 1, "1.0");
            setReasonableSize(widget);//from   ww  w.  jav  a 2  s .  com
        } else if (edge.equals("CENTER") && !oldMethodName.equals("add")) {
            getEditor().removeInvocationArgument(invocation, 1);
        }
        // prepare new method name
        String newMethodName;
        if (edge.equals("CENTER")) {
            newMethodName = "add";
        } else {
            newMethodName = "add" + StringUtils.capitalize(edge.toLowerCase());
        }
        // replace method name
        getEditor().replaceInvocationName(invocation, newMethodName);
        // ensure correct order
        ensureWidgetBeforeCenter(widget);
    }
}