Class TimeTransformer

  • All Implemented Interfaces:
    Transformer, Validator

    public class TimeTransformer
    extends DateTransformerBase

    A specialized transformer that transforms strings into date objects, taking only the time portion into account.

    Most of the required functionality is already implemented by the base class. This class only creates an appropriate DateFormat object that supports parsing time values.

    For the documentation of the supported properties refer to the super class. The error messaged produced by this class are analogous to the ones used by DateTransformerBase, but specific for time objects. So an application can display different error messages for invalid date and time inputs. The following table lists the possible error messages:

    Message key Description Parameters
    "ERR_INVALID_TIME" The passed in string cannot be parsed to a time object. {0} = the time string
    "ERR_TIME_AFTER" The entered time must be after the reference date. {0} = the (formatted) reference date
    "ERR_TIME_AFTER_EQUAL" The entered time must be after or equal the reference date. {0} = the (formatted) reference date
    "ERR_TIME_BEFORE" The entered time must be before the reference date. {0} = the (formatted) reference date
    "ERR_TIME_BEFORE_EQUAL" The entered time must be before or equal the reference date. {0} = the (formatted) reference date

    Version:
    $Id: TimeTransformer.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    See Also:
    ValidationMessageConstants
    • Constructor Detail

      • TimeTransformer

        public TimeTransformer()
    • Method Detail

      • createFormat

        protected DateFormat createFormat​(Locale locale,
                                          int style,
                                          org.apache.commons.configuration.Configuration config)
        Returns a format object for formatting and parsing time objects.
        Specified by:
        createFormat in class DateTransformerBase
        Parameters:
        locale - the locale
        style - the style to be used
        config - the configuration with the current properties
        Returns:
        the format object
      • errorResult

        protected ValidationResult errorResult​(String errorKey,
                                               TransformerContext ctx,
                                               Object... params)
        Returns a validation result object with an error message. This implementation transforms error messages for invalid dates to messages for invalid times.
        Overrides:
        errorResult in class DateTransformerBase
        Parameters:
        errorKey - the key of the error message
        ctx - the transformer context
        params - additional parameters
        Returns:
        the validation result object with the specified error message