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.jsweet.input.typescriptdef.visitor.StringTypeCreator.java

public static String toJavaStringType(String stringType) {
    String stripped = strip(stringType, "\"");
    if (Character.isDigit(stripped.charAt(0))) {
        stripped = "_" + stripped;
    }/*from  ww w .  j  a v  a 2  s  .  co  m*/
    stripped = stripped.replaceAll("[-:.!,;]", DASH_STRING_IN_JAVA_IDENTIFIERS);
    if (JSweetDefTranslatorConfig.JAVA_KEYWORDS.contains(stripped)) {
        stripped = StringUtils.capitalize(stripped);
    }
    return stripped;
}

From source file:org.jutge.joc.porra.utils.PlayerUtils.java

public final static String readableName(final String playerName) {
    if (playerName == null)
        return null;
    final String cleanPlayerName = playerName.trim().replace(".", " ");
    final Matcher matcher = PATTERN.matcher(cleanPlayerName);
    final StringBuffer buffer = new StringBuffer();
    while (matcher.find()) {
        final String replacement = StringUtils.capitalize(matcher.group());
        matcher.appendReplacement(buffer, replacement);
    }// w w  w . ja  v  a 2 s .c  om
    matcher.appendTail(buffer);
    return buffer.toString();
}

From source file:org.kawanfw.file.servlet.ServerFileManager.java

/**
 * Init./*from ww w  .  j ava2 s. c  o m*/
 */

