Example usage for org.apache.commons.lang3 StringUtils capitalize

List of usage examples for org.apache.commons.lang3 StringUtils capitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils capitalize.

Prototype

public static String capitalize(final String str) 

Source Link

Document

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

Usage

From source file:org.gvnix.occ.roo.addon.addon.OCCChecksumMetadata.java

/**
 * Locates the checksum accessor method.
 * //from   w w  w .j a  v  a 2 s  .c  o m
 * @return the version identifier (may return null if there is no version
 *         field declared in this class)
 */
public MethodMetadata getChecksumAccessor() {
    FieldMetadata checksum = getChecksumField();

    // Compute the name of the accessor that will be produced
    String requiredAccessorName = "get" + StringUtils.capitalize(checksum.getFieldName().getSymbolName());

    // See if the user provided the field, and thus the accessor method
    if (!getId().equals(checksum.getDeclaredByMetadataId())) {
        MethodMetadata method = MemberFindingUtils.getMethod(governorTypeDetails,
                new JavaSymbolName(requiredAccessorName), new ArrayList<JavaType>());
        return method;
    }

    // We declared the field in this ITD, so produce a public accessor for
    // it
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("return this." + checksum.getFieldName().getSymbolName() + ";");

    return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName(requiredAccessorName),
            checksum.getFieldType(), new ArrayList<AnnotatedJavaType>(), new ArrayList<JavaSymbolName>(),
            bodyBuilder).build();
}

From source file:org.gvnix.occ.roo.addon.addon.OCCChecksumMetadata.java

/**
 * Locates the checksum mutator/*from  w w w.ja v  a 2  s  . c o  m*/
 * 
 * @return the version identifier (may return null if there is no version
 *         field declared in this class)
 */
public MethodMetadata getChecksumMutator() {

    // Locate the version field, and compute the name of the mutator that
    // will be produced
    FieldMetadata chekcsum = getChecksumField();
    if (chekcsum == null) {
        // There's no version field, so there certainly won't be a mutator
        // for it
        return null;
    }
    String requiredMutatorName = "set" + StringUtils.capitalize(chekcsum.getFieldName().getSymbolName());

    List<JavaType> paramTypes = new ArrayList<JavaType>();
    paramTypes.add(chekcsum.getFieldType());
    List<JavaSymbolName> paramNames = new ArrayList<JavaSymbolName>();
    paramNames.add(new JavaSymbolName("checksum"));

    // See if the user provided the field, and thus the accessor method
    if (!getId().equals(chekcsum.getDeclaredByMetadataId())) {
        MethodMetadata method = MemberFindingUtils.getMethod(governorTypeDetails,
                new JavaSymbolName(requiredMutatorName), paramTypes);
        return method;
    }

    // We declared the field in this ITD, so produce a public mutator for it
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("this." + chekcsum.getFieldName().getSymbolName() + " = checksum;");

    return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName(requiredMutatorName),
            JavaType.VOID_PRIMITIVE, AnnotatedJavaType.convertFromJavaTypes(paramTypes), paramNames,
            bodyBuilder).build();
}

From source file:org.gvnix.service.roo.addon.addon.ws.export.WSExportOperationsImpl.java

/**
 * Creates the list of annotations attribute values to export a web service
 * class.//from w  w  w .ja  v a 2s.  c  o m
 * 
 * @param serviceClass to be exported.
 * @param serviceName Name of the service.
 * @param portTypeName Port type name.
 * @param targetNamespace defined.
 * @param addressName to publish the service.
 * @return List of annotation attribute values to update.
 */
