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.auraframework.integration.test.ClientOutOfSyncUITest.java

/**
 * A routine to do _many_ iterations of a client out of sync test.
 *
 * This test really shouldn't be run unless one of the tests is flapping. It lets you iterate a number of times to
 * force a failure.... No guarantees, but without the _waitingForReload check in the trigger function, this will
 * cause a failure in very few iterations.
 *///from   www.  j ava 2  s.c  o  m
@ThreadHostileTest("NamespaceDef modification affects namespace")
@Test
@Ignore
public void testPostManyAfterStyleChange() throws Exception {
    DefDescriptor<ComponentDef> cmpDesc = setupTriggerComponent("", "<div id='out'>hi</div>");
    String className = cmpDesc.getNamespace() + StringUtils.capitalize(cmpDesc.getName());
    DefDescriptor<?> styleDesc = definitionService.getDefDescriptor(cmpDesc, DefDescriptor.CSS_PREFIX,
            StyleDef.class);
    addSourceAutoCleanup(styleDesc, String.format(".%s {font-style:italic;}", className));
    open(cmpDesc);
    assertEquals("italic",
            getAuraUITestingUtil().findDomElement(By.cssSelector("." + className)).getCssValue("font-style"));
    for (int i = 0; i < 1000; i++) {
        updateStringSource(styleDesc, String.format(".%s {font-style:normal;}", className));
        triggerServerAction();
        getAuraUITestingUtil().waitForElementFunction(By.cssSelector("." + className),
                new Function<WebElement, Boolean>() {
                    @Override
                    public Boolean apply(WebElement element) {
                        return "normal".equals(element.getCssValue("font-style"));
                    }
                });
        updateStringSource(styleDesc, String.format(".%s {font-style:italic;}", className));
        triggerServerAction();
        getAuraUITestingUtil().waitForElementFunction(By.cssSelector("." + className),
                new Function<WebElement, Boolean>() {
                    @Override
                    public Boolean apply(WebElement element) {
                        return "italic".equals(element.getCssValue("font-style"));
                    }
                });
    }
}

From source file:org.auraframework.integration.test.ClientOutOfSyncUITest.java

@ThreadHostileTest("NamespaceDef modification affects namespace")
@Test/* w  w w  . j  a v a 2  s .  c  om*/
public void testPostAfterTokensChange() throws Exception {
    DefDescriptor<ComponentDef> cmpDesc = setupTriggerComponent("", "<div id='out'>hi</div>");
    String className = cmpDesc.getNamespace() + StringUtils.capitalize(cmpDesc.getName());
    DefDescriptor<?> styleDesc = definitionService.getDefDescriptor(cmpDesc, DefDescriptor.CSS_PREFIX,
            StyleDef.class);
    addSourceAutoCleanup(styleDesc, String.format(".%s {font-size:t(fsize);}", className));
    DefDescriptor<?> tokensDesc = definitionService.getDefDescriptor(String.format("%s://%s:%sNamespace",
            DefDescriptor.MARKUP_PREFIX, cmpDesc.getNamespace(), cmpDesc.getNamespace()), TokensDef.class);
    addSourceAutoCleanup(tokensDesc, "<aura:tokens><aura:token name='fsize' value='8px'/></aura:tokens>");
    open(cmpDesc);
    assertEquals("8px",
            getAuraUITestingUtil().findDomElement(By.cssSelector("." + className)).getCssValue("font-size"));
    updateStringSource(tokensDesc, "<aura:tokens><aura:token name='fsize' value='66px'/></aura:tokens>");
    triggerServerAction();
    getAuraUITestingUtil().waitForElementFunction(By.cssSelector("." + className),
            new Function<WebElement, Boolean>() {
                @Override
                public Boolean apply(WebElement element) {
                    return "66px".equals(element.getCssValue("font-size"));
                }
            });
}

From source file:org.ballerinalang.openapi.model.BallerinaOpenApi.java

/**
 * Populate path models into iterable structure.
 * This method will also add an operationId to each operation,
 * if operationId not provided in openApi definition
 *
 * @param openAPI {@code OpenAPI} definition object with schema definition
 * @throws BallerinaOpenApiException when context building fails
 *///ww  w .j a  v  a2  s  .c o  m
private void setPaths(OpenAPI openAPI) throws BallerinaOpenApiException {
    if (openAPI.getPaths() == null) {
        return;
    }

    this.paths = new LinkedHashSet<>();
    Paths pathList = openAPI.getPaths();
    for (Map.Entry<String, PathItem> path : pathList.entrySet()) {
        BallerinaPath balPath = new BallerinaPath().buildContext(path.getValue(), openAPI);
        if (balPath.isNoOperationsForPath()) {
            balPath.setResourceName(path.getKey());
        } else {
            balPath.getOperations().forEach(operation -> {
                if (operation.getValue().getOperationId() == null) {
                    String pathName = path.getKey().substring(1); //need to drop '/' prefix from the key, ex:'/path'
                    String operationId = operation.getKey() + StringUtils.capitalize(pathName);
                    operation.getValue().setOperationId(CodegenUtils.normalizeForBIdentifier(operationId));
                }
            });
        }
        paths.add(new AbstractMap.SimpleEntry<>(path.getKey(), balPath));
    }
}

