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:de.micromata.genome.util.types.Converter.java

/**
 * First to upper case.//from w  w w .j av a 2  s . co m
 *
 * @param str the str
 * @return the string
 */
public static String firstToUpperCase(String str) {
    if (StringUtils.isBlank(str) == true) {
        return str;
    }
    return StringUtils.capitalize(str.trim());
}

From source file:edu.usu.sdl.openstorefront.service.OrientPersistenceService.java

private <T> String generateExampleNames(T example, ComplexFieldStack complexFieldStack) {
    StringBuilder where = new StringBuilder();

    try {//  w w w .j a v  a 2s .  co  m
        Map fieldMap = BeanUtils.describe(example);
        boolean addAnd = false;
        for (Object field : fieldMap.keySet()) {

            if ("class".equalsIgnoreCase(field.toString()) == false) {
                Object value = fieldMap.get(field);
                if (value != null) {

                    Method method = example.getClass()
                            .getMethod("get" + StringUtils.capitalize(field.toString()), (Class<?>[]) null);
                    Object returnObj = method.invoke(example, (Object[]) null);
                    if (ReflectionUtil.isComplexClass(returnObj.getClass())) {
                        complexFieldStack.getFieldStack().push(field.toString());
                        if (addAnd) {
                            where.append(",");
                        } else {
                            addAnd = true;
                            where.append(" ");
                        }

                        where.append(generateExampleNames(returnObj, complexFieldStack));
                        complexFieldStack.getFieldStack().pop();
                    } else {
                        if (addAnd) {
                            where.append(",");
                        } else {
                            addAnd = true;
                            where.append(" ");
                        }
                        String fieldName = complexFieldStack.getQueryFieldName() + field.toString();

                        where.append(fieldName);
                    }
                }
            }
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
        throw new RuntimeException(ex);
    }
    return where.toString();
}

From source file:com.xpn.xwiki.XWiki.java

/**
 * Return the XWiki object (as in "the Wiki API") corresponding to the requested wiki.
 * //from   w ww.j a va 2  s. co  m
 * @param context the current context
 * @return an XWiki object configured for the wiki corresponding to the current request
 * @throws XWikiException if the requested URL does not correspond to a real wiki, or if there's an error in the
 *             storage
 */
public static XWiki getXWiki(XWikiContext context) throws XWikiException {
    XWiki xwiki = getMainXWiki(context);
    if (!xwiki.isVirtualMode()) {
        return xwiki;
    }

    // Host is full.host.name in DNS-based multiwiki, and wikiname in path-based multiwiki.
    String host = "";
    // Canonical name of the wiki (database)
    String wikiName = "";
    // wikiDefinition should be the document holding the definition of the virtual wiki, a document in the main
    // wiki with a XWiki.XWikiServerClass object attached to it
    DocumentReference wikiDefinition;

    XWikiRequest request = context.getRequest();
    try {
        URL requestURL = context.getURL();
        host = requestURL.getHost();
    } catch (Exception e) {
    }

    // In path-based multi-wiki, the wiki name is an element of the request path.
    // The url is in the form /xwiki (app name)/wiki (servlet name)/wikiname/
    if ("1".equals(xwiki.Param("xwiki.virtual.usepath", "0"))) {
        String uri = request.getRequestURI();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Request uri is: " + uri);
        }
        // Remove the (eventual) context path from the URI, usually /xwiki
        uri = stripSegmentFromPath(uri, request.getContextPath());
        // Remove the (eventual) servlet path from the URI, usually /wiki
        String servletPath = request.getServletPath();
        uri = stripSegmentFromPath(uri, servletPath);

        if (servletPath.equals("/" + xwiki.Param("xwiki.virtual.usepath.servletpath", "wiki"))) {
            // Requested path corresponds to a path-based wiki, now the wiki name is between the first and
            // second "/"
            host = StringUtils.substringBefore(StringUtils.removeStart(uri, "/"), "/");
        }
    }

    if (StringUtils.isEmpty(host) || host.equals(context.getMainXWiki())) {
        // Can't find any wiki name, return the main wiki
        return xwiki;
    }

    wikiDefinition = xwiki.findWikiServer(host, context);

    if (wikiDefinition == null) {
        // No definition found based on the full domain name/path wiki name, try to use the first part of the domain
        // name as the wiki name
        String servername = StringUtils.substringBefore(host, ".");

        // As a convenience, allow sites starting with www, localhost or using an
        // IP address not to have to create a XWikiServerXwiki page since we consider
        // in that case that they're pointing to the main wiki.
        if (!"0".equals(xwiki.Param("xwiki.virtual.autowww")) && (servername.equals("www")
                || host.equals("localhost") || host.matches("[0-9]{1,3}(?:\\.[0-9]{1,3}){3}"))) {
            return xwiki;
        }

        wikiDefinition = new DocumentReference(DEFAULT_MAIN_WIKI, SYSTEM_SPACE,
                "XWikiServer" + StringUtils.capitalize(servername));
    }

    // Check if this wiki definition exists in the Database
    XWikiDocument doc = xwiki.getDocument(wikiDefinition, context);
    if (doc.isNew()) {
        throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_DOES_NOT_EXIST,
                "The wiki " + host + " does not exist");
    }

    // Set the wiki owner
    String wikiOwner = doc.getStringValue(VIRTUAL_WIKI_DEFINITION_CLASS_REFERENCE, "owner");
    if (wikiOwner.indexOf(':') == -1) {
        wikiOwner = xwiki.getDatabase() + ":" + wikiOwner;
    }
    context.setWikiOwner(wikiOwner);
    context.setWikiServer(doc);

    wikiName = StringUtils.removeStart(wikiDefinition.getName(), "XWikiServer").toLowerCase();
    context.setDatabase(wikiName);
    context.setOriginalDatabase(wikiName);

    try {
        // Let's make sure the virtual wikis are upgraded to the latest database version
        xwiki.updateDatabase(wikiName, false, context);
    } catch (HibernateException ex) {
        // Just report it, hopefully the database is in a good enough state
        LOGGER.error("Failed to upgrade database: " + wikiName, ex);
    }
    return xwiki;
}

