public class GrailsNameUtils
extends java.lang.Object
| Constructor and Description |
|---|
GrailsNameUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
getClassName(java.lang.String logicalName)
Return the class name for the given logical name.
|
static java.lang.String |
getClassName(java.lang.String logicalName,
java.lang.String trailingName)
Returns the class name for the given logical name and trailing name.
|
static java.lang.String |
getClassNameRepresentation(java.lang.String name)
Returns the class name representation of the given name
|
static java.lang.String |
getGetterName(java.lang.String propertyName)
Calculate the name for a getter method to retrieve the specified property
|
static java.lang.String |
getLogicalName(java.lang.Class<?> clazz,
java.lang.String trailingName)
Retrieves the logical class name of a Grails artifact given the Grails class
and a specified trailing name.
|
static java.lang.String |
getLogicalName(java.lang.String name,
java.lang.String trailingName)
Retrieves the logical name of the class without the trailing name
|
static java.lang.String |
getLogicalPropertyName(java.lang.String className,
java.lang.String trailingName) |
static java.lang.String |
getNameFromScript(java.lang.String scriptName)
Calculates the class name from a script name in the form my-funk-grails-script.
|
static java.lang.String |
getNaturalName(java.lang.String name)
Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')
|
static java.lang.String |
getPluginName(java.lang.String descriptorName)
Returns the name of a plugin given the name of the *GrailsPlugin.groovy
descriptor file.
|
static java.lang.String |
getPropertyName(java.lang.Class<?> clazz)
Shorter version of getPropertyNameRepresentation.
|
static java.lang.String |
getPropertyName(java.lang.String name)
Shorter version of getPropertyNameRepresentation.
|
static java.lang.String |
getPropertyNameConvention(java.lang.Object object)
Returns an appropriate property name for the given object.
|
static java.lang.String |
getPropertyNameConvention(java.lang.Object object,
java.lang.String suffix)
Returns an appropriate property name for the given object.
|
static java.lang.String |
getPropertyNameForLowerCaseHyphenSeparatedName(java.lang.String name)
Converts foo-bar into fooBar.
|
static java.lang.String |
getPropertyNameRepresentation(java.lang.Class<?> targetClass)
Returns the property name equivalent for the specified class.
|
static java.lang.String |
getPropertyNameRepresentation(java.lang.String name)
Returns the property name representation of the given name.
|
static java.lang.String |
getScriptName(java.lang.Class<?> clazz)
Retrieves the script name representation of the supplied class.
|
static java.lang.String |
getScriptName(java.lang.String name)
Retrieves the script name representation of the given class name.
|
static java.lang.String |
getSetterName(java.lang.String propertyName)
Retrieves the name of a setter for the specified property name
|
static java.lang.String |
getShortName(java.lang.Class<?> targetClass)
Returns the class name without the package prefix.
|
static java.lang.String |
getShortName(java.lang.String className)
Returns the class name without the package prefix.
|
static boolean |
isBlank(java.lang.String str)
Determines whether a given string is
null, empty,
or only contains whitespace. |
public static java.lang.String getSetterName(java.lang.String propertyName)
propertyName - The property namepublic static java.lang.String getGetterName(java.lang.String propertyName)
propertyName - public static java.lang.String getClassName(java.lang.String logicalName,
java.lang.String trailingName)
logicalName - The logical nametrailingName - The trailing namepublic static java.lang.String getClassName(java.lang.String logicalName)
logicalName - The logical namepublic static java.lang.String getClassNameRepresentation(java.lang.String name)
name - The name to convertpublic static java.lang.String getLogicalName(java.lang.Class<?> clazz,
java.lang.String trailingName)
clazz - The classtrailingName - The trailing name such as "Controller" or "TagLib"public static java.lang.String getLogicalName(java.lang.String name,
java.lang.String trailingName)
name - The name of the classtrailingName - The trailing namepublic static java.lang.String getLogicalPropertyName(java.lang.String className,
java.lang.String trailingName)
public static java.lang.String getPropertyName(java.lang.String name)
name - The name to convertpublic static java.lang.String getPropertyName(java.lang.Class<?> clazz)
clazz - The clazz to convertpublic static java.lang.String getPropertyNameRepresentation(java.lang.Class<?> targetClass)
targetClass - The class to get the property name forpublic static java.lang.String getPropertyNameRepresentation(java.lang.String name)
name - The name to convertpublic static java.lang.String getPropertyNameForLowerCaseHyphenSeparatedName(java.lang.String name)
name - The lower case hyphen separated namepublic static java.lang.String getShortName(java.lang.Class<?> targetClass)
targetClass - The class to get a short name forpublic static java.lang.String getShortName(java.lang.String className)
className - The class name to get a short name forpublic static java.lang.String getScriptName(java.lang.Class<?> clazz)
clazz - The class to convertpublic static java.lang.String getScriptName(java.lang.String name)
name - The class name to convert.public static java.lang.String getNameFromScript(java.lang.String scriptName)
scriptName - The script namepublic static java.lang.String getPluginName(java.lang.String descriptorName)
descriptorName - The simple name of the plugin descriptor.null
if descriptorName is null, or an empty string
if descriptorName is an empty string.java.lang.IllegalArgumentException - if the given descriptor name is
not valid, i.e. if it doesn't end with "GrailsPlugin.groovy".public static java.lang.String getNaturalName(java.lang.String name)
name - The property name to convertpublic static boolean isBlank(java.lang.String str)
Determines whether a given string is null, empty,
or only contains whitespace. If it contains anything other than
whitespace then the string is not considered to be blank and the
method returns false.
We could use Commons Lang for this, but we don't want GrailsNameUtils to have a dependency on any external library to minimise the number of dependencies required to bootstrap Grails.
str - The string to test.true if the string is null, or
blank.public static java.lang.String getPropertyNameConvention(java.lang.Object object)
object - The objectpublic static java.lang.String getPropertyNameConvention(java.lang.Object object,
java.lang.String suffix)
object - The objectsuffix - The suffix to append to the name.