protected List<AnnotationAttributeValue<?>> exportServiceAnnotationAttributes(JavaType serviceClass,
        String serviceName, String portTypeName, String targetNamespace, String addressName) {
    // Checks serviceName parameter to publish the web service.
    serviceName = StringUtils.isNotBlank(serviceName) ? serviceName : serviceClass.getSimpleTypeName();

    // Checks correct namespace format.
    Validate.isTrue(wSExportValidationService.checkNamespaceFormat(targetNamespace),
            "The namespace for Target Namespace has to be defined using URI fromat.\ni.e.: http://name.of.namespace/");

    // Namespace for the web service.
    targetNamespace = StringUtils.isNotBlank(targetNamespace) ? targetNamespace
            : wSConfigService.convertPackageToTargetNamespace(serviceClass.getPackage().toString());

    // Check address name not blank and set service name if not defined.
    addressName = StringUtils.isNotBlank(addressName) ? StringUtils.capitalize(addressName)
            : serviceClass.getSimpleTypeName();

    // Define @GvNIXWebService annotation and attributes.
    // Check port type attribute name format and add attributes to a list.
    List<AnnotationAttributeValue<?>> gvNixAnnotationAttributes = new ArrayList<AnnotationAttributeValue<?>>();
    portTypeName = StringUtils.isNotBlank(portTypeName) ? portTypeName : serviceName.concat("PortType");
    gvNixAnnotationAttributes.add(new StringAttributeValue(new JavaSymbolName("name"), portTypeName));
    gvNixAnnotationAttributes
            .add(new StringAttributeValue(new JavaSymbolName("targetNamespace"), targetNamespace));
    gvNixAnnotationAttributes.add(new StringAttributeValue(new JavaSymbolName("serviceName"), serviceName));
    gvNixAnnotationAttributes.add(new StringAttributeValue(new JavaSymbolName("address"), addressName));
    gvNixAnnotationAttributes.add(new StringAttributeValue(new JavaSymbolName("fullyQualifiedTypeName"),
            serviceClass.getFullyQualifiedTypeName()));
    gvNixAnnotationAttributes.add(new BooleanAttributeValue(new JavaSymbolName("exported"), false));

    return gvNixAnnotationAttributes;
}

From source file:org.gvnix.service.roo.addon.addon.ws.export.WSExportOperationsImpl.java

/**
 * Creates gvNIX web method request attributes with the values defined.
 * <p>/*from   w w  w  .  j  a  v  a 2  s .c om*/
 * If the values are not set, define them using WS-i standard names.
 * Attributes created into gvNIX web service annotation are used to
 * generate:
 * </p>
 * <ul>
 * <li>javax.xml.ws.RequestWrapper: requestWrapperName,
 * requestWrapperNamespace, requestWrapperClassName</li>
 * <ul>
 * <p>
 * If parameters types or names are empty, empty list will return.
 * </p>
 * 
 * @param javaType Java type to export a method.
 * @param method Method to export.
 * @param operationName Name of the method to be showed as a Web Service
 *        operation.
 * @param requestWrapperName Name to define the Request Wrapper Object.
 * @param requestWrapperNamespace Request Wrapper Object Namespace.
 * @param targetNamespace Web Service Namespace.
 * @return gvNIX web method request attributes.
 */
protected List<AnnotationAttributeValue<?>> getRequestAnnotationAttributes(JavaType javaType,
        MethodMetadata method, String operationName, String requestWrapperName, String requestWrapperNamespace,
        String targetNamespace) {

    List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();

    // Check input parameters.
    if (!method.getParameterTypes().isEmpty() && !method.getParameterNames().isEmpty()) {

        // There are input parameters

        // gvNIX attributes for javax.xml.ws.RequestWrapper attributes

        requestWrapperName = StringUtils.isNotBlank(requestWrapperName) ? requestWrapperName : operationName;
        attrs.add(new StringAttributeValue(new JavaSymbolName("requestWrapperName"), requestWrapperName));

        // RequestWrapper namespace
        requestWrapperNamespace = StringUtils.isNotBlank(requestWrapperNamespace) ? requestWrapperNamespace
                : targetNamespace;
        attrs.add(new StringAttributeValue(new JavaSymbolName("requestWrapperNamespace"),
                requestWrapperNamespace));

        // Wrapper class
        String className = javaType.getPackage().getFullyQualifiedPackageName().concat(".")
                .concat(StringUtils.capitalize(requestWrapperName).concat("RequestWrapper"));
        attrs.add(new StringAttributeValue(new JavaSymbolName("requestWrapperClassName"), className));
    }

    return attrs;
}

From source file:org.gvnix.service.roo.addon.addon.ws.export.WSExportOperationsImpl.java