public void init(ServletConfig config) throws ServletException {
    super.init(config);

    // Clean the olders folders of uploader classes, can't be done when closing
    String classpathUsernames = ClassPathUtil.getUserHomeDotKawansoftDotClasspath() + File.separator
            + ".usernames";
    try {
        FileUtils.deleteDirectory(new File(classpathUsernames));
        new File(classpathUsernames).delete();
    } catch (IOException ignore) {
        ignore.printStackTrace(System.out);
    }

    // Variable use to store the current name when loading, used to
    // detail
    // the exception in the catch clauses
    String classNameToLoad = null;

    String commonsConfiguratorClassName = config.getInitParameter(COMMONS_CONFIGURATOR_CLASS_NAME);
    String fileConfiguratorClassName = config.getInitParameter(FILE_CONFIGURATOR_CLASS_NAME);

    try {

        // Check spelling with first letter capitalized
        if (commonsConfiguratorClassName == null || commonsConfiguratorClassName.isEmpty()) {
            String capitalized = StringUtils.capitalize(COMMONS_CONFIGURATOR_CLASS_NAME);
            commonsConfiguratorClassName = config.getInitParameter(capitalized);
        }

        if (fileConfiguratorClassName == null || fileConfiguratorClassName.isEmpty()) {
            String capitalized = StringUtils.capitalize(FILE_CONFIGURATOR_CLASS_NAME);
            fileConfiguratorClassName = config.getInitParameter(capitalized);
        }

        // Call the specific FILE Configurator class to use

        classNameToLoad = commonsConfiguratorClassName;
        if (commonsConfiguratorClassName != null && !commonsConfiguratorClassName.isEmpty()) {
            Class<?> c = Class.forName(commonsConfiguratorClassName);
            commonsConfigurator = (CommonsConfigurator) c.newInstance();
        } else {
            commonsConfigurator = new DefaultCommonsConfigurator();
        }

        // Immediately create the Logger
        Logger logger = null;
        try {
            logger = commonsConfigurator.getLogger();
            ServerLogger.createLogger(logger);
            ServerLogger.getLogger().log(Level.WARNING, "Starting " + FileVersion.PRODUCT.NAME + "...");
            serverLoggerOk = true;
        } catch (Exception e) {
            initErrrorMesage = Tag.PRODUCT_USER_CONFIG_FAIL + " Impossible to create the Logger: " + logger;
            exception = e;

        }

        classNameToLoad = fileConfiguratorClassName;
        if (fileConfiguratorClassName != null && !fileConfiguratorClassName.isEmpty()) {
            Class<?> c = Class.forName(fileConfiguratorClassName);
            fileConfigurator = (FileConfigurator) c.newInstance();
        } else {
            fileConfigurator = new DefaultFileConfigurator();
        }

    } catch (ClassNotFoundException e) {
        initErrrorMesage = Tag.PRODUCT_USER_CONFIG_FAIL
                + " Impossible to load (ClassNotFoundException) Configurator class: " + classNameToLoad;
        exception = e;
    } catch (InstantiationException e) {
        initErrrorMesage = Tag.PRODUCT_USER_CONFIG_FAIL
                + " Impossible to load (InstantiationException) Configurator class: " + classNameToLoad;
        exception = e;
    } catch (IllegalAccessException e) {
        initErrrorMesage = Tag.PRODUCT_USER_CONFIG_FAIL
                + " Impossible to load (IllegalAccessException) Configurator class: " + classNameToLoad;
        exception = e;
    } catch (Exception e) {
        initErrrorMesage = Tag.PRODUCT_PRODUCT_FAIL + " Please contact support support@kawansoft.com";
        exception = e;
    }

    if (commonsConfigurator == null) {
        commonsConfiguratorClassName = COMMONS_CONFIGURATOR_CLASS_NAME;
    } else {
        commonsConfiguratorClassName = commonsConfigurator.getClass().getName();
    }

    if (fileConfigurator == null) {
        fileConfiguratorClassName = FILE_CONFIGURATOR_CLASS_NAME;
    } else {
        fileConfiguratorClassName = fileConfigurator.getClass().getName();
    }

    System.out.println();
    System.out.println(Tag.PRODUCT_START + " " + org.kawanfw.file.version.FileVersion.getVersion());
    System.out.println(Tag.PRODUCT_START + " " + this.getServletName() + " Servlet:");
    System.out.println(Tag.PRODUCT_START + " - Init Parameter commonsConfiguratorClassName: " + CR_LF
            + Tag.PRODUCT_START + SPACES_3 + commonsConfiguratorClassName);
    System.out.println(Tag.PRODUCT_START + " - Init Parameter fileConfiguratorClassName: " + CR_LF
            + Tag.PRODUCT_START + SPACES_3 + fileConfiguratorClassName);

    if (exception == null) {
        System.out.println(Tag.PRODUCT_START + " " + FileVersion.PRODUCT.NAME + " Configurator Status: OK.");
        System.out.println();
    } else {
        System.out.println(Tag.PRODUCT_START + " " + FileVersion.PRODUCT.NAME + " Configurator Status: KO.");
        System.out.println(initErrrorMesage);
        System.out.println(ExceptionUtils.getStackTrace(exception));
    }

    if (serverLoggerOk) {
        if (KawanNotifier.existsNoNotifyTxt()) {
            ServerLogger.getLogger().log(Level.WARNING,
                    Tag.PRODUCT_START + " Notification to Kawan Servers: OFF");
        }
    } else {
        if (KawanNotifier.existsNoNotifyTxt()) {
            System.out.println(Tag.PRODUCT_START + " Notification to Kawan Servers: OFF");
        }
    }

}

From source file:org.kawanfw.sql.servlet.ServerSqlManager.java

/**
 * Init/*  w ww. j  av a  2s.c  o  m*/
 */

