- All Implemented Interfaces:
Handler
Handler
that generates message classes from Properties
files using Locale
s to match localized
strings and MessageFormat
to create typed method signatures.
The properties file name is used to name the class. The keys are used to name the methods.
Locale.getAvailableLocales()
and
ResourceBundle.Control.toBundleName(String, Locale)
are used to discover localized properties.
Generated method signatures will vary based on need.
- A method to return the raw value is always generated.
- If "localize" is true and localized files have been detected the method requires a
Locale
argument.
- If "localize" is true and localized files have been detected the method requires a
- q
A second method is generated if "format" is true and format expressions have been detected in the value.
Locale
is the first argument if "localize" is true and localized files have been detected and number/choice/date us used.-
Format expressions form the remaining arguments in index order.
MessageFormat
expressions are mapped as follows.- number or choice:
Number
- date or time:
ZonedDateTime
- none:
String
- number or choice:
Example
Example file Cosmic.properties
:
planet-event=At {1,time} on {2,date}, there was {3} on planet {0,number,integer}.
This will generate a class Cosmic
with the method signature:
static String planet_event(Locale l, Number v0, ZonedDateTime v1, ZonedDateTime v2, String v3)
Usage:
var now = ZonedDateTime.now(); Cosmic.planet_event(Locale.US, 4, now, "an attack")
Generally variables can be reused in MessageFormat
patterns but this is unsupported
when dates are present due to implementation limitations in time zone handling.
-
Constructor Details
-
GenerateMessagesFromProperties
public GenerateMessagesFromProperties()Ctor
-
-
Method Details
-
config
All configuration is optional.
"localize" is "true" by default.
"missing-key" is "error" by default.
"format" is "true" by default.
"incompatible-format" is "error" by default.
Use "visibility" to make the generated classes public.
-
handle
Description copied from interface:Handler
Handles the context resources.- Specified by:
handle
in interfaceHandler
- Parameters:
context
- processing context- Throws:
IOException
- See Also:
-