Java Code Examples for org.springframework.util.StringUtils.capitalize()

The following are Jave code examples for showing how to use capitalize() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: edoras-one-initializr   File: InitializrConfiguration.java   Source Code and License Vote up 6 votes
/**
 * Generate a suitable application name based on the specified name. If no suitable
 * application name can be generated from the specified {@code name}, the
 * {@link Env#fallbackApplicationName} is used instead.
 * <p>
 * No suitable application name can be generated if the name is {@code null} or if it
 * contains an invalid character for a class identifier.
 * @see Env#fallbackApplicationName
 * @see Env#invalidApplicationNames
 */
public String generateApplicationName(String name) {
	if (!StringUtils.hasText(name)) {
		return env.fallbackApplicationName;
	}
	String text = splitCamelCase(name.trim());
	// TODO: fix this
	String result = unsplitWords(text);
	if (!result.endsWith("Application")) {
		result = result + "Application";
	}
	String candidate = StringUtils.capitalize(result);
	if (hasInvalidChar(candidate)
			|| env.invalidApplicationNames.contains(candidate)) {
		return env.fallbackApplicationName;
	}
	else {
		return candidate;
	}
}
 
Example 2
Project: emergentmud   File: Emote.java   Source Code and License Vote up 6 votes
public String replaceVariables(String message, Entity self, Entity target) {
    if (message == null) {
        return null;
    }

    if (self.equals(target)) {
        message = message.replace("%self%", self.getName());
        message = message.replace("%target%", target.getName());
    } else {
        message = message.replace("%self%", self.getName());
        message = message.replace("%target%", (target == null ? "NULL" : target.getName()));
    }

    message = message.replace("%him%", "him");
    message = message.replace("%selfpos%", self.getName() + "'s");
    message = message.replace("%targetpos%", (target == null ? "NULL" : target.getName()) + "'s");
    message = message.replace("%his%", "his");
    message = message.replace("%he%", "he");
    message = message.replace("%himself%", "himself");
    message = message.replace("%hispos%", "his");

    return StringUtils.capitalize(message);
}
 
Example 3
Project: lams   File: ReflectivePropertyAccessor.java   Source Code and License Vote up 6 votes
@Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
	if (target == null) {
		return false;
	}
	Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());
	if (type.isArray()) {
		return false;
	}
	if (this.member instanceof Method) {
		Method method = (Method) this.member;
		String getterName = "get" + StringUtils.capitalize(name);
		if (getterName.equals(method.getName())) {
			return true;
		}
		getterName = "is" + StringUtils.capitalize(name);
		return getterName.equals(method.getName());
	}
	else {
		Field field = (Field) this.member;
		return field.getName().equals(name);
	}
}
 
Example 4
Project: edoras-one-initializr   File: VersionProperty.java   Source Code and License Vote up 5 votes
/**
 * Return a camel cased representation of this instance.
 */
public String toCamelCaseFormat() {
	String[] tokens = this.property.split("\\-|\\.");
	StringBuilder sb = new StringBuilder();
	for (int i  = 0; i < tokens.length; i++) {
		String part = tokens[i];
		if (i > 0) {
			part = StringUtils.capitalize(part);
		}
		sb.append(part);
	}
	return sb.toString();
}
 
Example 5
Project: kettle_support_kettle8.0   File: Reflection.java   Source Code and License Vote up 5 votes
/**
 * 调用Setter方法.
 * 
 * @param propertyType
 *            用于查找Setter方法,为空时使用value的Class替代.
 */
public static void invokeSetter(Object obj, String propertyName,
		Object value, Class<?> propertyType) {
	Class<?> type = propertyType != null ? propertyType : value.getClass();
	String setterMethodName = "set" + StringUtils.capitalize(propertyName);
	invokeMethod(obj, setterMethodName, new Class[] { type },
			new Object[] { value });
}
 
Example 6
Project: JRediClients   File: RedissonMultiLockDefinitionParser.java   Source Code and License Vote up 5 votes
@Override
protected String getBeanClassName(Element element) {
    String elementName
            = Conventions.attributeNameToPropertyName(
                    element.getLocalName());
    return RedissonNamespaceParserSupport.IMPL_CLASS_PATH_PREFIX
            + StringUtils.capitalize(elementName);
}
 