From source file:co.touchlab.squeaky.processor.AnnotationProcessor.java

private void assignId(List<FieldTypeGen> fieldTypeGens, ClassName className, TypeSpec.Builder configBuilder) {
    FieldTypeGen idField = findIdField(fieldTypeGens);

    ClassName helperName = ClassName.get(OrmLiteHelper.class);

    MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("assignId").addModifiers(Modifier.PUBLIC)
            .addAnnotation(Override.class).addParameter(className, "data").addParameter(Object.class, "val");

    if (idField == null) {
        //Do nothing
    } else if (idField.finalField) {
        methodBuilder.addStatement("throw new UnsupportedOperationException(\"Can't assign id to final field "
                + idField.fieldName + "\")");
    } else if (idField.useGetSet)
        methodBuilder.addCode(CodeBlock.builder()
                .addStatement("data.set$N(($N)$T.safeConvert($N.class, val))",
                        StringUtils.capitalize(idField.fieldName), idField.dataTypeClassname, helperName,
                        idField.dataTypeClassname)
                .build());//from w w w  .  j  av  a 2s . c om
    else
        methodBuilder.addCode(CodeBlock.builder().addStatement("data.$N = ($N)$T.safeConvert($N.class, val)",
                idField.fieldName, idField.dataTypeClassname, helperName, idField.dataTypeClassname).build());

    configBuilder.addMethod(methodBuilder.build());
}

From source file:de.escalon.hypermedia.spring.hydra.LinkListSerializer.java

