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:com.baasbox.controllers.Social.java

/**
 * Unlink given social network from current user.
 * In case that the user was generated by any social network and
 * at the moment of the unlink the user has only one social network connected
 * the controller will throw an Exception with a clear message.
 * Otherwise a 200 code will be returned
 * @param socialNetwork//  ww w.  jav  a 2s. c om
 * @return
 * @throws SqlInjectionException 
 */
@With({ UserCredentialWrapFilter.class, ConnectToDBFilter.class })
public static Result unlink(String socialNetwork) throws SqlInjectionException {
    ODocument user = null;
    try {
        user = UserService.getCurrentUser();
    } catch (Exception e) {
        internalServerError(ExceptionUtils.getMessage(e));
    }
    Map<String, ODocument> logins = user.field(UserDao.ATTRIBUTES_SYSTEM + "." + UserDao.SOCIAL_LOGIN_INFO);
    if (logins == null || logins.isEmpty() || !logins.containsKey(socialNetwork)
            || logins.get(socialNetwork) == null) {
        return notFound("User's account is not linked with " + StringUtils.capitalize(socialNetwork));
    } else {
        boolean generated = UserService.isSocialAccount(DbHelper.getCurrentUserNameFromConnection());
        if (logins.size() == 1 && generated) {
            return internalServerError("User's account can't be unlinked.");
        } else {
            try {
                UserService.removeSocialLoginTokens(user, socialNetwork);
                return ok();
            } catch (Exception e) {
                return internalServerError(ExceptionUtils.getMessage(e));
            }
        }
    }
}

From source file:me.utils.excel.ImportExcelme.java

/**
 * ??//from ww  w. j  av a  2  s.co  m
 * @wj
 * @param e
 * @param propertyName
 * @param val
 * @param i
 * @param column
 * @throws BusinessException
 */
private <E> void check(E e, String propertyName, Object val, int i, int column) throws BusinessException {
    //      NotNull notNullAnno = Reflections.getAccessibleField(e, propertyName).getAnnotation(NotNull.class);
    //      NotBlank notBlankAnno = Reflections.getAccessibleField(e, propertyName).getAnnotation(NotBlank.class);
    String getMethodName = "get" + StringUtils.capitalize(propertyName);
    NotNull notNullAnno = Reflections.getAccessibleMethodByName(e, getMethodName).getAnnotation(NotNull.class);
    NotBlank notBlankAnno = Reflections.getAccessibleMethodByName(e, getMethodName)
            .getAnnotation(NotBlank.class);

    if (notNullAnno != null) {
        if (StringUtils.isBlank(String.valueOf(val.toString()))) {
            throw new BusinessException(" [" + i + "," + column + "] ?");
        }
    }
    if (notBlankAnno != null) {
        if (StringUtils.isBlank(String.valueOf(val.toString()))) {
            throw new BusinessException(" [" + i + "," + column + "] ?");
        }
    }
}

From source file:cognitivej.vision.emotion.EmotionStringBuilder.java

/**
 * Returns the most dominate emotion//w ww . j  a va 2  s  .c o m
 *
 * @param emotion - the emotion
 * @return Tile-cased dominant emotion (e.g. Fear)
 */
@NotNull
public static String dominantEmotion(@NotNull Emotion emotion) {
    Map<Emotion.EmotionScore, Double> scores = emotion.scores.scores();
    Emotion.EmotionScore key = scores.entrySet().stream()
            .max((entry1, entry2) -> entry1.getValue() > entry2.getValue() ? 1 : -1).get().getKey();
    return StringUtils.capitalize(key.name());

}

From source file:android.databinding.tool.DataBinderPlugin.java

