Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## grails.util
[Java] Class GrailsNameUtils

    java.lang.Object
      grails.util.GrailsNameUtils

    public class GrailsNameUtils

Utility methods for converting between different name types, for example from class names -> property names and vice-versa. The key aspect of this class is that it has no dependencies outside the JDK!

Method Summary
`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.String name)` Shorter version of getPropertyNameRepresentation.
`static java.lang.String` | `getPropertyName(java.lang.Class clazz)` Shorter version of getPropertyNameRepresentation.
`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.

Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Method Detail

### getClassName

    public 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. For example "person" and "Controller" would evaluate to "PersonController"
  Parameters:
    `logicalName` - The logical name
    `trailingName` - The trailing name
  Returns:
    The class name

### getClassNameRepresentation

    public static java.lang.String getClassNameRepresentation(java.lang.String name)

  Returns the class name representation of the given name
  Parameters:
    `name` - The name to convert
  Returns:
    The property name representation

### getGetterName

    public static java.lang.String getGetterName(java.lang.String propertyName)

  Calculate the name for a getter method to retrieve the specified property
  Parameters:
    propertyName
  Returns:
    The name for the getter method for this property, if it were to exist, i.e. getConstraints

### getLogicalName

    public 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
  Parameters:
    `clazz` - The class
    `trailingName` - The trailing name such as "Controller" or "TagLib"
  Returns:
    The logical class name

### getLogicalName

    public static java.lang.String getLogicalName(java.lang.String name, java.lang.String trailingName)

  Retrieves the logical name of the class without the trailing name
  Parameters:
    `name` - The name of the class
    `trailingName` - The trailing name
  Returns:
    The logical name

### getLogicalPropertyName

    public static java.lang.String getLogicalPropertyName(java.lang.String className, java.lang.String trailingName)

### getNameFromScript

    public static java.lang.String getNameFromScript(java.lang.String scriptName)

  Calculates the class name from a script name in the form my-funk-grails-script.
  Parameters:
    `scriptName` - The script name
  Returns:
    A class name

### getNaturalName

    public static java.lang.String getNaturalName(java.lang.String name)

  Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')
  Parameters:
    `name` - The property name to convert
  Returns:
    The converted property name

### getPluginName

    public static java.lang.String getPluginName(java.lang.String descriptorName)

  Returns the name of a plugin given the name of the *GrailsPlugin.groovy descriptor file. For example, "DbUtilsGrailsPlugin.groovy" gives "db-utils".
  throws:
    IllegalArgumentException if the given descriptor name is not valid, i.e. if it doesn't end with "GrailsPlugin.groovy".
  Parameters:
    `descriptorName` - The simple name of the plugin descriptor.
  Returns:
    The plugin name for the descriptor, or `null` if descriptorName is `null`, or an empty string if descriptorName is an empty string.

### getPropertyName

    public static java.lang.String getPropertyName(java.lang.String name)

  Shorter version of getPropertyNameRepresentation.
  Parameters:
    `name` - The name to convert
  Returns:
    The property name version

### getPropertyName

    public static java.lang.String getPropertyName(java.lang.Class clazz)

  Shorter version of getPropertyNameRepresentation.
  Parameters:
    `clazz` - The clazz to convert
  Returns:
    The property name version

### getPropertyNameForLowerCaseHyphenSeparatedName

    public static java.lang.String getPropertyNameForLowerCaseHyphenSeparatedName(java.lang.String name)

  Converts foo-bar into fooBar.
  Parameters:
    `name` - The lower case hyphen separated name
  Returns:
    The property name equivalent

### getPropertyNameRepresentation

    public static java.lang.String getPropertyNameRepresentation(java.lang.Class targetClass)

  Returns the property name equivalent for the specified class.
  Parameters:
    `targetClass` - The class to get the property name for
  Returns:
    A property name reperesentation of the class name (eg. MyClass becomes myClass)

### getPropertyNameRepresentation

    public static java.lang.String getPropertyNameRepresentation(java.lang.String name)

  Returns the property name representation of the given name.
  Parameters:
    `name` - The name to convert
  Returns:
    The property name representation

### getScriptName

    public static java.lang.String getScriptName(java.lang.Class clazz)

  Retrieves the script name representation of the supplied class. For example MyFunkyGrailsScript would be my-funky-grails-script.
  Parameters:
    `clazz` - The class to convert
  Returns:
    The script name representation

### getScriptName

    public static java.lang.String getScriptName(java.lang.String name)

  Retrieves the script name representation of the given class name. For example MyFunkyGrailsScript would be my-funky-grails-script.
  Parameters:
    `name` - The class name to convert.
  Returns:
    The script name representation.

### getSetterName

    public static java.lang.String getSetterName(java.lang.String propertyName)

  Retrieves the name of a setter for the specified property name
  Parameters:
    `propertyName` - The property name
  Returns:
    The setter equivalent

### getShortName

    public static java.lang.String getShortName(java.lang.Class targetClass)

  Returns the class name without the package prefix.
  Parameters:
    `targetClass` - The class to get a short name for
  Returns:
    The short name of the class

### getShortName

    public static java.lang.String getShortName(java.lang.String className)

  Returns the class name without the package prefix.
  Parameters:
    `className` - The class name to get a short name for
  Returns:
    The short name of the class

### isBlank

    public 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.

  Parameters:
    `str` - The string to test.
  Returns:
    `true` if the string is `null`, or blank.

Groovy Documentation