com.opensymphony.xwork2.validator

## Class DelegatingValidatorContext

- java.lang.Object
- - com.opensymphony.xwork2.validator.DelegatingValidatorContext

- All Implemented Interfaces:
    ValidationAware, LocaleProvider, TextProvider, ValidatorContext
  Direct Known Subclasses:
    VisitorFieldValidator.AppendingValidatorContext

      public class DelegatingValidatorContext
      extends Object
      implements ValidatorContext

  A default implementation of the `ValidatorContext` interface.
  Author:
    Jason Carreira, Rainer Hermanns

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DelegatingValidatorContext(Class clazz)` Deprecated. will be removed, do not use!
    `DelegatingValidatorContext(Object object, TextProviderFactory textProviderFactory)` Creates a new validation context given an object - usually an Action.
    `DelegatingValidatorContext(ValidationAware validationAware, TextProvider textProvider, LocaleProvider localeProvider)` Creates a new validation context given a ValidationAware object, and a text and locale provider.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addActionError(String anErrorMessage)` Add an Action-level error message to this Action.
    `void` | `addActionMessage(String aMessage)` Add an Action-level message to this Action.
    `void` | `addFieldError(String fieldName, String errorMessage)` Add an error message for a given field.
    `Collection<String>` | `getActionErrors()` Get the Collection of Action-level error messages for this action.
    `Collection<String>` | `getActionMessages()` Get the Collection of Action-level messages for this action.
    `Map<String,List<String>>` | `getFieldErrors()` Get the field specific errors associated with this action.
    `String` | `getFullFieldName(String fieldName)` Translates a simple field name into a full field name in OGNL syntax.
    `Locale` | `getLocale()` Gets the provided locale.
    `String` | `getText(String aTextName)` Gets a message based on a message key or if no message is found the provided key is returned.
    `String` | `getText(String aTextName, List<?> args)` Gets a message based on a key using the supplied args, as defined in `MessageFormat` or the provided key if no message is found.
    `String` | `getText(String aTextName, String defaultValue)` Gets a message based on a key, or, if the message is not found, a supplied default value is returned.
    `String` | `getText(String key, String[] args)` Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or the provided key if no message is found.
    `String` | `getText(String aTextName, String defaultValue, List<?> args)` Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
    `String` | `getText(String key, String defaultValue, List<?> args, ValueStack stack)` Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
    `String` | `getText(String aTextName, String defaultValue, String obj)` Gets a message based on a key using the supplied obj, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
    `String` | `getText(String key, String defaultValue, String[] args)` Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
    `String` | `getText(String key, String defaultValue, String[] args, ValueStack stack)` Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
    `protected TextProvider` | `getTextProvider()`
    `ResourceBundle` | `getTexts()` Get the resource bundle associated with the implementing class (usually an action).
    `ResourceBundle` | `getTexts(String aBundleName)` Get the named bundle, such as "com/acme/Foo".
    `protected ValidationAware` | `getValidationAware()`
    `boolean` | `hasActionErrors()` Check whether there are any Action-level error messages.
    `boolean` | `hasActionMessages()` Checks whether there are any Action-level messages.
    `boolean` | `hasErrors()` Checks whether there are any action errors or field errors.
    `boolean` | `hasFieldErrors()` Check whether there are any field errors associated with this action.
    `boolean` | `hasKey(String key)` Checks if a message key exists.
    `boolean` | `isValidLocale(Locale locale)` Validates if provided `Locale` is value
    `boolean` | `isValidLocaleString(String localeStr)` Validates if provided string is a valid `Locale`
    `protected static LocaleProvider` | `makeLocaleProvider(Object object)`
    `TextProvider` | `makeTextProvider(Object object, TextProviderFactory textProviderFactory)`
    `protected static ValidationAware` | `makeValidationAware(Object object)`
    `void` | `setActionErrors(Collection<String> errorMessages)` Set the Collection of Action-level String error messages.
    `void` | `setActionMessages(Collection<String> messages)` Set the Collection of Action-level String messages (not errors).
    `void` | `setFieldErrors(Map<String,List<String>> errorMap)` Set the field error map of fieldname (String) to Collection of String error messages.
    `protected void` | `setTextProvider(TextProvider textProvider)`
    `protected void` | `setValidationAware(ValidationAware validationAware)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DelegatingValidatorContext

          public DelegatingValidatorContext(ValidationAware validationAware,
                                    TextProvider textProvider,
                                    LocaleProvider localeProvider)

      Creates a new validation context given a ValidationAware object, and a text and locale provider. These objects are used internally to set errors and get and set error text.
      Parameters:
        `validationAware` - a validation aware object
        `textProvider` - a text provider
        `localeProvider` - a local provider

    - #### DelegatingValidatorContext

          public DelegatingValidatorContext(Object object,
                                    TextProviderFactory textProviderFactory)

      Creates a new validation context given an object - usually an Action. The internal objects (validation aware instance and a locale and text provider) are created based on the given action.
      Parameters:
        `object` - the object to use for validation (usually an Action).

    - #### DelegatingValidatorContext

          @Deprecated
          public DelegatingValidatorContext(Class clazz)

      Deprecated. will be removed, do not use!
      Create a new validation context given a Class definition. The locale provider, text provider and the validation context are created based on the class.
      Parameters:
        `clazz` - the class to initialize the context with.

  - ### Method Detail

    - #### setActionErrors

          public void setActionErrors(Collection<String> errorMessages)

      Description copied from interface: `ValidationAware`
      Set the Collection of Action-level String error messages.
      Specified by:
        `setActionErrors` in interface `ValidationAware`
      Parameters:
        `errorMessages` - Collection of String error messages

    - #### getActionErrors

          public Collection<String> getActionErrors()

      Description copied from interface: `ValidationAware`
      Get the Collection of Action-level error messages for this action. Error messages should not be added directly here, as implementations are free to return a new Collection or an Unmodifiable Collection.
      Specified by:
        `getActionErrors` in interface `ValidationAware`
      Returns:
        Collection of String error messages

    - #### setActionMessages

          public void setActionMessages(Collection<String> messages)

      Description copied from interface: `ValidationAware`
      Set the Collection of Action-level String messages (not errors).
      Specified by:
        `setActionMessages` in interface `ValidationAware`
      Parameters:
        `messages` - Collection of String messages (not errors).

    - #### getActionMessages

          public Collection<String> getActionMessages()

      Description copied from interface: `ValidationAware`
      Get the Collection of Action-level messages for this action. Messages should not be added directly here, as implementations are free to return a new Collection or an Unmodifiable Collection.
      Specified by:
        `getActionMessages` in interface `ValidationAware`
      Returns:
        Collection of String messages

    - #### setFieldErrors

          public void setFieldErrors(Map<String,List<String>> errorMap)

      Description copied from interface: `ValidationAware`
      Set the field error map of fieldname (String) to Collection of String error messages.
      Specified by:
        `setFieldErrors` in interface `ValidationAware`
      Parameters:
        `errorMap` - field error map

    - #### getFieldErrors

          public Map<String,List<String>> getFieldErrors()

      Description copied from interface: `ValidationAware`
      Get the field specific errors associated with this action. Error messages should not be added directly here, as implementations are free to return a new Collection or an Unmodifiable Collection.
      Specified by:
        `getFieldErrors` in interface `ValidationAware`
      Returns:
        Map with errors mapped from fieldname (String) to Collection of String error messages

    - #### getFullFieldName

          public String getFullFieldName(String fieldName)

      Description copied from interface: `ValidatorContext`
      Translates a simple field name into a full field name in OGNL syntax.
      Specified by:
        `getFullFieldName` in interface `ValidatorContext`
      Parameters:
        `fieldName` - the field name to lookup.
      Returns:
        the full field name in OGNL syntax.

    - #### getLocale

          public Locale getLocale()

      Description copied from interface: `LocaleProvider`
      Gets the provided locale.
      Specified by:
        `getLocale` in interface `LocaleProvider`
      Returns:
        the locale.

    - #### isValidLocaleString

          public boolean isValidLocaleString(String localeStr)

      Description copied from interface: `LocaleProvider`
      Validates if provided string is a valid `Locale`
      Specified by:
        `isValidLocaleString` in interface `LocaleProvider`
      Parameters:
        `localeStr` - a String representing locale, e.g. en_EN
      Returns:
        true if valid

    - #### isValidLocale

          public boolean isValidLocale(Locale locale)

      Description copied from interface: `LocaleProvider`
      Validates if provided `Locale` is value
      Specified by:
        `isValidLocale` in interface `LocaleProvider`
      Parameters:
        `locale` - instance of `Locale` to validate
      Returns:
        true if valid

    - #### hasKey

          public boolean hasKey(String key)

      Description copied from interface: `TextProvider`
      Checks if a message key exists.
      Specified by:
        `hasKey` in interface `TextProvider`
      Parameters:
        `key` - message key to check for
      Returns:
        boolean true if key exists, false otherwise.

    - #### getText

          public String getText(String aTextName)

      Description copied from interface: `TextProvider`
      Gets a message based on a message key or if no message is found the provided key is returned.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `aTextName` - the resource bundle key that is to be searched for
      Returns:
        the message as found in the resource bundle, or the provided key if none is found.

    - #### getText

          public String getText(String aTextName,
                       String defaultValue)

      Description copied from interface: `TextProvider`
      Gets a message based on a key, or, if the message is not found, a supplied default value is returned.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `aTextName` - the resource bundle key that is to be searched for
        `defaultValue` - the default value which will be returned if no message is found
      Returns:
        the message as found in the resource bundle, or defaultValue if none is found

    - #### getText

          public String getText(String aTextName,
                       String defaultValue,
                       String obj)

      Description copied from interface: `TextProvider`
      Gets a message based on a key using the supplied obj, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `aTextName` - the resource bundle key that is to be searched for
        `defaultValue` - the default value which will be returned if no message is found
        `obj` - obj to be used in a `MessageFormat` message
      Returns:
        the message as found in the resource bundle, or defaultValue if none is found

    - #### getText

          public String getText(String aTextName,
                       List<?> args)

      Description copied from interface: `TextProvider`
      Gets a message based on a key using the supplied args, as defined in `MessageFormat` or the provided key if no message is found.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `aTextName` - the resource bundle key that is to be searched for
        `args` - a list args to be used in a `MessageFormat` message
      Returns:
        the message as found in the resource bundle, or the provided key if none is found.

    - #### getText

          public String getText(String key,
                       String[] args)

      Description copied from interface: `TextProvider`
      Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or the provided key if no message is found.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the resource bundle key that is to be searched for
        `args` - an array args to be used in a `MessageFormat` message
      Returns:
        the message as found in the resource bundle, or the provided key if none is found.

    - #### getText

          public String getText(String aTextName,
                       String defaultValue,
                       List<?> args)

      Description copied from interface: `TextProvider`
      Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `aTextName` - the resource bundle key that is to be searched for
        `defaultValue` - the default value which will be returned if no message is found
        `args` - a list args to be used in a `MessageFormat` message
      Returns:
        the message as found in the resource bundle, or defaultValue if none is found

    - #### getText

          public String getText(String key,
                       String defaultValue,
                       String[] args)

      Description copied from interface: `TextProvider`
      Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the resource bundle key that is to be searched for
        `defaultValue` - the default value which will be returned if no message is found
        `args` - an array args to be used in a `MessageFormat` message
      Returns:
        the message as found in the resource bundle, or defaultValue if none is found

    - #### getTexts

          public ResourceBundle getTexts(String aBundleName)

      Description copied from interface: `TextProvider`
      Get the named bundle, such as "com/acme/Foo".
      Specified by:
        `getTexts` in interface `TextProvider`
      Parameters:
        `aBundleName` - the name of the resource bundle, such as `"com/acme/Foo"`.
      Returns:
        the bundle

    - #### getText

          public String getText(String key,
                       String defaultValue,
                       List<?> args,
                       ValueStack stack)

      Description copied from interface: `TextProvider`
      Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned. Instead of using the value stack in the ActionContext this version of the getText() method uses the provided value stack.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the resource bundle key that is to be searched for
        `defaultValue` - the default value which will be returned if no message is found
        `args` - a list args to be used in a `MessageFormat` message
        `stack` - the value stack to use for finding the text
      Returns:
        the message as found in the resource bundle, or defaultValue if none is found

    - #### getText

          public String getText(String key,
                       String defaultValue,
                       String[] args,
                       ValueStack stack)

      Description copied from interface: `TextProvider`
      Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned. Instead of using the value stack in the ActionContext this version of the getText() method uses the provided value stack.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the resource bundle key that is to be searched for
        `defaultValue` - the default value which will be returned if no message is found
        `args` - an array args to be used in a `MessageFormat` message
        `stack` - the value stack to use for finding the text
      Returns:
        the message as found in the resource bundle, or defaultValue if none is found

    - #### getTexts

          public ResourceBundle getTexts()

      Description copied from interface: `TextProvider`
      Get the resource bundle associated with the implementing class (usually an action).
      Specified by:
        `getTexts` in interface `TextProvider`
      Returns:
        the bundle

    - #### addActionError

          public void addActionError(String anErrorMessage)

      Description copied from interface: `ValidationAware`
      Add an Action-level error message to this Action.
      Specified by:
        `addActionError` in interface `ValidationAware`
      Parameters:
        `anErrorMessage` - the error message

    - #### addActionMessage

          public void addActionMessage(String aMessage)

      Description copied from interface: `ValidationAware`
      Add an Action-level message to this Action.
      Specified by:
        `addActionMessage` in interface `ValidationAware`
      Parameters:
        `aMessage` - the message

    - #### addFieldError

          public void addFieldError(String fieldName,
                           String errorMessage)

      Description copied from interface: `ValidationAware`
      Add an error message for a given field.
      Specified by:
        `addFieldError` in interface `ValidationAware`
      Parameters:
        `fieldName` - name of field
        `errorMessage` - the error message

    - #### hasActionErrors

          public boolean hasActionErrors()

      Description copied from interface: `ValidationAware`
      Check whether there are any Action-level error messages.
      Specified by:
        `hasActionErrors` in interface `ValidationAware`
      Returns:
        true if any Action-level error messages have been registered

    - #### hasActionMessages

          public boolean hasActionMessages()

      Description copied from interface: `ValidationAware`
      Checks whether there are any Action-level messages.
      Specified by:
        `hasActionMessages` in interface `ValidationAware`
      Returns:
        true if any Action-level messages have been registered

    - #### hasErrors

          public boolean hasErrors()

      Description copied from interface: `ValidationAware`
      Checks whether there are any action errors or field errors.
      Specified by:
        `hasErrors` in interface `ValidationAware`
      Returns:
        `(hasActionErrors() || hasFieldErrors())`

    - #### hasFieldErrors

          public boolean hasFieldErrors()

      Description copied from interface: `ValidationAware`
      Check whether there are any field errors associated with this action.
      Specified by:
        `hasFieldErrors` in interface `ValidationAware`
      Returns:
        whether there are any field errors

    - #### makeTextProvider

          public TextProvider makeTextProvider(Object object,
                                      TextProviderFactory textProviderFactory)

    - #### makeLocaleProvider

          protected static LocaleProvider makeLocaleProvider(Object object)

    - #### makeValidationAware

          protected static ValidationAware makeValidationAware(Object object)

    - #### setTextProvider

          protected void setTextProvider(TextProvider textProvider)

    - #### getTextProvider

          protected TextProvider getTextProvider()

    - #### setValidationAware

          protected void setValidationAware(ValidationAware validationAware)

    - #### getValidationAware

          protected ValidationAware getValidationAware()

Copyright © 2000–2022 Apache Software Foundation. All rights reserved.