Example usage for org.apache.commons.lang StringUtils uncapitalize

List of usage examples for org.apache.commons.lang StringUtils uncapitalize

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils uncapitalize.

Prototype

public static String uncapitalize(String str) 

Source Link

Document

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

Usage

From source file:org.mule.modules.utils.mom.internal.CollectionInlinerMapObjectMapperInterceptor.java

protected String propertyName(final Class<?> type) {
    return StringUtils.uncapitalize(type.getSimpleName().replace("Collection", ""));
}

From source file:org.okj.commons.web.json.outputter.ListJsonOutputter.java

/**
 * /*from  w  w  w. j a  v  a 2s  .c o  m*/
 * @return
 */
protected JSONArray getCells(Object object) {
    //
    expression.addContext(StringUtils.uncapitalize(object.getClass().getSimpleName()), object);
    JSONArray cells = new JSONArray();
    for (Field field : fields.getFields()) {
        try {
            //
            Object value = expression.evaluate(field.getName());
            cells.add(String.valueOf(value));
        } catch (Exception ex) {
            LogUtils.warn(LOGGER, "", ex);
            cells.add(StringUtils.EMPTY);
        }
    }
    return cells;
}

From source file:org.openlegacy.db.loaders.support.DbActionsAnnotationLoader.java

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void load(EntitiesRegistry entitiesRegistry, Annotation annotation, Class<?> containingClass) {

    DbEntityDefinition dbEntityDefinition = (DbEntityDefinition) entitiesRegistry.get(containingClass);
    List<ActionDefinition> actionsRef = dbEntityDefinition.getActions();

    DbActions dbActions = (DbActions) annotation;
    Action[] actions = dbActions.actions();
    if (actions.length > 0) {
        for (Action action : actions) {
            Class<? extends DbAction> theAction = action.action();

            SimpleDbActionDefinition actionDefinition = null;
            String displayName = action.displayName().length() > 0 ? action.displayName()
                    : StringUtil.toDisplayName(action.action().getSimpleName());
            actionDefinition = new SimpleDbActionDefinition(ReflectionUtil.newInstance(theAction), displayName);

            if (StringUtils.isEmpty(action.alias())) {
                actionDefinition.setAlias(StringUtils.uncapitalize(displayName));
            } else {
                actionDefinition.setAlias(action.alias());
            }/*w ww. j  a  v  a  2 s . c om*/

            actionDefinition.setGlobal(action.global());
            if (action.targetEntity() != void.class) {
                actionDefinition.setTargetEntity(action.targetEntity());
            }
            actionsRef.add(actionDefinition);
        }
    }
}

From source file:org.openlegacy.designtime.generators.AbstractEntityMvcGenerator.java

private static void renameViews(String viewsDir, String viewsFile, String oldName, String newName,
        File projectPath) throws IOException {
    File webDir = new File(projectPath, viewsDir);
    if (webDir.exists()) {
        // rename views
        File[] listFiles = webDir.listFiles();
        for (File file : listFiles) {
            if (file.getAbsolutePath().endsWith(MessageFormat.format("{0}.{1}", oldName, "jspx"))) {
                file.renameTo(new File(file.getParentFile(), MessageFormat.format("{0}.{1}", newName, "jspx")));
                break;
            }//  ww w.ja v  a2  s  . com
        }
        // rename definition in views description file
        File templateViewsFile = new File(projectPath, MessageFormat.format("{0}/{1}", viewsDir, viewsFile));
        FileOutputStream fos = null;
        try {
            String viewsFileContent = FileUtils.readFileToString(templateViewsFile);
            viewsFileContent = viewsFileContent.replaceAll(MessageFormat.format("name=\"{0}\"", oldName),
                    MessageFormat.format("name=\"{0}\"", newName));
            viewsFileContent = viewsFileContent.replaceAll(MessageFormat.format("{0}.jspx", oldName),
                    MessageFormat.format("{0}.jspx", newName));
            fos = new FileOutputStream(templateViewsFile);
            IOUtils.write(viewsFileContent, fos);
        } finally {
            IOUtils.closeQuietly(fos);
        }

        // rename entity name in .jspx
        File file = new File(webDir, MessageFormat.format("{0}.{1}", newName, "jspx"));
        if (file.exists()) {
            fos = null;
            try {
                String fileContent = FileUtils.readFileToString(file);
                fileContent = fileContent.replaceAll(StringUtils.capitalize(oldName),
                        StringUtils.capitalize(newName));
                fileContent = fileContent.replaceAll(StringUtils.uncapitalize(oldName),
                        StringUtils.uncapitalize(newName));
                fos = new FileOutputStream(file);
                IOUtils.write(fileContent, fos);
            } finally {
                IOUtils.closeQuietly(fos);
            }
        }
    }
}

