freemarker.template.utility.StringUtil Java Examples

The following examples show how to use freemarker.template.utility.StringUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GherkinKeyword.java    From extentreports-java with Apache License 2.0 5 votes vote down vote up
public GherkinKeyword(String gk) throws ClassNotFoundException {
    GherkinDialect dialect = null;
    String apiKeyword = StringUtil.capitalize(gk.trim());
    String refPath = clazz.getPackage().getName();

    try {
        apiKeyword = apiKeyword.equals("*") ? Asterisk.class.getSimpleName() : apiKeyword;
        dialect = GherkinDialectManager.getDialect();
        if (dialect != null
                && !dialect.getLanguage().equalsIgnoreCase(GherkinDialectManager.getDefaultLanguage())) {
            apiKeyword = null;
            Map<String, List<String>> keywords = dialect.getKeywords();
            for (Entry<String, List<String>> key : keywords.entrySet()) {
                apiKeyword = key.getValue().stream()
                        .filter(x -> x.trim().equalsIgnoreCase(gk.trim()))
                        .findAny()
                        .map(x -> StringUtil.capitalize(x))
                        .orElse(null);
                if (apiKeyword != null) {
                    apiKeyword = StringUtil.capitalize(key.getKey());
                    break;
                }
            }
        }
        if (apiKeyword == null)
            throw new GherkinKeywordNotFoundException("Keyword cannot be found. " +
                    "You supplied: " + gk + " for dialect " + dialect + " which couldn't be mapped.");
        String clazzName = refPath + "." + apiKeyword.replace(" ", "");
        Class<?> c = Class.forName(clazzName);
        keyword = (IGherkinFormatterModel) c.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        logger.log(Level.SEVERE, "", e);
    }
}
 
Example #2
Source File: AssetNameConverter.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * Takes the existing value, and converts it to the requested type.
 *
 * @return
 */
@NotNull
public String getValue(@NotNull Type type) {
    String className = toClassName();
    switch (type) {
        case ACTIVITY:
            String activityName = TemplateUtils.extractClassName(className);
            if (activityName == null) {
                activityName = "Main";
            }
            return activityName + ACTIVITY_NAME_SUFFIX;

        case LAYOUT:
            // Convert CamelCase convention used in activity class names to underlined convention
            // used in layout names
            String layoutPrefix = getLayoutPrefixWithTrailingUnderscore();
            String layoutName = TemplateUtils.camelCaseToUnderlines(className);
            // We are going to add layoutNamePrefix to the result, so make sure we don't have that string already.
            layoutName = StringUtil.replace(layoutName, layoutPrefix, "", false, true);
            return layoutPrefix + layoutName;

        case RESOURCE:
            // Convert CamelCase convention used in activity class names to underlined convention
            // used in resource names
            return TemplateUtils.camelCaseToUnderlines(className);

        case CLASS_NAME:
            return className;

        default:
            throw new InvalidParameterException("Unhandled type: " + type);
    }
}
 
Example #3
Source File: ExecuteApiResource.java    From freemarker-online-tester with Apache License 2.0 5 votes vote down vote up
private <T> T parseChoiceField(ExecuteRequest.Field name, String rawValue, T defaultValue,
		Map<String, ? extends T> rawToParsedMap, List<ExecuteResponseProblem> problems) {
    if (StringUtils.isBlank(rawValue)) {
        return defaultValue;
    }
    
    T parsedValue = rawToParsedMap.get(rawValue);
    if (parsedValue == null) {
        problems.add(new ExecuteResponseProblem(name,
        		formatMessage("Invalid value for \"{0}\": {1}", name, StringUtil.jQuote(rawValue))));
    }
    return parsedValue;
}