use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.
the class TemplateManager method process.
public String process(String templatePath, Object model, String language) {
StopWatch watch = new StopWatch();
try {
HTMLTemplate template = get(templatePath, model.getClass(), language);
TemplateContext context = new TemplateContext(model, cdnManager);
return template.process(context);
} finally {
logger.debug("process, templatePath={}, elapsedTime={}", templatePath, watch.elapsedTime());
}
}
use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.
the class HTMLTemplateEngine method process.
public String process(String name, Object model) {
StopWatch watch = new StopWatch();
try {
HTMLTemplate template = templates.get(name);
if (template == null)
throw Exceptions.error("template not found, name={}", name);
TemplateContext context = new TemplateContext(model, cdnManager);
return template.process(context);
} finally {
logger.debug("process, name={}, elapsedTime={}", name, watch.elapsedTime());
}
}
use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.
the class HTMLTemplateEngine method add.
private void add(TemplateSource source, Class<?> modelClass) {
StopWatch watch = new StopWatch();
String name = source.name();
try {
HTMLTemplate previous = templates.putIfAbsent(name, new HTMLTemplateBuilder(source, modelClass).build());
if (previous != null)
throw Exceptions.error("template is already added, name={}", name);
} finally {
logger.info("add, name={}, modelClass={}, elapsedTime={}", name, modelClass.getCanonicalName(), watch.elapsedTime());
}
}
use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.
the class TemplateManager method load.
private Map<String, HTMLTemplate> load(String templatePath, Class<?> modelClass) {
HTMLTemplateBuilder builder = new HTMLTemplateBuilder(new FileTemplateSource(webDirectory.root(), templatePath), modelClass);
builder.cdn = cdnManager;
Map<String, HTMLTemplate> templates = Maps.newHashMap();
for (String language : message.languages) {
builder.message = key -> message.get(key, language);
HTMLTemplate htmlTemplate = builder.build();
templates.put(language, htmlTemplate);
}
return templates;
}
use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.
the class TemplateManager method add.
public void add(String templatePath, Class<?> modelClass) {
StopWatch watch = new StopWatch();
try {
Map<String, HTMLTemplate> previous = templates.putIfAbsent(templatePath, load(templatePath, modelClass));
if (previous != null)
throw Exceptions.error("template was registered, templatePath={}", templatePath);
if (webDirectory.localEnv) {
Path path = webDirectory.path(templatePath);
templateLastModifiedTimes.put(templatePath, Files.lastModified(path));
}
} finally {
logger.info("add, templatePath={}, modelClass={}, elapsedTime={}", templatePath, modelClass.getCanonicalName(), watch.elapsedTime());
}
}
Aggregations