Class GenerateMessagesFromProperties
- java.lang.Object
-
- uk.autores.processing.handlers.GenerateMessagesFromProperties
-
- All Implemented Interfaces:
Handler
public final class GenerateMessagesFromProperties extends Object implements Handler
Handler
that generates message classes fromProperties
files usingLocale
s to match localized strings andMessageFormat
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()
andResourceBundle.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/or 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 expressions:
TemporalAccessor
- none:
String
- number or choice:
Example
Example file
Cosmic.properties
:planet-event=At {1,dtf-time} on {2,dtf-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, TemporalAccessor v1, TemporalAccessor 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 Summary
Constructors Constructor Description GenerateMessagesFromProperties()
Ctor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<ConfigDef>
config()
All configuration is optional.void
handle(Context context)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface uk.autores.handling.Handler
validConfig
-
-
-
-
Method Detail
-
config
public Set<ConfigDef> 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.
- Specified by:
config
in interfaceHandler
- Returns:
- visibility, localize, missing-key, incompatible-format
- See Also:
CfgVisibility
,CfgLocalize
,CfgMissingKey
,CfgFormat
,CfgIncompatibleFormat
-
handle
public void handle(Context context) throws IOException
- Specified by:
handle
in interfaceHandler
- Throws:
IOException
-
-