use of freemarker.template.Configuration in project jforum2 by rafaelsteil.
the class TestCaseUtils method init.
private void init() throws IOException {
getRootDir();
SystemGlobals.initGlobals(this.rootDir, this.rootDir + "/WEB-INF/config/SystemGlobals.properties");
if (new File(SystemGlobals.getValue(ConfigKeys.INSTALLATION_CONFIG)).exists()) {
SystemGlobals.loadAdditionalDefaults(SystemGlobals.getValue(ConfigKeys.INSTALLATION_CONFIG));
}
// Configure the template engine
Configuration templateCfg = new Configuration();
templateCfg.setDirectoryForTemplateLoading(new File(SystemGlobals.getApplicationPath() + "/templates"));
templateCfg.setTemplateUpdateDelay(0);
JForumExecutionContext.setTemplateConfig(templateCfg);
I18n.load();
}
use of freemarker.template.Configuration in project spring-framework by spring-projects.
the class FreeMarkerConfigurationFactory method createConfiguration.
/**
* Prepare the FreeMarker Configuration and return it.
* @return the FreeMarker Configuration object
* @throws IOException if the config file wasn't found
* @throws TemplateException on FreeMarker initialization failure
*/
public Configuration createConfiguration() throws IOException, TemplateException {
Configuration config = newConfiguration();
Properties props = new Properties();
// Load config file if specified.
if (this.configLocation != null) {
if (logger.isInfoEnabled()) {
logger.info("Loading FreeMarker configuration from " + this.configLocation);
}
PropertiesLoaderUtils.fillProperties(props, this.configLocation);
}
// Merge local properties if specified.
if (this.freemarkerSettings != null) {
props.putAll(this.freemarkerSettings);
}
// setAllSharedVariables methods.
if (!props.isEmpty()) {
config.setSettings(props);
}
if (!CollectionUtils.isEmpty(this.freemarkerVariables)) {
config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper()));
}
if (this.defaultEncoding != null) {
config.setDefaultEncoding(this.defaultEncoding);
}
List<TemplateLoader> templateLoaders = new LinkedList<>(this.templateLoaders);
// Register template loaders that are supposed to kick in early.
if (this.preTemplateLoaders != null) {
templateLoaders.addAll(this.preTemplateLoaders);
}
// Register default template loaders.
if (this.templateLoaderPaths != null) {
for (String path : this.templateLoaderPaths) {
templateLoaders.add(getTemplateLoaderForPath(path));
}
}
postProcessTemplateLoaders(templateLoaders);
// Register template loaders that are supposed to kick in late.
if (this.postTemplateLoaders != null) {
templateLoaders.addAll(this.postTemplateLoaders);
}
TemplateLoader loader = getAggregateTemplateLoader(templateLoaders);
if (loader != null) {
config.setTemplateLoader(loader);
}
postProcessConfiguration(config);
return config;
}
use of freemarker.template.Configuration in project spring-framework by spring-projects.
the class FreeMarkerConfigurerTests method freeMarkerConfigurationFactoryBeanWithResourceLoaderPath.
@Test
public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
fcfb.setTemplateLoaderPath("file:/mydir");
fcfb.afterPropertiesSet();
Configuration cfg = fcfb.getObject();
assertTrue(cfg.getTemplateLoader() instanceof SpringTemplateLoader);
}
use of freemarker.template.Configuration in project camel by apache.
the class SpringBootStarterMojo method getTemplate.
private Template getTemplate(String name) throws IOException {
Configuration cfg = new Configuration(Configuration.getVersion());
cfg.setTemplateLoader(new URLTemplateLoader() {
@Override
protected URL getURL(String name) {
return SpringBootStarterMojo.class.getResource("/" + name);
}
});
cfg.setDefaultEncoding("UTF-8");
Template template = cfg.getTemplate(name);
return template;
}
use of freemarker.template.Configuration in project greenDAO by greenrobot.
the class DaoGenerator method getConfiguration.
private Configuration getConfiguration(String probingTemplate) throws IOException {
Configuration config = new Configuration(Configuration.VERSION_2_3_23);
config.setClassForTemplateLoading(getClass(), "/");
try {
config.getTemplate(probingTemplate);
} catch (TemplateNotFoundException e) {
// When running from an IDE like IntelliJ, class loading resources may fail for some reason (Gradle is OK)
// Working dir is module dir
File dir = new File("src/main/resources/");
if (!dir.exists()) {
// Working dir is base module dir
dir = new File("DaoGenerator/src/main/resources/");
}
if (dir.exists() && new File(dir, probingTemplate).exists()) {
config.setDirectoryForTemplateLoading(dir);
config.getTemplate(probingTemplate);
} else {
throw e;
}
}
return config;
}
Aggregations