public void init(ServletConfig config) throws ServletException {
    super.init(config);

    // Variable use to store the current name when loading, used to
    // detail
    // the exception in the catch clauses
    String classNameToLoad = null;

    String commonsConfiguratorClassName;
    String fileConfiguratorClassName;
    String sqlConfiguratorClassName;

    String servletName = this.getServletName();

    String index = null;

    if (!TomcatModeStore.isTomcatEmbedded()) {
        System.out.println(SqlTag.SQL_PRODUCT_START + " " + Version.getServerVersion());
    }

    // We are in SQL Framework
    TomcatModeStore.setFrameworkSql(true);

    try {

        if (!TomcatModeStore.isTomcatEmbedded()) {
            String propertiesFileStr = config.getInitParameter("properties");

            if (propertiesFileStr == null || propertiesFileStr.isEmpty()) {

                String aceqlHome = System.getenv("ACEQL_HOME");

                if (aceqlHome != null) {

                    // Remove surrounding " if present
                    aceqlHome = aceqlHome.replaceAll("\"", "");

                    if (aceqlHome.endsWith(File.separator)) {
                        aceqlHome = StringUtils.substringBeforeLast(aceqlHome, File.separator);
                    }
                    propertiesFileStr = aceqlHome + File.separator + "conf" + File.separator
                            + "aceql-server.properties";
                } else {
                    throw new SqlConfigurationException(Tag.PRODUCT_USER_CONFIG_FAIL
                            + " ACEQL_HOME property not set. Impossible to use the default ACEQL_HOME"
                            + File.separator + "conf" + File.separator + "aceql-server.properties file");
                }

                //          throw new SqlConfigurationException(
                //             Tag.PRODUCT_USER_CONFIG_FAIL
                //                + " <param-name> \"properties\" not found for servlet "
                //                + servletName);
            }

            File propertiesFile = new File(propertiesFileStr);

            if (!propertiesFile.exists()) {
                throw new SqlConfigurationException(
                        Tag.PRODUCT_USER_CONFIG_FAIL + " properties file not found: " + propertiesFile);
            }

            System.out.println(SqlTag.SQL_PRODUCT_START + " " + "Using properties file: " + propertiesFile);

            properties = TomcatStarterUtil.getProperties(propertiesFile);

            index = TomcatStarterUtil.getIndexFromServletName(properties, servletName);

            TomcatStarterUtil.setInitParametersInStore(properties, index);

            // Create the default DataSource if necessary
            TomcatStarterUtil.createAndStoreDataSource(properties, index);
        }

        commonsConfiguratorClassName = ServletParametersStore.getInitParameter(servletName,
                COMMONS_CONFIGURATOR_CLASS_NAME);
        fileConfiguratorClassName = ServletParametersStore.getInitParameter(servletName,
                FILE_CONFIGURATOR_CLASS_NAME);
        sqlConfiguratorClassName = ServletParametersStore.getInitParameter(servletName,
                SQL_CONFIGURATOR_CLASS_NAME);

        debug("commonsConfiguratorClassName: " + commonsConfiguratorClassName);
        debug("fileConfiguratorClassName   : " + fileConfiguratorClassName);
        debug("sqlConfiguratorClassName    : " + sqlConfiguratorClassName);

        // Check spelling with first letter capitalized

        if (commonsConfiguratorClassName == null || commonsConfiguratorClassName.isEmpty()) {
            String capitalized = StringUtils.capitalize(ServerFileManager.COMMONS_CONFIGURATOR_CLASS_NAME);
            commonsConfiguratorClassName = ServletParametersStore.getInitParameter(servletName, capitalized);
        }

        if (fileConfiguratorClassName == null || fileConfiguratorClassName.isEmpty()) {
            String capitalized = StringUtils.capitalize(ServerFileManager.FILE_CONFIGURATOR_CLASS_NAME);
            fileConfiguratorClassName = ServletParametersStore.getInitParameter(servletName, capitalized);
        }

        if (sqlConfiguratorClassName == null || sqlConfiguratorClassName.isEmpty()) {
            String capitalized = StringUtils.capitalize(SQL_CONFIGURATOR_CLASS_NAME);
            sqlConfiguratorClassName = ServletParametersStore.getInitParameter(servletName, capitalized);
        }

        // Call the specific Configurator class to use

        classNameToLoad = commonsConfiguratorClassName;
        if (commonsConfiguratorClassName != null && !commonsConfiguratorClassName.isEmpty()) {
            Class<?> c = Class.forName(commonsConfiguratorClassName);
            commonsConfigurator = (CommonsConfigurator) c.newInstance();
        } else {

            commonsConfigurator = new DefaultCommonsConfigurator();

        }

        // Immediately create the ServerLogger
        Logger logger = null;
        try {
            logger = commonsConfigurator.getLogger();
            ServerLogger.createLogger(logger);
            serverLoggerOk = true;
        } catch (Exception e) {
            exception = e;
            initErrrorMesage = Tag.PRODUCT_USER_CONFIG_FAIL + " Impossible to create the Logger: " + logger
                    + ". Reason: " + e.getMessage();
        }

        classNameToLoad = fileConfiguratorClassName;
        if (fileConfiguratorClassName != null && !fileConfiguratorClassName.isEmpty()) {
            Class<?> c = Class.forName(fileConfiguratorClassName);
            fileConfigurator = (FileConfigurator) c.newInstance();
        } else {
            fileConfigurator = new DefaultFileConfigurator();
        }

        classNameToLoad = sqlConfiguratorClassName;
        if (sqlConfiguratorClassName != null && !sqlConfiguratorClassName.isEmpty()) {
            Class<?> c = Class.forName(sqlConfiguratorClassName);
            sqlConfigurator = (SqlConfigurator) c.newInstance();
        } else {
            sqlConfigurator = new DefaultSqlConfigurator();
        }

    } catch (ClassNotFoundException e) {
        initErrrorMesage = Tag.PRODUCT_USER_CONFIG_FAIL
                + " Impossible to load (ClassNotFoundException) Configurator class: " + classNameToLoad;
        exception = e;
    } catch (InstantiationException e) {
        initErrrorMesage = Tag.PRODUCT_USER_CONFIG_FAIL
                + " Impossible to load (InstantiationException) Configurator class: " + classNameToLoad;
        exception = e;
    } catch (IllegalAccessException e) {
        initErrrorMesage = Tag.PRODUCT_USER_CONFIG_FAIL
                + " Impossible to load (IllegalAccessException) Configurator class: " + classNameToLoad;
        exception = e;
    } catch (SqlConfigurationException e) {
        initErrrorMesage = e.getMessage();
        exception = e;
    } catch (Exception e) {
        initErrrorMesage = Tag.PRODUCT_PRODUCT_FAIL + " Please contact support at: support@kawansoft.com";
        exception = e;
    }

    if (commonsConfigurator == null) {
        commonsConfiguratorClassName = COMMONS_CONFIGURATOR_CLASS_NAME;
    } else {
        commonsConfiguratorClassName = commonsConfigurator.getClass().getName();
    }

    if (fileConfigurator == null) {
        fileConfiguratorClassName = FILE_CONFIGURATOR_CLASS_NAME;
    } else {
        fileConfiguratorClassName = fileConfigurator.getClass().getName();
    }

    if (sqlConfigurator == null) {
        sqlConfiguratorClassName = SQL_CONFIGURATOR_CLASS_NAME;
    } else {
        sqlConfiguratorClassName = sqlConfigurator.getClass().getName();
    }

    System.out.println(SqlTag.SQL_PRODUCT_START + " " + servletName + " Servlet Configurators:");
    System.out.println(
            SqlTag.SQL_PRODUCT_START + "  -> commonsConfiguratorClassName: " + commonsConfiguratorClassName);
    System.out.println(
            SqlTag.SQL_PRODUCT_START + "  -> sqlConfiguratorClassName    : " + sqlConfiguratorClassName);
    System.out.println(
            SqlTag.SQL_PRODUCT_START + "  -> fileConfiguratorClassName   : " + fileConfiguratorClassName);

    if (exception == null) {
        System.out.println(SqlTag.SQL_PRODUCT_START + "  -> Configurators Status: OK.");
    } else {

        if (!TomcatModeStore.isTomcatEmbedded()) {
            String errorMessage1 = SqlTag.SQL_PRODUCT_START + "  -> Configurators Status: KO.";
            String errorMessage2 = initErrrorMesage;
            String errorMessage3 = ExceptionUtils.getStackTrace(exception);

            System.out.println(errorMessage1);
            System.out.println(errorMessage2);
            System.out.println(errorMessage3);

            if (serverLoggerOk) {
                ServerLogger.getLogger().log(Level.WARNING, errorMessage1);
                ServerLogger.getLogger().log(Level.WARNING, errorMessage2);
                ServerLogger.getLogger().log(Level.WARNING, errorMessage3);
            }

            System.out.println();
        }

    }
}

