Example usage for org.apache.commons.lang WordUtils capitalizeFully

List of usage examples for org.apache.commons.lang WordUtils capitalizeFully

Introduction

In this page you can find the example usage for org.apache.commons.lang WordUtils capitalizeFully.

Prototype

public static String capitalizeFully(String str, char[] delimiters) 

Source Link

Document

Converts all the delimiter separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.

Usage

From source file:org.apache.hadoop.hive.ql.udf.generic.UDFInitCap.java

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    String val = getStringValue(arguments, 0, converters);
    if (val == null) {
        return null;
    }/*from   ww w .ja v  a2 s  . c o  m*/

    String valCap = WordUtils.capitalizeFully(val, new char[] { '-', ',', ' ' });
    output.set(valCap);
    return output;
}

From source file:org.carewebframework.cal.api.patientlist.PatientListUtil.java

public static String formatName(final String name) {
    if (StringUtils.isEmpty(name)) {
        return "";
    }//  w  ww. ja v a2 s.c o  m

    String pcs[] = StrUtil.split(WordUtils.capitalizeFully(name, WORD_DELIMITERS), ",");
    StringBuilder sb = new StringBuilder(name.length() + 5);

    for (String pc : pcs) {
        if (sb.length() > 0) {
            sb.append(", ");
        }

        sb.append(pc.trim());
    }

    return sb.toString();
}

From source file:org.chililog.server.common.AppProperties.java

/**
 * <p>/*from  ww  w  .  j a v  a  2 s . co m*/
 * Parses the properties into strongly typed class fields.
 * </p>
 * 
 * <p>
 * Use reflection to simulate the likes of: <code>_appName = loadAppName(properties);</code>
 * </p>
 * 
 * @param properties
 *            Properties to parse
 * @throws Exception
 */
private void parseProperties(Properties properties) throws Exception {
    Class<AppProperties> cls = AppProperties.class;
    Field[] ff = cls.getDeclaredFields();
    for (Field f : ff) {
        // Look for field names like APP_NAME
        String propertyNameFieldName = f.getName();
        if (!propertyNameFieldName.matches("^[A-Z0-9_]+$")) {
            continue;
        }

        // Build cache field (_appName) and method (loadAppName) methods
        String baseName = WordUtils.capitalizeFully(propertyNameFieldName, new char[] { '_' });
        baseName = baseName.replace("_", "");
        String cacheMethodName = "load" + baseName;
        String cacheFieldName = "_" + StringUtils.uncapitalize(baseName);

        // If field not exist, then skip
        Field cacheField = null;
        try {
            cacheField = cls.getDeclaredField(cacheFieldName);
        } catch (NoSuchFieldException e) {
            continue;
        }

        // Get and set the value
        Method m = cls.getDeclaredMethod(cacheMethodName, Properties.class);
        Object cacheValue = m.invoke(null, properties);
        cacheField.set(this, cacheValue);
    }

    return;
}

From source file:org.chililog.server.common.AppProperties.java

/**
 * Returns a string representation of the parsed properties
 *//*from   w w  w  . j  a  v a  2  s  .c om*/
public String toString() {
    StringBuilder sb = new StringBuilder();

    Class<AppProperties> cls = AppProperties.class;
    for (Field f : cls.getDeclaredFields()) {
        // Look for field names like APP_NAME
        String propertyNameFieldName = f.getName();
        if (!propertyNameFieldName.matches("^[A-Z0-9_]+$")) {
            continue;
        }

        // Build cache field (_appName) and method (loadAppName) methods
        String baseName = WordUtils.capitalizeFully(propertyNameFieldName, new char[] { '_' });
        baseName = baseName.replace("_", "");
        String cacheFieldName = "_" + StringUtils.uncapitalize(baseName);

        // If field not exist, then skip
        Field cacheField = null;
        try {
            cacheField = cls.getDeclaredField(cacheFieldName);
        } catch (NoSuchFieldException e) {
            continue;
        }

        // Get the value
        try {
            Object o = cacheField.get(this);
            sb.append(f.get(null));
            sb.append(" = ");
            sb.append(o == null ? "<not set>" : o.toString());
            sb.append("\n");
        } catch (Exception e) {
            sb.append("ERROR: Cannot load value for: " + propertyNameFieldName);
        }

    }

    return sb.toString();
}

From source file:org.chililog.server.common.BuildProperties.java

