本文整理匯總了Java中freemarker.template.Configuration.setOutputEncoding方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.setOutputEncoding方法的具體用法?Java Configuration.setOutputEncoding怎麽用?Java Configuration.setOutputEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setOutputEncoding方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: message
import freemarker.template.Configuration; //導入方法依賴的package包/類
private String message() throws IOException, TemplateException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
cfg.setClassForTemplateLoading(EventEmail.class, "");
cfg.setLocale(Localization.getJavaLocale());
cfg.setOutputEncoding("utf-8");
Template template = cfg.getTemplate("confirmation.ftl");
Map<String, Object> input = new HashMap<String, Object>();
input.put("msg", MESSAGES);
input.put("const", CONSTANTS);
input.put("subject", subject());
input.put("event", event());
input.put("operation", request().getOperation() == null ? "NONE" : request().getOperation().name());
if (response().hasCreatedMeetings())
input.put("created", EventInterface.getMultiMeetings(response().getCreatedMeetings(), true, false));
if (response().hasDeletedMeetings())
input.put("deleted", EventInterface.getMultiMeetings(response().getDeletedMeetings(), true, false));
if (response().hasCancelledMeetings())
input.put("cancelled", EventInterface.getMultiMeetings(response().getCancelledMeetings(), true, false));
if (response().hasUpdatedMeetings())
input.put("updated", EventInterface.getMultiMeetings(response().getUpdatedMeetings(), true, false));
if (request().hasMessage())
input.put("message", request().getMessage());
if (request().getEvent().getId() != null) {
if (event().hasMeetings()) {
input.put("meetings", EventInterface.getMultiMeetings(event().getMeetings(), true, false));
} else
input.put("meetings", new TreeSet<MultiMeetingInterface>());
}
input.put("version", MESSAGES.pageVersion(Constants.getVersion(), Constants.getReleaseDate()));
input.put("ts", new Date());
input.put("link", ApplicationProperty.UniTimeUrl.value());
input.put("sessionId", iRequest.getSessionId());
StringWriter s = new StringWriter();
template.process(input, new PrintWriter(s));
s.flush(); s.close();
return s.toString();
}
示例3: FreeMarkerService
import freemarker.template.Configuration; //導入方法依賴的package包/類
private FreeMarkerService(Builder bulder) {
maxOutputLength = bulder.getMaxOutputLength();
maxThreads = bulder.getMaxThreads();
maxQueueLength = bulder.getMaxQueueLength();
maxTemplateExecutionTime = bulder.getMaxTemplateExecutionTime();
int actualMaxQueueLength = maxQueueLength != null
? maxQueueLength
: Math.max(
MIN_DEFAULT_MAX_QUEUE_LENGTH,
(int) (MAX_DEFAULT_MAX_QUEUE_LENGTH_MILLISECONDS / maxTemplateExecutionTime));
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
maxThreads, maxThreads,
THREAD_KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS,
new BlockingArrayQueue<Runnable>(actualMaxQueueLength));
threadPoolExecutor.allowCoreThreadTimeOut(true);
templateExecutor = threadPoolExecutor;
freeMarkerConfig = new Configuration(Configuration.getVersion());
freeMarkerConfig.setNewBuiltinClassResolver(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER);
freeMarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
freeMarkerConfig.setLogTemplateExceptions(false);
freeMarkerConfig.setAttemptExceptionReporter(new AttemptExceptionReporter() {
@Override
public void report(TemplateException te, Environment env) {
// Suppress it
}
});
freeMarkerConfig.setLocale(AllowedSettingValuesMaps.DEFAULT_LOCALE);
freeMarkerConfig.setTimeZone(AllowedSettingValuesMaps.DEFAULT_TIME_ZONE);
freeMarkerConfig.setOutputFormat(AllowedSettingValuesMaps.DEFAULT_OUTPUT_FORMAT);
freeMarkerConfig.setOutputEncoding("UTF-8");
}
示例4: FreemarkerTemplate
import freemarker.template.Configuration; //導入方法依賴的package包/類
public FreemarkerTemplate()
{
cfg = new Configuration();
try
{
//File cfgPath = new File(config.getConfigurationPath());
//cfg.setDirectoryForTemplateLoading( new File(cfgPath.getParent()) );
cfg.setServletContextForTemplateLoading(TernContext.getServletContext(),"/WEB-INF/views");
//cfg.setTemplateLoader(loader)
//cfg.setLocale(Locale.CHINA);
cfg.setSetting("date_format", "yyyy-MM-dd");
cfg.setSetting("time_format", "HH:mm:ss");
cfg.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss");
}
catch (Exception e)
{
cfg = null;
Trace.write(Trace.Error, e,"init freemarker failed!");
return;
}
cfg.setDefaultEncoding(config.getEncoding());
cfg.setOutputEncoding(config.getEncoding());
wrapper = new ActionDataWrapper();//ObjectWrapper.BEANS_WRAPPER;//.DEFAULT_WRAPPER;
/*wrapper = new DefaultObjectWrapper(){
public TemplateModel wrap(Object obj) throws TemplateModelException {
if(obj instanceof com.tern.dao.RecordSet){
return new freemarker.template.SimpleCollection(((com.tern.dao.RecordSet)obj).iterator(), this);
}
return super.wrap(obj);
}
};*/
cfg.setObjectWrapper(wrapper);
cfg.setTemplateExceptionHandler(new TemplateExceptionHandler(){
@Override
public void handleTemplateException(TemplateException te,
Environment env, Writer writer) throws TemplateException {
if(config.isDebug())
{
if(te.getCause() instanceof RedirectRequest)
{
throw (RedirectRequest)te.getCause();
}
TemplateExceptionHandler.HTML_DEBUG_HANDLER.handleTemplateException(te, env, writer);
}
throw te;
}
});
/*if(config.isDebug())
{
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
cfg.setTemplateUpdateDelay(0);
}
else
{
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setTemplateUpdateDelay(config.getInt("template.delay", 3600));
}*/
if(!config.isDebug())
{
cfg.setTemplateUpdateDelay(config.getInt("template.delay", 3600));
}
}