parent
04c12896d1
commit
02f54b22c6
@ -0,0 +1,33 @@ |
||||
package de.kreth.property2java; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.net.URL; |
||||
|
||||
import freemarker.template.Configuration; |
||||
import freemarker.template.Template; |
||||
|
||||
public enum FreemarkerConfig { |
||||
|
||||
INSTANCE; |
||||
|
||||
private final Configuration cfg; |
||||
|
||||
public Template getTemplate() throws IOException { |
||||
return cfg.getTemplate("enum_template.tpl"); |
||||
} |
||||
|
||||
private FreemarkerConfig() { |
||||
cfg = new Configuration(Configuration.VERSION_2_3_28); |
||||
URL url = getClass().getResource("/template/enum_template.tpl"); |
||||
try { |
||||
cfg.setDirectoryForTemplateLoading(new File(url.getFile()).getParentFile()); |
||||
} |
||||
catch (IOException e) { |
||||
throw new IllegalStateException("Unable to configure freemarker", e); |
||||
} |
||||
|
||||
cfg.setDefaultEncoding("UTF-8"); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
<#if package??>package ${package}; |
||||
|
||||
</#if>import java.util.Properties; |
||||
import java.util.ResourceBundle; |
||||
import java.util.function.UnaryOperator; |
||||
|
||||
/** |
||||
* Property key from ${fileName} |
||||
*/ |
||||
public enum ${classname} { |
||||
|
||||
<#list entries as entry> |
||||
/** |
||||
* "${entry.value}" |
||||
*/ |
||||
${entry.key} ("${entry.value}")<#sep>, |
||||
</#sep> |
||||
</#list>; |
||||
|
||||
private final String value; |
||||
|
||||
private ${classname} (String value) { |
||||
this.value = value; |
||||
} |
||||
|
||||
/** |
||||
* Represented Key in property File. |
||||
* @return key |
||||
*/ |
||||
public String getValue() { |
||||
return value; |
||||
} |
||||
|
||||
/** |
||||
* Resolves the value for this key from the parameter function. |
||||
* <p> |
||||
* e.g. <code>${classname}.getString(resBundle::getString)</code> |
||||
* @param resourceFunction {@link Properties#getProperty(String)} or {@link ResourceBundle#getString(String)} |
||||
* @return |
||||
*/ |
||||
public String getString(UnaryOperator<String> resourceFunction) { |
||||
return resourceFunction.apply(value); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue