- java.lang.Object
-
- uk.autores.handling.GenerateMessagesFromProperties
-
- All Implemented Interfaces:
Handler
public final class GenerateMessagesFromProperties extends Object implements Handler
Handlerthat generates message classes fromPropertiesfiles usingLocales to match localized strings andMessageFormatto 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
Localeargument.
- 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.
Localeis 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.
MessageFormatexpressions 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
Cosmicwith 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
MessageFormatpatterns 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.voidhandle(Context context)Handles the context resources.-
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.
Use "visibility" to make the generated classes public.
- Specified by:
configin interfaceHandler- Returns:
- visibility, localize, missing-key
- See Also:
CfgVisibility,CfgLocalize,CfgMissingKey,CfgFormat
-
handle
public void handle(Context context) throws IOException
Description copied from interface:HandlerHandles the context resources.- Specified by:
handlein interfaceHandler- Parameters:
context- processing context- Throws:
IOException- See Also:
Context.resources()
-
-