From source file:org.biokoframework.system.entity.EntityClassNameTranslator.java

public static String fromSplittedWithChar(String splittedName, String character) {
    String[] splits = splittedName.split(character);
    for (int i = 0; i < splits.length; i++) {
        splits[i] = StringUtils.capitalize(splits[i].toLowerCase());
    }/*w w w. ja  va  2s. co  m*/
    return StringUtils.join(splits);
}

From source file:org.biokoframework.system.entity.EntityClassNameTranslator.java

public static String fromFieldName(String fieldName) {
    return StringUtils.capitalize(fieldName);
}

From source file:org.blocks4j.reconf.client.constructors.SimpleConstructor.java

public Object construct(MethodData data) throws Throwable {
    Class<?> returnClass = (Class<?>) data.getReturnType();

    String trimmed = StringUtils.defaultString(StringUtils.trim(data.getValue()));
    if (!trimmed.startsWith("'") || !trimmed.endsWith("'")) {
        throw new RuntimeException(msg.format("error.invalid.string", data.getValue(), data.getMethod()));
    }//from   w ww .jav  a2  s .c  om

    String wholeValue = StringUtils.substring(trimmed, 1, trimmed.length() - 1);

    if (String.class.equals(returnClass)) {
        return wholeValue;
    }

    if (null == data.getValue()) {
        return null;
    }

    if (Object.class.equals(returnClass)) {
        returnClass = String.class;
    }

    if (char.class.equals(data.getReturnType()) || Character.class.equals(data.getReturnType())) {
        if (StringUtils.length(wholeValue) == 1) {
            return CharUtils.toChar(wholeValue);
        }
        return CharUtils.toChar(StringUtils.replace(wholeValue, " ", ""));
    }

    if (primitiveBoxing.containsKey(returnClass)) {
        if (StringUtils.isBlank(wholeValue)) {
            return null;
        }
        Method parser = primitiveBoxing.get(returnClass).getMethod(
                "parse" + StringUtils.capitalize(returnClass.getSimpleName()), new Class<?>[] { String.class });
        return parser.invoke(primitiveBoxing.get(returnClass), new Object[] { StringUtils.trim(wholeValue) });
    }

    Method valueOf = null;
    try {
        valueOf = returnClass.getMethod("valueOf", new Class<?>[] { String.class });
    } catch (NoSuchMethodException ignored) {
    }

    if (valueOf == null) {
        try {

            valueOf = returnClass.getMethod("valueOf", new Class<?>[] { Object.class });
        } catch (NoSuchMethodException ignored) {
        }
    }

    if (null != valueOf) {
        if (StringUtils.isEmpty(wholeValue)) {
            return null;
        }
        return valueOf.invoke(data.getReturnType(), new Object[] { StringUtils.trim(wholeValue) });
    }

    Constructor<?> constructor = null;

    try {
        constructor = returnClass.getConstructor(String.class);
        constructor.setAccessible(true);

    } catch (NoSuchMethodException ignored) {
        throw new IllegalStateException(
                msg.format("error.string.constructor", returnClass.getSimpleName(), data.getMethod()));
    }

    try {
        return constructor.newInstance(wholeValue);

    } catch (Exception e) {
        if (e.getCause() != null && e.getCause() instanceof NumberFormatException) {
            return constructor.newInstance(StringUtils.trim(wholeValue));
        }
        throw e;
    }
}

From source file:org.cloud.mblog.controller.exception.ResourceNotFoundException.java

@Override
public String getMessage() {
    return StringUtils.capitalize(resourceName) + " with id " + id + " is not found.";
}

From source file:org.craftercms.engine.navigation.impl.DefaultItemConverter.java

protected String getNavigationLabel(SiteItem siteItem) {
    String navLabel = siteItem.getItem().queryDescriptorValue(navLabelXPath);
    if (StringUtils.isEmpty(navLabel)) {
        navLabel = siteItem.getItem().queryDescriptorValue(internalNameXPath);
        if (StringUtils.isEmpty(navLabel)) {
            navLabel = FilenameUtils.removeExtension(siteItem.getStoreName());
            navLabel = StringUtils.replace(navLabel, "-", " ");
            navLabel = StringUtils.capitalize(navLabel);
        }/*from w w w  .ja va2s  .  com*/
    }

    return navLabel;
}

From source file:org.craftercms.engine.util.breadcrumb.BreadcrumbBuilder.java

