Search in sources :

Example 6 with HTMLTemplate

use of core.framework.impl.template.HTMLTemplate in project core-ng-project by neowu.

the class TemplateManager method get.

private HTMLTemplate get(String templatePath, Class<?> modelClass, String language) {
    Map<String, HTMLTemplate> templates = this.templates.get(templatePath);
    if (templates == null)
        throw Exceptions.error("template is not registered, please use site().template() to add template, templatePath={}", templatePath);
    if (webDirectory.localEnv) {
        Path path = webDirectory.path(templatePath);
        if (Files.lastModified(path).isAfter(templateLastModifiedTimes.get(templatePath))) {
            // put modified time first, then template, for zero cost to handle local threading
            templateLastModifiedTimes.put(templatePath, Files.lastModified(path));
            templates = load(templatePath, modelClass);
            this.templates.put(templatePath, templates);
        }
    }
    String targetLanguage = language == null ? MessageImpl.DEFAULT_LANGUAGE : language;
    HTMLTemplate template = templates.get(targetLanguage);
    if (template == null)
        throw Exceptions.error("language is not defined, please check site().message(), language={}", targetLanguage);
    return template;
}
Also used : Path(java.nio.file.Path) HTMLTemplate(core.framework.impl.template.HTMLTemplate)

Aggregations

HTMLTemplate (core.framework.impl.template.HTMLTemplate)6 StopWatch (core.framework.util.StopWatch)4 HTMLTemplateBuilder (core.framework.impl.template.HTMLTemplateBuilder)2 TemplateContext (core.framework.impl.template.TemplateContext)2 Path (java.nio.file.Path)2 FileTemplateSource (core.framework.impl.template.source.FileTemplateSource)1