public class LocaleTransposition extends Object implements Transposition<String>, Constraint<String>
Transposition
and/or Constraint
responsible for translating values from their matching translation
from a ResourceBundle
. The lookup in the properties file is case-sensitive. The properties file should use
ISO-8859-1 encoding as defined by PropertyResourceBundle
.
Requires inverted properties files in the form of translated_name=name_to_bind.
TODO Should we allow to load the properties file in a different encoding? TODO Allow to enable case insensitive
and/or ascii-folding on property lookup?Modifier and Type | Method and Description |
---|---|
static LocaleTransposition |
bundle(String bundleName,
String localeParam)
Create a
Binding to a ResourceBundle , where the initial bound Parameter value is used as
the bundle lookup key. |
boolean |
isSatisfiedBy(Rewrite event,
EvaluationContext context,
String value)
|
LocaleTransposition |
onTranspositionFailed(Operation onFailureOperation)
Specify an
Operation to be added as a preOperation in case the Transposition failed. |
String |
transpose(Rewrite event,
EvaluationContext context,
String value)
Perform an operation on the given value.
|
public static LocaleTransposition bundle(String bundleName, String localeParam)
Binding
to a ResourceBundle
, where the initial bound Parameter
value is used as
the bundle lookup key. The resultant value of the bundle lookup is stored as the new bound Parameter
value.
For example, consider the following URL-based rule:
Configuration config = ConfigurationBuilder.begin() .addRule(Join.path("/{lang}/{path}").to("/{path}")) .where("path").transposedBy(LocaleTransposition.bundle("org.example.Paths", "lang"));
In the above scenario, "org.example.Paths" is the resource bundle name. The value of the Parameter
"lang"
is extracted from the inbound request URL, and used as the bundle Locale
. The initial value of the
Parameter
"path" is used as the lookup key, and is transposed to the value of the corresponding resource
bundle entry. Once transposition has occurred, after rule evaluation, subsequent references to the "path"
Parameter
will return the value from the ResourceBundle
entry.
When this example is applied to a URL of: "/de/bibliotek", assuming a bundle called "org.example.Paths_de" exists
and contains the an entry "bibliotek=library", the rule will forward to the new URL: "/library", because the value
of "path" has been transposed by LocaleTransposition
.
bundleName
- Fully qualified name of the ResourceBundle
localeParam
- The name of the Parameter
that contains the ISO 639-1 language code to be used with
Locale
.public LocaleTransposition onTranspositionFailed(Operation onFailureOperation)
Operation
to be added as a preOperation in case the Transposition
failed. Failure
occurs when no ResourceBundle
can be found for the requested language or when a value can not be
transposed due to a missing key in the resource bundle.onFailureOperation
- public String transpose(Rewrite event, EvaluationContext context, String value)
Transposition
transpose
in interface Transposition<String>
public boolean isSatisfiedBy(Rewrite event, EvaluationContext context, String value)
Constraint
isSatisfiedBy
in interface Constraint<String>
Copyright © 2014 OCPsoft. All Rights Reserved.