From source file:org.kawanfw.sql.tomcat.PoolPropertiesCreator.java

/**
 * Call the method corresponding to the property name with the property
 * value./*  w  w w .  j a  va  2 s.c  o  m*/
 * 
 * @param propertyName
 * @param propertyValue
 * 
 * @throws NoSuchMethodException
 * @throws SecurityException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 * @throws NumberFormatException
 * @throws Exception
 */
private void callMethod(String propertyName, String propertyValue)
        throws SecurityException, NoSuchMethodException, NumberFormatException, IllegalArgumentException,
        IllegalAccessException, InvocationTargetException {

    String theMethod = "set" + StringUtils.capitalize(propertyName);

    String propertyValueToDisplay = propertyValue;
    if (propertyName.equals("password")) {
        propertyValueToDisplay = TomcatStarter.MASKED_PASSWORD;
    }

    Class<?>[] pType = methodNamesAndParms.get(theMethod);

    // if (pType[0] == String.class) {
    // System.out.println(SqlTag.SQL_PRODUCT_START + "poolProperties." +
    // theMethod
    // + "(\"" + propertyValueToDisplay + "\")");
    // } else {
    // System.out.println(SqlTag.SQL_PRODUCT_START + "poolProperties." +
    // theMethod
    // + "(" + propertyValueToDisplay + ")");
    // }

    System.out.println(SqlTag.SQL_PRODUCT_START + "  -> " + propertyName + " = " + propertyValueToDisplay);

    // Invoke the method
    Method main = theClass.getDeclaredMethod(theMethod, pType);

    // if (argTypes[i] == Connection.class) {
    if (pType[0] == long.class) {
        main.invoke(theObject, Long.parseLong(propertyValue));
    } else if (pType[0] == String.class) {
        main.invoke(theObject, propertyValue);
    } else if (pType[0] == boolean.class) {
        main.invoke(theObject, Boolean.parseBoolean(propertyValue));
    } else if (pType[0] == int.class) {
        main.invoke(theObject, Integer.parseInt(propertyValue));
    } else {
        throw new SqlConfigurationException("Invalid Connection Pool property: " + propertyName);
    }

}

