Search in sources :

Example 1 with QNameAwareObjectWrapper

use of org.alfresco.repo.template.QNameAwareObjectWrapper in project alfresco-remote-api by Alfresco.

the class RepositoryTemplateProcessor method initConfig.

/**
 * Initialise FreeMarker Configuration
 */
protected void initConfig() {
    Configuration config = new Configuration();
    // setup template cache
    config.setCacheStorage(new StrongCacheStorage());
    config.setTemplateUpdateDelay(updateDelay);
    // setup template loaders
    List<TemplateLoader> loaders = new ArrayList<TemplateLoader>();
    for (Store apiStore : searchPath.getStores()) {
        TemplateLoader loader = apiStore.getTemplateLoader();
        if (loader == null) {
            throw new WebScriptException("Unable to retrieve template loader for Web Script store " + apiStore.getBasePath());
        }
        loaders.add(loader);
    }
    MultiTemplateLoader loader = new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()]));
    config.setTemplateLoader(loader);
    // use our custom object wrapper that can deal with QNameMap objects directly
    config.setObjectWrapper(new QNameAwareObjectWrapper());
    // rethrow any exception so we can deal with them
    config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    // turn off locale sensitive lookup - to save numerous wasted calls to nodeservice.exists()
    config.setLocalizedLookup(false);
    // set template encoding
    if (defaultEncoding != null) {
        config.setDefaultEncoding(defaultEncoding);
    }
    // set output encoding
    config.setOutputEncoding("UTF-8");
    config.setIncompatibleImprovements(new Version(2, 3, 20));
    config.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
    templateConfig = config;
}
Also used : MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) Configuration(freemarker.template.Configuration) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) Version(freemarker.template.Version) TemplateLoader(freemarker.cache.TemplateLoader) MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) ArrayList(java.util.ArrayList) Store(org.springframework.extensions.webscripts.Store) StrongCacheStorage(freemarker.cache.StrongCacheStorage) QNameAwareObjectWrapper(org.alfresco.repo.template.QNameAwareObjectWrapper)

Aggregations

MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 StrongCacheStorage (freemarker.cache.StrongCacheStorage)1 TemplateLoader (freemarker.cache.TemplateLoader)1 Configuration (freemarker.template.Configuration)1 Version (freemarker.template.Version)1 ArrayList (java.util.ArrayList)1 QNameAwareObjectWrapper (org.alfresco.repo.template.QNameAwareObjectWrapper)1 Store (org.springframework.extensions.webscripts.Store)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1