本文整理汇总了Java中freemarker.template.Configuration.setDefaultEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setDefaultEncoding方法的具体用法?Java Configuration.setDefaultEncoding怎么用?Java Configuration.setDefaultEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setDefaultEncoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import freemarker.template.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) {
Map<String,Object> tmp = new HashMap<>();
tmp.put("user","邢天宇");
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
StringTemplateLoader loader = new StringTemplateLoader();
loader.putTemplate(NAME,"hello ${user}");
cfg.setTemplateLoader(loader);
cfg.setDefaultEncoding("UTF-8");
try {
Template template = cfg.getTemplate(NAME);
StringWriter writer = new StringWriter();
template.process(tmp,writer);
System.out.println(writer.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: 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");
}
示例3: buildFreemarkerHelper
import freemarker.template.Configuration; //导入方法依赖的package包/类
private FreemarkerHelper buildFreemarkerHelper(File templateBaseDir) {
Configuration configuration = new Configuration(new Version(2, 3, 0));
try {
TemplateLoader templateLoader = new FileTemplateLoader(templateBaseDir);
configuration.setTemplateLoader(templateLoader);
} catch (IOException e) {
throw new GeneratorException("构建模板助手出错:" + e.getMessage());
}
configuration.setNumberFormat("###############");
configuration.setBooleanFormat("true,false");
configuration.setDefaultEncoding("UTF-8");
// 自动导入公共文件,用于支持灵活变量
if (autoIncludeFile.exists()) {
List<String> autoIncludeList = new ArrayList<>();
autoIncludeList.add(FREEMARKER_AUTO_INCLUDE_SUFFIX);
configuration.setAutoIncludes(autoIncludeList);
}
return new FreemarkerHelper(configuration);
}
示例4: templateConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
private static Configuration templateConfiguration() {
Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
configuration.setDefaultEncoding("UTF-8");
configuration.setLogTemplateExceptions(false);
try {
configuration.setSetting("object_wrapper",
"DefaultObjectWrapper(2.3.26, forceLegacyNonListCollections=false, "
+ "iterableSupport=true, exposeFields=true)");
} catch (TemplateException e) {
e.printStackTrace();
}
configuration.setAPIBuiltinEnabled(true);
configuration.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(),
"templates/ccda");
return configuration;
}
示例5: prepareConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
private static Configuration prepareConfiguration() {
Configuration result = new Configuration(Configuration.VERSION_2_3_26);
result.setNumberFormat("computer");
result.setDefaultEncoding(StandardCharsets.UTF_8.name());
result.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
result.setLogTemplateExceptions(false);
return result;
}
示例6: 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;
}
示例7: init
import freemarker.template.Configuration; //导入方法依赖的package包/类
private void init() {
if (inited) {
return;
}
lock.lock();
try {
if (!inited) {
cfg = new Configuration(Configuration.VERSION_2_3_25);
cfg.setDefaultEncoding(encode);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), tmplPath);
}
} finally {
lock.unlock();
}
}
示例8: 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;
}
示例9: getConfigurationByClass
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* 根据根路径的类,获取配置文件
* @author nan.li
* @param paramClass
* @param prefix
* @return
*/
public static Configuration getConfigurationByClass(Class<?> paramClass, String prefix)
{
try
{
Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
configuration.setClassForTemplateLoading(paramClass, prefix);
//等价于下面这种方法
// configuration.setTemplateLoader( new ClassTemplateLoader(paramClass,prefix));
configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_25));
configuration.setDefaultEncoding(CharEncoding.UTF_8);
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build());
return configuration;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
示例10: getConfigurationByClassLoader
import freemarker.template.Configuration; //导入方法依赖的package包/类
public static Configuration getConfigurationByClassLoader(ClassLoader classLoader, String prefix)
{
try
{
Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
configuration.setClassLoaderForTemplateLoading(classLoader, prefix);
//等价于下面这种方法
// configuration.setTemplateLoader( new ClassTemplateLoader(paramClass,prefix));
configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_25));
configuration.setDefaultEncoding(CharEncoding.UTF_8);
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build());
return configuration;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
示例11: getConfigurationByDirectory
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* 根据模板的路径,获取一个配置文件
* @author [email protected]
* @param templateLoadingPath
* @return
*/
public static Configuration getConfigurationByDirectory(File templateLoadingPath)
{
try
{
Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
//以下这两种设置方式是等价的
// configuration.setDirectoryForTemplateLoading(templateLoadingPath);
configuration.setTemplateLoader(new FileTemplateLoader(templateLoadingPath));
configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_25));
configuration.setDefaultEncoding(CharEncoding.UTF_8);
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build());
return configuration;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
示例12: PluginStatusReportViewBuilder
import freemarker.template.Configuration; //导入方法依赖的package包/类
private PluginStatusReportViewBuilder() throws IOException {
configuration = new Configuration(Configuration.VERSION_2_3_23);
configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
configuration.setDefaultEncoding("UTF-8");
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
configuration.setLogTemplateExceptions(false);
configuration.setDateTimeFormat("iso");
}
示例13: 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());
}
示例14: initTemplateEngineCfg
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* Initializes template engine configuration.
*/
private void initTemplateEngineCfg() {
configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");
final ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
configuration.setServletContextForTemplateLoading(servletContext, "/plugins/" + dirName);
logger.debug("Initialized template configuration:{}", dirName);
readLangs();
}
示例15: 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;
}
}