com.causecode.converters.FormattedStringValueConverter.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nucleus Show documentation
Show all versions of nucleus Show documentation
nucleus is a Grails-Groovy plugin which contains utility methods, classes and endpoints.
package com.causecode.converters
import grails.databinding.converters.FormattedValueConverter
/**
* A convertor class used to provide String binding according to specified format in domain.
*
* @BindingFormat("LOWERCASE")
* String email
*
*
* @author Priyanshu Chauhan
* @since 0.3.3
*/
class FormattedStringValueConverter implements FormattedValueConverter {
/**
* Field to Specify the type to which this converter may be applied.
*/
final Class targetType = String
/**
* A generic method to convert incoming data to either lower case or upper case.
* @param value String whose value is to be converted to lower case.
* @param format String the required conversion format.
* @return String converted format.
*/
Object convert(Object value, String format) {
Object tempValue = value
if (!tempValue) {
return null
}
if (format == 'LOWERCASE') {
tempValue = value.toLowerCase()
} else {
if (format == 'UPPERCASE') {
tempValue = value.toUpperCase()
}
}
return tempValue
}
}