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.evolveum.midpoint.model.impl.util.AbstractSearchIterativeResultHandler.java

protected String getProcessShortNameCapitalized() {
    return StringUtils.capitalize(processShortName);
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.content.ContentLinkTag.java

public static Object getObject(final Object object, final String property) {
    final String methodName = "get" + StringUtils.capitalize(property);
    try {/*w  ww  . j  av a 2s. c  o  m*/
        final Method method = object.getClass().getMethod(methodName);
        return method.invoke(object);
    } catch (final NoSuchMethodException e) {
        throw new Error(e);
    } catch (final IllegalArgumentException e) {
        throw new Error(e);
    } catch (final IllegalAccessException e) {
        throw new Error(e);
    } catch (final InvocationTargetException e) {
        throw new Error(e);
    }
}

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

private static String getRegionMethod(String region) {
    return "set" + StringUtils.capitalize(region) + "Widget";
}

From source file:net.sf.eclipsecs.ui.quickfixes.coding.StringLiteralEqualityQuickfix.java

/**
 * {@inheritDoc}/* w  w w.  j av  a  2 s  .  com*/
 */
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartPosition) {

    return new ASTVisitor() {

        public boolean visit(InfixExpression node) {

            if (containsPosition(lineInfo, node.getStartPosition())) {

                StringLiteral literal = null;
                Expression otherOperand = null;

                if (node.getLeftOperand() instanceof StringLiteral) {
                    literal = (StringLiteral) node.getLeftOperand();
                    otherOperand = node.getRightOperand();
                } else if (node.getRightOperand() instanceof StringLiteral) {
                    literal = (StringLiteral) node.getRightOperand();
                    otherOperand = node.getLeftOperand();
                } else {
                    return true;
                }

                Expression replacementNode = null;

                MethodInvocation equalsInvocation = node.getAST().newMethodInvocation();
                equalsInvocation.setName(node.getAST().newSimpleName("equals")); //$NON-NLS-1$
                equalsInvocation.setExpression((Expression) ASTNode.copySubtree(node.getAST(), literal));
                equalsInvocation.arguments().add(ASTNode.copySubtree(node.getAST(), otherOperand));

                // if the string was compared with != create a not
                // expression
                if (node.getOperator().equals(InfixExpression.Operator.NOT_EQUALS)) {
                    PrefixExpression prefixExpression = node.getAST().newPrefixExpression();
                    prefixExpression.setOperator(PrefixExpression.Operator.NOT);
                    prefixExpression.setOperand(equalsInvocation);
                    replacementNode = prefixExpression;
                } else {
                    replacementNode = equalsInvocation;
                }

                replaceNode(node, replacementNode);
            }
            return true;
        }

        /**
         * Replaces the given node with the replacement node (using
         * reflection since I am not aware of a proper API to do this).
         * 
         * @param node
         *            the node to replace
         * @param replacementNode
         *            the replacement
         */
        private void replaceNode(ASTNode node, ASTNode replacementNode) {

            try {
                if (node.getLocationInParent().isChildProperty()) {

                    String property = node.getLocationInParent().getId();

                    String setterMethodName = "set" + StringUtils.capitalize(property);

                    Class testClass = node.getClass();

                    while (testClass != null) {

                        try {
                            Method setterMethod = node.getParent().getClass().getMethod(setterMethodName,
                                    testClass);
                            setterMethod.invoke(node.getParent(), replacementNode);
                            break;
                        } catch (NoSuchMethodException e) {
                            testClass = testClass.getSuperclass();
                        }
                    }

                } else if (node.getLocationInParent().isChildListProperty()) {
                    Method listMethod = node.getParent().getClass()
                            .getMethod(node.getLocationInParent().getId(), (Class<?>[]) null);
                    List list = (List) listMethod.invoke(node.getParent(), (Object[]) null);
                    list.set(list.indexOf(node), replacementNode);
                }
            } catch (InvocationTargetException e) {
                CheckstyleLog.log(e);
            } catch (IllegalAccessException e) {
                CheckstyleLog.log(e);
            } catch (NoSuchMethodException e) {
                CheckstyleLog.log(e);
            }
        }
    };
}

From source file:com.google.gdt.eclipse.designer.uibinder.refactoring.UiFieldRenameParticipant.java

/**
 * Adds {@link TextEdit}s into existing Java file {@link Change}.
 *///from  ww  w  .ja va2 s .c  o m
