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

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

Introduction

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

Prototype

public static String capitalize(String str) 

Source Link

Document

Capitalizes all the whitespace separated words in a String.

Usage

From source file:pt.ist.fenix.task.updateData.fixNames.DBField2Cap.java

/**
 * Capitalizes a string that may contain whitespaces and special characters.
 * This method uses <code>capitalizeWord</code> and <code>capitalizeWordWithSpecChars<code>.
 * //  ww w  . j a v  a2s.  com
 * @param uglyDuckling the string to capitalize.
 * @return the capitalized string.
 */
public static String prettyPrint(String uglyDuckling) {
    String[] lowerCaseName = uglyDuckling.toLowerCase().split(" ");
    StringBuilder capitalizedName = new StringBuilder();

    for (int i = 0; i < lowerCaseName.length; i++) {

        if (!containsNoneSpecialChars(lowerCaseName[i]) && !allCapSet.contains(lowerCaseName[i])) {
            capitalizedName.append(capitalizeWordWithSpecChars(lowerCaseName[i]));
        } else {
            // The first word is always capitalized (some courses' name
            // begin with an article)
            // (ex: Os Lseres na Instrumentao e Medida)
            if (i == 0) {
                capitalizedName.append(WordUtils.capitalize(lowerCaseName[i]));
            } else {
                // Exception to the general case: if "A" is the last word
                // converts to UPPERCASE
                // (needed for courses that occur in alternative semesters)
                if (i == (lowerCaseName.length - 1) & lowerCaseName[i].equals("a")) {
                    capitalizedName.append(lowerCaseName[i].toUpperCase());
                } else {
                    capitalizedName.append(capitalizeWord(lowerCaseName[i]));
                }
            }
        }

        capitalizedName.append(" ");
    }

    return capitalizedName.toString().substring(0, capitalizedName.length() - 1);
}

From source file:pt.ist.fenix.task.updateData.fixNames.DBField2Cap.java

/**
 * Capitalizes a string according to its type. The first letter is changed
 * to title case (no other letters are changed) if the string isn't supposed
 * to be in upper (e.g.: roman numeration) or lower case (e.g.: articles and
 * prepositions)./*  w  ww  . j  av a 2 s. co m*/
 * 
 * @param uglyWord
 *            the string to capitalize
 * @return the capitalized word
 */
private static String capitalizeWord(String uglyWord) {
    StringBuilder prettyWord = new StringBuilder();

    if (allCapSet.contains(uglyWord)) {
        prettyWord.append(uglyWord.toUpperCase());
    } else {
        if (allLowerSet.contains(uglyWord)) {
            prettyWord.append(uglyWord);
        } else {
            prettyWord.append(WordUtils.capitalize(uglyWord));
        }
    }
    return prettyWord.toString();
}

From source file:pt.ist.vaadinframework.data.metamodel.RolePropertyDescriptor.java