From source file:org.kew.rmf.matchconf.utils.GetterSetter.java

@SuppressWarnings("unchecked")
public <ObjClass> ReturnType getattr(ObjClass obj, String fieldName) throws IllegalAccessException,
        IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    String method = "get" + StringUtils.capitalize(fieldName);
    return (ReturnType) obj.getClass().getMethod(method).invoke(obj);
}

From source file:org.kew.rmf.matchconf.utils.GetterSetter.java

public <T> void setattr(T obj, String fieldName, int n) throws IllegalAccessException, IllegalArgumentException,
        InvocationTargetException, NoSuchMethodException, SecurityException {
    String method = "set" + StringUtils.capitalize(fieldName);
    obj.getClass().getMethod(method, int.class).invoke(obj, n);
}

From source file:org.kew.rmf.matchconf.utils.GetterSetter.java

public <T> void setattr(T obj, String fieldName, ReturnType b) throws IllegalAccessException,
        IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    String method = "set" + StringUtils.capitalize(fieldName);
    obj.getClass().getMethod(method, b.getClass()).invoke(obj, b);
}

From source file:org.kie.appformer.formmodeler.codegen.view.impl.java.inputs.impl.MultipleSubFormHelper.java

private void amendUpdateNestedModels(final MultipleSubFormFieldDefinition fieldDefinition,
        final SourceGenerationContext context, final JavaClassSource viewClass) {
    final MethodSource<JavaClassSource> updateNestedModelsMethod = getUpdateNestedModelsMethod(context,
            viewClass);// w  ww .ja  v a2s  .c  o m
    if (updateNestedModelsMethod != null) {

        viewClass.addImport(JAVA_UTIL_LIST_CLASSNAME);
        viewClass.addImport(JAVA_UTIL_ARRAYLIST_CLASSNAME);

        String body = updateNestedModelsMethod.getBody();

        final String pName = fieldDefinition.getBinding();
        final String pType = fieldDefinition.getStandaloneClassName();

        final String modelName = StringUtils.capitalize(context.getFormDefinition().getModel().getName());

        body += "List " + pName + " = getModel().get" + modelName + "().get" + StringUtils.capitalize(pName)
                + "();\n";
        body += "if (" + pName + " == null && init) {\n";
        body += "  " + pName + " = new ArrayList<" + pType + ">();\n";
        body += "  getModel().get" + modelName + "().set" + StringUtils.capitalize(pName) + "(" + pName
                + ");\n";
        body += "}\n";
        body += fieldDefinition.getName() + ".setModel(" + pName + ");\n";
        updateNestedModelsMethod.setBody(body);
    }
}