use of freemarker.cache.MultiTemplateLoader in project freemarker by apache.
the class GetOptionalTemplateTest method createConfiguration.
@Override
protected Configuration createConfiguration() throws Exception {
Configuration cfg = super.createConfiguration();
cfg.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[] { new StringTemplateLoader(), byteArrayTemplateLoader }));
return cfg;
}
use of freemarker.cache.MultiTemplateLoader in project spring-framework by spring-projects.
the class FreeMarkerConfigurerTests method freeMarkerConfigurerWithResourceLoaderPath.
@Test
public void freeMarkerConfigurerWithResourceLoaderPath() throws Exception {
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
freeMarkerConfigurer.afterPropertiesSet();
Configuration cfg = freeMarkerConfigurer.getConfiguration();
assertThat(cfg.getTemplateLoader()).isInstanceOf(MultiTemplateLoader.class);
MultiTemplateLoader multiTemplateLoader = (MultiTemplateLoader) cfg.getTemplateLoader();
assertThat(multiTemplateLoader.getTemplateLoader(0)).isInstanceOf(SpringTemplateLoader.class);
assertThat(multiTemplateLoader.getTemplateLoader(1)).isInstanceOf(ClassTemplateLoader.class);
}
use of freemarker.cache.MultiTemplateLoader in project spring-framework by spring-projects.
the class FreeMarkerConfigurerTests method freeMarkerConfigurerWithResourceLoaderPath.
@Test
public void freeMarkerConfigurerWithResourceLoaderPath() throws Exception {
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
freeMarkerConfigurer.afterPropertiesSet();
Configuration cfg = freeMarkerConfigurer.getConfiguration();
assertThat(cfg.getTemplateLoader()).isInstanceOf(MultiTemplateLoader.class);
MultiTemplateLoader multiTemplateLoader = (MultiTemplateLoader) cfg.getTemplateLoader();
assertThat(multiTemplateLoader.getTemplateLoader(0)).isInstanceOf(SpringTemplateLoader.class);
assertThat(multiTemplateLoader.getTemplateLoader(1)).isInstanceOf(ClassTemplateLoader.class);
}
use of freemarker.cache.MultiTemplateLoader 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;
}
use of freemarker.cache.MultiTemplateLoader in project jforum2 by rafaelsteil.
the class JForumBaseServlet method init.
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
String appPath = config.getServletContext().getRealPath("");
debug = "true".equals(config.getInitParameter("development"));
DOMConfigurator.configure(appPath + "/WEB-INF/log4j.xml");
logger.info("Starting JForum. Debug mode is " + debug);
ConfigLoader.startSystemglobals(appPath);
ConfigLoader.startCacheEngine();
// Configure the template engine
Configuration templateCfg = new Configuration();
templateCfg.setTemplateUpdateDelay(2);
templateCfg.setSetting("number_format", "#");
templateCfg.setSharedVariable("startupTime", new Long(new Date().getTime()));
// Create the default template loader
String defaultPath = SystemGlobals.getApplicationPath() + "/templates";
FileTemplateLoader defaultLoader = new FileTemplateLoader(new File(defaultPath));
String extraTemplatePath = SystemGlobals.getValue(ConfigKeys.FREEMARKER_EXTRA_TEMPLATE_PATH);
if (StringUtils.isNotBlank(extraTemplatePath)) {
// An extra template path is configured, we need a MultiTemplateLoader
FileTemplateLoader extraLoader = new FileTemplateLoader(new File(extraTemplatePath));
TemplateLoader[] loaders = new TemplateLoader[] { extraLoader, defaultLoader };
MultiTemplateLoader multiLoader = new MultiTemplateLoader(loaders);
templateCfg.setTemplateLoader(multiLoader);
} else {
// An extra template path is not configured, we only need the default loader
templateCfg.setTemplateLoader(defaultLoader);
}
ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR));
this.loadConfigStuff();
if (!this.debug) {
templateCfg.setTemplateUpdateDelay(3600);
}
JForumExecutionContext.setTemplateConfig(templateCfg);
} catch (Exception e) {
throw new ForumStartupException("Error while starting JForum", e);
}
}
Aggregations