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

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

Introduction

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

Prototype

public static String capitalize(String str) 

Source Link

Document

Capitalizes all the whitespace separated words in a String.

Usage

From source file:au.org.theark.core.dao.StudyDao.java

/**
 * Gets a list of all Address Types/*from   w ww .ja va  2 s.co m*/
 * 
 * @return
 */
public List<AddressType> getAddressTypes() {
    List<AddressType> AddressTypeLstNew = new ArrayList<AddressType>();
    Criteria criteria = getSession().createCriteria(AddressType.class);
    criteria.addOrder(Order.asc("name"));

    List<AddressType> AddressTypeLst = criteria.list();
    for (AddressType addressType : AddressTypeLst) {
        String name = addressType.getName().toLowerCase();
        addressType.setName(WordUtils.capitalize(name));
        AddressTypeLstNew.add(addressType);
    }
    return AddressTypeLstNew;
}

From source file:com.boundlessgeo.geoserver.api.controllers.IO.java

/**
 * Encode the description of a resource into the passed object
 * @param obj the object to encode/*from   w ww .  ja  v a 2s. c o  m*/
 * @param store the resource
 * @param name the name of the resource
 * @param geoServer GeoServer instance
 * @return the encoded object
 * @throws IOException
 */
public static JSONObj resource(JSONObj obj, StoreInfo store, String name, GeoServer geoServer)
        throws IOException {
    obj.put("name", name);
    if (store instanceof DataStoreInfo) {
        DataStoreInfo data = (DataStoreInfo) store;

        @SuppressWarnings("rawtypes")
        DataAccess dataStore = data.getDataStore(new NullProgressListener());
        FeatureType schema;
        org.geotools.data.ResourceInfo info;
        if (dataStore instanceof DataStore) {
            schema = ((DataStore) dataStore).getSchema(name);
            info = ((DataStore) dataStore).getFeatureSource(name).getInfo();
        } else {
            NameImpl qname = new NameImpl(name);
            schema = dataStore.getSchema(qname);
            info = dataStore.getFeatureSource(qname).getInfo();
        }
        String title = info.getTitle() == null ? WordUtils.capitalize(name) : info.getTitle();
        String description = info.getDescription() == null ? "" : info.getDescription();
        obj.put("title", title);
        obj.put("description", description);

        JSONArr keywords = obj.putArray("keywords");
        keywords.raw().addAll(info.getKeywords());
        bounds(obj.putObject("bounds"), info.getBounds());
        schema(obj.putObject("schema"), schema, false);
    }
    if (store instanceof CoverageStoreInfo) {
        CoverageStoreInfo data = (CoverageStoreInfo) store;
        GridCoverageReader r = data.getGridCoverageReader(null, null);
        obj.put("title", WordUtils.capitalize(name));
        obj.put("description", "");
        if (r instanceof GridCoverage2DReader) {
            GridCoverage2DReader reader = (GridCoverage2DReader) r;
            CoordinateReferenceSystem crs = reader.getCoordinateReferenceSystem(name);
            schemaGrid(obj.putObject("schema"), crs, false);
        } else {
            schemaGrid(obj.putObject("schema"), AbstractGridFormat.getDefaultCRS(), false);
        }
    }

    JSONArr layers = obj.putArray("layers");
    Catalog cat = geoServer.getCatalog();
    if (store instanceof CoverageStoreInfo) {
        // coverage store does not respect native name so we search by id
        for (CoverageInfo info : cat.getCoveragesByCoverageStore((CoverageStoreInfo) store)) {
            layers(info, layers, geoServer);
        }
    } else {
        Filter filter = and(equal("namespace.prefix", store.getWorkspace().getName()),
                equal("nativeName", name));
        try (CloseableIterator<ResourceInfo> published = cat.list(ResourceInfo.class, filter);) {
            while (published.hasNext()) {
                ResourceInfo info = published.next();
                if (!info.getStore().getId().equals(store.getId())) {
                    continue; // native name is not enough, double check store id
                }
                layers(info, layers, geoServer);
            }
        }
    }
    return obj;
}

From source file:at.bitfire.davdroid.mirakel.resource.LocalAddressBook.java

protected static String xNameToLabel(String xname) {
    // "X-MY_PROPERTY"
    // 1. ensure lower case -> "x-my_property"
    // 2. remove x- from beginning -> "my_property"
    // 3. replace "_" by " " -> "my property"
    // 4. capitalize -> "My Property"
    String lowerCase = StringUtils.lowerCase(xname, Locale.US),
            withoutPrefix = StringUtils.removeStart(lowerCase, "x-"),
            withSpaces = StringUtils.replace(withoutPrefix, "_", " ");
    return WordUtils.capitalize(withSpaces);
}

From source file:de.tudarmstadt.ukp.clarin.webanno.project.page.ProjectLayersPanel.java

private void saveFeature(AnnotationFeature aFeature) {
    // Set properties of link features since these are currently not configurable in the UI
    if (!PRIMITIVE_TYPES.contains(aFeature.getType())) {
        aFeature.setMode(MultiValueMode.ARRAY);
        aFeature.setLinkMode(LinkMode.WITH_ROLE);
        aFeature.setLinkTypeRoleFeatureName("role");
        aFeature.setLinkTypeTargetFeatureName("target");
        aFeature.setLinkTypeName(/*from  w  w  w . ja v a 2  s .  c o m*/
                aFeature.getLayer().getName() + WordUtils.capitalize(aFeature.getName()) + "Link");
    }

    // If the feature is not a string feature or a link-with-role feature, force the tagset
    // to null.
    if (!(CAS.TYPE_NAME_STRING.equals(aFeature.getType()) || !PRIMITIVE_TYPES.contains(aFeature.getType()))) {
        aFeature.setTagset(null);
    }

    annotationService.createFeature(aFeature);
    featureDetailForm.setVisible(false);
}

