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:org.talend.dataprep.filter.ObjectPredicateVisitor.java

private Method[] getMethods(String field) {
    StringTokenizer tokenizer = new StringTokenizer(field, ".");
    List<String> methodNames = new ArrayList<>();
    while (tokenizer.hasMoreTokens()) {
        methodNames.add(tokenizer.nextToken());
    }//from  w ww  .  j  a v a  2 s.  co  m

    Class currentClass = targetClass;
    Method[] methods = new Method[methodNames.size()];
    for (int i = 0; i < methodNames.size(); i++) {
        String[] getterCandidates = new String[] { "get" + WordUtils.capitalize(methodNames.get(i)), //
                methodNames.get(i), //
                "is" + WordUtils.capitalize(methodNames.get(i)) };

        for (String getterCandidate : getterCandidates) {
            try {
                methods[i] = currentClass.getMethod(getterCandidate);
                break;
            } catch (Exception e) {
                LOGGER.debug("Can't find getter '{}'.", field, e);
            }
        }
        if (methods[i] == null) {
            throw new UnsupportedOperationException("Can't find getter '" + field + "'.");
        } else {
            currentClass = methods[i].getReturnType();
        }
    }
    return methods;
}

From source file:org.talend.tql.bean.BeanPredicateVisitor.java

private Method[] getMethods(String field) {
    StringTokenizer tokenizer = new StringTokenizer(field, ".");
    List<String> methodNames = new ArrayList<>();
    while (tokenizer.hasMoreTokens()) {
        methodNames.add(tokenizer.nextToken());
    }/*from   www.  j  a  v a  2s  .  co m*/

    Class currentClass = targetClass;
    LinkedList<Method> methods = new LinkedList<>();
    for (String methodName : methodNames) {
        if ("_class".equals(methodName)) {
            try {
                methods.add(Class.class.getMethod("getClass"));
                methods.add(Class.class.getMethod("getName"));
            } catch (NoSuchMethodException e) {
                throw new IllegalArgumentException("Unable to get methods for class' name.", e);
            }
        } else {
            String[] getterCandidates = new String[] { "get" + WordUtils.capitalize(methodName), //
                    methodName, //
                    "is" + WordUtils.capitalize(methodName) };

            final int beforeFind = methods.size();
            for (String getterCandidate : getterCandidates) {
                try {
                    methods.add(currentClass.getMethod(getterCandidate));
                    break;
                } catch (Exception e) {
                    LOGGER.debug("Can't find getter '{}'.", field, e);
                }
            }
            if (beforeFind == methods.size()) {
                throw new UnsupportedOperationException("Can't find getter '" + field + "'.");
            } else {
                currentClass = methods.getLast().getReturnType();
            }
        }
    }
    return methods.toArray(new Method[0]);
}

From source file:org.tellervo.desktop.print.SeriesReport.java