Example 7
Project: ARCLib   File: Gatherer.java   Source Code and License Vote up 5 votes
private AnnotatedMethod findSetter(BeanDescription beanDesc,
                                   BeanPropertyWriter writer) {
    String name = "set" + StringUtils.capitalize(writer.getName());
    Class<?> type = writer.getPropertyType();
    AnnotatedMethod setter = beanDesc.findMethod(name, new Class<?>[] { type });
    // The enabled property of endpoints returns a boolean primitive but is set
    // using a Boolean class
    if (setter == null && type.equals(Boolean.TYPE)) {
        setter = beanDesc.findMethod(name, new Class<?>[] { Boolean.class });
    }
    return setter;
}
 
Example 8
Project: lams   File: ReflectivePropertyAccessor.java   Source Code and License Vote up 5 votes
/**
 * Return the method suffixes for a given property name. The default implementation
 * uses JavaBean conventions with additional support for properties of the form 'xY'
 * where the method 'getXY()' is used in preference to the JavaBean convention of
 * 'getxY()'.
 */
protected String[] getPropertyMethodSuffixes(String propertyName) {
	String suffix = getPropertyMethodSuffix(propertyName);
	if (suffix.length() > 0 && Character.isUpperCase(suffix.charAt(0))) {
		return new String[] { suffix };
	}
	return new String[] { suffix, StringUtils.capitalize(suffix) };
}
 
Example 9
Project: lams   File: ReflectivePropertyAccessor.java   Source Code and License Vote up 5 votes
/**
 * Return the method suffix for a given property name. The default implementation
 * uses JavaBean conventions.
 */
protected String getPropertyMethodSuffix(String propertyName) {
	if (propertyName.length() > 1 && Character.isUpperCase(propertyName.charAt(1))) {
		return propertyName;
	}
	return StringUtils.capitalize(propertyName);
}
 
Example 10
Project: kettle_support_kettle8.0   File: Reflection.java   Source Code and License Vote up 4 votes
/**
 * 调用Getter方法.
 */
public static Object invokeGetter(Object obj, String propertyName) {
	String getterMethodName = "get" + StringUtils.capitalize(propertyName);
	return invokeMethod(obj, getterMethodName, new Class[] {},
			new Object[] {});
}
 
Example 11
Project: xm-commons   File: XmExtensionService.java   Source Code and License Vote up 4 votes
/**
 * Return composite resource key for specified extension key.
 * If extension has no resource or extension with specified key doesn't exist the method
 * returns {@code null}.
 *
 * @param extensionKey             the extension key
 * @param extensionResourceVersion ignored in current implementation
 * @return composite resource key or {@code null} if not found
 */
@Override
public LepResourceKey getResourceKey(LepKey extensionKey, Version extensionResourceVersion) {
    if (extensionKey == null) {
        return null;
    }

    LepKey groupKey = extensionKey.getGroupKey();
    String extensionKeyId = extensionKey.getId();
    String extensionName;
    String[] groupSegments;
    if (groupKey == null) {
        groupSegments = EMPTY_GROUP_SEGMENTS;
        extensionName = extensionKeyId;
    } else {
        groupSegments = groupKey.getId().split(EXTENSION_KEY_SEPARATOR_REGEXP);

        // remove group from id
        extensionName = extensionKeyId.replace(groupKey.getId(), "");
        if (extensionName.startsWith(XmLepConstants.EXTENSION_KEY_SEPARATOR)) {
            extensionName = extensionName.substring(XmLepConstants.EXTENSION_KEY_SEPARATOR.length());
        }
    }

    // change script name: capitalize first character & add script type extension
    String scriptName = extensionName.replaceAll(EXTENSION_KEY_SEPARATOR_REGEXP, SCRIPT_NAME_SEPARATOR_REGEXP);
    scriptName = StringUtils.capitalize(scriptName);

    String urlPath = URL_DELIMITER;
    if (groupSegments.length > 0) {
        urlPath += String.join(URL_DELIMITER, groupSegments) + URL_DELIMITER;
    }
    urlPath += scriptName + SCRIPT_EXTENSION_SEPARATOR + SCRIPT_EXTENSION_GROOVY;

    // TODO if possible add check that returned resourceKey contains resources (for speed up executor reaction)
    // Check example : return isResourceExists(resourceKey) ? resourceKey : null;
    UrlLepResourceKey urlLepResourceKey = UrlLepResourceKey.valueOfUrlResourcePath(urlPath);

    if (extensionResourceVersion == null) {
        log.debug("LEP extension key: '{}' translated to --> composite resource key: '{}'", extensionKey, urlLepResourceKey);
    } else {
        log.debug("LEP extension 'key: {}, v{}' translated to --> composite resource key: '{}'", extensionKey,
                  extensionResourceVersion, urlLepResourceKey);
    }
    return urlLepResourceKey;
}
 
