org.restlet.routing

## Class TemplateRoute

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

All Implemented Interfaces:
  Uniform

Direct Known Subclasses:
  Route

    public class TemplateRoute
    extends Filter

Filter scoring the affinity of calls with the attached Restlet. The score is used by an associated Router in order to determine the most appropriate Restlet for a given call. The routing is based on a reference template.
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:
  `Template`

### Field Summary

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

`CONTINUE, SKIP, STOP`

### Constructor Summary

Constructors
Constructor and Description
`TemplateRoute(Restlet next)` Constructor behaving as a simple extractor filter.
`TemplateRoute(Router router, java.lang.String uriTemplate, Restlet next)` Constructor.
`TemplateRoute(Router router, Template template, Restlet next)` Constructor.

### Method Summary

Methods
`protected int` `beforeHandle(Request request, Response response)` Allows filtering before its handling by the target Restlet.
`int` `getMatchingMode()` Returns the matching mode to use on the template when parsing a formatted reference.
`boolean` `getMatchQuery()` Deprecated. Use `isMatchingQuery()` instead.
`Router` `getRouter()` Returns the parent router.
`Template` `getTemplate()` Returns the reference template to match.
`boolean` `isMatchingQuery()` Indicates whether the query part should be taken into account when matching a reference with the template.
`float` `score(Request request, Response response)` Returns the score for a given call (between 0 and 1.0).
`void` `setMatchingMode(int matchingMode)` Sets the matching mode to use on the template when parsing a formatted reference.
`void` `setMatchingQuery(boolean matchingQuery)` Sets whether the matching should be done on the URI with or without query string.
`void` `setMatchQuery(boolean matchingQuery)` Deprecated. Use `setMatchingQuery(boolean)` instead.
`void` `setRouter(Router router)` Sets the parent router.
`void` `setTemplate(Template template)` Sets the reference template to match.
`java.lang.String` `toString()`

### 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, wait, wait, wait`

### Constructor Detail

#### TemplateRoute

    public TemplateRoute(Restlet next)

Constructor behaving as a simple extractor filter.

Parameters:
  `next` - The next Restlet.

#### TemplateRoute

    public TemplateRoute(Router router,
                 java.lang.String uriTemplate,
                 Restlet next)

Constructor. The URIs will be matched agains the template using the `Template.MODE_STARTS_WITH` matching mode. This can be changed by getting the template and calling `Template.setMatchingMode(int)` with `Template.MODE_EQUALS` for exact matching.

Parameters:
  `router` - The parent router.
  `uriTemplate` - The URI template.
  `next` - The next Restlet.

#### TemplateRoute

    public TemplateRoute(Router router,
                 Template template,
                 Restlet next)

Constructor.

Parameters:
  `router` - The parent router.
  `template` - The URI template.
  `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 of the target resource's reference.

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

#### getMatchingMode

    public int getMatchingMode()

Returns the matching mode to use on the template when parsing a formatted reference.

Returns:
  The matching mode to use.

#### getMatchQuery

    @Deprecated
    public boolean getMatchQuery()

Deprecated. Use `isMatchingQuery()` instead.
Indicates whether the query part should be taken into account when matching a reference with the template.

Returns:
  True if the query part of the reference should be taken into account, false otherwise.

#### getRouter

    public Router getRouter()

Returns the parent router.

Returns:
  The parent router.

#### getTemplate

    public Template getTemplate()

Returns the reference template to match.

Returns:
  The reference template to match.

#### isMatchingQuery

    public boolean isMatchingQuery()

Indicates whether the query part should be taken into account when matching a reference with the template.

Returns:
  True if the query part of the reference should be taken into account, false otherwise.

#### score

    public float score(Request request,
              Response response)

Returns the score for a given call (between 0 and 1.0).

Parameters:
  `request` - The request to score.
  `response` - The response to score.
Returns:
  The score for a given call (between 0 and 1.0).

#### setMatchingMode

    public void setMatchingMode(int matchingMode)

Sets the matching mode to use on the template when parsing a formatted reference.

Parameters:
  `matchingMode` - The matching mode to use.

#### setMatchingQuery

    public void setMatchingQuery(boolean matchingQuery)

Sets whether the matching should be done on the URI with or without query string.

Parameters:
  `matchingQuery` - True if the matching should be done with the query string, false otherwise.

#### setMatchQuery

    @Deprecated
    public void setMatchQuery(boolean matchingQuery)

Deprecated. Use `setMatchingQuery(boolean)` instead.
Sets whether the matching should be done on the URI with or without query string.

Parameters:
  `matchingQuery` - True if the matching should be done with the query string, false otherwise.

#### setRouter

    public void setRouter(Router router)

Sets the parent router.

Parameters:
  `router` - The parent router.

#### setTemplate

    public void setTemplate(Template template)

Sets the reference template to match.

Parameters:
  `template` - The reference template to match.

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`