|
@@ -22,8 +22,8 @@ import java.util.Map; |
|
|
*/ |
|
|
*/ |
|
|
public class CodeGenerator { |
|
|
public class CodeGenerator { |
|
|
private final static String KEY_MODEL = "model"; |
|
|
private final static String KEY_MODEL = "model"; |
|
|
private final static String TEMPLATE_JAVA_BEAN = "java_bean"; |
|
|
|
|
|
private final static String TEMPLATE_JAVA_CACHE = "java_cache"; |
|
|
|
|
|
|
|
|
private final static String TEMPLATE_JAVA_BEAN = "../java_bean"; |
|
|
|
|
|
private final static String TEMPLATE_JAVA_CACHE = "../java_cache"; |
|
|
private final static String TEMPLATE_JAVA_SERVICE = "java_service"; |
|
|
private final static String TEMPLATE_JAVA_SERVICE = "java_service"; |
|
|
private final static String TEMPLATE_JS_EVENT = "js_event"; |
|
|
private final static String TEMPLATE_JS_EVENT = "js_event"; |
|
|
private static CodeGenerator instance = null; |
|
|
private static CodeGenerator instance = null; |
|
@@ -42,7 +42,7 @@ public class CodeGenerator { |
|
|
mapTemplate = YamlUtil.readValue(this.getClass().getResourceAsStream("/static/template/" + SwConsts.modelPath + "/index.yaml"), SwMap.class); |
|
|
mapTemplate = YamlUtil.readValue(this.getClass().getResourceAsStream("/static/template/" + SwConsts.modelPath + "/index.yaml"), SwMap.class); |
|
|
configuration = new Configuration(Configuration.VERSION_2_3_31); |
|
|
configuration = new Configuration(Configuration.VERSION_2_3_31); |
|
|
try { |
|
|
try { |
|
|
configuration.setClassForTemplateLoading(this.getClass(), "/static/template/"); |
|
|
|
|
|
|
|
|
configuration.setClassForTemplateLoading(this.getClass(), "/static/template/" + SwConsts.modelPath); |
|
|
// configuration.setDirectoryForTemplateLoading(new File(templatesDir)); |
|
|
// configuration.setDirectoryForTemplateLoading(new File(templatesDir)); |
|
|
configuration.setClassicCompatible(true); |
|
|
configuration.setClassicCompatible(true); |
|
|
configuration.setDefaultEncoding(encode); |
|
|
configuration.setDefaultEncoding(encode); |
|
@@ -98,7 +98,7 @@ public class CodeGenerator { |
|
|
|
|
|
|
|
|
public String generate(Map<String, Object> model, String templateName) { |
|
|
public String generate(Map<String, Object> model, String templateName) { |
|
|
StringWriter out = new StringWriter(); |
|
|
StringWriter out = new StringWriter(); |
|
|
generate(model, SwConsts.modelPath + "/" + templateName + ".ftl", out); |
|
|
|
|
|
|
|
|
generate(model, templateName + ".ftl", out); |
|
|
return out.getBuffer().toString(); |
|
|
return out.getBuffer().toString(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -196,7 +196,7 @@ public class CodeGenerator { |
|
|
|
|
|
|
|
|
map.put("title", "thisIsATest!"); |
|
|
map.put("title", "thisIsATest!"); |
|
|
map.put("newId", new PKGenerator()); |
|
|
map.put("newId", new PKGenerator()); |
|
|
CodeGenerator.getInstance().generate(map, SwConsts.modelPath + "/model_card.ftl", out); |
|
|
|
|
|
|
|
|
CodeGenerator.getInstance().generate(map, "model_card.ftl", out); |
|
|
System.out.println(out.getBuffer().toString()); |
|
|
System.out.println(out.getBuffer().toString()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |