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.ecyrd.management.SimpleMBean.java

/**
 *  Gets an attribute using reflection from the MBean.
 *  //www. j  a v  a2 s .c om
 *  @param name Name of the attribute to find.
 *  @return The value returned by the corresponding getXXX() call
 *  @throws AttributeNotFoundException If there is not such attribute
 *  @throws MBeanException 
 *  @throws ReflectionException
 */
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    Method m;
    Object res = null;
    try {
        String mname = "get" + StringUtils.capitalize(name);
        m = findGetterSetter(getClass(), mname, null);

        if (m == null)
            throw new AttributeNotFoundException(name);
        res = m.invoke(this, (Object[]) null);
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return res;
}

From source file:com.baidu.bjf.remoting.protobuf.IDLProxyObject.java

/**
 * @param value//from ww w.j  a  v a  2 s.  c  o  m
 * @param object
 * @param f
 * @throws SecurityException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 */
private void setField(Object value, Object object, Field f) {
    f.setAccessible(true);

    Object valueToSet = value;
    try {
        // check if field type is enum
        if (Enum.class.isAssignableFrom(f.getType())) {
            Enum v = Enum.valueOf((Class<Enum>) f.getType(), String.valueOf(value));
            {
                valueToSet = v;
            }
        }
        if (f.getType().getName().equals("java.util.List")) {
            // Method[] ms = object.getClass().getMethods();
            Method method = MethodUtils.findMethod(object.getClass(),
                    "add" + StringUtils.capitalize(f.getName()), new Class[] { value.getClass() });
            method.invoke(object, value);
        } else {
            f.set(object, valueToSet);
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.importer.XmiHelper.java

/**
 * Returns the WriteMethod for the given EStructuralFeature
 * /*from w  ww  .  j  a  va2 s  . c om*/
 * @param esf the given EStructuralFeature
 * @param entityClass the entity class to get the method from
 * @return the corresponding WriteMethod
 */
public static Method getWriteMethod(EStructuralFeature esf, Class<? extends IdEntity> entityClass) {
    try {
        String methodName = "set" + StringUtils.capitalize(esf.getName());
        Class<?> firstMethodParameterType = getReadMethod(esf, entityClass).getReturnType();

        return entityClass.getMethod(methodName, firstMethodParameterType);
    } catch (NoSuchMethodException e) {
        LOGGER.error(e);
    } catch (SecurityException e) {
        LOGGER.error(e);
    }

    LOGGER.error("No setMethod for:" + esf.getName());

    return null;
}

From source file:com.agimatec.annotations.jam.JAMDtoFieldAnnotation.java

public static String getGetterName(String name, String type) {
    if (type.equals("boolean")) {
        return "is" + StringUtils.capitalize(name);
    } else {//from  w  ww .ja v a2 s . c o m
        return "get" + StringUtils.capitalize(name);
    }
}

From source file:edu.ku.brc.specify.utilapps.ERDTable.java

/**
 * @param p//from   w ww . ja  va2 s  .com
 * @param r
 * @param font
 * @param y
 * @param all
 * @return
 */
public JComponent build(final PanelBuilder p, final DBRelationshipInfo r, final Font font, final int y,
        boolean all) {
    String type = r.getType().toString().toLowerCase();
    type = getResourceString(type);

    CellConstraints cc = new CellConstraints();
    p.add(ERDVisualizer.mkLabel(font, StringUtils.substringAfterLast(r.getClassName(), "."),
            SwingConstants.LEFT), cc.xy(1, y));
    p.add(ERDVisualizer.mkLabel(font, StringUtils.capitalize(r.getTitle()), SwingConstants.LEFT), cc.xy(3, y));
    JComponent comp = ERDVisualizer.mkLabel(font, type, SwingConstants.CENTER);
    p.add(comp, cc.xy(5, y));
    if (all) {
        comp = ERDVisualizer.mkLabel(font, r.isRequired() ? yesStr : "", SwingConstants.CENTER);
        p.add(comp, cc.xy(7, y));
    }
    return comp;
}

From source file:com.activecq.api.helpers.WCMHelper.java

/**
 * Creates a String HTML representation of the Component's edit block. If
 * EditType DropTargets equals specified, Block will created by inspecting the
 * Drop Targets./*from w w w. ja v  a2s  . c o m*/
 *
 * @param request
 * @param editType
 * @param isConfigured will display edit block if evaluates to false
 * @return
 */
public static String getEditBlock(SlingHttpServletRequest request, WCMEditType.Type editType,
        boolean... isConfigured) {

    final Resource resource = request.getResource();
    final com.day.cq.wcm.api.components.Component component = WCMUtils.getComponent(resource);
    if (!isAuthoringMode(request) || conditionAndCheck(isConfigured)) {
        return null;
    } else if (WCMEditType.NONE.equals(editType)) {
        return "<!-- Edit Mode Placeholder is specified as: " + editType.getName() + " -->";
    }

    String html = "<div class=\"wcm-edit-mode " + CSS_EDIT_MODE + "\">";

    if (component == null) {
        html += getCssStyle();
        html += "Could not resolve CQ Component type.";
    } else if (WCMEditType.NOICON.equals(editType) || WCMEditType.NONE.equals(editType)) {
        final String title = StringUtils.capitalize(component.getTitle());

        html += getCssStyle();
        html += "<dl>";
        html += "<dt>" + title + " Component</dt>";

        if (component.isEditable()) {
            html += "<dd>Double click or Right click to Edit</dd>";
        }

        if (component.isDesignable()) {
            html += "<dd>Switch to Design mode and click the Edit button</dd>";
        }

        if (!component.isEditable() && !component.isDesignable()) {
            html += "<dd>The component cannot be directly authored</dd>";
        }

        html += "</dl>";
    } else if (WCMEditType.DROPTARGETS.equals(editType)) {
        // Use DropTargets
        ComponentEditConfig editConfig = component.getEditConfig();
        Map<String, DropTarget> dropTargets = (editConfig != null) ? editConfig.getDropTargets() : null;

        if (dropTargets != null && !dropTargets.isEmpty()) {
            // Auto generate images with drop-targets
            for (String key : dropTargets.keySet()) {
                final DropTarget dropTarget = (DropTarget) dropTargets.get(key);

                html += "<img src=\"/libs/cq/ui/resources/0.gif\"" + " " + "class=\"" + dropTarget.getId() + " "
                        + getWCMEditType(dropTarget).getCssClass() + "\"" + " " + "alt=\"Drop Target: "
                        + dropTarget.getName() + "\"" + " " + "title=\"Drop Target: " + dropTarget.getName()
                        + "\"" + "/>";
            }
        }
    } else {
        final String title = StringUtils.capitalize(component.getTitle());

        // Use specified EditType
        html += "<img src=\"/libs/cq/ui/resources/0.gif\"" + " " + "class=\"" + editType.getCssClass() + "\""
                + " " + "alt=\"" + title + "\"" + " " + "title=\"" + title + "\"" + "/>";
    }

    html += "</div>";

    return html;
}

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

/**
 * Generate the operation name, method and title attributes. This method
 * will check for duplicates (overloaded methods) and generate a different
 * method name for these overloaded methods, also setting the method
 * attribute in the process (otherwise not needed). If the method seems to
 * be overloaded, then the operationName tag in the javadoc is looked up. If
 * it does not exist, a long name will be generated using the concatenated
 * method name and parameter names and their types.
 * /*from ww  w  . java  2  s  .co  m*/
 * @param operationList
 *            the operation list to check for overloaded methods
 * @param javaMethod
 *            the java method
 * @param operation
 *            the operation
 */
final protected void generateOperationNameMethodTitle(final List<String> existingOperationNames,
        final JavaMethod javaMethod, final OperationType operation, String suggestedName) {
    JavaParameter[] parameters = javaMethod.getParameters();
    String methodName = javaMethod.getName();
    String operationName;

    if (existingOperationNames.contains(methodName)) {
        // An overloaded method has been found, we will need to generate a
        // name
        // Let's see if the developer specified his preference
        if (StringUtils.isNotBlank(suggestedName)) {
            // Yes, he did!
            if (existingOperationNames.contains(suggestedName)) {
                throw new RuntimeException("Could not generate component XML, the method " + methodName
                        + " in class " + javaMethod.getParentClass().getName()
                        + " has no unique operation name, please check your definition and make sure you specify a unique name");
            }
            operationName = suggestedName;
        } else {
            // Generate one, using the parameter names and types
            StringBuilder generated = new StringBuilder(methodName);
            generated.append("With");

            for (JavaParameter javaParameter : parameters) {
                generated.append(StringUtils.capitalize(javaParameter.getName()));
                generated.append("As");
                generated.append(StringUtils.capitalize(javaParameter.getType().getJavaClass().getName()));
            }
            operationName = generated.toString();
            if (existingOperationNames.contains(operationName)) {
                throw new RuntimeException(
                        "Could not generate component XML, the system could not generate a unique operation name for method "
                                + methodName + " in class " + javaMethod.getParentClass().getName()
                                + ", please check your definition and make sure you specify a unique name");
            }
        }
        operation.setMethod(methodName);
    } else {
        if (StringUtils.isNotBlank(suggestedName)) {
            operationName = suggestedName;
        } else {
            operationName = methodName;
        }
    }
    operation.setName(operationName);
    operation.setTitle(generateTitle(operationName));
}

From source file:ml.shifu.shifu.util.ClassUtils.java

public static Method getDeclaredSetter(String name, Class<?> clazz) throws NoSuchMethodException {
    Method method = getFirstMethodWithName("set" + StringUtils.capitalize(name), clazz);
    if (method == null) {
        throw new NoSuchMethodException();
    }// www.  j  av  a  2 s.c  o m
    return method;
}

From source file:it.unimi.di.big.mg4j.index.BitStreamIndex.java

protected static String featureName(final Coding coding) {
    return StringUtils.capitalize((coding == null ? CompressionFlags.NONE : coding.toString()).toLowerCase());
}

From source file:com.atlassian.plugins.studio.storage.examples.it.IntegrationTestServlet.java

private String getTestName(Method test) {
    return Joiner.on(' ').skipNulls()
            .join(Iterables.transform(Arrays.asList(StringUtils.splitByCharacterTypeCamelCase(test.getName())),
                    new Function<String, String>() {
                        @Override
                        public String apply(@Nullable String from) {
                            return StringUtils.capitalize(from);
                        }//  w w  w  .j ava 2  s .c  o  m
                    }));
}