Example 12
Project: xm-ms-entity   File: XmExtensionService.java   Source Code and License Vote up 4 votes
/**
 * Return composite resource key for specified extension key.
 * If extension has no resource or extension with specified key doesn't exist the method
 * returns {@code null}.
 *
 * @param extensionKey             the extension key
 * @param extensionResourceVersion ignored in current implementation
 * @return composite resource key or {@code null} if not found
 */
@Override
public LepResourceKey getResourceKey(LepKey extensionKey, Version extensionResourceVersion) {
    if (extensionKey == null) {
        return null;
    }

    LepKey groupKey = extensionKey.getGroupKey();
    String extensionKeyId = extensionKey.getId();
    String extensionName;
    String[] groupSegments;
    if (groupKey == null) {
        groupSegments = EMPTY_GROUP_SEGMENTS;
        extensionName = extensionKeyId;
    } else {
        groupSegments = groupKey.getId().split(EXTENSION_KEY_SEPARATOR_REGEXP);

        // remove group from id
        extensionName = extensionKeyId.replace(groupKey.getId(), "");
        if (extensionName.startsWith(EXTENSION_KEY_SEPARATOR)) {
            extensionName = extensionName.substring(EXTENSION_KEY_SEPARATOR.length());
        }
    }

    // change script name: capitalize first character & add script type extension
    String scriptName = extensionName.replaceAll(EXTENSION_KEY_SEPARATOR_REGEXP, SCRIPT_NAME_SEPARATOR_REGEXP);
    scriptName = StringUtils.capitalize(scriptName);

    String urlPath = URL_DELIMITER;
    if (groupSegments.length > 0) {
        urlPath += String.join(URL_DELIMITER, groupSegments) + URL_DELIMITER;
    }
    urlPath += scriptName + SCRIPT_EXTENSION_SEPARATOR + XmLepConstants.SCRIPT_EXTENSION_GROOVY;


    // TODO if possible add check that returned resourceKey contains resources (for speed up executor reaction)
    // Check example : return isResourceExists(resourceKey) ? resourceKey : null;
    UrlLepResourceKey urlLepResourceKey = UrlLepResourceKey.valueOfUrlResourcePath(urlPath);

    if (extensionResourceVersion == null) {
        log.debug("LEP extension key: '{}' translated to --> composite resource key: '{}'", extensionKey, urlLepResourceKey);
    } else {
        log.debug("LEP extension 'key: {}, v{}' translated to --> composite resource key: '{}'", extensionKey,
                  extensionResourceVersion, urlLepResourceKey);
    }
    return urlLepResourceKey;
}
 
Example 13
Project: spring-cloud-dashboard   File: QualifiedApplicationNameConverter.java   Source Code and License Vote up 4 votes
private String pretty(String type) {
	return StringUtils.capitalize(type) + "s";
}
 
Example 14
Project: lams   File: JmxUtils.java   Source Code and License Vote up 3 votes
/**
 * Return the JMX attribute name to use for the given JavaBeans property.
 * <p>When using strict casing, a JavaBean property with a getter method
 * such as {@code getFoo()} translates to an attribute called
 * {@code Foo}. With strict casing disabled, {@code getFoo()}
 * would translate to just {@code foo}.
 * @param property the JavaBeans property descriptor
 * @param useStrictCasing whether to use strict casing
 * @return the JMX attribute name to use
 */
public static String getAttributeName(PropertyDescriptor property, boolean useStrictCasing) {
	if (useStrictCasing) {
		return StringUtils.capitalize(property.getName());
	}
	else {
		return property.getName();
	}
}