public List<BreadcrumbItem> buildBreadcrumb(final String url) {
    final Context context = SiteContext.getCurrent().getContext();

    return cacheTemplate.getObject(context, new Callback<List<BreadcrumbItem>>() {

        @Override//from  ww w .  ja v a2s.co m
        public List<BreadcrumbItem> execute() {
            String indexFileName = SiteProperties.getIndexFileName();
            CachingAwareList<BreadcrumbItem> breadcrumb = new CachingAwareList<BreadcrumbItem>();
            String breadcrumbUrl = StringUtils.substringBeforeLast(StringUtils.substringAfter(url, homePath),
                    indexFileName);
            String[] breadcrumbUrlComponents = breadcrumbUrl.split("/");
            String currentUrl = homePath;

            for (String breadcrumbUrlComponent : breadcrumbUrlComponents) {
                if (StringUtils.isNotEmpty(breadcrumbUrlComponent)) {
                    currentUrl += "/" + breadcrumbUrlComponent;
                }

                Item item = storeService.getItem(context, UrlUtils.concat(currentUrl, indexFileName));
                if (item != null && item.getDescriptorDom() != null) {
                    String breadcrumbName = item.queryDescriptorValue(breadcrumbNameXPathQuery);
                    if (StringUtils.isEmpty(breadcrumbName)) {
                        if (StringUtils.isNotEmpty(breadcrumbUrlComponent)) {
                            breadcrumbName = StringUtils
                                    .capitalize(breadcrumbUrlComponent.replace("-", " ").replace(".xml", ""));
                        } else {
                            breadcrumbName = HOME_BREADCRUMB_NAME;
                        }
                    }

                    breadcrumb.add(new BreadcrumbItem(currentUrl, breadcrumbName));
                    breadcrumb.addDependencyKey(item.getKey());
                }
            }

            return breadcrumb;
        }

    }, url, BREADCRUMB_CONST_KEY_ELEM);
}

From source file:org.dbgl.util.searchengine.PouetSearchEngine.java

private static List<WebProfile> extractEntries(String html) {
    List<WebProfile> allEntries = new ArrayList<WebProfile>();
    html = html.replaceAll("\\\\\"", "\"");
    int gameMatchEntryIndex = html.indexOf(HTML_MULTIPLE_RESULT_MARKER_START);
    if (gameMatchEntryIndex != -1)
        gameMatchEntryIndex += HTML_MULTIPLE_RESULT_MARKER_START.length();

    while (gameMatchEntryIndex != -1) {

        String category = StringUtils
                .capitalize(extractNextContent(html, gameMatchEntryIndex, HTML_SPAN_OPEN, HTML_SPAN_CLOSE));

        int startPlatformIdx = html.indexOf("<span class='platformiconlist'>", gameMatchEntryIndex);
        int gameTitleIdx = html.indexOf("<span class='prod'>", gameMatchEntryIndex);

        String gameTitleData = extractNextContent(html, gameTitleIdx, HTML_ANCHOR_OPEN, HTML_ANCHOR_CLOSE);
        String gameTitle = StringUtils.capitalize(unescapeHtml(removeAllTags(gameTitleData)));
        String url = extractNextHrefContentSingleQuotes(html, gameTitleIdx);
        url = absoluteUrl(HOST_NAME, url);

        gameMatchEntryIndex = html.indexOf(HTML_TD_OPEN, gameMatchEntryIndex);

        String developerName = extractNextContent(html, gameMatchEntryIndex + HTML_TD_OPEN.length(),
                HTML_ANCHOR_OPEN, HTML_ANCHOR_CLOSE);
        developerName = StringUtils.capitalize(developerName);

        String year = StringUtils
                .right(extractNextContent(html, gameMatchEntryIndex, "<td class='date'>", HTML_TD_CLOSE), 4);

        int rank = 0;
        try {/*  w  w  w .j a v  a 2 s  .  c o  m*/
            String score = extractNextContent(html, gameMatchEntryIndex, "<td class='votes'>", "&nbsp;<img");
            rank = (int) ((Double.parseDouble(score) + 1.0) * 50.0);
        } catch (Exception e) {
        }

        String details = html.substring(startPlatformIdx, gameTitleIdx);
        int platformIdx = details.indexOf(HTML_PLATFORM_MARKER);

        while (platformIdx != -1) {
            String platform = extractNextContent(details, platformIdx, HTML_SPAN_OPEN, HTML_SPAN_CLOSE);

            WebProfile gameEntry = new WebProfile();
            gameEntry.setTitle(gameTitle);
            gameEntry.setUrl(url);
            gameEntry.setPlatform(platform);
            gameEntry.setPublisherName("");
            gameEntry.setDeveloperName(developerName);
            gameEntry.setYear(year);
            gameEntry.setGenre(category);
            gameEntry.setRank(rank);
            gameEntry.setNotes("");
            allEntries.add(gameEntry);

            platformIdx = details.indexOf(HTML_PLATFORM_MARKER, platformIdx + 1);
        }

        int endIdx = html.indexOf(HTML_GAME_END_MARKER, gameTitleIdx);
        gameMatchEntryIndex = html.indexOf(HTML_NEXT_RESULT_MARKER_START,
                endIdx + HTML_GAME_END_MARKER.length());
        if (gameMatchEntryIndex != -1)
            gameMatchEntryIndex += HTML_NEXT_RESULT_MARKER_START.length();
    }
    return allEntries;
}