Class LocaleTransposition
- All Implemented Interfaces:
Constraint<String>,ParameterConfigurator,Transposition<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?- Author:
- Christian Gendreau
-
Method Summary
Modifier and TypeMethodDescriptionstatic LocaleTranspositionCreate aBindingto aResourceBundle, where the initial boundParametervalue is used as the bundle lookup key.booleanisSatisfiedBy(Rewrite event, EvaluationContext context, String value) onTranspositionFailed(Operation onFailureOperation) Specify anOperationto be added as a preOperation in case theTranspositionfailed.transpose(Rewrite event, EvaluationContext context, String value) Perform an operation on the given value.
-
Method Details
-
bundle
Create aBindingto aResourceBundle, where the initial boundParametervalue is used as the bundle lookup key. The resultant value of the bundle lookup is stored as the new boundParametervalue.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 bundleLocale. The initial value of theParameter"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"Parameterwill return the value from theResourceBundleentry.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.- Parameters:
bundleName- Fully qualified name of theResourceBundlelocaleParam- The name of theParameterthat contains the ISO 639-1 language code to be used withLocale.- Returns:
- new instance of LocaleBinding
-
onTranspositionFailed
Specify anOperationto be added as a preOperation in case theTranspositionfailed. Failure occurs when noResourceBundlecan be found for the requested language or when a value can not be transposed due to a missing key in the resource bundle.- Parameters:
onFailureOperation-- Returns:
-
transpose
Description copied from interface:TranspositionPerform an operation on the given value.- Specified by:
transposein interfaceTransposition<String>
-
isSatisfiedBy
Description copied from interface:Constraint- Specified by:
isSatisfiedByin interfaceConstraint<String>
-