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

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

Introduction

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

Prototype

public static String uncapitalize(final String str) 

Source Link

Document

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

Usage

From source file:ch.cyberduck.core.worker.TransferPromptFilterWorker.java

@Override
public String getActivity() {
    return MessageFormat.format(LocaleFactory.localizedString("Apply {0} filter", "Status"),
            StringUtils.uncapitalize(action.getTitle()));
}

From source file:com.conversantmedia.mapreduce.tool.DistributedResourceManager.java

@SuppressWarnings("unchecked")
protected void configureBeanDistributedResources(Object annotatedBean)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
    MaraAnnotationUtil util = MaraAnnotationUtil.INSTANCE;
    Distribute distribute;/*from ww  w  .  j  a  va 2  s  .  c  o  m*/
    // Search for annotated resources to distribute
    List<Field> fields = util.findAnnotatedFields(annotatedBean.getClass(), Distribute.class);
    for (Field field : fields) {
        distribute = field.getAnnotation(Distribute.class);
        String key = StringUtils.isBlank(distribute.name()) ? field.getName() : distribute.name();

        field.setAccessible(true);
        Object value = field.get(annotatedBean);
        if (value != null) {
            registerResource(key, value);
        }
    }

    // Search for annotated methods
    List<Method> methods = util.findAnnotatedMethods(annotatedBean.getClass(), Distribute.class);
    for (Method method : methods) {
        distribute = AnnotationUtils.findAnnotation(method, Distribute.class);
        // Invoke the method to retrieve the cache file path. Needs to return either a String or a Path
        String defaultName = StringUtils.uncapitalize(StringUtils.removeStart(method.getName(), "get"));
        String key = StringUtils.isBlank(distribute.name()) ? defaultName : distribute.name();
        Object value = method.invoke(annotatedBean);
        if (value != null) {
            registerResource(key, value);
        }
    }
}

From source file:com.newtranx.util.cassandra.spring.MapperScannerConfigurer.java

@SuppressWarnings("unused") // compiler bug?
@Override/* w w  w.  ja v a2s  . c o  m*/
public void postProcessBeanFactory(ConfigurableListableBeanFactory context) throws BeansException {
    synchronized (lock) {
        ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
                false);
        scanner.addIncludeFilter(new AnnotationTypeFilter(Table.class));
        for (BeanDefinition bd : scanner.findCandidateComponents(basePackage)) {
            Class<?> entityCls;
            try {
                entityCls = Class.forName(bd.getBeanClassName());
            } catch (ClassNotFoundException e) {
                throw new AssertionError(e);
            }
            log.info("Creating proxy mapper for entity: " + entityCls.getName());
            CassandraMapper annotation = entityCls.getAnnotation(CassandraMapper.class);
            Mapper<?> bean = createProxy(Mapper.class, new MyInterceptor(entityCls, annotation.singleton()));
            String beanName;
            if (annotation == null)
                beanName = StringUtils.uncapitalize(entityCls.getSimpleName()) + "Mapper";
            else
                beanName = annotation.value();
            context.registerSingleton(beanName, bean);
            log.info("Bean registed, name=" + beanName + ", bean=" + bean.toString());
        }
    }
}

From source file:com.google.code.siren4j.util.ReflectionUtils.java

/**
 * Remove the getter prefix ('is', 'get') from the the method name passed in.
 *
 * @param name the method name./*from  w  w w  .j a  v a  2  s  . com*/
 * @return the method name without the prefix, may be <code>null</code> or empty if the name passed in was that way.
 */
public static String stripGetterPrefix(String name) {
    if (StringUtils.isBlank(name)) {
        return name; // This should never happen.
    }
    String[] mName = StringUtils.splitByCharacterTypeCamelCase(name);
    StringBuilder sb = new StringBuilder();
    for (int i = 1; i < mName.length; i++) {
        sb.append(mName[i]);
    }
    return StringUtils.uncapitalize(sb.toString());
}

From source file:apm.generate.Generate.java