From source file:com.boundlessgeo.geoserver.api.controllers.IO.java

/** Encode a parameter */
public static JSONObj param(JSONObj json, Parameter<?> p) {
    if (p != null) {
        String title = p.getTitle() != null ? p.getTitle().toString() : WordUtils.capitalize(p.getName());
        String description = p.getDescription() != null ? p.getDescription().toString() : null;

        JSONObj def = json.putObject(p.getName());
        def.put("title", title).put("description", description).put("type", p.getType().getSimpleName())
                .put("default", safeValue(p.getDefaultValue())).put("level", p.getLevel())
                .put("required", p.isRequired());

        if (!(p.getMinOccurs() == 1 && p.getMaxOccurs() == 1)) {
            def.putArray("occurs").add(p.getMinOccurs()).add(p.getMaxOccurs());
        }//  w  w  w .j av a  2  s  .c  o  m

        if (p.metadata != null) {
            for (String key : p.metadata.keySet()) {
                if (Parameter.LEVEL.equals(key)) {
                    continue;
                }
                def.put(key, p.metadata.get(key));
            }
        }
    }
    return json;
}

From source file:me.ryanhamshire.PopulationDensity.PopulationDensity.java

public static String capitalize(String string) {
    if (string == null || string.length() == 0)

        return string;

    if (string.length() == 1)

        return string.toUpperCase();

    //return string.substring(0, 1).toUpperCase() + string.substring(1);
    return WordUtils.capitalize(string);
}

From source file:com.cloudera.whirr.cm.server.impl.CmServerImpl.java

private ApiCommand execute(String label, ApiCommand command, Callback callback, boolean checkReturn)
        throws InterruptedException {
    label = WordUtils.capitalize(label.replace("-", " ").replace("_", " ")).replace(" ", "");
    logger.logOperationStartedAsync(label);
    ApiCommand commandReturn = null;/*from ww w  .  java  2  s  .c  om*/
    int apiPollPeriods = 1;
    int apiPollPeriodLog = 1;
    int apiPollPeriodBackoffNumber = API_POLL_PERIOD_BACKOFF_NUMBER;
    while (true) {
        if (apiPollPeriods++ % apiPollPeriodLog == 0) {
            logger.logOperationInProgressAsync(label);
            if (apiPollPeriodBackoffNumber-- == 0) {
                apiPollPeriodLog += API_POLL_PERIOD_BACKOFF_INCRAMENT;
                apiPollPeriodBackoffNumber = API_POLL_PERIOD_BACKOFF_NUMBER;
            }
        }
        if (callback.poll()) {
            if (checkReturn && command != null
                    && !(commandReturn = apiResourceRootV3.getCommandsResource().readCommand(command.getId()))
                            .getSuccess()) {
                logger.logOperationFailedAsync(label);
                throw new RuntimeException("Command [" + command + "] failed [" + commandReturn + "]");
            }
            logger.logOperationFinishedAsync(label);
            return commandReturn;
        }
        Thread.sleep(API_POLL_PERIOD_MS);
    }
}

From source file:com.yucheng.cmis.pub.util.NewStringUtils.java

/**
 * <p>Capitalizes all the whitespace separated words in a String.
 * Only the first letter of each word is changed.</p>
 *
 * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.
 * A <code>null</code> input String returns <code>null</code>.</p>
 *
 * @param str  the String to capitalize, may be null
 * @return capitalized String, <code>null</code> if null String input
 * @deprecated Use the relocated {@link WordUtils#capitalize(String)}.
 *             Method will be removed in Commons Lang 3.0.
 *///from   ww  w  . j ava2s  .  co m
public static String capitaliseAllWords(String str) {
    return WordUtils.capitalize(str);
}

From source file:gdv.xport.feld.Bezeichner.java

private static String toShortcut(final String input) {
    StringBuilder converted = new StringBuilder();
    char[] chars = input.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        switch (chars[i]) {
        case '\u00c4':
            converted.append("Ae");
            break;
        case '\u00d6':
            converted.append("Oe");
            break;
        case '\u00dc':
            converted.append("Ue");
            break;
        case '\u00e4':
            converted.append("ae");
            break;
        case '\u00f6':
            converted.append("oe");
            break;
        case '\u00fc':
            converted.append("ue");
            break;
        case '\u00df':
            converted.append("ss");
            break;
        default:/*from  w w  w  .jav  a2s.c  om*/
            if (Character.isLetterOrDigit(chars[i])) {
                converted.append(chars[i]);
            }
            break;
        }
    }
    String word = converted.toString();
    if (word.endsWith("datum")) {
        return word.substring(0, word.length() - 2);
    }
    if ("Waehrungseinheiten".equals(word)) {
        return "WE";
    }
    return WordUtils.capitalize(word);
}

From source file:no.sesat.search.view.velocity.CapitalizeWordsDirective.java

/**
  * {@inheritDoc}//from ww w . j  a  va  2  s. c om
  */
public boolean render(final InternalContextAdapter context, final Writer writer, final Node node)
        throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
    if (node.jjtGetNumChildren() != 1) {
        rsvc.error("#" + getName() + " - wrong number of arguments");
        return false;
    }

    final String input = node.jjtGetChild(0).value(context).toString();

    writer.write(WordUtils.capitalize(input));

    final Token lastToken = node.getLastToken();

    if (lastToken.image.endsWith("\n")) {
        writer.write("\n");
    }

    return true;
}