| java.lang.Object org.kuali.core.web.format.Formatter
All known Subclasses: org.kuali.core.web.format.PhoneNumberFormatter, org.kuali.core.web.format.BooleanFormatter, org.kuali.core.web.format.LittleBooleanFormatter, org.kuali.core.web.format.TimestampAMPMFormatter, org.kuali.core.web.format.NoOpStringFormatter, org.kuali.module.financial.web.struts.form.CashReceiptDepositTypeFormatter, org.kuali.core.web.format.LongFormatter, org.kuali.core.web.format.BigDecimalFormatter, org.kuali.core.web.format.TypeFormatter, org.kuali.core.web.format.CollectionFormatter, org.kuali.core.web.format.SimpleBooleanFormatter, org.kuali.core.web.format.SummarizableFormatter, org.kuali.core.web.format.DateFormatter, org.kuali.module.financial.web.struts.form.CashDrawerStatusCodeFormatter, org.kuali.core.web.format.PercentageFormatter, org.kuali.core.web.format.CurrencyFormatter, org.kuali.core.web.format.IntegerFormatter, org.kuali.core.web.format.EncryptionFormatter,
Formatter | public class Formatter implements Serializable(Code) | | It provides default formatting and conversion behavior for most value types, including primitives, arrays, and instances of most
Collection types. Formatter and its subclasses were designed primarily to be used by web app framework
components, though they can also be used in other contexts.
During request processing, the
PojoActionForm uses Formatter instances to convert inbound request values
to JavaBean property types. Whenever a given value cannot be converted to its target type, the conversion method
PojoPropertyUtilsBean.getProperty(ObjectString) throws a
FormatException to signal this condition to the
calling code.
During the response phase, Struts tags make calls to the
PojoRequestProcessor in order to access bean property values.
The PojoRequestProcessor then uses Formatter instances to format the bean values for presentation
in the user interface.
In either case, Formatter instances are obtained by calling
Formatter.getFormatter(Class) , which looks in an
internal registry to determine which Formatter class to instantiate, and returns a new instance. The StrutsLive
framework includes a number of Formatter classes that are registered statically; additional
Formatter classes can be registered at compile
time or at run time.
Subclasses of Formatter typically override the callback methods
Formatter.convertToObject(String) and
Formatter.formatObject(Object) , which
otherwise provide default conversion and formmating behavior needed for
atomic values (i.e., an ordinary bean property such as a String
or Integer , or else an element of a property typed as
array or Collection).
See Also: PojoActionForm.populate(HttpServletRequest) See Also: PojoPropertyUtilsBean.getProperty(ObjectString) |
convertFromPresentationFormat | public Object convertFromPresentationFormat(Object value)(Code) | | Returns an object representation of the provided string after first removing any extraneous formatting characters. If the
argument is a native array wrapping the actual value, the value is removed (unwrapped) from the array prior to invoking the
callback method
Formatter.convertToObject(String) , which performs the actual conversion.
If the provided object is null , a blank String , or a String[] of length 0
or that has null or a blank String in the first position, returns null .
Otherwise, If the destination property is a Collection , returns an instance of that type containing the
string values of the array elements.
If the provided object is an array, uses a Formatter corresponding to the array's component type to convert each of its
elements, and returns a new array containing the converted values.
May be overidden by subclasses to customize conversion, though ordinarily
Formatter.convertToObject(String) is a better choice
since it takes advantage of convertFromPresentationFormat 's built-in behavior.
Parameters: value - the string value to be converted the object value corresponding to the provided string value See Also: convertToObject(String) |
convertToCollection | protected Collection convertToCollection(String[] strings)(Code) | | Converts an array of strings to a Collection type corresponding to the value of propertyType . Since we don't
have type information for the elements of the collection, no attempt is made to convert the elements from String
to other types. However, subclasses can override this method if they need to provide the ability to convert the elements to a
given type.
|
convertToObject | protected Object convertToObject(String string)(Code) | | May be orverridden by subclasses to customize its behavior. The default implementation simply trims and returns the provided
string.
|
formatBean | protected Object formatBean(Object bean)(Code) | | If an element of the Collection isn't a supported type, assume it's a JavaBean, and format each of its properties. Returns a
Map containing the formatted properties keyed by property name.
|
formatForPresentation | public Object formatForPresentation(Object value)(Code) | | begin Kuali Foundation modification
Returns a String representation of the given value. May be overridden by subclasses to provide customized behavior for
different types, though generally the callback method
Formatter.format(Object) provides a better customization hook.
Provides default handling for properties typed as array or Collection. Subclass implementations of this method must invoke
super.formatForPresentation() to take advantage of this built-in behavior.
Delegates to callback method
formatObject for all other types. This method in turn invokes the callback method
format , which serves as an extension point for subclasses; the default implementation simply returns its
argument. Overriding format allows subclasses to take advantage of all of the array, primitive type, and
Collection handling functionality provided by the base class.
Parameters: value - the object to be formatted a formatted string representation of the given object See Also: Formatter.formatObject(Object) See Also: end Kuali Foundation modification |
formatNull | protected Object formatNull()(Code) | | May be overridden by subclasses to provide special handling for null values when formatting a bean property
value for presentation. The default implementation simply returns null
|
formatObject | public Object formatObject(Object value)(Code) | | May be overridden by subclasses to provide custom formatting behavior. Provides default formatting implementation for
primitive types. (Note that primitive types are will always be wrapped in an array in order to be passed as an argument of
type Object ).
|
formatterForType | public static Class formatterForType(Class type)(Code) | | Return the Formatter associated with the given type, by consulting an internal registry. Additional associations can be made
by calling
registerFormatter(Class, Class) .
a new Formatter instance |
getFormatter | public static Formatter getFormatter(Class aType, Map settings)(Code) | | Returns an instance of the Formatter class to be used to format the provided value type.
Parameters: type - the class of the value to be formatted Parameters: settings - parameters used by subclasses to customize behavior an instance of Formatter or one of its subclasses |
getImplementationClass | public String getImplementationClass()(Code) | | |
getNullObjectValue | protected Object getNullObjectValue()(Code) | | May be overridden by subclasses to provide special handling for null values when converting from presentation
format to a bean property type. The default implementation simply returns null
|
isBlank | protected boolean isBlank(String string)(Code) | | StringUtils.isEmptyString(String) |
isEmptyValue | public static boolean isEmptyValue(Object obj)(Code) | | |
isNullValue | public static boolean isNullValue(Object obj)(Code) | | |
isSupportedType | public static boolean isSupportedType(Class type)(Code) | | Returns true if the provided class is an array type, implements either the
List or
Set interfaces, or is one of the Formatter classes currently registered.
See Also: registerFormatter(Class, Class) |
registerFormatter | public static void registerFormatter(Class type, Class formatterType)(Code) | | Binds the provided value type to a Formatter type. Note that a single Formatter class can be associated with more than one
type.
Parameters: type - a value type Parameters: formatterType - a Formatter type |
setPropertyType | public void setPropertyType(Class propertyType)(Code) | | |
setSettings | public void setSettings(Map settings)(Code) | | |
|
|