/**
 * Creates gvNIX web method response attributes with the values defined.
 * <p>//  w w w  . j ava  2  s. c o  m
 * If the values are not set, define them using WS-i standard names.
 * Attributes created for gvNIX web service annotation are used to generate:
 * </p>
 * <ul>
 * <li>javax.xml.ws.WebResult: resultName, resultNamespace, webResultType</li>
 * <li>javax.xml.ws.ResponseWrapper: responseWrapperName,
 * responseWrapperNamespace, responseWrapperClassName</li>
 * <ul>
 * 
 * @param javaType Java type to export a method.
 * @param operationName Name of the method to be showed as a Web Service
 *        operation.
 * @param resultName Method result name.
 * @param returnType JavaType class to return.
 * @param resultNamespace Result type Namespace.
 * @param responseWrapperName Name to define the Response Wrapper Object.
 * @param responseWrapperNamespace Response Wrapper Object Namespace.
 * @param targetNamespace Web Service Namespace.
 * @return gvNIX web method response attributes.
 */
protected List<AnnotationAttributeValue<?>> getResponseNoVoidAnnotationAttributes(JavaType javaType,
        String operationName, String resultName, JavaType returnType, String resultNamespace,
        String responseWrapperName, String responseWrapperNamespace, String targetNamespace) {

    List<AnnotationAttributeValue<?>> attrs = new ArrayList<AnnotationAttributeValue<?>>();

    // gvNIX attributes for javax.xml.ws.WebResult attributes

    // Result name
    attrs.add(new StringAttributeValue(new JavaSymbolName("resultName"), resultName));

    // Result namespace
    resultNamespace = StringUtils.isNotBlank(resultNamespace) ? resultNamespace : targetNamespace;
    attrs.add(new StringAttributeValue(new JavaSymbolName("resultNamespace"), resultNamespace));

    // Web result type
    attrs.add(new ClassAttributeValue(new JavaSymbolName("webResultType"), returnType));

    // gvNIX attributes for javax.xml.ws.ResponseWrapper attributes

    // Response wrapper name
    responseWrapperName = StringUtils.isNotBlank(responseWrapperName) ? responseWrapperName
            : operationName.concat("Response");
    StringAttributeValue responseWrapperNameAttr = new StringAttributeValue(
            new JavaSymbolName("responseWrapperName"), responseWrapperName);
    attrs.add(responseWrapperNameAttr);

    // Response wrapper namespace
    responseWrapperNamespace = StringUtils.isNotBlank(responseWrapperNamespace) ? responseWrapperNamespace
            : targetNamespace;
    attrs.add(
            new StringAttributeValue(new JavaSymbolName("responseWrapperNamespace"), responseWrapperNamespace));

    // Response wrapper class name
    String className = javaType.getPackage().getFullyQualifiedPackageName().concat(".")
            .concat(StringUtils.capitalize(responseWrapperName));
    attrs.add(new StringAttributeValue(new JavaSymbolName("responseWrapperClassName"), className));

    return attrs;
}

From source file:org.gvnix.web.menu.roo.addon.MenuEntryOperationsImpl.java