private void writePossiblePropertyValues(JsonGenerator jgen, String currentVocab,
        ActionInputParameter actionInputParameter, @SuppressWarnings("unused") Object[] possiblePropertyValues)
        throws IOException {
    // Enable the following to list possible values.
    // Problem: how to express individuals only for certain hydra:options
    // not all hydra:options should be taken as uris, sometimes they might be just literals
    // how to make that clear to the client?
    // maybe we must write them out for options
    //        if (possiblePropertyValues.length > 0) {
    //            jgen.writeArrayFieldStart("hydra:option");
    ///*from  w w w.j a  v  a2s .  c o  m*/
    //            for (Object possibleValue : possiblePropertyValues) {
    //                // TODO: apply "hydra:option" : { "@type": "@vocab"} to context for enums
    //                writeScalarValue(jgen, possibleValue, rootParameter.getParameterType());
    //            }
    //            jgen.writeEndArray();
    //        }

    if (actionInputParameter.isArrayOrCollection()) {
        jgen.writeBooleanField(getPropertyOrClassNameInVocab(currentVocab, "multipleValues",
                LdContextFactory.HTTP_SCHEMA_ORG, "schema:"), true);
    }

    //  valueRequired (hard to say, using @Access on Event is for all update requests - or make
    //     specific request beans for different
    //     purposes rather than always passing an instance of e.g. Event?)
    //       -> update is a different use case than create - or maybe have an @Requires("eventStatus")
    //          annotation alongside requestBody to tell which attributes are required or writable, and use
    // Requires over
    //          bean structure, where ctor with least length of args is required and setters are supported
    //          but optional? The bean structure does say what is writable for updates, but not what is required
    // for creation. Right now setters are supportedProperties. For creation we would have to add constructor
    // arguments as supportedProperties.
    //  (/) defaultValue (pre-filled value, e.g. list of selected items for option)
    //  valueName (for iri templates only)
    //  (/) readonlyValue (true for final public field or absence of setter, send fixed value like hidden field?)
    // -> use hydra:readable, hydra:writable
    //  (/) multipleValues
    //  (/) valueMinLength
    //  (/) valueMaxLength
    //  (/) valuePattern
    //  minValue (DateTime support)
    //  maxValue (DateTime support)
    //  (/) stepValue
    final Map<String, Object> inputConstraints = actionInputParameter.getInputConstraints();

    if (actionInputParameter.hasValue()) {
        if (actionInputParameter.isArrayOrCollection()) {
            Object[] callValues = actionInputParameter.getValues();
            Class<?> componentType = callValues.getClass().getComponentType();
            // only write defaultValue for array of scalars
            if (DataType.isSingleValueType(componentType)) {
                jgen.writeFieldName(getPropertyOrClassNameInVocab(currentVocab, "defaultValue",
                        LdContextFactory.HTTP_SCHEMA_ORG, "schema:"));
                jgen.writeStartArray();
                for (Object callValue : callValues) {
                    writeScalarValue(jgen, callValue, componentType);
                }
                jgen.writeEndArray();
            }
        } else {
            jgen.writeFieldName(getPropertyOrClassNameInVocab(currentVocab, "defaultValue",
                    LdContextFactory.HTTP_SCHEMA_ORG, "schema:"));

            writeScalarValue(jgen, actionInputParameter.getValue(), actionInputParameter.getParameterType());
        }
    }

    if (!inputConstraints.isEmpty()) {
        final List<String> keysToAppendValue = Arrays.asList(Input.MAX, Input.MIN, Input.STEP);
        for (String keyToAppendValue : keysToAppendValue) {
            final Object constraint = inputConstraints.get(keyToAppendValue);
            if (constraint != null) {
                jgen.writeFieldName(getPropertyOrClassNameInVocab(currentVocab, keyToAppendValue + "Value",
                        LdContextFactory.HTTP_SCHEMA_ORG, "schema:"));
                jgen.writeNumber(constraint.toString());
            }
        }

        final List<String> keysToPrependValue = Arrays.asList(Input.MAX_LENGTH, Input.MIN_LENGTH,
                Input.PATTERN);
        for (String keyToPrependValue : keysToPrependValue) {
            final Object constraint = inputConstraints.get(keyToPrependValue);
            if (constraint != null) {
                jgen.writeFieldName(getPropertyOrClassNameInVocab(currentVocab,
                        "value" + StringUtils.capitalize(keyToPrependValue), LdContextFactory.HTTP_SCHEMA_ORG,
                        "schema:"));
                if (Input.PATTERN.equals(keyToPrependValue)) {
                    jgen.writeString(constraint.toString());
                } else {
                    jgen.writeNumber(constraint.toString());
                }
            }
        }

    }

}

From source file:co.touchlab.squeaky.processor.AnnotationProcessor.java

private static String simpleExtractor(FieldTypeGen fieldTypeGen) {
    StringBuilder convertBuilder = new StringBuilder();
    if (fieldTypeGen.useGetSet) {
        String accessPrefix = fieldTypeGen.dataType == DataType.BOOLEAN ? "is" : "get";
        convertBuilder.append("data.").append(accessPrefix)
                .append(StringUtils.capitalize(fieldTypeGen.fieldName)).append("(").append(")");
    } else {/* www  .  j  a v a  2 s  .  co  m*/
        convertBuilder.append("data.").append(fieldTypeGen.fieldName);
    }

    return convertBuilder.toString();
}

From source file:it.appify.generator.WebAppGenerator.java

