Example usage for java.lang Character isLowerCase

List of usage examples for java.lang Character isLowerCase

Introduction

In this page you can find the example usage for java.lang Character isLowerCase.

Prototype

public static boolean isLowerCase(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a lowercase character.

Usage

From source file:org.apache.openjpa.lib.conf.ConfigurationImpl.java

/**
 * Convert <code>propName</code> to a lowercase-with-hyphens-style string.
 * This algorithm is only designed for mixes of uppercase and lowercase 
 * letters and lone digits. A more sophisticated conversion should probably 
 * be handled by a proper parser generator or regular expressions.
 *///ww  w  .j  av a2  s . c  o m
public static String toXMLName(String propName) {
    if (propName == null)
        return null;
    StringBuilder buf = new StringBuilder();
    char c;
    for (int i = 0; i < propName.length(); i++) {
        c = propName.charAt(i);

        // convert sequences of all-caps to downcase with dashes around 
        // them. put a trailing cap that is followed by downcase into the
        // downcase word.
        if (i != 0 && Character.isUpperCase(c)
                && (Character.isLowerCase(propName.charAt(i - 1))
                        || (i > 1 && i < propName.length() - 1 && Character.isUpperCase(propName.charAt(i - 1))
                                && Character.isLowerCase(propName.charAt(i + 1)))))
            buf.append('-');

        // surround sequences of digits with dashes.
        if (i != 0 && ((!Character.isLetter(c) && Character.isLetter(propName.charAt(i - 1)))
                || (Character.isLetter(c) && !Character.isLetter(propName.charAt(i - 1)))))
            buf.append('-');

        buf.append(Character.toLowerCase(c));
    }
    return buf.toString();
}

From source file:org.wso2.andes.management.ui.views.ViewUtility.java

/**
 * Converts the input string to displayable format by converting some character case or inserting space
 * @param input//from   w  w  w  .  j a  v  a 2s  .  com
 * @return formatted string
 */
public static String getDisplayText(String input) {
    StringBuffer result = new StringBuffer(input);
    if (Character.isLowerCase(result.charAt(0))) {
        result.setCharAt(0, Character.toUpperCase(result.charAt(0)));
    }
    for (int i = 1; i < input.length(); i++) {
        if (Character.isUpperCase(result.charAt(i)) && !Character.isWhitespace(result.charAt(i - 1))
                && Character.isLowerCase(result.charAt(i - 1))) {
            result.insert(i, " ");
            i++;
        } else if (Character.isLowerCase(result.charAt(i)) && Character.isWhitespace(result.charAt(i - 1))) {
            result.setCharAt(i, Character.toUpperCase(result.charAt(i)));
        }

    }

    return result.toString();
}

From source file:org.gvnix.service.roo.addon.addon.util.WsdlParserUtils.java

/**
 * Map an XML name to a Java identifier per the mapping rules of JSR 101 (in
 * version 1.0 this is "Chapter 20: Appendix: Mapping of XML Names"
 * //  w w  w  .ja  v  a2 s .c  o  m
 * @param name is the xml name
 * @return the java name per JSR 101 specification
 */
public static String xmlNameToJava(String name) {

    // protect ourselves from garbage
    if (name == null || name.equals(""))
        return name;

    char[] nameArray = name.toCharArray();
    int nameLen = name.length();
    StringBuffer result = new StringBuffer(nameLen);
    boolean wordStart = false;

    // The mapping indicates to convert first character.
    int i = 0;
    while (i < nameLen && (isPunctuation(nameArray[i]) || !Character.isJavaIdentifierStart(nameArray[i]))) {
        i++;
    }
    if (i < nameLen) {
        // Decapitalization code used to be here, but we use the
        // Introspector function now after we filter out all bad chars.

        result.append(nameArray[i]);
        // wordStart = !Character.isLetter(nameArray[i]);
        wordStart = !Character.isLetter(nameArray[i]) && nameArray[i] != "_".charAt(0);
    } else {
        // The identifier cannot be mapped strictly according to
        // JSR 101
        if (Character.isJavaIdentifierPart(nameArray[0])) {
            result.append("_" + nameArray[0]);
        } else {
            // The XML identifier does not contain any characters
            // we can map to Java. Using the length of the string
            // will make it somewhat unique.
            result.append("_" + nameArray.length);
        }
    }

    // The mapping indicates to skip over
    // all characters that are not letters or
    // digits. The first letter/digit
    // following a skipped character is
    // upper-cased.
    for (++i; i < nameLen; ++i) {
        char c = nameArray[i];

        // if this is a bad char, skip it and remember to capitalize next
        // good character we encounter
        if (isPunctuation(c) || !Character.isJavaIdentifierPart(c)) {
            wordStart = true;
            continue;
        }
        if (wordStart && Character.isLowerCase(c)) {
            result.append(Character.toUpperCase(c));
        } else {
            result.append(c);
        }
        // If c is not a character, but is a legal Java
        // identifier character, capitalize the next character.
        // For example: "22hi" becomes "22Hi"
        // wordStart = !Character.isLetter(c);
        wordStart = !Character.isLetter(c) && c != "_".charAt(0);
    }

    // covert back to a String
    String newName = result.toString();

    // Follow JavaBean rules, but we need to check if the first
    // letter is uppercase first
    if (Character.isUpperCase(newName.charAt(0)))
        newName = Introspector.decapitalize(newName);

    // check for Java keywords
    if (isJavaKeyword(newName))
        newName = makeNonJavaKeyword(newName);

    return newName;
}

From source file:com.amazon.carbonado.repo.jdbc.JDBCStorableIntrospector.java

/**
 * Generates aliases for the given name, converting camel case form into
 * various underscore forms./*  w  w w. j  a  v a 2  s .c  om*/
 */
static String[] generateAliases(String base) {
    int length = base.length();
    if (length <= 1) {
        return new String[] { base.toUpperCase(), base.toLowerCase() };
    }

    ArrayList<String> aliases = new ArrayList<String>(4);

    StringBuilder buf = new StringBuilder();

    int i;
    for (i = 0; i < length;) {
        char c = base.charAt(i++);
        if (c == '_' || !Character.isJavaIdentifierPart(c)) {
            // Keep scanning for first letter.
            buf.append(c);
        } else {
            buf.append(Character.toUpperCase(c));
            break;
        }
    }

    boolean canSeparate = false;
    boolean appendedIdentifierPart = false;

    for (; i < length; i++) {
        char c = base.charAt(i);
        if (c == '_' || !Character.isJavaIdentifierPart(c)) {
            canSeparate = false;
            appendedIdentifierPart = false;
        } else if (Character.isLowerCase(c)) {
            canSeparate = true;
            appendedIdentifierPart = true;
        } else {
            if (appendedIdentifierPart && i + 1 < length && Character.isLowerCase(base.charAt(i + 1))) {
                canSeparate = true;
            }
            if (canSeparate) {
                buf.append('_');
            }
            canSeparate = false;
            appendedIdentifierPart = true;
        }
        buf.append(c);
    }

    String derived = buf.toString();

    addToSet(aliases, derived.toUpperCase());
    addToSet(aliases, derived.toLowerCase());
    addToSet(aliases, derived);
    addToSet(aliases, base.toUpperCase());
    addToSet(aliases, base.toLowerCase());
    addToSet(aliases, base);

    return aliases.toArray(new String[aliases.size()]);
}

From source file:com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.java

protected String guessResultType(String type) {
    StringBuilder sb = null;/*  w w  w . j a v a2s .  co m*/
    if (type != null) {
        sb = new StringBuilder();
        boolean capNext = false;
        for (int x = 0; x < type.length(); x++) {
            char c = type.charAt(x);
            if (c == '-') {
                capNext = true;
                continue;
            } else if (Character.isLowerCase(c) && capNext) {
                c = Character.toUpperCase(c);
                capNext = false;
            }
            sb.append(c);
        }
    }
    return (sb != null ? sb.toString() : null);
}

From source file:net.java.sip.communicator.gui.AuthenticationSplash.java

public boolean valid() {
    int idx;//w  w w  . ja v a  2  s .c  om
    boolean usern = true, pwd = true, nme = true, lnme = true, ml = true;
    // Username checks

    // Starts with a letter
    if (userName.length() == 0)
        usern = false;
    else if (!Character.isLetter(userName.charAt(0)))
        usern = false;

    // Contains only letters and numbers
    for (idx = 0; idx < userName.length(); idx++) {
        if (!Character.isLetterOrDigit(userName.charAt(idx)))
            usern = false;
    }

    // Is between 4 and 10 characters
    if ((userName.length() < 4) || (userName.length() > 18))
        usern = false;

    // Name and last name checks

    // Both begin with uppercase
    if (name.length() == 0)
        nme = false;
    else if (!Character.isUpperCase(name.charAt(0)))
        nme = false;

    if (lastName.length() == 0)
        lnme = false;
    else if (!Character.isUpperCase(lastName.charAt(0)))
        lnme = false;

    // Both contain only letters
    for (idx = 0; idx < name.length(); idx++) {
        if (!Character.isLetter(name.charAt(idx)))
            nme = false;
    }

    for (idx = 0; idx < lastName.length(); idx++) {
        if (!Character.isLetter(lastName.charAt(idx)))
            lnme = false;
    }

    // Mail chekcs
    Pattern ptr = Pattern.compile(
            "(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \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?:\\r\\n)?[ \\t])*)?(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*))*)?;\\s*)");
    if (!ptr.matcher(mail).matches())
        ml = false;

    // Password checks

    // Check that we have a variety of different characters
    boolean lower = false, upper = false, number = false, other = false;
    for (idx = 0; idx < password.length(); idx++) {
        if (Character.isUpperCase(password.charAt(idx)))
            upper = true;
        if (Character.isLowerCase(password.charAt(idx)))
            lower = true;
        if (!Character.isLetterOrDigit(password.charAt(idx)))
            other = true;
        if (Character.isDigit(password.charAt(idx)))
            number = true;
    }
    if (!(upper && lower && number && other))
        pwd = false;

    // Verify that the size is acceptable
    if (password.length() < 6 || password.length() > 30)
        pwd = false;

    // Change the label colors
    if (!nme) {
        nameLabel.setForeground(Color.RED);
        nameTextField.setText("");
    }

    if (!lnme) {
        lastNameLabel.setForeground(Color.RED);
        lastNameTextField.setText("");
    }

    if (!ml) {
        mailLabel.setForeground(Color.RED);
        mailTextField.setText("");
    }

    if (!usern) {
        userNameLabel.setForeground(Color.RED);
        userNameTextField.setText("");
    }

    if (!pwd) {
        passwordLabel.setForeground(Color.RED);
        passwordTextField.setText("");
    }

    if (!(nme && lnme && usern && ml && pwd))
        return false;

    return true;
}

From source file:org.rdkit.knime.wizards.RDKitNodesWizardsPage.java

/**
 * Validates the page, e.g. checks whether the text fields contain valid
 * values.//from  w w w  .j a v  a  2  s.c om
 *
 * @return Returns true, if all information on page is correct. False otherwise.
 */
protected boolean validatePage() {
    // Check existing project setting
    if (getProjectName().trim().equals("")) { //$NON-NLS-1$
        setErrorMessage(null);
        setMessage("Please select an existing project.");
        return false;
    }

    // Check the node name
    String nodeName = m_textNodeName.getText();
    if (nodeName.trim().isEmpty()) {
        setErrorMessage(null);
        setMessage("Please provide a valid node name.");
        return false;
    }
    if ((!Character.isLetter(nodeName.charAt(0))) || (nodeName.charAt(0) != nodeName.toUpperCase().charAt(0))) {
        setErrorMessage("The node name must start with an uppercase letter.");
        return false;
    }

    String strClassName = getNodeClassName();
    for (int i = 0; i < strClassName.length(); i++) {
        char c = strClassName.charAt(i);
        if (!(i == 0 && Character.isJavaIdentifierStart(c)) && !(i > 0 && Character.isJavaIdentifierPart(c))) {
            setErrorMessage("The class name '" + strClassName + "' is invalid.");
            return false;
        }
    }

    // Check package name
    String basePackage = m_textBasePackage.getText();
    if (basePackage.length() == 0) {
        setErrorMessage(null);
        setMessage("Please provide a package name.");
        return false;
    }
    for (int i = 0; i < basePackage.length(); i++) {
        char c = basePackage.charAt(i);
        if (!(Character.isLowerCase(c) || Character.isDigit(c) || c == '.' || c == '_')) {
            setErrorMessage("The package name '" + basePackage + "' is invalid.");
            return false;
        }
    }

    // Check for existing classes (naming conflict?)
    IProject project = RDKitNodesWizards.getProjectForName(getProjectName());
    String path = "src/" + m_textBasePackage.getText().trim().replace('.', '/') + "/" + nodeName;
    IFile file = project.getFile(new Path(path + "NodeModel.java"));
    if (file.exists()) {
        setErrorMessage("A node with the given name exists already. Please provide another name or package.");
        return false;
    }

    // Check percentages for pre- and post processing
    try {
        double dPrePerc = getPreProcessingPercentage();
        double dPostPerc = getPostProcessingPercentage();

        if (dPrePerc + dPostPerc > 1.0d) {
            setErrorMessage("The total of pre and post processing activities cannot be greater than 100%.");
            return false;
        }
    } catch (NumberFormatException exc) {
        setErrorMessage("Bad number format: " + exc.getMessage());
        return false;
    }

    // Everything is ok so far
    setErrorMessage(null);
    setMessage(null);
    return true;
}

From source file:de.aschoerk.javaconv.RustDumpVisitor.java

@Override
public void visit(final FieldAccessExpr n, final Object arg) {
    printJavaComment(n.getComment(), arg);
    int mark = printer.push();
    n.getScope().accept(this, arg);
    String scope = printer.getMark(mark);
    printer.drop();//from  ww  w. j ava 2s.c  o m
    int i = StringUtils.lastIndexOfAny(StringUtils.stripEnd(scope, " "), "\n", "\t", " ", ".");
    String accessed = i <= 0 ? scope : scope.substring(i + 1);
    if (Character.isUpperCase(accessed.charAt(0)) && accessed.length() > 1
            && Character.isLowerCase(accessed.charAt(1))) {
        printer.print("::");
    } else {
        printer.print(".");
    }
    printer.print(replaceLengthAtEnd(n.getField()));
}

From source file:util.program.ProgramTextCreator.java

private static void addEntry(ExtendedHTMLDocument doc, StringBuilder buffer, Program prog,
        ProgramFieldType fieldType, boolean createLinks, boolean showHelpLinks, boolean showPersonLinks) {

    try {//  w  w  w . j  av  a  2s.  c  o m
        String text = null;
        String name = fieldType.getLocalizedName();
        int blank = name.indexOf(' ', 16);
        if (blank > 0) {
            name = name.substring(0, blank) + "<br>" + name.substring(blank + 1);
        }
        if (fieldType.getFormat() == ProgramFieldType.TEXT_FORMAT) {
            text = prog.getTextField(fieldType);
            if (ProgramFieldType.SHORT_DESCRIPTION_TYPE == fieldType) {
                text = checkDescription(text);
            }

            // Lazily add short description, but only if it differs from description
            if (fieldType == ProgramFieldType.DESCRIPTION_TYPE) {
                String description = checkDescription(prog.getDescription());
                text = description;

                if (prog.getShortInfo() != null) {
                    StringBuilder shortInfo = new StringBuilder(checkDescription(prog.getShortInfo()).trim());

                    // delete "..." at the end, but only for duplication check, not for display
                    while (shortInfo.toString().endsWith(".")) {
                        shortInfo.deleteCharAt(shortInfo.length() - 1);
                    }

                    if (!description.trim().startsWith(shortInfo.toString())) {
                        addEntry(doc, buffer, prog, ProgramFieldType.SHORT_DESCRIPTION_TYPE, true,
                                showHelpLinks);
                    }
                }
                text = text.replace("\\-", ""); // replace conditional dashes
                text = removeArtificialLineBreaks(text);
                text = HTMLTextHelper.convertTextToHtml(text, createLinks);
                // scan for moderation in beginning of description
                String[] lines = text.split("<br>");
                String[] tags = { "von und mit", "prsentiert von", "mit", "film von", "moderation",
                        "zu gast" };
                for (int i = 0; i < 2; i++) {
                    if (lines.length > i && lines[i].length() < 60) {
                        String line = lines[i];
                        for (String tag : tags) {
                            if (line.toLowerCase().startsWith(tag)
                                    || line.toLowerCase().startsWith(tag + ':')) {
                                String personsString = line.substring(tag.length(), line.length()).trim();
                                if (personsString.startsWith(":")) {
                                    personsString = personsString.substring(1).trim();
                                }
                                if (personsString.endsWith(".")) {
                                    personsString = personsString.substring(0, personsString.length() - 1)
                                            .trim();
                                }
                                String[] persons = personsString.split(" und ");
                                boolean doLink = true;
                                for (String person : persons) {
                                    if (person.isEmpty() || !Character.isLetter(person.charAt(0))
                                            || Character.isLowerCase(person.charAt(0))) {
                                        doLink = false;
                                        break;
                                    }
                                }
                                if (doLink) {
                                    for (String person : persons) {
                                        String[] names = person.split(" ");
                                        int partCount = names.length;
                                        if (partCount >= 2 && partCount < 4) {
                                            for (String n : names) {
                                                if (!StringUtils.isAlpha(n)) {
                                                    doLink = false;
                                                }
                                            }
                                            if (doLink) {
                                                text = StringUtils.replaceOnce(text, person,
                                                        addSearchLink(person));
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }

        } else if (fieldType.getFormat() == ProgramFieldType.TIME_FORMAT) {
            text = prog.getTimeFieldAsString(fieldType);
        } else if (fieldType.getFormat() == ProgramFieldType.INT_FORMAT) {
            if (fieldType == ProgramFieldType.RATING_TYPE) {
                int value = prog.getIntField(fieldType);
                if (value > -1) {
                    text = new DecimalFormat("##.#").format((double) prog.getIntField(fieldType) / 10) + "/10";
                }
            } else {
                text = prog.getIntFieldAsString(fieldType);
                if (text == null && fieldType == ProgramFieldType.AGE_LIMIT_TYPE) {
                    final String ageRating = prog.getTextField(ProgramFieldType.AGE_RATING_TYPE);
                    if (ageRating != null && !ageRating.isEmpty()) {
                        int age = ProgramUtilities.getAgeLimit(ageRating);
                        if (age >= 0) {
                            text = Integer.toString(age);
                        }
                    }
                }
            }
        }

        if (fieldType == ProgramFieldType.ORIGIN_TYPE) {
            String temp = prog.getIntFieldAsString(ProgramFieldType.PRODUCTION_YEAR_TYPE);
            if (temp != null && temp.trim().length() > 0) {
                if (text == null || text.trim().length() < 1) {
                    name = ProgramFieldType.PRODUCTION_YEAR_TYPE.getLocalizedName();
                    text = temp;
                } else {
                    name += "/<br>" + ProgramFieldType.PRODUCTION_YEAR_TYPE.getLocalizedName();
                    text += " " + temp;
                }
            }
            temp = prog.getIntFieldAsString(ProgramFieldType.LAST_PRODUCTION_YEAR_TYPE);
            if (temp != null && temp.trim().length() > 0) {
                if (text == null || text.trim().length() < 1) {
                    name = ProgramFieldType.LAST_PRODUCTION_YEAR_TYPE.getLocalizedName();
                    text = temp;
                } else {

                    text += " - " + temp;
                }
            }
        }

        if (text == null || text.trim().length() < 1) {
            if (ProgramFieldType.CUSTOM_TYPE == fieldType) {
                text = mLocalizer.msg("noCustom", "No custom information ");
            } else {
                return;
            }
        }

        startInfoSection(buffer, name);

        // add person links
        if (ProgramFieldType.DIRECTOR_TYPE == fieldType || ProgramFieldType.SCRIPT_TYPE == fieldType
                || ProgramFieldType.CAMERA_TYPE == fieldType || ProgramFieldType.CUTTER_TYPE == fieldType
                || ProgramFieldType.MUSIC_TYPE == fieldType || ProgramFieldType.MODERATION_TYPE == fieldType
                || ProgramFieldType.ADDITIONAL_PERSONS_TYPE == fieldType
                || ProgramFieldType.PRODUCER_TYPE == fieldType) {
            if (showPersonLinks && text.length() < 200) {
                // if field is longer, this is probably not a list of names
                if (text.endsWith(".")) {
                    text = text.substring(0, text.length() - 1);
                }
                String[] persons = splitPersons(text);
                for (int i = 0; i < persons.length; i++) {
                    // remove duplicate entries
                    boolean duplicate = false;
                    if (i < persons.length - 1) {
                        for (int j = i + 1; j < persons.length; j++) {
                            if (persons[i].equalsIgnoreCase(persons[j])) {
                                duplicate = true;
                                break;
                            }
                        }
                    }
                    if (duplicate) {
                        text = text.replaceFirst(Pattern.quote(persons[i]), "").trim();
                        if (text.startsWith(",")) {
                            text = text.substring(1).trim();
                        }
                        text = text.replaceAll(",\\s*,", ",");
                        continue;
                    }
                    // a name shall not have more name parts
                    if (persons[i].trim().split(" ").length <= 3) {
                        String link;
                        if (persons[i].contains("(")) {
                            int index = persons[i].indexOf('(');
                            String topic = persons[i].substring(0, index).trim();
                            link = addSearchLink(topic) + " " + persons[i].substring(index).trim();
                        } else {
                            link = addSearchLink(persons[i]);
                        }
                        text = text.replace(persons[i], link);
                    }
                }
            }
            buffer.append(text);
        } else if (ProgramFieldType.DESCRIPTION_TYPE == fieldType) {
            buffer.append(text);
        } else {
            buffer.append(HTMLTextHelper.convertTextToHtml(text, createLinks));
        }

        if ((ProgramFieldType.CUSTOM_TYPE == fieldType) && (showHelpLinks)) {
            buffer.append(" (<a href=\"").append(
                    mLocalizer.msg("customInfo", "http://enwiki.tvbrowser.org/index.php/CustomInformation"))
                    .append("\">?</a>)");
        }
        if ((ProgramFieldType.AGE_RATING_TYPE == fieldType) && (showHelpLinks)) {
            addHelpLink(buffer,
                    mLocalizer.msg("ratingInfo", "http://en.wikipedia.org/wiki/Motion_picture_rating_system"));
        }

        buffer.append("</td></tr>");

        addSeparator(doc, buffer);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.googlecode.wicketwebbeans.model.BeanMetaData.java

/**
 * Creates a human readable label from a Java identifier.
 * //from   w w w.j  av  a2 s.  c  o  m
 * @param identifier the Java identifier.
 * 
 * @return the label.
 */
private static String createLabel(String identifier) {
    // Check for a complex property.
    int idx = identifier.lastIndexOf('.');
    if (idx < 0) {
        idx = identifier.lastIndexOf('$'); // Java nested classes.
    }

    if (idx >= 0 && identifier.length() > 1) {
        identifier = identifier.substring(idx + 1);
    }

    if (identifier.length() == 0) {
        return "";
    }

    char[] chars = identifier.toCharArray();
    StringBuffer buf = new StringBuffer(chars.length + 10);

    // Capitalize the first letter.
    buf.append(Character.toUpperCase(chars[0]));
    boolean lastLower = false;
    for (int i = 1; i < chars.length; ++i) {
        if (!Character.isLowerCase(chars[i])) {
            // Lower to upper case transition -- add space before it
            if (lastLower) {
                buf.append(' ');
            }
        }

        buf.append(chars[i]);
        lastLower = Character.isLowerCase(chars[i]) || Character.isDigit(chars[i]);
    }

    return buf.toString();
}