/** {@inheritDoc} */
public String addMenuItem(JavaSymbolName menuCategoryName, JavaSymbolName menuItemId, String menuItemLabel,
        String globalMessageCode, String link, String idPrefix, String roles, boolean hide,
        boolean writeProps) {

    Validate.notNull(menuCategoryName, "Menu category name required");
    Validate.notNull(menuItemId, "Menu item name required");

    // Properties to be written
    Map<String, String> properties = new HashMap<String, String>();

    if (idPrefix == null || idPrefix.length() == 0) {
        idPrefix = MenuOperations.DEFAULT_MENU_ITEM_PREFIX;
    }//w  w  w .j  a v  a 2  s . c  o  m

    Document document = getMenuDocument();

    // make the root element of the menu the one with the menu identifier
    // allowing for different decorations of menu
    Element rootElement = XmlUtils.findFirstElement(ID_MENU_EXP, (Element) document.getFirstChild());

    if (!rootElement.getNodeName().equals(GVNIX_MENU)) {
        throw new IllegalArgumentException(INVALID_XML);
    }

    // build category name and Id:
    // - menuCategoryName is a name if it doesn't start with c_: create the
    // id
    // - menuCategoryName is an identifier if it starts with c_: create the
    // name
    String categoryName = menuCategoryName.getSymbolName();
    StringBuilder categoryId = new StringBuilder();
    Element category = null;

    // check for existence of menu category by looking for the
    // identifier
    // provided

    // build category name and Id:
    // - menuCategoryName is a name if it doesn't start with c_: create
    // the
    // id
    // - menuCategoryName is an identifier if it starts with c_: create
    // the name
    // don't create any categoryId if there is already an id prefix
    if (!categoryName.startsWith(MenuEntryOperations.CATEGORY_MENU_ITEM_PREFIX)
            && !categoryName.startsWith(idPrefix)) {

        // create categoryId using the category name
        categoryId.append(MenuEntryOperations.CATEGORY_MENU_ITEM_PREFIX).append(categoryName.toLowerCase());
    } else {
        categoryId.append(categoryName.toLowerCase());
        // create category name using the category Id
        categoryName = StringUtils.capitalize(categoryName.substring(2));
    }

    List<Element> givenCategory = XmlUtils.findElements(ID_EXP.concat(categoryId.toString()).concat("']"),
            rootElement);

    // if given category not exists, create new one
    if (givenCategory.isEmpty()) {

        String categoryLabelCode = "menu_category_".concat(categoryName.toLowerCase()).concat("_label");

        category = (Element) rootElement.appendChild(new XmlElementBuilder(MENU_ITEM, document)
                .addAttribute("id", categoryId.toString()).addAttribute("name", categoryName)
                .addAttribute(LABEL_CODE, categoryLabelCode).build());

        properties.put(categoryLabelCode, menuCategoryName.getReadableSymbolName());
    } else {
        category = givenCategory.get(0);
    }

    // build menu item Id:
    // - if menu item id starts with 'i_', it is a valid ID but we remove
    // 'i_' for convenience
    // - otherwise, have to compose the ID
    StringBuilder itemId = new StringBuilder();

    if (menuItemId.getSymbolName().toLowerCase().startsWith(idPrefix)) {
        itemId.append(menuItemId.getSymbolName().toLowerCase());
        itemId.delete(0, idPrefix.length());
    } else {
        itemId.append(categoryName.toLowerCase()).append("_").append(menuItemId.getSymbolName().toLowerCase());
    }

    // check for existence of menu item by looking for the identifier
    // provided
    // Note that in view files, menu item ID has idPrefix_, but it doesn't
    // have
    // at application.properties, so we have to add idPrefix_ to look for
    // the given menu item but we have to add without idPrefix_ to
    // application.properties
    List<Element> menuList = XmlUtils
            .findElements(ID_EXP.concat(idPrefix).concat(itemId.toString()).concat("']"), rootElement);

    String itemLabelCode = "menu_item_".concat(itemId.toString()).concat("_label");

    if (menuList.isEmpty()) {
        Element menuItem = new XmlElementBuilder(MENU_ITEM, document)
                .addAttribute("id", idPrefix.concat(itemId.toString())).addAttribute(LABEL_CODE, itemLabelCode)
                .addAttribute(MESSAGE_CODE, StringUtils.isNotBlank(globalMessageCode) ? globalMessageCode : "")
                .addAttribute(URL, StringUtils.isNotBlank(link) ? link : "")
                .addAttribute(HIDDEN, Boolean.toString(hide))
                .addAttribute("roles", StringUtils.isNotBlank(roles) ? roles : "").build();

        // TODO: gvnix*.tagx uses destination in spite of url, change to url
        category.appendChild(menuItem);
    }

    if (StringUtils.isNotBlank(menuItemLabel)) {
        properties.put(itemLabelCode, menuItemLabel);
    }

    if (writeProps) {
        propFileOperations.addProperties(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""),
                "/WEB-INF/i18n/application.properties", properties, true, false);
    }

    writeXMLConfigIfNeeded(document);

    // return the ID assigned to new entry
    return idPrefix.concat(itemId.toString());
}

From source file:org.gvnix.web.menu.roo.addon.MenuEntryOperationsImpl.java