private void getTableKey() throws DocumentException, IOException, IOException {
    PdfPTable mainTable = new PdfPTable(12);
    float[] widths = { 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f, 0.1f, 0.1f, 0.8f };
    mainTable.setWidths(widths);//  w  w  w  .  j  av  a  2 s.  c o m
    mainTable.setWidthPercentage(100);

    PdfPTable userRemarksTable = new PdfPTable(2);
    float[] widths2 = { 0.083f, 0.92f };
    userRemarksTable.setWidths(widths2);
    userRemarksTable.setWidthPercentage(100);

    Boolean userRemarkUsed = false;

    DecadalModel model;
    model = new UnitAwareDecadalModel(s);
    int rows = model.getRowCount();
    List<TridasRemark> masterList = null;

    // Loop through rows
    for (int row = 0; row < rows; row++) {
        // Loop through columns
        for (int col = 0; col < 11; col++) {
            org.tellervo.desktop.Year year = model.getYear(row, col);
            List<TridasRemark> remarksList = null;
            remarksList = s.getRemarksForYear(year);

            // If masterlist is still null initialize it with this remarks list
            if (remarksList.size() > 0 && masterList == null)
                masterList = remarksList;

            for (TridasRemark remark : remarksList) {
                if (!masterList.contains(remark))
                    masterList.add(remark);
            }
        }
    }

    for (TridasRemark remark : masterList) {
        PdfPCell iconCell = new PdfPCell();
        PdfPCell equalsCell = new PdfPCell();
        PdfPCell descriptionCell = new PdfPCell();

        iconCell.setBorder(0);
        equalsCell.setBorder(0);
        descriptionCell.setBorder(0);

        iconCell.setVerticalAlignment(Element.ALIGN_TOP);
        equalsCell.setVerticalAlignment(Element.ALIGN_TOP);
        descriptionCell.setVerticalAlignment(Element.ALIGN_TOP);

        Image icon = null;
        String remarkStr = null;

        // Get actual icon (either tridas or tellervo)
        if (remark.isSetNormalTridas()) {
            remarkStr = remark.getNormalTridas().toString().toLowerCase();
            remarkStr = remarkStr.replace("_", " ");
            icon = getTridasIcon(remark.getNormalTridas());
            if (icon == null)
                icon = Builder.getITextImageMissingIcon();
        } else if (TELLERVO.equals(remark.getNormalStd())) {
            remarkStr = remark.getNormal();
            icon = getCorinaIcon(remark.getNormal());
            if (icon == null)
                icon = Builder.getITextImageMissingIcon();
        } else {
            if (!userRemarkUsed) {
                remarkStr = "User Remark (See Below)";
                icon = Builder.getITextImageIcon("user.png");
                userRemarkUsed = true;
            } else {
                // User remark and we already have a key for this so continue
                continue;
            }
        }

        iconCell.addElement(icon);
        equalsCell.addElement(new Phrase("=", tableBodyFont));
        descriptionCell.addElement(new Phrase(WordUtils.capitalize(remarkStr), tableBodyFont));

        mainTable.addCell(iconCell);
        mainTable.addCell(equalsCell);
        mainTable.addCell(descriptionCell);
    }

    // Pad out empty cells
    PdfPCell blankCell = new PdfPCell();
    blankCell.addElement(new Phrase(""));
    blankCell.setBorder(0);
    for (int i = 0; i < 12; i++) {
        mainTable.addCell(blankCell);
    }

    document.add(mainTable);

    if (userRemarkUsed) {
        PdfPCell yearCell = new PdfPCell();
        yearCell.setBorder(0);
        yearCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        yearCell.addElement(new Phrase("Year", tableHeaderFont));
        userRemarksTable.addCell(yearCell);

        PdfPCell remarkCell = new PdfPCell();
        remarkCell.setBorder(0);
        remarkCell.addElement(new Phrase("User ring remarks", tableHeaderFont));
        userRemarksTable.addCell(remarkCell);

        for (int row = 0; row < rows; row++) {
            // Loop through columns
            for (int col = 0; col < 11; col++) {
                org.tellervo.desktop.Year year = model.getYear(row, col);
                List<TridasRemark> remarksList = null;
                remarksList = s.getRemarksForYear(year);

                for (TridasRemark remark : remarksList) {
                    if (remark.isSetNormalTridas() || remark.isSetNormalStd())
                        continue;

                    yearCell = new PdfPCell();
                    yearCell.setBorder(0);
                    yearCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    yearCell.addElement(new Phrase(year.toString(), tableHeaderFont));
                    userRemarksTable.addCell(yearCell);

                    remarkCell = new PdfPCell();
                    remarkCell.setBorder(0);
                    remarkCell.addElement(new Phrase(remark.getValue(), tableBodyFont));
                    userRemarksTable.addCell(remarkCell);
                }
            }
        }

        document.add(userRemarksTable);
    }
}

From source file:org.tridas.io.formats.sheffield.SheffieldToTridasDefaults.java

/**
 * @see org.tridas.io.defaults.TridasMetadataFieldSet#getDefaultTridasObject()
 *//*from   w  w  w  .j  a v  a 2s . c  om*/
@SuppressWarnings("unchecked")
@Override
protected TridasObject getDefaultTridasObject() {
    TridasObject o = super.getDefaultTridasObject();

    o.setTitle(getStringDefaultValue(DefaultFields.SHORT_TITLE).getStringValue());

    // If Lat Long is available use it
    if (getDefaultValue(DefaultFields.LATITUDE).getValue() != null
            && getDefaultValue(DefaultFields.LONGITUDE).getValue() != null) {
        TridasLocationGeometry geometry = SpatialUtils.getWGS84LocationGeometry(
                getDoubleDefaultValue(DefaultFields.LATITUDE).getValue(),
                getDoubleDefaultValue(DefaultFields.LONGITUDE).getValue());
        TridasLocation location = new TridasLocation();
        location.setLocationGeometry(geometry);
        o.setLocation(location);
    } else if (getStringDefaultValue(DefaultFields.UK_COORDS).getValue() != null) {
        // Convert UK coords and use these 
        try {
            o.setLocation(SpatialUtils
                    .getLocationGeometryFromBNG(getStringDefaultValue(DefaultFields.UK_COORDS).getValue()));
        } catch (NumberFormatException e) {
        }
    }

    if (getStringDefaultValue(DefaultFields.UK_COORDS).getValue() != null) {
        // Add UK Coords as a generic field
        TridasGenericField coords = new TridasGenericField();
        coords.setName("sheffield.UKCoords");
        coords.setType("xs:string");
        coords.setValue(getStringDefaultValue(DefaultFields.UK_COORDS).getValue());
        ArrayList<TridasGenericField> genericFields = new ArrayList<TridasGenericField>();
        genericFields.add(coords);
        o.setGenericFields(genericFields);
    }

    // Add group/phase as subobject
    if (getStringDefaultValue(DefaultFields.GROUP_PHASE).getValue() != null) {
        TridasObject subobj = super.getDefaultTridasObject();
        subobj.setTitle(getStringDefaultValue(DefaultFields.GROUP_PHASE).getValue());
        ControlledVoc type = new ControlledVoc();
        type.setValue(I18n.getText("sheffield.groupOrPhase"));
        subobj.setType(type);
        ArrayList<TridasObject> objects = new ArrayList<TridasObject>();
        objects.add(subobj);
        o.setObjects(objects);
    }

    // Temporal coverage
    try {
        GenericDefaultValue<SheffieldPeriodCode> periodField = (GenericDefaultValue<SheffieldPeriodCode>) getDefaultValue(
                DefaultFields.SHEFFIELD_PERIOD_CODE);
        SheffieldPeriodCode value = periodField.getValue();
        String sheffieldPeriod = value.toString();
        TridasCoverage coverage = new TridasCoverage();
        coverage.setCoverageTemporal(WordUtils.capitalize(sheffieldPeriod.toLowerCase()));
        coverage.setCoverageTemporalFoundation(I18n.getText("unknown"));
        o.setCoverage(coverage);
    } catch (NullPointerException e1) {
    }

    return o;
}

From source file:org.walkmod.settergetter.visitors.SetterGetterGenerator.java

@Override
public void visit(ClassOrInterfaceDeclaration n, VisitorContext arg) {
    if (!n.isInterface()) {

        ClassOrInterfaceDeclaration coid = new ClassOrInterfaceDeclaration();
        coid.setName(n.getName());/*from   w  ww .j a  v  a2 s.co  m*/
        coid.setModifiers(n.getModifiers());
        coid.setInterface(false);

        List<BodyDeclaration> members = new LinkedList<BodyDeclaration>();
        coid.setMembers(members);
        List<TypeDeclaration> types = new LinkedList<TypeDeclaration>();
        types.add(coid);
        cu.setTypes(types);

        Collection<FieldDeclaration> fields = getFields(n);
        if (fields != null) {

            arg.addResultNode(cu);
            for (FieldDeclaration fd : fields) {

                List<VariableDeclarator> variables = fd.getVariables();
                for (VariableDeclarator vd : variables) {
                    String fieldName = vd.getId().getName();
                    Parameter parameter = createParameter(fd.getType(), fieldName);
                    try {
                        if (!Modifier.isFinal(fd.getModifiers())) {

                            addMethodDeclaration(coid, ModifierSet.PUBLIC, ASTManager.VOID_TYPE,
                                    "set" + WordUtils.capitalize(fieldName), parameter,
                                    "{ this." + fieldName + " = " + fieldName + "; }");

                        }
                        if (!isBoolean(fd.getType())) {
                            Parameter p = null;
                            addMethodDeclaration(coid, ModifierSet.PUBLIC, fd.getType(),
                                    "get" + WordUtils.capitalize(fieldName), p, "{return " + fieldName + ";}");
                        } else {
                            Parameter p = null;
                            addMethodDeclaration(coid, ModifierSet.PUBLIC, fd.getType(),
                                    "is" + WordUtils.capitalize(fieldName), p, "{return " + fieldName + ";}");
                        }

                    } catch (ParseException e1) {
                        throw new WalkModException(e1);
                    }
                }
            }
        }
    }
}

