org.restlet.routing

## Class Validator

- java.lang.Object
- - org.restlet.Restlet
  - - org.restlet.routing.Filter
    - - org.restlet.routing.Validator

All Implemented Interfaces:
  Uniform

    public class Validator
    extends Filter

Filter validating attributes from a call. Validation is verified based on regex pattern matching.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.

Author:
  Jerome Louvel
See Also:
  `Pattern`

### Field Summary

### Fields inherited from class org.restlet.routing.Filter

`CONTINUE, SKIP, STOP`

### Constructor Summary

Constructors
Constructor and Description
`Validator()` Constructor.
`Validator(Context context)` Constructor.
`Validator(Context context, Restlet next)` Constructor.

### Method Summary

Methods
`protected int` `beforeHandle(Request request, Response response)` Allows filtering before its handling by the target Restlet.
`void` `validate(java.lang.String attribute, boolean required, java.lang.String format)` Checks the request attributes for presence or format.
`void` `validateFormat(java.lang.String attribute, java.lang.String format)` Checks the request attributes for format only.
`void` `validatePresence(java.lang.String attribute)` Checks the request attributes for presence only.

### Methods inherited from class org.restlet.routing.Filter

`afterHandle, doHandle, getNext, handle, hasNext, setNext, setNext, start, stop`

### Methods inherited from class org.restlet.Restlet

`finalize, getApplication, getAuthor, getContext, getDescription, getLogger, getName, getOwner, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner`

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

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

### Constructor Detail

#### Validator

    public Validator()

Constructor.

#### Validator

    public Validator(Context context)

Constructor.

Parameters:
  `context` - The context.

#### Validator

    public Validator(Context context,
             Restlet next)

Constructor.

Parameters:
  `context` - The context.
  `next` - The next Restlet.

### Method Detail

#### beforeHandle

    protected int beforeHandle(Request request,
                   Response response)

Allows filtering before its handling by the target Restlet. By default it parses the template variable, adjust the base reference, then extracts the attributes from form parameters (query, cookies, entity) and finally tries to validate the variables as indicated by the `validate(String, boolean, String)` method.

Overrides:
  `beforeHandle` in class `Filter`
Parameters:
  `request` - The request to filter.
  `response` - The response to filter.
Returns:
  The `Filter.CONTINUE` status.

#### validate

    public void validate(java.lang.String attribute,
                boolean required,
                java.lang.String format)

Checks the request attributes for presence or format. If the check fails, then a response status CLIENT_ERROR_BAD_REQUEST is returned with the proper status description.

Parameters:
  `attribute` - Name of the attribute to look for.
  `required` - Indicates if the attribute presence is required.
  `format` - Format of the attribute value, using Regex pattern syntax.

#### validateFormat

    public void validateFormat(java.lang.String attribute,
                      java.lang.String format)

Checks the request attributes for format only. If the check fails, then a response status CLIENT_ERROR_BAD_REQUEST is returned with the proper status description.

Parameters:
  `attribute` - Name of the attribute to look for.
  `format` - Format of the attribute value, using Regex pattern syntax.

#### validatePresence

    public void validatePresence(java.lang.String attribute)

Checks the request attributes for presence only. If the check fails, then a response status CLIENT_ERROR_BAD_REQUEST is returned with the proper status description.

Parameters:
  `attribute` - Name of the attribute to look for.