docs: add Javadoc
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

pull/3/head
Davide Polonio 2023-04-15 12:50:36 +02:00
parent 7f632d2b6e
commit 8dd547404d
1 changed files with 21 additions and 0 deletions

View File

@ -9,6 +9,14 @@ import org.apache.velocity.tools.ToolManager;
import org.apache.velocity.util.StringBuilderWriter; import org.apache.velocity.util.StringBuilderWriter;
// FIXME doc, tests // FIXME doc, tests
/**
* This class aims to generate localized messages or strings either merging Velocity templates or
* taking directly the keys from {@link java.util.ResourceBundle}
*
* @author Davide Polonio
* @since 1.0
*/
public class TemplateContentGenerator { public class TemplateContentGenerator {
private final LocalizedMessageFactory localizedMessageFactory; private final LocalizedMessageFactory localizedMessageFactory;
@ -18,6 +26,19 @@ public class TemplateContentGenerator {
this.localizedMessageFactory = localizedMessageFactory; this.localizedMessageFactory = localizedMessageFactory;
} }
/**
* Merge a Velocity template located in the local Jar resource path with the given {@link Locale},
* provided as a {@link String}. A {@link Consumer} is provided in order to let the user customize
* the {@link VelocityContext} with additional variables. Localization strings will be directly
* taken via the use of {@link LocalizedTool} class.
*
* @param velocityContextConsumer a lambda function that allows for the customization of {@link
* VelocityContext} instance
* @param localeAsString a {@link Locale} formatted as a {@link String}. Note that {@link
* Locale#forLanguageTag(String)} will be used for the conversion
* @param templateName the path to the local Jar resource
* @return a {@link String} containing the localized message
*/
public String mergeTemplate( public String mergeTemplate(
Consumer<VelocityContext> velocityContextConsumer, Consumer<VelocityContext> velocityContextConsumer,
String localeAsString, String localeAsString,