From source file:org.wso2.carbon.appfactory.application.mgt.listners.InitialArtifactDeployerHandler.java

@Override
public void onCreation(Application application, String userName, String tenantDomain,
        boolean isUploadableAppType) throws AppFactoryException {
    String version = isUploadableAppType ? "1.0.0" : "trunk";
    String stage = isUploadableAppType
            ? WordUtils.capitalize(AppFactoryConstants.ApplicationStage.PRODUCTION.getStageStrValue())
            : WordUtils.capitalize(AppFactoryConstants.ApplicationStage.DEVELOPMENT.getStageStrValue());
    List<NameValuePair> params = AppFactoryCoreUtil.getDeployParameterMap(application.getId(),
            application.getType(), stage, AppFactoryConstants.ORIGINAL_REPOSITORY);

    //TODO - Fix properly in 2.2.0-M1
    params.add(new NameValuePair("tenantUserName", userName + "@" + tenantDomain));
    Map<String, String[]> deployInfoMap = new HashMap<String, String[]>();
    for (Iterator<NameValuePair> ite = params.iterator(); ite.hasNext();) {
        NameValuePair pair = ite.next();
        deployInfoMap.put(pair.getName(), new String[] { pair.getValue() });
    }/*www. j a v  a2 s.  c o m*/

    int tenantId = -1;
    String initialDeployerClassName = null;
    try {
        tenantId = Util.getRealmService().getTenantManager().getTenantId(tenantDomain);
        deployInfoMap.put(AppFactoryConstants.TENANT_DOMAIN, new String[] { tenantDomain });
        deployInfoMap.put(AppFactoryConstants.APPLICATION_VERSION, new String[] { version });
        deployInfoMap.put("tenantId", new String[] { Integer.toString(tenantId) });
        initialDeployerClassName = ApplicationTypeManager.getInstance()
                .getApplicationTypeBean(application.getType()).getInitialDeployerClassName();
        InitialArtifactDeployer deployer;
        if (initialDeployerClassName != null) {
            ClassLoader loader = getClass().getClassLoader();
            Class<?> initialDeployerClass = Class.forName(initialDeployerClassName, true, loader);
            Object instance = initialDeployerClass.getDeclaredConstructor(Map.class, int.class, String.class)
                    .newInstance(deployInfoMap, tenantId, tenantDomain);
            if (instance instanceof InitialArtifactDeployer) {
                deployer = (InitialArtifactDeployer) instance;
            } else {
                throw new AppFactoryException(initialDeployerClassName + "is not a implementation of "
                        + InitialArtifactDeployer.class);
            }
        } else {
            deployer = new InitialArtifactDeployer(deployInfoMap, tenantId, tenantDomain);
        }
        deployer.deployLatestSuccessArtifact(deployInfoMap);
    } catch (UserStoreException e) {
        throw new AppFactoryException("Initial code committing error " + application.getName(), e);
    } catch (ClassNotFoundException e) {
        throw new AppFactoryException(
                "Initial deployer class : " + initialDeployerClassName + " not found " + application.getName(),
                e);
    } catch (InstantiationException e) {
        throw new AppFactoryException("Cannot create instance of initial deployer class : "
                + initialDeployerClassName + " not found " + application.getName(), e);
    } catch (IllegalAccessException e) {
        throw new AppFactoryException("Cannot access initial deployer class : " + initialDeployerClassName
                + " not found " + application.getName(), e);
    } catch (NoSuchMethodException e) {
        throw new AppFactoryException("Cannot create instance of initial deployer class : "
                + initialDeployerClassName + " not found " + application.getName(), e);
    } catch (InvocationTargetException e) {
        throw new AppFactoryException("Cannot create instance of initial deployer class : "
                + initialDeployerClassName + " not found " + application.getName(), e);
    }
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.file.FilePollingConsumer.java

private void addOptions(String scheme, Map<String, String> schemeFileOptions) {
    if (scheme.equals(VFSConstants.SCHEME_SFTP)) {
        for (VFSConstants.SFTP_FILE_OPTION option : VFSConstants.SFTP_FILE_OPTION.values()) {
            String strValue = vfsProperties
                    .getProperty(VFSConstants.SFTP_PREFIX + WordUtils.capitalize(option.toString()));
            if (strValue != null && !strValue.equals("")) {
                schemeFileOptions.put(option.toString(), strValue);
            }//ww  w.  j a  v  a2 s.  co m
        }
    }
}

From source file:org.wso2.developerstudio.datamapper.diagram.custom.configuration.function.Function.java

private String createFunctionCall() {
    String inputSection = getInputParameter().getName();
    String outputSection = getOutputParameter().getName();

    String inputParameter = getInputTreeHierarchy();
    String outputParameter = getOutputTreeHierarchy();

    if (inputSection.equals(outputSection)) {
        outputSection = "output" + WordUtils.capitalize(outputSection);
    }/*from  ww  w  . j  av  a 2  s  .  c  om*/

    /*
     * If input parameter and output parameter names are identical, append
     * term 'output' to the output parameter as a convention.
     */
    if (inputParameter.equals(outputParameter)) {
        outputParameter = "output" + WordUtils.capitalize(outputParameter);
    }

    String functinCall = "map_" + getFlag() + "_" + inputSection + "_" + getFlag() + "_" + outputSection + "("
            + inputParameter + ", " + outputParameter + ");";

    return functinCall;
}

From source file:org.wso2.developerstudio.datamapper.diagram.custom.configuration.function.Function.java

/**
 * when the function call parent is an array, the arguments should be call in for loop
 * @param functionCall//  w  w  w . j a  v  a  2  s  . co m
 * @param parentFunction
 */
public String getFunctionCall(Function parentFunction) {
    String inputSection = getInputParameter().getName();
    String outputSection = getOutputParameter().getName();

    String inputParameter = removeLastNode(getInputTreeHierarchy());
    String outputParameter = removeLastNode(getOutputTreeHierarchy());
    //
    //      String parentFunctionInput = parentFunction.getInputParameter().getName();
    //      String parentFunctionOutput = parentFunction.getOutputParameter().getName();

    if (inputSection.equals(outputSection)) {
        outputSection = "output" + WordUtils.capitalize(outputSection);
    }

    /*
     * If input parameter and output parameter names are identical, append
     * term 'output' to the output parameter as a convention.
     */
    if (inputParameter.equals(outputParameter)) {
        outputParameter = "output" + WordUtils.capitalize(outputParameter);
    }

    String functinCallString = "map_" + getFlag() + "_" + inputSection + "_" + getFlag() + "_" + outputSection
            + "(" + inputParameter + ", " + outputParameter + ");";

    return functinCallString;

}

From source file:org.wso2.developerstudio.datamapper.diagram.custom.configuration.function.Function.java

private void createMainFunction() {
    try {/*from w ww. j  a v  a 2s. co m*/
        String inputParameter = getInputParameter().getName();
        String outputParameter = getOutputParameter().getName();

        /*
         * If input parameter and output parameter names are identical,
         * append term 'output' to the output parameter as a convention.
         */
        if (inputParameter.equals(outputParameter)) {
            outputParameter = "output" + WordUtils.capitalize(outputParameter);
        }

        String mainFunctionDeclaration = "function map_" + getFlag() + "_" + inputParameter + "_" + getFlag()
                + "_" + outputParameter + "(" + inputParameter + ", " + outputParameter + ") {";

        setDeclaration(mainFunctionDeclaration);

        if (mainFunction) {
            setReturnStatement("return " + getOutputParameter().getName() + ";");
        } else {
            setReturnStatement("");
        }
    } catch (Exception e) {
        log.error("Exception while creating main function decleration", e);
        String simpleMessage = ExceptionMessageMapper.getNonTechnicalMessage(e.getMessage());
        IStatus editorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, simpleMessage);
        ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                "Cannot generate configuration. The following error(s) have been detected. Please see the error log for more details ",
                editorStatus);
    }
}