private TypeSpec.Builder addInjectViewElementsMethod(JField[] jFields, TypeSpec.Builder controllerHolderSpec) {
    MethodSpec.Builder injectViewElementsBuilder = MethodSpec.methodBuilder("injectViewElements")
            .addAnnotation(Override.class).addModifiers(Modifier.PUBLIC);

    if (jFields == null || jFields.length == 0) {
        controllerHolderSpec.addMethod(injectViewElementsBuilder.build());
        return controllerHolderSpec;
    }/*from w  w w .j a  va2  s.co m*/

    for (JField jField : jFields) {
        ViewElement el = jField.getAnnotation(ViewElement.class);

        if (jField.isPublic()) {
            if (el != null) {
                String elId = el.value();
                injectViewElementsBuilder.addStatement("this.controller.$L = ($T) getViewFragment($S)",
                        jField.getName(), Element.class, elId);
            }
        } else if (jField.isPrivate() || jField.isProtected()) {
            if (el != null) {
                String elId = el.value();
                injectViewElementsBuilder.addStatement("this.controller.set$L(($T)getViewFragment($S))",
                        StringUtils.capitalize(jField.getName()), Element.class, elId);
            }
        }
    }
    controllerHolderSpec.addMethod(injectViewElementsBuilder.build());
    return controllerHolderSpec;
}

From source file:com.sonicle.webtop.core.app.WebTopSession.java

public void fillStartup(JsWTSPrivate js) {
    if (!isReady())
        return;/*ww w .  j  a  va 2s.  c  o  m*/

    ServiceManager svcm = wta.getServiceManager();
    ServiceManifest coreManifest = svcm.getManifest(CoreManifest.ID);
    CoreUserSettings cus = new CoreUserSettings(CoreManifest.ID, profile.getId());
    String theme = cus.getTheme(), layout = cus.getLayout(), lookAndFeel = cus.getLookAndFeel();
    ReadableDeviceCategory.Category deviceCategory = getClientUserAgent().getDeviceCategory().getCategory();
    if (ReadableDeviceCategory.Category.SMARTPHONE.equals(deviceCategory)
            || ReadableDeviceCategory.Category.TABLET.equals(deviceCategory)) {
        if (theme.equals("crisp") || theme.equals("neptune")) {
            theme += "-touch";
        } else {
            theme = "crisp-touch";
        }
    }
    Locale locale = getLocale();

    fillAppReferences(js, locale, theme, false);
    js.layoutClassName = StringUtils.capitalize(layout);

    List<String> privateSids = getPrivateServices(true);

    // Include Core references
    //js.appManifest.name = coreManifest.getJsPackageName();
    fillServiceManifest(js, coreManifest, locale, svcm.isInMaintenance(coreManifest.getId()));
    fillCoreServiceJsReferences(svcm.isInDevMode(CoreManifest.ID), "private", js, coreManifest, locale);
    fillServiceCssReferences(js, coreManifest, theme, lookAndFeel);

    // Include other services references
    if (RunContext.isWebTopAdmin()) {
        for (String sid : svcm.listRegisteredServices()) {
            if (sid.equals(CoreManifest.ID))
                continue;
            ServiceDescriptor descriptor = svcm.getDescriptor(sid);
            fillServiceReferences(svcm, js, descriptor, locale, theme, lookAndFeel);
        }
    } else {
        for (String sid : privateSids) {
            if (sid.equals(CoreManifest.ID))
                continue;
            ServiceDescriptor descriptor = svcm.getDescriptor(sid);
            fillServiceReferences(svcm, js, descriptor, locale, theme, lookAndFeel);
        }
    }

    fillRolesMap(js.roles);

    // Evaluate services
    for (String sid : privateSids) {
        ServiceDescriptor descriptor = svcm.getDescriptor(sid);
        //fillServiceReferences(svcm, js, descriptor, locale, theme, lookAndFeel);
        fillStartupForService(svcm, js, descriptor, locale);
    }
}

From source file:com.xpn.xwiki.XWiki.java

public static String getServerWikiPage(String servername) {
    return "XWiki.XWikiServer" + StringUtils.capitalize(servername);
}

From source file:com.sap.research.connectivity.gw.GWOperationsUtils.java

private String generateDBKeyFromODataKeys(Map<String[], String> keys, String tabs, String instanceMethod) {
    String returnString;/*from   w ww.ja v  a 2 s  .co m*/
    String keyBuilderString = "";
    String separator = "";
    for (Map.Entry<String[], String> key : keys.entrySet()) {
        String remoteFieldName = key.getKey()[0];
        String localFieldName = key.getKey()[1];
        keyBuilderString += separator + "\"" + remoteFieldName + "\", ";
        keyBuilderString += instanceMethod + "get" + StringUtils.capitalize(localFieldName) + "()";
        separator = ",";
    }

    returnString = tabs + "OEntityKey " + ODATA_KEY + " = OEntityKey.create(" + keyBuilderString + ");\n";
    return returnString;
}