private void attachXmlProcessor(Project project, final BaseVariantData variantData, final File sdkDir,
        final Boolean isLibrary) {
    final GradleVariantConfiguration configuration = variantData.getVariantConfiguration();
    final ApiVersion minSdkVersion = configuration.getMinSdkVersion();
    ProcessAndroidResources generateRTask = variantData.generateRClassTask;
    final String packageName = generateRTask.getPackageForR();
    String fullName = configuration.getFullName();
    List<File> resourceFolders = Arrays.asList(variantData.mergeResourcesTask.getOutputDir());

    final File codeGenTargetFolder = new File(
            project.getBuildDir() + "/data-binding-info/" + configuration.getDirName());
    String writerOutBase = codeGenTargetFolder.getAbsolutePath();
    JavaFileWriter fileWriter = new GradleFileWriter(writerOutBase);
    final LayoutXmlProcessor xmlProcessor = new LayoutXmlProcessor(packageName, resourceFolders, fileWriter,
            minSdkVersion.getApiLevel(), isLibrary);
    final ProcessAndroidResources processResTask = generateRTask;
    final File xmlOutDir = new File(project.getBuildDir() + "/layout-info/" + configuration.getDirName());
    final File generatedClassListOut = isLibrary ? new File(xmlOutDir, "_generated.txt") : null;
    logD("xml output for %s is %s", variantData, xmlOutDir);
    String layoutTaskName = "dataBindingLayouts" + StringUtils.capitalize(processResTask.getName());
    String infoClassTaskName = "dataBindingInfoClass" + StringUtils.capitalize(processResTask.getName());

    final DataBindingProcessLayoutsTask[] processLayoutsTasks = new DataBindingProcessLayoutsTask[1];
    project.getTasks().create(layoutTaskName, DataBindingProcessLayoutsTask.class,
            new Action<DataBindingProcessLayoutsTask>() {
                @Override//from   w  ww  .  jav  a2 s  . c  o m
                public void execute(final DataBindingProcessLayoutsTask task) {
                    processLayoutsTasks[0] = task;
                    task.setXmlProcessor(xmlProcessor);
                    task.setSdkDir(sdkDir);
                    task.setXmlOutFolder(xmlOutDir);
                    task.setMinSdk(minSdkVersion.getApiLevel());

                    logD("TASK adding dependency on %s for %s", task, processResTask);
                    processResTask.dependsOn(task);
                    processResTask.getInputs().dir(xmlOutDir);
                    for (Object dep : processResTask.getDependsOn()) {
                        if (dep == task) {
                            continue;
                        }
                        logD("adding dependency on %s for %s", dep, task);
                        task.dependsOn(dep);
                    }
                    processResTask.doLast(new Action<Task>() {
                        @Override
                        public void execute(Task unused) {
                            try {
                                task.writeLayoutXmls();
                            } catch (JAXBException e) {
                                // gradle sometimes fails to resolve JAXBException.
                                // We get stack trace manually to ensure we have the log
                                logE(e, "cannot write layout xmls %s", ExceptionUtils.getStackTrace(e));
                            }
                        }
                    });
                }
            });
    final DataBindingProcessLayoutsTask processLayoutsTask = processLayoutsTasks[0];
    project.getTasks().create(infoClassTaskName, DataBindingExportInfoTask.class,
            new Action<DataBindingExportInfoTask>() {

                @Override
                public void execute(DataBindingExportInfoTask task) {
                    task.dependsOn(processLayoutsTask);
                    task.dependsOn(processResTask);
                    task.setXmlProcessor(xmlProcessor);
                    task.setSdkDir(sdkDir);
                    task.setXmlOutFolder(xmlOutDir);
                    task.setExportClassListTo(generatedClassListOut);
                    task.setPrintEncodedErrors(printEncodedErrors);
                    task.setEnableDebugLogs(logger.isEnabled(LogLevel.DEBUG));

                    variantData.registerJavaGeneratingTask(task, codeGenTargetFolder);
                }
            });
    String packageJarTaskName = "package" + StringUtils.capitalize(fullName) + "Jar";
    final Task packageTask = project.getTasks().findByName(packageJarTaskName);
    if (packageTask instanceof Jar) {
        String removeGeneratedTaskName = "dataBindingExcludeGeneratedFrom"
                + StringUtils.capitalize(packageTask.getName());
        if (project.getTasks().findByName(removeGeneratedTaskName) == null) {
            final AbstractCompile javaCompileTask = variantData.javacTask;
            Preconditions.checkNotNull(javaCompileTask);

            project.getTasks().create(removeGeneratedTaskName, DataBindingExcludeGeneratedTask.class,
                    new Action<DataBindingExcludeGeneratedTask>() {
                        @Override
                        public void execute(DataBindingExcludeGeneratedTask task) {
                            packageTask.dependsOn(task);
                            task.dependsOn(javaCompileTask);
                            task.setAppPackage(packageName);
                            task.setInfoClassQualifiedName(xmlProcessor.getInfoClassFullName());
                            task.setPackageTask((Jar) packageTask);
                            task.setLibrary(isLibrary);
                            task.setGeneratedClassListFile(generatedClassListOut);
                        }
                    });
        }
    }
}

From source file:cognitivej.vision.emotion.EmotionStringBuilder.java

/**
 * Returns the most dominate emotion and the score
 *
 * @param emotion - the emotion/* w ww  . j  av  a 2 s.c  om*/
 * @return Tile-cased dominant emotion (e.g. Fear)
 */
@NotNull
public static String dominantEmotionWithScore(@NotNull Emotion emotion) {
    Map.Entry<Emotion.EmotionScore, Double> scoreVal = emotion.scores.scores().entrySet().stream()
            .max((entry1, entry2) -> entry1.getValue() > entry2.getValue() ? 1 : -1).get();
    return String.format("%s:%.2f", StringUtils.capitalize(scoreVal.getKey().name()), scoreVal.getValue());

}

From source file:fi.foyt.fni.view.gamelibrary.GameLibraryEditPublicationBackingBean.java