private void addHandlerMethodChanges(CompositeChange compositeChange, IProgressMonitor pm) throws Exception {
    TextChange change = new CompilationUnitChange("(No matter)", m_field.getCompilationUnit());
    change.setEdit(new MultiTextEdit());
    // update handler methods
    String oldMethodPrefix = "on" + StringUtils.capitalize(m_oldName);
    String newMethodPrefix = "on" + StringUtils.capitalize(m_newName);
    IType type = (IType) m_field.getParent();
    for (IMethod method : type.getMethods()) {
        // prepare @UiHandler annotation
        IAnnotation annotation = getHandlerAnnotation(method);
        if (annotation == null) {
            continue;
        }
        // update @UiHandler name
        {
            ISourceRange annoRange = annotation.getSourceRange();
            ISourceRange nameRange = annotation.getNameRange();
            int nameEnd = nameRange.getOffset() + nameRange.getLength();
            int annoEnd = annoRange.getOffset() + annoRange.getLength();
            change.addEdit(new ReplaceEdit(nameEnd, annoEnd - nameEnd, "(\"" + m_newName + "\")"));
        }
        // rename method
        String methodName = method.getElementName();
        if (methodName.startsWith(oldMethodPrefix)) {
            String newName = newMethodPrefix + StringUtils.removeStart(methodName, oldMethodPrefix);
            Change renameChange = createRenameChange(method, newName, pm);
            compositeChange.add(renameChange);
            RefactoringUtils.mergeTextChange(this, renameChange);
        }
    }
    // merge edits into existing (rename) change
    RefactoringUtils.mergeTextChange(this, change);
}

From source file:com.googlecode.fascinator.portal.services.cache.JythonCacheEntryFactory.java

/**
 * Creates a jython object instance for the script cache.
 * //from   w w  w . j  a  v  a2  s.  c o m
 * @param key the path to the jython script
 * @return an instantiated jython object
 * @throws Exception if the jython object failed to be instantiated
 */
@Override
public Object createEntry(Object key) throws Exception {
    // log.debug("createEntry({})", key);
    String path = key.toString();
    int qmarkPos = path.lastIndexOf("?");
    if (qmarkPos != -1) {
        path = path.substring(0, qmarkPos);
    }
    int slashPos = path.indexOf("/");
    String portalId = path.substring(0, slashPos);
    PyObject scriptObject = null;
    InputStream in = velocityService.getResource(path);
    if (in == null) {
        log.debug("Failed to load script: '{}'", path);
    } else {
        // add current and default portal directories to python sys.path
        addSysPaths(portalId, Py.getSystemState());
        // setup the python interpreter
        PythonInterpreter python = PythonInterpreter.threadLocalStateInterpreter(null);
        // expose services for backward compatibility - deprecated
        python.set("Services", scriptingServices);
        // python.setLocals(scriptObject);
        JythonLogger jythonLogger = new JythonLogger(path);
        python.setOut(jythonLogger);
        python.setErr(jythonLogger);
        python.execfile(in, path);
        String scriptClassName = StringUtils.capitalize(FilenameUtils.getBaseName(path)) + "Data";
        PyObject scriptClass = python.get(scriptClassName);
        if (scriptClass != null) {
            scriptObject = scriptClass.__call__();
        } else {
            log.debug("Failed to find class '{}'", scriptClassName);
        }
        python.cleanup();
    }
    return scriptObject;
}

From source file:com.manydesigns.elements.fields.PasswordField.java

@Override
public void toXhtml(@NotNull XhtmlBuffer xb) {
    if (mode.isEdit() && (mode.isCreate() || updatable)) { //was !immutable
        openVisibleField(xb);//from   ww w . ja v a 2s. c o  m
        valueToXhtml(xb, id, inputName, stringValue);
        helpToXhtml(xb);
        if (confirmationRequired) {
            closeVisibleField(xb);
            //Open another input
            xb.openElement("div");
            String cssClass = "control-group readwrite required";
            if (errors.size() > 0) {
                cssClass += " error";
            }
            xb.addAttribute("class", cssClass);
            String confirmationHtmlId = id + "_confirm";
            String confirmationInputName = inputName + "_confirm";
            String confirmLabel = ElementsThreadLocals.getText("elements.field.password.confirm") + " " + label;
            String actualLabel;
            boolean capitalize = elementsConfiguration.getBoolean(ElementsProperties.FIELDS_LABEL_CAPITALIZE);
            if (capitalize) {
                actualLabel = StringUtils.capitalize(confirmLabel);
            } else {
                actualLabel = confirmLabel;
            }
            xb.writeLabel(actualLabel, confirmationHtmlId, FORM_LABEL_CLASS);
            xb.openElement("div");
            xb.addAttribute("class", "controls");
            // print out confirmation input field
            valueToXhtml(xb, confirmationHtmlId, confirmationInputName, confirmationValue);
        }
        errorsToXhtml(xb);
        closeVisibleField(xb);
    } else {
        super.toXhtml(xb);
    }
}