private void calc()
        throws IntrospectionException, SecurityException, NoSuchMethodException, ClassNotFoundException {
    if (role.getMultiplicityUpper() == 1) {
        java.beans.PropertyDescriptor property = new java.beans.PropertyDescriptor(role.getName(), type);
        reader = property.getReadMethod();
        writer = property.getWriteMethod();
    } else {//  www. j  a  v a  2 s  .c o  m
        reader = type.getMethod("get" + WordUtils.capitalize(role.getName()) + "Set");
        elementType = (Class<? extends AbstractDomainObject>) Class.forName(role.getType().getFullName());
    }
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.SpotLocationProvider.java

@Periodic(millisBetweenUpdates = 1000 * 60)
public void updateSpots() throws Exception {
    if (!enabled)
        return;/*from  w ww .ja  v  a  2s.c  om*/
    try {
        URL urlSpot = new URL(url);
        File tmp = File.createTempFile("neptus", "spots");
        FileUtils.copyURLToFile(urlSpot, tmp);

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();

        Document doc = db.parse(tmp);

        NodeList messages = doc.getElementsByTagName("message");
        for (int i = 0; i < messages.getLength(); i++) {
            NodeList elems = messages.item(i).getChildNodes();
            String name = null;
            double lat = 0, lon = 0;
            long timestamp = System.currentTimeMillis();
            String battState = null, msgType = null;
            for (int j = 0; j < elems.getLength(); j++) {
                Node nd = elems.item(j);
                switch (nd.getNodeName()) {
                case "unixTime":
                    timestamp = Long.parseLong(nd.getTextContent()) * 1000;
                    break;
                case "latitude":
                    lat = Double.parseDouble(nd.getTextContent());
                    break;
                case "longitude":
                    lon = Double.parseDouble(nd.getTextContent());
                    break;
                case "messengerName":
                    name = nd.getTextContent().toLowerCase();
                    break;
                case "batteryState":
                    battState = nd.getTextContent();
                    break;
                case "messageType":
                    msgType = nd.getTextContent();
                    break;
                default:
                    break;
                }
            }
            if (name != null) {
                AssetPosition pos = new AssetPosition(name, lat, lon);
                pos.setTimestamp(timestamp);
                pos.setSource(getName());
                pos.setType("SPOT Tag");
                if (battState != null)
                    pos.putExtra("Battery", WordUtils.capitalize(battState.toLowerCase()));
                if (msgType != null)
                    pos.putExtra("SPOT Mode", WordUtils.capitalize(msgType.toLowerCase()));
                parent.addAssetPosition(pos);
            }
        }
    } catch (Exception e) {
        NeptusLog.pub().error(e);
        parent.postNotification(Notification
                .error("Situation Awareness",
                        e.getClass().getSimpleName() + " while polling SPOT positions from Web.")
                .requireHumanAction(false));
    }
}

From source file:raptor.pref.page.ConnectorQuadrantsPage.java

public ConnectorQuadrantsPage(String connectorShortName) {
    super(GRID);//  ww w.j a va 2  s. c  o  m
    setTitle(local.getString("quadConn", WordUtils.capitalize(connectorShortName)));
    setPreferenceStore(Raptor.getInstance().getPreferences());
    this.connectorShortName = connectorShortName;
}

From source file:ro.cs.om.web.controller.root.ControllerUtils.java

/**
 * //from  w  w  w.ja v  a 2  s.  c o  m
 * Gets description in locale language from localization
 * @author mitziuro
 *
 * @param localization
 * @param locale
 * @return
 * @throws Exception
 */
public String getDescriptionForLocale(Localization localization, String locale) throws Exception {

    //we use java reflexive to call dynamic method
    Class usedClass = Class.forName(SETTER);
    Class[] partypes = new Class[] {};
    Object[] arglist = new Object[] {};

    Method meth = usedClass.getMethod("get".concat(WordUtils.capitalize(locale)), partypes);
    String output = (String) meth.invoke(localization, arglist);
    return output;
}

From source file:ru.org.linux.topic.TopicListController.java

/**
 * @param section/*from w  ww  . jav  a 2s  . c om*/
 * @param group
 * @param topicListForm
 * @return
 * @throws BadDateException
 */
private static String calculatePTitle(Section section, Group group, TopicListRequest topicListForm)
        throws BadDateException {
    StringBuilder ptitle = new StringBuilder();

    if (topicListForm.getMonth() == null) {
        if (section != null) {
            ptitle.append(section.getName());
            if (group != null) {
                ptitle.append(" - ").append(group.getTitle());
            }

            if (topicListForm.getTag() != null) {
                ptitle.append(" - ").append(WordUtils.capitalize(topicListForm.getTag()));
            }
        } else {
            ptitle.append(topicListForm.getTag());
        }
    } else {
        ptitle.append("?: ").append(section.getName());

        if (group != null) {
            ptitle.append(" - ").append(group.getTitle());
        }

        if (topicListForm.getTag() != null) {
            ptitle.append(" - ").append(topicListForm.getTag());
        }

        ptitle.append(", ").append(topicListForm.getYear()).append(", ")
                .append(DateUtil.getMonth(topicListForm.getMonth()));
    }
    return ptitle.toString();
}

From source file:ru.org.linux.topic.TopicListController.java

/**
 * @param section/*from w  w  w  .j a  v  a2s . c o  m*/
 * @param group
 * @param topicListForm
 * @return
 * @throws BadDateException
 * @throws SectionNotFoundException
 */
private static String calculateNavTitle(Section section, Group group, TopicListRequest topicListForm)
        throws BadDateException, SectionNotFoundException {

    StringBuilder navTitle = new StringBuilder();

    if (!Strings.isNullOrEmpty(topicListForm.getTag())) {
        navTitle.append(WordUtils.capitalize(topicListForm.getTag()));

        if (section != null) {
            navTitle.append(" - ");
            navTitle.append(section.getName());
        }
    } else if (group == null) {
        if (section != null) {
            navTitle.setLength(0);
            navTitle.append(section.getName());
        }
    } else if (section != null) {
        navTitle.setLength(0);
        navTitle.append("<a href=\"").append(Section.getNewsViewerLink(group.getSectionId())).append("\">")
                .append(section.getName()).append("</a> - <strong>").append(group.getTitle())
                .append("</strong>");
    }
    if (topicListForm.getMonth() != null) {
        navTitle.append(" - ? ").append(topicListForm.getYear()).append(", ")
                .append(DateUtil.getMonth(topicListForm.getMonth()));
    }
    return navTitle.toString();
}

From source file:schemagenerator.DBbeheer.java

private void jbToevoegenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbToevoegenActionPerformed
    if (jtfSpiergroep.getText().isEmpty() || jtfOefening.getText().isEmpty()) {
        JOptionPane.showMessageDialog(null, "Check of er een spiergroep of oefening ingevuld", "Insert Error",
                JOptionPane.ERROR_MESSAGE);
    } else {//from w w  w .  j  a  v a  2  s  . c  o m
        try {
            //eerste letter van spiergroep, oefening en categorie textboxen
            //worden omgezet naar hoofdletter, rest naar kleine letters
            String sql = "INSERT INTO oefeningen (spiergroep, oefening, categorie, plaatje) VALUES (?,?,?,?)";
            pst = con.prepareStatement(sql);

            pst.setString(1, WordUtils.capitalize(jtfSpiergroep.getText()));
            pst.setString(2, WordUtils.capitalize(jtfOefening.getText()));
            pst.setString(3, WordUtils.capitalize(jtfCategorie.getText()));
            pst.setBytes(4, oefening_image);
            pst.executeUpdate();

            ClearAllTextFields();
            FillComboBox();
            UpdateTable();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex);
        }
    }
}

From source file:schemagenerator.HandmatigSchema.java

private void jbSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSaveActionPerformed
    File desktop = new File(System.getProperty("user.home"), "/Desktop");
    File dirSchema = new File(desktop + "/schemas");

    if (!dirSchema.exists()) {
        dirSchema.mkdirs();//from w  w  w . j  a  va 2  s  . c  o m
    }

    String naam = WordUtils.capitalize(jtfNaam.getText());
    try (PrintWriter out = new PrintWriter(
            new BufferedWriter(new FileWriter(dirSchema + "/Schema van " + naam + ".txt")))) {
        out.write(jTextArea1.getText());
        out.close();
        JOptionPane.showMessageDialog(this,
                "Schema van " + naam + " opgeslagen op het bureaublad in de schema map");
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex);
    }
}