From source file:org.openlegacy.designtime.generators.AbstractEntityMvcGenerator.java

private void scanDir(File parentDir, String oldName, String newName) {
    if (!parentDir.exists()) {
        return;/* w  w w .  ja  v a  2  s  .c  o m*/
    }
    File[] listFiles = parentDir.listFiles();
    for (File file : listFiles) {
        if (file.isDirectory()) {
            scanDir(file, oldName, newName);
        } else {
            // renamed <newName>.java
            if (file.getName().equals(MessageFormat.format("{0}.java", newName))) {
                BufferedWriter bw = null;
                try {
                    List<String> lines = FileUtils.readLines(file);
                    bw = new BufferedWriter(new FileWriter(file));
                    for (String line : lines) {
                        if (line.contains(MessageFormat.format("{0}Record", StringUtils.capitalize(oldName)))
                                || line.contains(
                                        MessageFormat.format("{0}Part", StringUtils.capitalize(oldName)))) {
                            line = line
                                    .replaceAll(StringUtils.capitalize(oldName),
                                            StringUtils.capitalize(newName))
                                    .replaceAll(StringUtils.uncapitalize(oldName),
                                            StringUtils.uncapitalize(newName));
                        }
                        bw.write(line);
                        bw.newLine();
                    }
                } catch (IOException e) {
                } finally {
                    IOUtils.closeQuietly(bw);
                }
            }
            // rename <oldName>Controller.java
            if (file.getName().equals(MessageFormat.format("{0}Controller.java", oldName))) {
                File newFile = new File(file.getParentFile(),
                        MessageFormat.format("{0}Controller.java", newName));
                if (file.renameTo(newFile)) {
                    // renamed <newName>Controller.java
                    updateControllerOrAspectFile(newFile, oldName, newName);
                }
            }
            // rename <newName>Controller_Aspect.aj
            if (file.getName().equals(
                    MessageFormat.format("{0}Controller{1}", oldName, DesignTimeExecuter.ASPECT_SUFFIX))) {
                // NOTE: if we delete Controller Aspect, it will not be generated again
                File newFile = new File(file.getParentFile(),
                        MessageFormat.format("{0}Controller{1}", newName, DesignTimeExecuter.ASPECT_SUFFIX));
                if (file.renameTo(newFile)) {
                    // renamed <newName>Controller_Aspect.aj
                    updateControllerOrAspectFile(newFile, oldName, newName);
                }
            }
        }
    }
}

From source file:org.openlegacy.designtime.generators.AbstractEntityMvcGenerator.java

private static void updateControllerOrAspectFile(File newFile, String oldName, String newName) {
    if (newFile.exists()) {
        FileOutputStream fos = null;
        try {//from w ww  .ja  v  a 2s  .c  o  m
            String fileContent = FileUtils.readFileToString(newFile);
            fileContent = fileContent.replaceAll(StringUtils.capitalize(oldName),
                    StringUtils.capitalize(newName));
            fileContent = fileContent.replaceAll(StringUtils.uncapitalize(oldName),
                    StringUtils.uncapitalize(newName));
            fos = new FileOutputStream(newFile);
            IOUtils.write(fileContent, fos);
        } catch (IOException e) {
        } finally {
            IOUtils.closeQuietly(fos);
        }
    }
}

From source file:org.openlegacy.designtime.generators.AbstractEntitySpaGenerator.java