/**
 * <p>/*w  w w.  ja  v a 2 s .co  m*/
 * Parses the properties into strongly typed class fields.
 * </p>
 * 
 * <p>
 * Use reflection to simulate the likes of: <code>_appName = loadAppName(properties);</code>
 * </p>
 * 
 * @param properties
 *            Properties to parse
 * @throws Exception
 */
private void parseProperties(Properties properties) throws Exception {
    Class<BuildProperties> cls = BuildProperties.class;
    Field[] ff = cls.getDeclaredFields();
    for (Field f : ff) {
        // Look for field names like APP_NAME
        String propertyNameFieldName = f.getName();
        if (!propertyNameFieldName.matches("^[A-Z0-9_]+$")) {
            continue;
        }

        // Build cache field (_appName) and method (loadAppName) methods
        String baseName = WordUtils.capitalizeFully(propertyNameFieldName, new char[] { '_' });
        baseName = baseName.replace("_", "");
        String cacheMethodName = "load" + baseName;
        String cacheFieldName = "_" + StringUtils.uncapitalize(baseName);

        // If field not exist, then skip
        Field cacheField = null;
        try {
            cacheField = cls.getDeclaredField(cacheFieldName);
        } catch (NoSuchFieldException e) {
            continue;
        }

        // Get and set the value
        Method m = cls.getDeclaredMethod(cacheMethodName, Properties.class);
        Object cacheValue = m.invoke(null, properties);
        cacheField.set(this, cacheValue);
    }

    return;
}

From source file:org.chililog.server.common.BuildProperties.java

/**
 * Returns a string representation of the parsed properties
 *///from w  w w.j av  a 2  s.  c  o m
public String toString() {
    StringBuilder sb = new StringBuilder();

    Class<BuildProperties> cls = BuildProperties.class;
    for (Field f : cls.getDeclaredFields()) {
        // Look for field names like APP_NAME
        String propertyNameFieldName = f.getName();
        if (!propertyNameFieldName.matches("^[A-Z0-9_]+$")) {
            continue;
        }

        // Build cache field (_appName) and method (loadAppName) methods
        String baseName = WordUtils.capitalizeFully(propertyNameFieldName, new char[] { '_' });
        baseName = baseName.replace("_", "");
        String cacheFieldName = "_" + StringUtils.uncapitalize(baseName);

        // If field not exist, then skip
        Field cacheField = null;
        try {
            cacheField = cls.getDeclaredField(cacheFieldName);
        } catch (NoSuchFieldException e) {
            continue;
        }

        // Get the value
        try {
            Object o = cacheField.get(this);
            sb.append(f.get(null));
            sb.append(" = ");
            sb.append(o == null ? "<not set>" : o.toString());
            sb.append("\n");
        } catch (Exception e) {
            sb.append("ERROR: Cannot load value for: " + propertyNameFieldName);
        }

    }

    return sb.toString();
}

From source file:org.chililog.server.common.SystemProperties.java

/**
 * <p>/*w ww  . j  av a 2s .  c o  m*/
 * Loads/Reloads the properties. This method is NOT thread-safe and should only be called for unit-testing.
 * </p>
 * 
 * <p>
 * Use reflection to simulate the likes of:
 * <code>_chiliLogConfigDirectory = loadChiliLogConfigDirectory(properties);</code>
 * </p>
 * 
 * @throws Exception
 */
public void loadProperties() throws Exception {
    Class<SystemProperties> cls = SystemProperties.class;
    for (Field f : cls.getDeclaredFields()) {
        // Look for field names like CHILILOG_CONFIG_DIRECTORY
        String propertyNameFieldName = f.getName();
        if (!propertyNameFieldName.matches("^[A-Z0-9_]+$")) {
            continue;
        }

        // Build cache field (_chiliLogConfigDirectory) and method (loadChiliLogConfigDirectory) names
        String baseName = WordUtils.capitalizeFully(propertyNameFieldName, new char[] { '_' });
        baseName = baseName.replace("Chililog", "ChiliLog").replace("_", "");
        String cacheMethodName = "load" + baseName;
        String cacheFieldName = "_" + StringUtils.uncapitalize(baseName);

        // If field not exist, then skip
        Field cacheField = null;
        try {
            cacheField = cls.getDeclaredField(cacheFieldName);
        } catch (NoSuchFieldException e) {
            continue;
        }

        // Get and set the value
        Method m = cls.getDeclaredMethod(cacheMethodName, (Class[]) null);
        Object cacheValue = m.invoke(null, (Object[]) null);
        cacheField.set(this, cacheValue);
    }

    return;
}