From source file:jp.co.tis.gsp.tools.dba.mojo.GenerateEntity.java

/**
 * S2JDBC-GEN??Entity??/*from ww  w. j  a v a 2 s.  c  o  m*/
 * Entity??dicon????????
 */
@Override
protected void executeMojoSpec() throws MojoExecutionException, MojoFailureException {
    Configuration fmConfig = new Configuration();
    fmConfig.setTemplateLoader(new ClassTemplateLoader(Erd.class, "/jp/co/tis/gsp/tools/dba/template/dicon"));

    Map<String, Object> param = new HashMap<String, Object>();
    param.put("driver", driver);
    param.put("url", url);
    param.put("user", adminUser);
    /* NULL?freemarker??InvalidReferenceException????
       Mojo?parameter??NULL???????????? */
    param.put("password", (adminPassword == null) ? "" : adminPassword);
    param.put("rootPackage", rootPackage);

    String[] urlTokens = StringUtils.split(url, ':');
    if (urlTokens.length < 3) {
        throw new MojoExecutionException("Invalid url:" + url);
    }
    String databaseProduct = StringUtils.capitalize(urlTokens[1]);
    if ("Postgresql".equals(databaseProduct)) {
        databaseProduct = "Postgre";
    } else if ("Sqlserver".equals(databaseProduct)) {
        databaseProduct = "Mssql";
    }
    String dialectClass = this.dialectClassName != null ? dialectClassName
            : "org.seasar.extension.jdbc.dialect." + databaseProduct + "Dialect";
    if (StringUtil.equals(databaseProduct, "Solr")) {
        dialectClass = "net.unit8.solr.jdbc.extension.s2jdbc.dialect.SolrDialect";
    }
    param.put("databaseProduct", databaseProduct);
    param.put("dialectClass", dialectClass);

    try {
        if (!diconDir.exists())
            FileUtils.forceMkdir(diconDir);
        for (String templateName : templateNames) {
            Template template = fmConfig.getTemplate(templateName + ".dicon.ftl");
            template.process(param, new FileWriter(new File(diconDir, templateName + ".dicon")));
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Can't generate dicon file.", e);
    } catch (TemplateException e) {
        throw new MojoExecutionException("Can't generate dicon file.", e);
    }

    executeGenerateEntity();
}

From source file:mrcg.domain.JavaField.java

public String getLabelOrSynthetic() {
    if (label == null) {
        return Utils.toSpacedCamelCase(StringUtils.capitalize(name));
    } else {//www . jav a  2  s. c  o m
        return label;
    }
}

From source file:com.healthcit.analytics.utils.CAHopeDataSourceUtils.java

/**
 * Transforms a list of AbstractColumn objects into ColumnDescription entities
 *//*w  ww.  j  av  a  2  s .  c  o  m*/
private static ColumnDescription[] generateColumnDescriptions(List<AbstractColumn> columns,
        List<Map<String, Object>> columnDataArray) {

    List<ColumnDescription> list = new LinkedList<ColumnDescription>();

    // get the full list of column data types
    ValueType[] dataTypes = getFullColumnDataTypeList(columnDataArray);

    for (int i = 0; i < columns.size(); ++i) {
        AbstractColumn column = columns.get(i);

        // get the column's data type
        //TODO: The datatypes for each column should be dynamically determined.
        //( Currently, the datatypes have been hardcoded as "text" fields,
        // and in some cases they have been hardcoded as "numeric" fields 
        // on the client side.)
        ValueType columnType = dataTypes[i];

        ColumnDescription columnDescription = new ColumnDescription(column.getId(), columnType,
                StringUtils.capitalize(column.getId()));

        list.add(columnDescription);
    }

    return list.toArray(new ColumnDescription[list.size()]);
}