|
|
|
@ -3,12 +3,13 @@ package de.kreth.property2java; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.Reader; |
|
|
|
import java.io.Reader; |
|
|
|
import java.io.Writer; |
|
|
|
import java.io.Writer; |
|
|
|
|
|
|
|
import java.text.DateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map.Entry; |
|
|
|
|
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
|
|
|
|
import de.kreth.property2java.cli.ArgumentConfiguration; |
|
|
|
import de.kreth.property2java.cli.ArgumentConfiguration; |
|
|
|
@ -17,9 +18,11 @@ import freemarker.template.TemplateException; |
|
|
|
|
|
|
|
|
|
|
|
public class Generator { |
|
|
|
public class Generator { |
|
|
|
|
|
|
|
|
|
|
|
private Configuration config; |
|
|
|
private static final DateFormat dateTimeInstance = DateFormat.getDateTimeInstance(); |
|
|
|
|
|
|
|
|
|
|
|
private Template template; |
|
|
|
private final Configuration config; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Template template; |
|
|
|
|
|
|
|
|
|
|
|
public Generator(Configuration config) { |
|
|
|
public Generator(Configuration config) { |
|
|
|
this.config = config; |
|
|
|
this.config = config; |
|
|
|
@ -27,14 +30,13 @@ public class Generator { |
|
|
|
template = FreemarkerConfig.INSTANCE.getTemplate(); |
|
|
|
template = FreemarkerConfig.INSTANCE.getTemplate(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IOException e) { |
|
|
|
catch (IOException e) { |
|
|
|
|
|
|
|
|
|
|
|
throw new IllegalStateException("Unable to load freemarker template", e); |
|
|
|
throw new IllegalStateException("Unable to load freemarker template", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void start() throws IOException, TemplateException { |
|
|
|
public void start() throws IOException, TemplateException { |
|
|
|
|
|
|
|
|
|
|
|
for (Entry<String, Reader> entry : config.getInput().entrySet()) { |
|
|
|
for (Map.Entry<String, Reader> entry : config.getInput().entrySet()) { |
|
|
|
String fileName = entry.getKey(); |
|
|
|
String fileName = entry.getKey(); |
|
|
|
Writer out = config.outWriter(fileName); |
|
|
|
Writer out = config.outWriter(fileName); |
|
|
|
Properties properties = new Properties(); |
|
|
|
Properties properties = new Properties(); |
|
|
|
@ -47,11 +49,13 @@ public class Generator { |
|
|
|
throws IOException, TemplateException { |
|
|
|
throws IOException, TemplateException { |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> root = new HashMap<>(); |
|
|
|
Map<String, Object> root = new HashMap<>(); |
|
|
|
|
|
|
|
root.put("generator_name", getClass().getName()); |
|
|
|
|
|
|
|
root.put("generation_date", dateTimeInstance.format(new Date())); |
|
|
|
root.put("package", config.getPackage()); |
|
|
|
root.put("package", config.getPackage()); |
|
|
|
root.put("fileName", fileName); |
|
|
|
root.put("fileName", fileName); |
|
|
|
root.put("classname", config.mapFilenameToClassName(fileName)); |
|
|
|
root.put("classname", config.mapFilenameToClassName(fileName)); |
|
|
|
|
|
|
|
|
|
|
|
List<Entry<String, String>> entries = new ArrayList<>(); |
|
|
|
List<Entry> entries = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
root.put("entries", entries); |
|
|
|
root.put("entries", entries); |
|
|
|
|
|
|
|
|
|
|
|
@ -62,24 +66,8 @@ public class Generator { |
|
|
|
final String propertyKeyString = propertyNames.nextElement(); |
|
|
|
final String propertyKeyString = propertyNames.nextElement(); |
|
|
|
final String propertyValue = properties.getProperty(propertyKeyString); |
|
|
|
final String propertyValue = properties.getProperty(propertyKeyString); |
|
|
|
|
|
|
|
|
|
|
|
Entry<String, String> entry = new Entry<String, String>() { |
|
|
|
entries.add(new Entry(propertyKeyString.toUpperCase().replaceAll("[\\.-]", "_"), propertyKeyString, |
|
|
|
|
|
|
|
propertyValue)); |
|
|
|
@Override |
|
|
|
|
|
|
|
public String getKey() { |
|
|
|
|
|
|
|
return propertyKeyString.toUpperCase().replaceAll("[\\.-]", "_"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String getValue() { |
|
|
|
|
|
|
|
return propertyValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String setValue(String value) { |
|
|
|
|
|
|
|
throw new UnsupportedOperationException("Set Value not supported!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
entries.add(entry); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
template.process(root, out); |
|
|
|
template.process(root, out); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -89,4 +77,32 @@ public class Generator { |
|
|
|
generator.start(); |
|
|
|
generator.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Entry { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final String constant; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final String key; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final String value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Entry(String constant, String key, String value) { |
|
|
|
|
|
|
|
super(); |
|
|
|
|
|
|
|
this.constant = constant; |
|
|
|
|
|
|
|
this.key = key; |
|
|
|
|
|
|
|
this.value = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getConstant() { |
|
|
|
|
|
|
|
return constant; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getKey() { |
|
|
|
|
|
|
|
return key; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getValue() { |
|
|
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|