/**
 * Create menu.xml from menu.jspx./*from   w  w  w.jav  a 2  s  .  com*/
 * <p>
 * Iterates over menu.jspx elements and delegates menu.xml creation to
 * {@link #addMenuItem(JavaSymbolName, JavaSymbolName, String, String, String, String)}
 * , the same method used to create menu entries from shell.
 */
private void createMenu() {

    InputStream rooMenuInput = fileManager.getInputStream(getMenuFile());

    try {
        Document rooMenuDoc = XmlUtils.getDocumentBuilder().parse(rooMenuInput);
        Element root = rooMenuDoc.getDocumentElement();
        Element menu = XmlUtils.findFirstElement("/div/menu", root);
        if (menu == null) {
            // Roo menu exists but is still empty: there is no menu element
            // into div element already
            // Avoid error when execute "web mvc setup" and next
            // "menu setup"
            return;
        }

        // root categories and items
        NodeList menuElements = menu.getChildNodes();
        for (int i = 0; i < menuElements.getLength(); i++) {
            Node tmpNode = menuElements.item(i);
            if (tmpNode.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            String nodeName = tmpNode.getNodeName();

            // process root category elements
            if (nodeName.equals("menu:category")) {
                Element menuCategory = (Element) tmpNode;

                // We have to recover original categoryName to success
                // addMenuItem
                // execution
                JavaSymbolName categoryId = new JavaSymbolName(menuCategory.getAttribute("id"));
                JavaSymbolName categoryName = new JavaSymbolName(
                        StringUtils.capitalize(categoryId.getSymbolName().substring(2)));

                NodeList menuItems = menuCategory.getChildNodes();

                // process category inner item elements
                for (int j = 0; j < menuItems.getLength(); j++) {
                    tmpNode = menuItems.item(j);
                    if (tmpNode.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }
                    Element menuItem = (Element) tmpNode;

                    // - At menu.jspx there isn't label, no prob because it
                    // was added to
                    // application.properties
                    JavaSymbolName menuItemId = new JavaSymbolName(menuItem.getAttribute("id"));
                    String menuItemPrefix = getMenuItemPrefix(menuItemId.getSymbolName());

                    addMenuItem(categoryName, menuItemId, null, menuItem.getAttribute(MESSAGE_CODE),
                            menuItem.getAttribute(URL), menuItemPrefix);
                }
            }
            // item elements must be inside a category
            else if (nodeName.equals("menu:item")) {
                Element menuItem = (Element) tmpNode;
                JavaSymbolName menuItemId = new JavaSymbolName(menuItem.getAttribute("id"));
                logger.log(Level.SEVERE, "Found menu:item '".concat(menuItemId.getSymbolName())
                        .concat("' in menu:menu tag. It must be in ".concat("menu:category tag [Ignored]")));
            } else {
                logger.warning(
                        "Found unknow element in menu:menu tag: '".concat(nodeName).concat("' [Ignored]"));
            }

        }
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:org.gvnix.web.report.roo.addon.addon.ReportMetadata.java

/**
 * Given a reportName returns the name for the controller method
 * "generate<reportName>". If isForm = true, it will add "Form" to the
 * returned method name./*from w w  w .j  av  a 2s.c o  m*/
 * 
 * @param reportName
 * @param isForm
 */
public static String generateMethodName(String reportName, boolean isForm) {
    String methodName = "generate" + StringUtils.capitalize(reportName);

    if (isForm) {
        methodName = methodName.concat("Form");
    }
    return methodName;
}

From source file:org.gvnix.web.screen.roo.addon.AbstractPatternJspMetadataListener.java

protected String uncapitalize(String term) {
    // [ROO-1790] this is needed to adhere to the JavaBean naming
    // conventions (see JavaBean spec section 8.8)
    return Introspector.decapitalize(StringUtils.capitalize(term));
}

From source file:org.gvnix.web.screen.roo.addon.EntityBatchMetadata.java

/**
 * Generate a getter for <code>field</code>
 * //  w  w  w  . j  a v  a2 s.com
 * @param field field metadata
 * @return
 */
private MethodMetadataBuilder getListInner_getter(FieldMetadata field) {
    // Gets filed name
    String fieldName = field.getFieldName().getSymbolName();

    // Generate method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine(MessageFormat.format("return {0};", new Object[] { fieldName }));

    // Creates Method builder
    MethodMetadataBuilder builder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
            new JavaSymbolName("get".concat(StringUtils.capitalize(fieldName))), field.getFieldType(),
            bodyBuilder);

    return builder;
}