本文整理汇总了Java中freemarker.template.Configuration.setDirectoryForTemplateLoading方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setDirectoryForTemplateLoading方法的具体用法?Java Configuration.setDirectoryForTemplateLoading怎么用?Java Configuration.setDirectoryForTemplateLoading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setDirectoryForTemplateLoading方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initConfig
import freemarker.template.Configuration; //导入方法依赖的package包/类
@PostConstruct
public void initConfig() throws Exception {
Configuration configuration = new Configuration();
File file = new File(servletContext.getRealPath("/WEB-INF/layouts"));
configuration.setDirectoryForTemplateLoading(file);
configuration.setDefaultEncoding("UTF-8");
this.template = configuration.getTemplate("email.template");
}
示例2: generateResumeHTML
import freemarker.template.Configuration; //导入方法依赖的package包/类
private String generateResumeHTML(String json, String theme) throws Exception {
if (!isValidJSON(json)) {
throw new InvalidJSONException();
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
cfg.setDirectoryForTemplateLoading(new File("themes"));
cfg.setDefaultEncoding("UTF-8");
Template temp = cfg.getTemplate(theme + ".html");
//System.out.println(json);
Resume resume = gson.fromJson(json, Resume.class);
resume.getRidOfArraysWithEmptyElements();
resume.setConfig(config);
StringWriter htmlStringWriter = new StringWriter();
temp.process(resume, htmlStringWriter);
String html = htmlStringWriter.toString();
return html;
}
示例3: writeCommandCards
import freemarker.template.Configuration; //导入方法依赖的package包/类
private IStatus writeCommandCards(boolean obsRefreshFlag, String templateInputDirectory, String templateOutputDirectory) {
Writer playerArmyFile = null;
try {
Configuration config = us.nineworlds.xstreamer.core.Activator.getDefault().getFreemarkerConfig();
config.setDirectoryForTemplateLoading(new File(templateInputDirectory));
java.nio.file.Path jpath = java.nio.file.Paths.get(templateFilename);
Template armyTemplate = config.getTemplate(jpath.getFileName().toString());
playerArmyFile = new FileWriter(new File(templateOutputDirectory + File.separator + commandFilename));
Map<String, Object> input = new HashMap<>();
input.put("iaspec", iaspec);
input.put("allDeployments", Activator.getDefault().getDeploymentsLookup().getDeployments());
input.put("allCommandCards", Activator.getDefault().getCommandCardLookup().getCommandCards());
input.put("obs_refresh", obsRefreshFlag);
armyTemplate.process(input, playerArmyFile);
} catch (Exception e) {
e.printStackTrace();
return Status.CANCEL_STATUS;
} finally {
IOUtils.closeQuietly(playerArmyFile);
}
return Status.OK_STATUS;
}
示例4: initializeConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* Configures freemarker for usage.
* @return
* @throws URISyntaxException
* @throws TemplateNotFoundException
* @throws MalformedTemplateNameException
* @throws ParseException
* @throws IOException
* @throws TemplateException
*/
private Configuration initializeConfiguration() throws URISyntaxException, TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
cfg.setClassForTemplateLoading(DwFeatureModelSVGGenerator.class, "templates");
cfg.setDefaultEncoding("UTF-8");
cfg.setLocale(Locale.US);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Bundle bundle = Platform.getBundle("de.darwinspl.feature.graphical.editor");
URL fileURL = bundle.getEntry("templates/");
File file = new File(FileLocator.resolve(fileURL).toURI());
cfg.setDirectoryForTemplateLoading(file);
Map<String, TemplateNumberFormatFactory> customNumberFormats = new HashMap<String, TemplateNumberFormatFactory>();
customNumberFormats.put("hex", DwHexTemplateNumberFormatFactory.INSTANCE);
cfg.setCustomNumberFormats(customNumberFormats);
return cfg;
}
示例5: initializeConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
private Configuration initializeConfiguration() throws URISyntaxException, TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
cfg.setClassForTemplateLoading(DwFeatureModelOverviewGenerator.class, "templates");
cfg.setDefaultEncoding("UTF-8");
cfg.setLocale(Locale.US);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
Map<String, TemplateDateFormatFactory> customDateFormats = new HashMap<String, TemplateDateFormatFactory>();
customDateFormats.put("simple", DwSimpleTemplateDateFormatFactory.INSTANCE);
cfg.setCustomDateFormats(customDateFormats);
cfg.setDateTimeFormat("@simle");
Bundle bundle = Platform.getBundle("eu.hyvar.feature.graphical.editor");
URL fileURL = bundle.getEntry("templates/");
File file = new File(FileLocator.resolve(fileURL).toURI());
cfg.setDirectoryForTemplateLoading(file);
return cfg;
}
示例6: TemplateService
import freemarker.template.Configuration; //导入方法依赖的package包/类
public TemplateService() {
String templatePath = new File("").getAbsolutePath();
System.out.println("Using template path '" + templatePath + "'.");
try {
config = new Configuration(Configuration.VERSION_2_3_25);
config.setDirectoryForTemplateLoading(new File(templatePath));
config.setDefaultEncoding("UTF-8");
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
config.setLogTemplateExceptions(false);
} catch (IOException e) {
throw new FileLibraryException(e);
}
}
示例7: getTemplate
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* 获取模板
*
* @param templateName
* 模板名称(含后缀名)
* @return Template
* @throws IOException
*/
public static Template getTemplate(String templateName) throws IOException {
Configuration cfg = new Configuration();
Template temp = null;
File tmpRootFile = getResource(templateName).getFile().getParentFile();
if (tmpRootFile == null) {
throw new RuntimeException("无法取得模板根路径!");
}
try {
cfg.setDefaultEncoding("utf-8");
cfg.setOutputEncoding("utf-8");
cfg.setDirectoryForTemplateLoading(tmpRootFile);
/* cfg.setDirectoryForTemplateLoading(getResourceURL()); */
cfg.setObjectWrapper(new DefaultObjectWrapper());
temp = cfg.getTemplate(templateName);
} catch (IOException e) {
e.printStackTrace();
}
return temp;
}
示例8: createTemplateConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
private void createTemplateConfiguration(final CompositeConfiguration config, final File templatesPath) {
templateCfg = new Configuration();
templateCfg.setDefaultEncoding(config.getString(Keys.RENDER_ENCODING));
try {
templateCfg.setDirectoryForTemplateLoading(templatesPath);
} catch (IOException e) {
e.printStackTrace();
}
templateCfg.setObjectWrapper(new DefaultObjectWrapper());
}
示例9: testSpeedOfFreemarker
import freemarker.template.Configuration; //导入方法依赖的package包/类
public void testSpeedOfFreemarker() throws Exception {
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(getWorkDir());
cfg.setObjectWrapper(new BeansWrapper());
Template templ = cfg.getTemplate("template.txt");
for(int i = 0; i < whereTo.length; i++) {
Writer out = new BufferedWriter(new FileWriter(whereTo[i]));
templ.process(parameters, out);
out.close();
}
}
示例10: init
import freemarker.template.Configuration; //导入方法依赖的package包/类
@PostConstruct
public void init() throws IOException {
try {
cfg = new Configuration(Configuration.getVersion());
cfg.setDirectoryForTemplateLoading(new File(templateLocation));
cfg.setDefaultEncoding(templateEncoding);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
} catch (IOException e) {
logger.error("Problem getting rule template location." + e.getMessage());
throw e;
}
}
示例11: generateUserDockerrunFile
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* Generate a dockerrun.aws.json file with a custom user template
* @param dockerrunFilePath the location of the dockerrun template
* @param dockerrunOutputDestination the output directory
* @param parameters a map to hydrate the template with
* @throws IOException if failed to load the template file
* @throws TemplateException if template generation fails
*/
public static void generateUserDockerrunFile(
String dockerrunFilePath,
String dockerrunOutputDestination,
Map<String, Object> parameters
) throws IOException, TemplateException {
File templateFile = new File(dockerrunFilePath);
Configuration cfg = initializeTemplateConfiguration();
cfg.setDirectoryForTemplateLoading(templateFile.getParentFile());
generateFileFromTemplate(cfg, templateFile.getName(), dockerrunOutputDestination, parameters);
}
示例12: init
import freemarker.template.Configuration; //导入方法依赖的package包/类
@PostConstruct
public void init() throws IOException {
configuration = new Configuration(Configuration.VERSION_2_3_21);
File templateDir = new File(baseDir);
templateDir.mkdirs();
configuration.setDirectoryForTemplateLoading(templateDir);
}
示例13: init
import freemarker.template.Configuration; //导入方法依赖的package包/类
public void init() {
try {
configuration = new Configuration();
File root = new File("");
File absoluteFile = root.getAbsoluteFile();
configuration.setDirectoryForTemplateLoading(new File(absoluteFile + "/FreeMakerTemplate"));
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: processTemplate
import freemarker.template.Configuration; //导入方法依赖的package包/类
public static File processTemplate(File template) throws IOException, TemplateException {
Configuration config = new Configuration();
config.setDirectoryForTemplateLoading(template.getParentFile());
config.setObjectWrapper(new DefaultObjectWrapper());
config.setDefaultEncoding("UTF-8");
Template temp = config.getTemplate(template.getName());
String child = template.getName() + RandomStringUtils.randomAlphanumeric(8);
File fileOutput = new File(template.getParentFile(), child);
Writer fileWriter = new FileWriter(fileOutput);
Map<Object, Object> currentSession = Thucydides.getCurrentSession();
temp.process(currentSession, fileWriter);
return fileOutput;
}
示例15: prepareFreemarkerTemplate
import freemarker.template.Configuration; //导入方法依赖的package包/类
private File prepareFreemarkerTemplate(String filePath) throws IOException, TemplateException {
File template = getFileFromResourcesByFilePath(filePath);
Configuration config = new Configuration();
config.setDirectoryForTemplateLoading(template.getParentFile());
config.setObjectWrapper(new DefaultObjectWrapper());
config.setDefaultEncoding("UTF-8");
Template temp = config.getTemplate(template.getName());
String child = template.getName() + RandomStringUtils.randomAlphanumeric(8);
File fileOutput = new File(template.getParentFile(), child);
Writer fileWriter = new FileWriter(fileOutput);
Map<Object, Object> currentSession = Thucydides.getCurrentSession();
temp.process(currentSession, fileWriter);
return fileOutput;
}