本文整理匯總了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;
}
}