.. _configuration.layers.parameterfilters: Parameter Filters ================= Parameter filters provide templates for extracting arbitrary parameters from requests. This allows using GeoWebCache in scenarios such as time series data, multiple styles for the same layer or with CQL filters set by the client. There are four types of parameter filters: #. **String filters** (````) #. **Floating point number filters** (````) #. **Integer filters** (````) #. **Regular expression filters** (````) A given layer can have multiple types of parameter filters. If a request does not comply with the allowed values of the set parameter, the request will fail, usually with an error such as:: 400: violates filter for parameter String filter ------------- GeoWebCache can also use an allowable list of string values in a parameter filter for a given key. If the string in the request matches one of the string specified in the parameter filter, the request will proceed. When specifying a string filter, three pieces of information are required: * **Key** (````). The key is not case sensitive. * **Default value** (````). * **List of strings** (````, ````). The strings are case sensitive. This information is presented in the following schema inside the ```` tag: .. code-block:: xml ... ... ... ... ... For example, it is possible to set the allowed values of the "styles" parameter to one of three values: "polygon", "population", with a third default blank value for when the parameter is unspecified. The resulting parameter filter would be: .. code-block:: xml styles population polygon Floating point filter --------------------- Similar to a string filter, GeoWebCache can also recognize a list of numerical values for a given key. If the value requested matches one of the values specified in the filter, the request will proceed. When specifying a numerical filter, four pieces of information are required: * **Key** (````). This key is not case sensitive. * **Default value** (````). * **List of values** (````, ````). * **Threshold** (````). This information is presented in the following schema inside the ```` tag: .. code-block:: xml ... ... ... ... ... ... For example, given a parameter called ``elevation``, where the allowed values are ``-42.5``, ``0``, and ``100`` and the default value being ``100``, the filter would be: .. code-block:: xml elevation -42.5 42.5 0 100 50 Note also the above example sets a threshold of ``50``. A value that is within the threshold of any of the allowed values will still proceed, albeit rounded to one of the allowed values. So in this example, a value of ``75`` would be successfully requested as ``100.0``, but a value of ``200`` will fail. Thresholds are also valuable when managing possible floating point rounding errors. For example, if your data has accuracy down to the sixth decimal place, you may want to use a threshold of ``1e-6`` to ensure proper matching. Note that the request value produced by the filter will *always* include a decimal point and floating point arithmetic has limitted precision that can means certain values can't be correctly represented. If you are working with exclusively integer ("whole number") values, it's better to use the ``integerParameterFilter`` instead. Integer filter -------------- This works in much the same way as the floating point filter, but only allows whole numbers, including negatives. Again, four pieces of information are required: * **Key** (````). This key is not case sensitive. * **Default value** (````). * **List of values** (````, ````). * **Threshold** (````). This information is presented in the following schema inside the ```` tag: .. code-block:: xml ... ... ... ... ... ... If the paramter were ``dim_year``, where the allowed values are ``1996``, and ``2006`` and the default value being ``2006``, the filter would be: .. code-block:: xml dim_year 2006 1996 2006 2 Note also the above example sets a threshold of ``2`` to only cover the specific value listed and one year either side. So in this example, a value of ``2007`` would be successfully requested as ``2006``, but a value of ``2008`` will fail. Note that unlike the ``floatParameterFilter``, there is no decimal point in the requested value. Regular expression filter ------------------------- For a finer control of parameter values, GeoWebCache can recognize regular expressions for the value in a filter. If a requested value matches the pattern in the regular expression, the request will proceed. .. note:: GeoWebCache uses standard Java regular expressions. For more information, please see the regular expression pattern documentation at: ``_. When specifying a regular expression filter, three pieces of information are required: * **Key** (````). The key is not case sensitive. * **Default value** (````). * **Regular expression** (````). This information is presented in the following schema inside the ```` tag: .. code-block:: xml ... ... ... Regular expressions allows you to specify the same allowed styles as in the above string filter example. To set two allowed values for the "styles" parameter: "polygon", "population", with a third default blank value for when the parameter is unspecified, the regular expression would be:: ^(|polygon|population)$ The resulting parameter filter would be: .. code-block:: xml styles ^(|polygon|population)$ Case normalization ------------------ You can normalize the case of a Regular Expression or String rule to upper or lower case by adding a ``normalize`` element. This takes a ``case`` and an optional ``locale``. ``case`` may be ``NONE`` for no normalization, ``UPPER`` for upper case, or ``LOWER`` for lower case. ``locale`` may be any Java locale identifier supported by the JVM and the JVM default locale will be used if not specified. .. code-block:: xml styles UPPER en_CA ^(|polygon|population)$ If upper or lower case normalization is used, matching with legal values will be case insensitive, otherwise it will be case sensitive. The default value is never normalized.