From source file:org.chililog.server.workbench.ApiRequestHandler.java

/**
 * <p>//from ww w.j a  v  a 2s . co m
 * Instance our API worker class using the name passed in on the URI.
 * </p>
 * <p>
 * If <code>/api/Authentication</code> is passed in, the class
 * <code>com.chililog.server.intefaces.management.workers.AuthenticationWorker</code> will be instanced.
 * </p>
 */
private ApiResult instanceApiWorker() throws Exception {
    // TODO - Invoke in another thread because we are mostly reading and writing to mongodb
    String className = null;
    try {
        String uri = _request.getUri();
        String[] segments = uri.split("/");
        String apiName = segments[2];

        // Get rid of query string
        int qs = apiName.indexOf("?");
        if (qs > 0) {
            apiName = apiName.substring(0, qs);
        }

        // Merge _ to camel case
        apiName = WordUtils.capitalizeFully(apiName, new char[] { '_' });
        apiName = apiName.replace("_", "");

        className = "org.chililog.server.workbench.workers." + apiName + "Worker";
        _logger.debug("Instancing ApiWorker: %s", className);

        Class<?> apiClass = ClassUtils.getClass(className);
        _apiWorker = (Worker) ConstructorUtils.invokeConstructor(apiClass, _request);

        return _apiWorker.validate();
    } catch (ClassNotFoundException ex) {
        return new ApiResult(HttpResponseStatus.NOT_FOUND,
                new ChiliLogException(ex, Strings.API_NOT_FOUND_ERROR, className, _request.getUri()));
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterDelegateTest.java

/**
 * Creates a geospatial Filter string.//from w  w  w .ja v a  2  s  . com
 *
 * @param spatialOperator The spatial operator (e.g., BBOX, INTERSECTS, WITHIN) to use in the
 *     Filter string
 * @param propertyName he PropertyName to use in the Filter string
 * @param geoType The type of geometry (e.g., LINESTRING, POINT, POLYGON) the Filter string will
 *     represent
 * @param coordinatesString A string of space-separated coordinates to use when constructing the
 *     geometry Filter string
 * @param propertyMap A map of additional properties. Currently valid properties that will be used
 *     when applicable include:
 *     <p>{@link #USE_POS_LIST_GEO_FILTER_PROP_MAP_KEY} A string with a value of either "true" or
 *     "false." When true, a single <posList> element, rather than a set of <pos> elements, is
 *     used in building a <LinearRing>.
 *     <p>{@link #DISTANCE_GEO_FILTER_PROP_MAP_KEY} When present, a <Distance> element will be
 *     included in the geospatial Filter string using the distance value included in the property
 *     map.
 * @return A string representing a geospatial Filter
 */
private String createGeospatialFilterString(SpatialOperatorNameType spatialOperator,
        GeospatialPropertyName propertyName, Geometries geoType, String coordinatesString,
        Map<String, String> propertyMap) {

    if (null == propertyMap) {
        propertyMap = new HashMap<>();
    }

    char[] delimiters = { '_' };
    String spatialOpName = WordUtils.capitalizeFully(spatialOperator.name(), delimiters).replaceAll("_", "");

    String geoTypeName;
    switch (geoType) {
    case LINESTRING:
        geoTypeName = "LineString";
        break;
    case MULTIPOINT:
        geoTypeName = "MultiPoint";
        break;
    default:
        geoTypeName = WordUtils.capitalizeFully(geoType.name());
    }

    String geoFilterStr = getXmlHeaderString() + "<ns3:" + spatialOpName + ">" + "<ns3:PropertyName>"
            + propertyName + "</ns3:PropertyName>" + "<ns4:" + geoTypeName;

    switch (geoType) {
    case LINESTRING:
    case MULTIPOINT:
    case POINT:
    case POLYGON:
        geoFilterStr += " srsName=\"EPSG:4326\"";
        break;
    default:
        break;
    }

    geoFilterStr += ">";

    switch (geoType) {
    case LINESTRING:
    case POINT:
        geoFilterStr += createPosElementsString(coordinatesString);
        break;
    case MULTIPOINT:
        geoFilterStr += createMultiPointMembersFilterString(coordinatesString);
        break;
    case POLYGON:
        geoFilterStr += "<ns4:exterior>" + createLinearRingFilterString(
                Boolean.valueOf(propertyMap.get(USE_POS_LIST_GEO_FILTER_PROP_MAP_KEY)), coordinatesString)
                + "</ns4:exterior>";
        break;
    default:
        // Do nothing
    }

    geoFilterStr += "</ns4:" + geoTypeName + ">";

    String distance = propertyMap.get(DISTANCE_GEO_FILTER_PROP_MAP_KEY);
    if (!StringUtils.isBlank(distance)) {
        geoFilterStr += "<ns3:Distance units=\"METERS\">" + distance + "</ns3:Distance>";
    }

    geoFilterStr += "</ns3:" + spatialOpName + ">" + getXmlFooterString();

    LOGGER.debug("geoFilterString: {}", geoFilterStr);
    return geoFilterStr;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.TestCswFilterDelegate.java

/**
 * Creates a geospatial Filter string./*from   w w w  .jav  a 2  s .  c  om*/
 *
 * @param spatialOperator   The spatial operator (e.g., BBOX, INTERSECTS,
 *                          WITHIN) to use in the Filter string
 * @param propertyName      he PropertyName to use in the Filter string
 * @param geoType           The type of geometry (e.g., LINESTRING, POINT, POLYGON)
 *                          the Filter string will represent
 * @param coordinatesString A string of space-separated coordinates to
 *                          use when constructing the geometry Filter string
 * @param propertyMap       A map of additional properties. Currently valid
 *                          properties that will be used when applicable include:
 *                          <p>
 *                          {@link #USE_POS_LIST_GEO_FILTER_PROP_MAP_KEY} A string with a value
 *                          of either "true" or "false." When true, a single <posList> element,
 *                          rather than a set of <pos> elements, is used in building a
 *                          <LinearRing>.
 *                          <p>
 *                          {@link #DISTANCE_GEO_FILTER_PROP_MAP_KEY} When present, a
 *                          <Distance> element will be included in the geospatial Filter string
 *                          using the distance value included in the property map.
 * @return A string representing a geospatial Filter
 */
private String createGeospatialFilterString(SpatialOperatorNameType spatialOperator,
        GeospatialPropertyName propertyName, Geometries geoType, String coordinatesString,
        Map<String, String> propertyMap) {

    if (null == propertyMap) {
        propertyMap = new HashMap<String, String>();
    }

    char[] delimiters = { '_' };
    String spatialOpName = WordUtils.capitalizeFully(spatialOperator.name(), delimiters).replaceAll("_", "");

    String geoTypeName = null;
    switch (geoType) {
    case LINESTRING:
        geoTypeName = "LineString";
        break;
    case MULTIPOINT:
        geoTypeName = "MultiPoint";
        break;
    default:
        geoTypeName = WordUtils.capitalizeFully(geoType.name());
    }

    String geoFilterStr = getXmlHeaderString() + "<ns3:" + spatialOpName + ">" + "<ns3:PropertyName>"
            + propertyName + "</ns3:PropertyName>" + "<ns4:" + geoTypeName;

    switch (geoType) {
    case LINESTRING:
    case MULTIPOINT:
    case POINT:
    case POLYGON:
        geoFilterStr += " srsName=\"EPSG:4326\"";
        break;
    default:
        break;
    }

    geoFilterStr += ">";

    switch (geoType) {
    case LINESTRING:
    case POINT:
        geoFilterStr += createPosElementsString(coordinatesString);
        break;
    case MULTIPOINT:
        geoFilterStr += createMultiPointMembersFilterString(coordinatesString);
        break;
    case POLYGON:
        geoFilterStr += "<ns4:exterior>" + createLinearRingFilterString(
                Boolean.valueOf(propertyMap.get(USE_POS_LIST_GEO_FILTER_PROP_MAP_KEY)), coordinatesString)
                + "</ns4:exterior>";
        break;
    default:
        // Do nothing
    }

    geoFilterStr += "</ns4:" + geoTypeName + ">";

    String distance = propertyMap.get(DISTANCE_GEO_FILTER_PROP_MAP_KEY);
    if (!StringUtils.isBlank(distance)) {
        geoFilterStr += "<ns3:Distance units=\"METERS\">" + distance + "</ns3:Distance>";
    }

    geoFilterStr += "</ns3:" + spatialOpName + ">" + getXmlFooterString();

    LOGGER.debug("geoFilterString: {}", geoFilterStr);
    return geoFilterStr;
}