Search in sources :

Example 1 with AbstractTaskDirective

use of com.publiccms.common.base.AbstractTaskDirective in project PublicCMS-preview by sanluan.

the class TemplateComponent method init.

@Autowired
private void init(FreeMarkerConfigurer freeMarkerConfigurer, DirectiveComponent directiveComponent) throws IOException, TemplateModelException {
    Map<String, Object> freemarkerVariables = new HashMap<>();
    adminConfiguration = freeMarkerConfigurer.getConfiguration();
    for (Entry<String, AbstractTemplateDirective> entry : directiveComponent.getTemplateDirectiveMap().entrySet()) {
        freemarkerVariables.put(directivePrefix + entry.getKey(), entry.getValue());
    }
    freemarkerVariables.putAll(directiveComponent.getMethodMap());
    adminConfiguration.setAllSharedVariables(new SimpleHash(freemarkerVariables, adminConfiguration.getObjectWrapper()));
    webConfiguration = new Configuration(Configuration.getVersion());
    File webFile = new File(siteComponent.getWebTemplateFilePath());
    webFile.mkdirs();
    webConfiguration.setDirectoryForTemplateLoading(webFile);
    copyConfig(adminConfiguration, webConfiguration);
    Map<String, Object> webFreemarkerVariables = new HashMap<String, Object>(freemarkerVariables);
    webFreemarkerVariables.put(TemplateCacheComponent.CONTENT_CACHE, new NoCacheDirective());
    webConfiguration.setAllSharedVariables(new SimpleHash(webFreemarkerVariables, webConfiguration.getObjectWrapper()));
    taskConfiguration = new Configuration(Configuration.getVersion());
    File taskFile = new File(siteComponent.getTaskTemplateFilePath());
    taskFile.mkdirs();
    taskConfiguration.setDirectoryForTemplateLoading(taskFile);
    copyConfig(adminConfiguration, taskConfiguration);
    for (Entry<String, AbstractTaskDirective> entry : directiveComponent.getTaskDirectiveMap().entrySet()) {
        freemarkerVariables.put(directivePrefix + entry.getKey(), entry.getValue());
    }
    taskConfiguration.setAllSharedVariables(new SimpleHash(freemarkerVariables, taskConfiguration.getObjectWrapper()));
}
Also used : Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) AbstractTemplateDirective(com.publiccms.common.base.AbstractTemplateDirective) SimpleHash(freemarker.template.SimpleHash) AbstractTaskDirective(com.publiccms.common.base.AbstractTaskDirective) File(java.io.File) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 2 with AbstractTaskDirective

use of com.publiccms.common.base.AbstractTaskDirective in project PublicCMS-preview by sanluan.

the class DirectiveComponent method init.

@Autowired
private void init(List<AbstractTemplateDirective> templateDirectiveList, List<AbstractTaskDirective> taskDirectiveList, List<BaseMethod> methodList) {
    for (AbstractTemplateDirective directive : templateDirectiveList) {
        if (null == directive.getName()) {
            directive.setName(getDirectiveName(directive.getClass().getSimpleName()));
        }
        templateDirectiveMap.put(directive.getName(), directive);
    }
    log.info(new StringBuilder().append(templateDirectiveMap.size()).append(" template directives created:").append(templateDirectiveMap.keySet()).toString());
    for (AbstractTaskDirective directive : taskDirectiveList) {
        if (null == directive.getName()) {
            directive.setName(getDirectiveName(directive.getClass().getSimpleName()));
        }
        taskDirectiveMap.put(directive.getName(), directive);
    }
    log.info(new StringBuilder().append(taskDirectiveMap.size()).append(" task directives created:").append(taskDirectiveMap.keySet()).toString());
    for (BaseMethod method : methodList) {
        if (null == method.getName()) {
            method.setName(StringUtils.uncapitalize(method.getClass().getSimpleName().replaceAll(methodRemoveRegex, BLANK)));
        }
        methodMap.put(method.getName(), method);
    }
    log.info(new StringBuilder().append(methodMap.size()).append(" methods created:").append(methodMap.keySet()).toString());
}
Also used : BaseMethod(com.publiccms.common.base.BaseMethod) AbstractTemplateDirective(com.publiccms.common.base.AbstractTemplateDirective) AbstractTaskDirective(com.publiccms.common.base.AbstractTaskDirective) Autowired(org.springframework.beans.factory.annotation.Autowired)

Aggregations

AbstractTaskDirective (com.publiccms.common.base.AbstractTaskDirective)2 AbstractTemplateDirective (com.publiccms.common.base.AbstractTemplateDirective)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 BaseMethod (com.publiccms.common.base.BaseMethod)1 Configuration (freemarker.template.Configuration)1 SimpleHash (freemarker.template.SimpleHash)1 File (java.io.File)1 HashMap (java.util.HashMap)1