public static void parameters(String packageName, String moduleName, String className, String classAuthor,
        String functionName, String tableName, String entityContent, String flag) throws Exception {
    // ==========  ?? ====================
    // ??????// w  ww . j av a 2s. c  o  m
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}
    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?

    //String packageName = "lms.modules";//???

    //String moduleName = "test";         //???sys
    String subModuleName = ""; // ?????? 
    //String className = "test";         // ??user
    //String classAuthor = "htd";         // ThinkGem
    //String functionName = "";         //??

    // ???
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        //logger.error("????isEnable = true");
        System.out.println("????isEnable = true");
        return;
    }

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        //logger.error("??????????????");
        System.out.println("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = new DefaultResourceLoader().getResource("").getFile();
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    //logger.info("Project Path: {}", projectPath);
    System.out.println("-------------------------------------------------");
    System.out.println(":" + projectPath);
    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/apm/generate/template", "/", separator);
    //logger.info("Template Path: {}", tplPath);
    System.out.println("?:" + tplPath);
    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    //logger.info("Java Path: {}", javaPath);
    System.out.println("Java:" + javaPath);
    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    //logger.info("View Path: {}", viewPath);
    System.out.println(":" + viewPath);
    // ???
    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", moduleName);
    model.put("subModuleName",
            StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : "");
    model.put("className", StringUtils.uncapitalize(className));
    model.put("ClassName", StringUtils.capitalize(className));
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
    model.put("classVersion", DateUtils.getDate());
    model.put("functionName", functionName);
    model.put("tableName", tableName);

    model.put("urlPrefix", "/" + model.get("className"));
    model.put("viewUrlPrefix", "/" + model.get("moduleName"));
    model.put("returnPrefix", "modules" + //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("viewUrlPrefix") + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));

    model.put("permissionPrefix", model.get("className"));
    String[] strs = entityContent.split("##");
    model.put("columnContent", strs[0]);
    model.put("entityContent", strs[1]);

    System.out.println("-------------------------?------------------------");
    Template template = null;
    String content = null;
    String filePath = null;
    if (flag.indexOf("entity") != -1 || flag.length() == 0) {
        // ? Entity
        template = cfg.getTemplate("entity.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + ".java";
        writeFile(content, filePath);
        System.out.println("? Entity:" + filePath);
    }

    if (flag.indexOf("dao") != -1 || flag.length() == 0) {

        // ? Dao
        template = cfg.getTemplate("dao.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Dao.java";
        writeFile(content, filePath);
        System.out.println("? Dao:" + filePath);

    }

    if (flag.indexOf("service") != -1 || flag.length() == 0) {

        // ? Service
        template = cfg.getTemplate("service.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Service.java";
        writeFile(content, filePath);
        System.out.println("? Service:" + filePath);

    }

    if (flag.indexOf("controler") != -1 || flag.length() == 0) {

        // ? Controller
        template = cfg.getTemplate("controller.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Controller.java";
        writeFile(content, filePath);
        System.out.println("? Controller:" + filePath);

    }

    if (flag.indexOf("form") != -1 || flag.length() == 0) {

        // ? ViewForm
        template = cfg.getTemplate("viewForm.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".")
                + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName)
                + model.get("className") + "Form.jsp";
        writeFile(content, filePath);
        System.out.println("? ViewForm:" + filePath);

    }

    if (flag.indexOf("list") != -1 || flag.length() == 0) {

        // ? ViewList
        template = cfg.getTemplate("viewList.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".")
                + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName)
                + model.get("className") + "List.jsp";
        writeFile(content, filePath);
        System.out.println("? ViewList:" + filePath);

    }

}

From source file:com.hesine.manager.generate.Generate.java

public static void execute(File curProjectPath) {
    // ==========  ?? ====================

    // ??????/*from  w w w . j a  v  a2  s.c  om*/
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.hesine.manager";

    //      String moduleName = "function";         // ???sys
    String moduleName = ""; // ???sys
    String tableName = "tb_product"; // ???sys
    String subModuleName = ""; // ?????
    String className = "product"; // ??product
    String classAuthor = "Jason"; // ThinkGem
    String functionName = "?"; // ??
    List<Map<String, String>> fileds = new ArrayList<Map<String, String>>();
    // map
    Map<String, String> dataName = new HashMap<String, String>();
    dataName.put("dataType", "String");
    dataName.put("name", "name");
    dataName.put("methodName", "Name");
    dataName.put("comment", "??");
    dataName.put("dbName", "name");

    Map<String, String> dataDesc = new HashMap<String, String>();
    dataDesc.put("dataType", "String");
    dataDesc.put("name", "description");
    dataDesc.put("methodName", "Description");
    dataDesc.put("comment", "??");
    dataDesc.put("dbName", "description");

    fileds.add(dataName);
    fileds.add(dataDesc);

    // ???
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        logger.error("????isEnable = true");
        return;
    }

    //        StringUtils.isBlank(moduleName) ||
    if (StringUtils.isBlank(packageName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = curProjectPath;
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    logger.info("Project Path: {}", projectPath);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/hesine/manager/generate/template",
            "/", separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // Xml
    String xmlPath = StringUtils.replace(projectPath + "/src/main/resources/mybatis", "/", separator);
    logger.info("Xml Path: {}", xmlPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Map<String, Object> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(moduleName));
    model.put("subModuleName",
            StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : "");
    model.put("className", StringUtils.uncapitalize(className));
    model.put("ClassName", StringUtils.capitalize(className));
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
    model.put("classVersion", DateUtils.getDate());
    model.put("functionName", functionName);
    //      model.put("tableName", model.get("moduleName")+(StringUtils.isNotBlank(subModuleName)
    //            ?"_"+StringUtils.lowerCase(subModuleName):"")+"_"+model.get("className"));
    model.put("tableName", tableName);

    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));
    model.put("fileds", fileds);

    //        // ? Entity
    //        FileGenUtils.generateEntity(tplPath, javaPath, model);
    //
    //        // ? sqlMap
    //        FileGenUtils.generateSqlMap(tplPath, xmlPath, model);
    //
    //        // ? Model
    //        FileGenUtils.generateModel(tplPath, javaPath, model);
    //
    //        // ? Dao
    //        FileGenUtils.generateDao(tplPath, javaPath, model);
    //
    //        // ? Service
    //        FileGenUtils.generateService(tplPath, javaPath, model);
    //
    //        // ? ServiceImpl
    //        FileGenUtils.generateServiceImpl(tplPath, javaPath, model);
    //
    //        // ? Controller
    //        FileGenUtils.generateController(tplPath, javaPath, model);

    // ? add.ftl
    FileGenUtils.generateAddFtl(tplPath, viewPath, model);

    // ? edit.ftl
    FileGenUtils.generateEditFtl(tplPath, viewPath, model);

    // ? list.ftl
    FileGenUtils.generateListFtl(tplPath, viewPath, model);

    logger.info("Generate Success.");
}

From source file:com.conversantmedia.mapreduce.mrunit.UnitTestDistributedResourceManager.java

@SuppressWarnings("unchecked")
protected void addDistributedProperties(Class<?> clazz, List<String> properties) {
    Distribute distribute;//from  ww  w. ja v  a 2s. c  o  m
    MaraAnnotationUtil util = MaraAnnotationUtil.INSTANCE;
    List<Field> fields = util.findAnnotatedFields(clazz, Distribute.class);
    for (Field field : fields) {
        distribute = field.getAnnotation(Distribute.class);
        String prop = StringUtils.isBlank(distribute.name()) ? field.getName() : distribute.name();
        properties.add(prop);
    }

    List<Method> methods = util.findAnnotatedMethods(clazz, Distribute.class);
    for (Method method : methods) {
        distribute = AnnotationUtils.findAnnotation(method, Distribute.class);
        String defaultName = StringUtils.uncapitalize(StringUtils.removeStart(method.getName(), "get"));
        String prop = StringUtils.isBlank(distribute.name()) ? defaultName : distribute.name();
        properties.add(prop);
    }
}

From source file:com.newtranx.util.cassandra.spring.AccessorScannerConfigurer.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory context) throws BeansException {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false) {/*from  w  w w.jav  a  2  s . c o  m*/

        @Override
        protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
            return beanDefinition.getMetadata().isInterface();
        }

    };
    scanner.addIncludeFilter(new AnnotationTypeFilter(Accessor.class));
    for (BeanDefinition bd : scanner.findCandidateComponents(basePackage)) {
        Class<?> accessorCls;
        try {
            accessorCls = Class.forName(bd.getBeanClassName());
        } catch (ClassNotFoundException e) {
            throw new AssertionError(e);
        }
        log.info("Creating proxy accessor: " + accessorCls.getName());
        MethodInterceptor interceptor = new MethodInterceptor() {

            private final Lazy<?> target = new Lazy<>(() -> {
                log.info("Creating actual accessor: " + accessorCls.getName());
                Session session;
                if (AccessorScannerConfigurer.this.session == null)
                    session = mainContext.getBean(Session.class);
                else
                    session = AccessorScannerConfigurer.this.session;
                MappingManager mappingManager = new MappingManager(session);
                return mappingManager.createAccessor(accessorCls);
            });

            @Override
            public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
                    throws Throwable {
                if ("toString".equals(method.getName())) {
                    return accessorCls.getName();
                }
                return method.invoke(target.get(), args);
            }

        };
        Enhancer enhancer = new Enhancer();
        enhancer.setInterfaces(new Class<?>[] { accessorCls });
        enhancer.setCallback(interceptor);
        Object bean = enhancer.create();
        String beanName = StringUtils.uncapitalize(accessorCls.getSimpleName());
        context.registerSingleton(beanName, bean);
        log.info("Bean registed, name=" + beanName + ", bean=" + bean.toString());
    }
}

From source file:com.htmlhifive.pitalium.core.config.PtlTestConfig.java

/**
 * ????/*from   w ww  .  j a v  a  2s  .  c  om*/
 * 
 * @param clss ??????
 * @param <T> ????
 * @param name ??
 * @return 
 */
@SuppressWarnings("unchecked")
public <T> T getConfig(Class<T> clss, String name) {
    synchronized (configs) {
        // Check cached
        if (configs.containsKey(name)) {
            LOG.trace("[Load config] use cached ({}).", name);
            return (T) configs.get(name);
        }

        // Load configuration file
        PtlConfiguration configuration = clss.getAnnotation(PtlConfiguration.class);
        if (configuration == null) {
            throw new TestRuntimeException("Configuration class must be annotated with @PtlConfiguration");
        }

        String argumentName = configuration.argumentName();
        if (Strings.isNullOrEmpty(argumentName)) {
            argumentName = StringUtils.uncapitalize(clss.getSimpleName());
        }
        String defaultFileName = configuration.defaultFileName();
        if (Strings.isNullOrEmpty(defaultFileName)) {
            defaultFileName = StringUtils.uncapitalize(clss.getSimpleName()) + ".json";
        }

        T config = loadConfig(clss, startupArguments.get(argumentName), defaultFileName);
        LOG.trace("[Load config] original values ({}): {}", name, config);
        fillConfigProperties(config, startupArguments);
        LOG.debug("[Load config] ({}): {}", name, config);

        configs.put(name, config);
        LOG.trace("[Load config] config cached ({})", name);
        return config;
    }
}

From source file:com.iorga.iraj.json.MethodTemplate.java

private static String getPropertyNameFromMethod(final Method targetMethod) {
    String name = targetMethod.getName();
    if (name.startsWith("get")) {
        name = name.substring(3);/*from  ww w  .  j a v  a2  s. c  o m*/
    } else if (name.startsWith("is")) {
        name = name.substring(2);
    }
    return StringUtils.uncapitalize(name);
}