@Override
public void renameViews(String fileNoExtension, String newName, File projectPath) {
    // views//from   w  w w .ja v  a  2 s  .c o  m
    File viewsDir = new File(projectPath, SpaGenerateUtil.VIEWS_DIR);
    if (viewsDir.exists()) {
        File[] listFiles = viewsDir.listFiles();
        for (File file : listFiles) {
            if (file.getAbsolutePath().endsWith(MessageFormat.format("{0}.{1}", fileNoExtension, "html"))) {
                file.renameTo(new File(file.getParentFile(), MessageFormat.format("{0}.{1}", newName, "html")));
                break;
            }
            if (file.getAbsolutePath().endsWith(
                    MessageFormat.format("{0}.{1}", StringUtils.uncapitalize(fileNoExtension), "html"))) {
                file.renameTo(new File(file.getParentFile(),
                        MessageFormat.format("{0}.{1}", StringUtils.uncapitalize(newName), "html")));
                break;
            }
        }
    }
    // app.js
    File appJsFile = new File(projectPath, SpaGenerateUtil.JS_APP_DIR + APP_JS);
    FileOutputStream fos = null;
    try {
        String appJsFileContent = FileUtils.readFileToString(appJsFile);
        // replace e.g.: /items -> /newItems
        appJsFileContent = appJsFileContent.replaceAll(
                MessageFormat.format("/{0}", StringUtils.uncapitalize(fileNoExtension)),
                MessageFormat.format("/{0}", StringUtils.uncapitalize(newName)));
        // replace e.g.: itemsController -> newItemsController
        appJsFileContent = appJsFileContent.replaceAll(
                MessageFormat.format("{0}Controller", StringUtils.uncapitalize(fileNoExtension)),
                MessageFormat.format("{0}Controller", StringUtils.uncapitalize(newName)));
        fos = new FileOutputStream(appJsFile);
        IOUtils.write(appJsFileContent, fos);
    } catch (IOException e) {
        logger.info(e.getMessage());
    } finally {
        IOUtils.closeQuietly(fos);
    }
    // controller.js
    File controllersJsFile = new File(projectPath, SpaGenerateUtil.JS_APP_DIR + CONTROLLERS_JS);
    fos = null;
    try {
        String controllerJsFileContent = FileUtils.readFileToString(controllersJsFile);
        // replace e.g.: itemsController -> newItemsController
        controllerJsFileContent = controllerJsFileContent.replaceAll(
                MessageFormat.format("{0}Controller", StringUtils.uncapitalize(fileNoExtension)),
                MessageFormat.format("{0}Controller", StringUtils.uncapitalize(newName)));
        // replace e.g.: Items -> NewItems
        controllerJsFileContent = controllerJsFileContent.replaceAll(fileNoExtension, newName);
        fos = new FileOutputStream(controllersJsFile);
        IOUtils.write(controllerJsFileContent, fos);
    } catch (IOException e) {
        logger.info(e.getMessage());
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:org.openlegacy.mvc.web.AbstractGenericEntitiesController.java

@SuppressWarnings("unchecked")
protected String prepareView(Object entity, Model uiModel, boolean partial, HttpServletRequest request)
        throws MalformedURLException {
    String entityName = ProxyUtil.getOriginalClass(entity.getClass()).getSimpleName();
    uiModel.addAttribute(StringUtils.uncapitalize(entityName), entity);
    EntityDefinition<?> entityDefinition = entitiesRegistry.get(entityName);
    uiModel.addAttribute(PAGE, pageBuilder.build(entityDefinition));

    SitePreference sitePreference = SitePreferenceUtils.getCurrentSitePreference(request);

    boolean isComposite = entityDefinition.getChildEntitiesDefinitions().size() > 0 && !partial;
    String suffix = isComposite ? MvcConstants.COMPOSITE_SUFFIX : "";
    String viewName = entityDefinition.getEntityName() + suffix;

    boolean isEmpty = !isComposite && entityDefinition.isEmpty();

    List<String> viewsPaths = sitePreference == SitePreference.MOBILE ? mobileViewsPaths : webViewsPaths;

    // check if custom view exists, if not load generic view by
    // characteristics
    if (!isResourceExists(viewsPaths, viewName, viewsSuffix)) {
        if (isComposite) {
            // generic composite view (multi tabbed page)
            viewName = MvcConstants.COMPOSITE;
        } else if (entityDefinition.getType() == MenuEntity.class) {
            // generic menu view
            viewName = MvcConstants.ROOTMENU_VIEW;
        } else if (partial) {
            // generic inner page view (inner tab)
            viewName = MvcConstants.GENERIC_VIEW;
        } else if (entityDefinition.isWindow()) {
            // generic window pop-pup view
            viewName = MvcConstants.GENERIC_WINDOW;
        } else if (isEmpty) {
            viewName = MvcConstants.REDIRECT + openlegacyWebProperties.getFallbackUrl();
        } else {//from   www  .j a va  2s.  c  o m
            // generic view
            viewName = MvcConstants.GENERIC;
        }
    }

    return viewName;
}

From source file:org.openlegacy.rpc.loaders.support.RpcActionsAnnotationLoader.java

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void load(EntitiesRegistry entitiesRegistry, Annotation annotation, Class<?> containingClass) {

    RpcEntityDefinition rpcEntityDefinition = (RpcEntityDefinition) entitiesRegistry.get(containingClass);
    List<ActionDefinition> actionsRef;
    RpcPartEntityDefinition partEntityDefinition;
    Class<?> holdingClass;/*  www.ja v a  2 s .co m*/
    if (rpcEntityDefinition == null) {
        partEntityDefinition = (RpcPartEntityDefinition) entitiesRegistry.getPart(containingClass);
        Assert.notNull(partEntityDefinition, MessageFormat.format(
                "RPC entity definition for class {0} not found. Verify @RpcActions is defined along @RpcEntity or @RpcPart annotation",
                containingClass.getName()));
        actionsRef = partEntityDefinition.getActions();
        holdingClass = partEntityDefinition.getPartClass();
    } else {
        actionsRef = rpcEntityDefinition.getActions();
        holdingClass = rpcEntityDefinition.getEntityClass();
    }

    RpcActions rpcActions = (RpcActions) annotation;

    org.openlegacy.annotations.rpc.Action[] actions = rpcActions.actions();
    if (actions.length > 0) {
        for (org.openlegacy.annotations.rpc.Action action : actions) {
            Class<? extends RpcAction> theAction = action.action();

            SimpleRpcActionDefinition actionDefinition = null;
            String displayName = action.displayName().length() > 0 ? action.displayName()
                    : StringUtil.toDisplayName(action.action().getSimpleName());
            actionDefinition = new SimpleRpcActionDefinition(ReflectionUtil.newInstance(theAction),
                    displayName);

            if (StringUtils.isEmpty(action.alias())) {
                actionDefinition.setAlias(StringUtils.uncapitalize(displayName));
            } else {
                actionDefinition.setAlias(action.alias());
            }
            actionDefinition.setProgramPath(action.path());
            actionDefinition.setGlobal(action.global());

            if (action.targetEntity() != RpcEntity.NONE.class) {
                actionDefinition.setTargetEntity(action.targetEntity());
            }
            actionsRef.add(actionDefinition);
            if (logger.isDebugEnabled()) {
                logger.debug(MessageFormat.format(
                        "Action {0} - \"{1}\" was added to the registry for rpc entity {2}",
                        theAction.getSimpleName(), displayName, containingClass));
            }
        }
        logger.info(
                MessageFormat.format("RPC actions for \"{0}\" was added to the rpc registry", holdingClass));
    }
}

From source file:org.openlegacy.rpc.mvc.web.interceptors.InsertEntityDefinitionsInterceptor.java

@Override
protected void insertModelData(ModelAndView modelAndView, HttpServletRequest request,
        HttpServletResponse response) {//  w  w  w. j  a  va  2 s  .com
    String modelName = StringUtils.uncapitalize(modelAndView.getViewName());
    Object model = modelAndView.getModel().get(modelName);
    if (model != null && model instanceof RpcEntity) {
        mvcUtils.insertModelObjects(modelAndView, model, entitiesRegistry);
    } else {
        PageDefinition page = (PageDefinition) modelAndView.getModel().get("page");
        if (page != null) {

            EntityDefinition<?> definitions = page.getEntityDefinition();
            model = modelAndView.getModel().get(StringUtils.uncapitalize(definitions.getEntityName()));
            if (model != null && model instanceof RpcEntity) {
                // mvcUtils.insertModelObjects(modelAndView, model, definitions);
                modelAndView.addObject("definitions", definitions);
                List<Object> keysValues = EntityUtils.getKeysValues(model, definitions);
                String keysValuesText = StringUtil.toString(keysValues, '_');
                modelAndView.addObject("ol_entityId", keysValuesText);
                modelAndView.addObject("ol_entityUniqueId", definitions.getEntityName() + keysValuesText);
            }
        }
    }
    if (entitiesRegistry.isDirty()) {
        // set the registry back to clean - for design-time purposes only!
        ((AbstractEntitiesRegistry<?, ?, ?>) entitiesRegistry).setDirty(false);
    }

    Menu menuModule = getSession().getModule(Menu.class);
    if (menuModule != null) {
        modelAndView.addObject("ol_menu", menuModule.getMenuTree());
        modelAndView.addObject("ol_flatMenus", menuModule.getFlatMenuEntries());
    }
}