private List<SelectItemGroup> createTagSelectItems() {
    List<GameLibraryTag> gameLibraryTags = gameLibraryTagController.listGameLibraryTags();

    ArrayList<SelectItemGroup> result = new ArrayList<>();

    List<SelectItem> tagItems = new ArrayList<>();
    for (GameLibraryTag tag : gameLibraryTags) {
        tagItems.add(new SelectItem(tag.getText(), StringUtils.capitalize(tag.getText())));
    }/*from  w  w  w  .  j a  v  a  2 s. co m*/

    SelectItemGroup existingTagGroup = new SelectItemGroup(
            FacesUtils.getLocalizedValue("gamelibrary.editPublication.existingTagsGroup"), "", false,
            tagItems.toArray(new SelectItem[0]));
    SelectItemGroup newTagGroup = new SelectItemGroup(
            FacesUtils.getLocalizedValue("gamelibrary.editPublication.createTagGroup"), "", false,
            new SelectItem[] { new SelectItem("_NEW_",
                    FacesUtils.getLocalizedValue("gamelibrary.editPublication.createTagItem")) });

    result.add(newTagGroup);
    result.add(existingTagGroup);

    return result;
}

From source file:edu.usu.sdl.openstorefront.service.OrientPersistenceService.java

private Map<String, Object> findIdField(Class entityClass, Object id) {
    Map<String, Object> fieldValueMap = new HashMap<>();

    //Start at the root (The fist Id found wins ...there should only be one)
    if (entityClass.getSuperclass() != null) {
        fieldValueMap = findIdField(entityClass.getSuperclass(), id);
    }//  w w  w  .j  av a2s .  c  om
    if (fieldValueMap.isEmpty()) {
        for (Field field : entityClass.getDeclaredFields()) {
            PK idAnnotation = field.getAnnotation(PK.class);
            if (idAnnotation != null) {
                if (ReflectionUtil.isComplexClass(field.getType())) {
                    //PK class should only be one level deep
                    for (Field pkField : field.getType().getDeclaredFields()) {
                        try {
                            //                        Method pkMethod = id.getClass().getMethod("get" + StringUtils.capitalize(field.getName()), (Class<?>[]) null);
                            //                        Object pkObj = pkMethod.invoke(id, (Object[]) null);
                            //
                            //                        Method method = pkObj.getClass().getMethod("get" + StringUtils.capitalize(pkField.getName()), (Class<?>[]) null);
                            //                        Object returnObj = method.invoke(pkObj, (Object[]) null);
                            Method method = id.getClass().getMethod(
                                    "get" + StringUtils.capitalize(pkField.getName()), (Class<?>[]) null);
                            Object returnObj = method.invoke(id, (Object[]) null);
                            fieldValueMap.put(field.getName() + "." + pkField.getName(), returnObj);
                        } catch (NoSuchMethodException | SecurityException | IllegalAccessException
                                | IllegalArgumentException | InvocationTargetException ex) {
                            throw new OpenStorefrontRuntimeException(ex);
                        }
                    }
                } else {
                    fieldValueMap.put(field.getName(), id);
                    break;
                }
            }
        }
    }
    return fieldValueMap;
}

From source file:com.wrmsr.wava.compile.memory.LoadStoreCompilerImpl.java

private JMethod createLengthStore(Class<?> p, Class<?> t, int len) {
    return new JMethod(immutableEnumSet(JAccess.PROTECTED, JAccess.FINAL), JTypeSpecifier.of(p.getName()),
            JName.of("_store" + StringUtils.capitalize(p.getName()) + len),
            ImmutableList//from www.java 2 s . c  o m
                    .of(new JArg(JTypeSpecifier.of("int"), JName.of("ptr")), new JArg(
                            JTypeSpecifier.of(p.getName()), JName.of("value"))),
            Optional.of(
                    new JBlock(
                            ImmutableList.of(
                                    new JExpressionStatement(
                                            JMethodInvocation.of(
                                                    JQualifiedName.of(
                                                            "this", "_memory",
                                                            "put" + (t == byte.class ? ""
                                                                    : StringUtils
                                                                            .capitalize(t.getSimpleName()))),
                                                    ImmutableList.of(new JIdent(JQualifiedName.of("ptr")),
                                                            new JCast(JTypeSpecifier.of(t.getName()),
                                                                    new JIdent(JQualifiedName.of("value")))))),
                                    new JReturn(Optional.of(new JIdent(JQualifiedName.of("value"))))))));
}

From source file:com.wesleyhome.dao.processor.method.IncludeQueryMethodGenerator.java

/**
 * @param fieldElement//  w  w  w  . j  a  v  a  2  s  .  c o m
 * @param predicateString
 * @return
 */
protected String getMethodName(final String entityName, final Element fieldElement) {
    return String.format("find%sBy%sThatInclude", entityName,
            StringUtils.capitalize(fieldElement.getSimpleName().toString()));
}

From source file:it.larusba.integration.neo4j.jsonloader.transformer.UnrefactoredDomainBasedJsonTransformer.java

private String buildNodeLabel(String documentType, Map<String, Object> documentMap,
        JsonObjectDescriptorHelper objectDescriptorHelper) {

    String typeAttribute = (String) documentMap.get(objectDescriptorHelper.getTypeAttribute(documentType));

    if (StringUtils.isBlank(typeAttribute)) {
        typeAttribute = StringUtils.lowerCase(documentType);
    }//from w  ww .j a v a2 s.  c  om

    return StringUtils.capitalize(typeAttribute);
}