本文整理汇总了Java中freemarker.template.Configuration.setObjectWrapper方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setObjectWrapper方法的具体用法?Java Configuration.setObjectWrapper怎么用?Java Configuration.setObjectWrapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.setObjectWrapper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFreemarkerConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
@Override
protected Configuration getFreemarkerConfiguration(RepoCtx ctx)
{
if (useRemoteCallbacks)
{
// as per 3.0, 3.1
return super.getFreemarkerConfiguration(ctx);
}
else
{
Configuration cfg = new Configuration();
cfg.setObjectWrapper(new DefaultObjectWrapper());
cfg.setTemplateLoader(new ClassPathRepoTemplateLoader(nodeService, contentService, defaultEncoding));
// TODO review i18n
cfg.setLocalizedLookup(false);
cfg.setIncompatibleImprovements(new Version(2, 3, 20));
cfg.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
return cfg;
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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());
}
示例7: 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();
}
}
示例8: getFreemarkerConfiguration
import freemarker.template.Configuration; //导入方法依赖的package包/类
protected Configuration getFreemarkerConfiguration(RepoCtx ctx)
{
Configuration cfg = new Configuration();
cfg.setObjectWrapper(new DefaultObjectWrapper());
// custom template loader
cfg.setTemplateLoader(new TemplateWebScriptLoader(ctx.getRepoEndPoint(), ctx.getTicket()));
// TODO review i18n
cfg.setLocalizedLookup(false);
cfg.setIncompatibleImprovements(new Version(2, 3, 20));
cfg.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
return cfg;
}
示例9: getStringConfig
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* FreeMarker configuration for loading the specified template directly from a String
*
* @param path Pseudo Path to the template
* @param template Template content
*
* @return FreeMarker configuration
*/
protected Configuration getStringConfig(String path, String template)
{
Configuration config = new Configuration();
// setup template cache
config.setCacheStorage(new MruCacheStorage(2, 0));
// use our custom loader to load a template directly from a String
StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
stringTemplateLoader.putTemplate(path, template);
config.setTemplateLoader(stringTemplateLoader);
// use our custom object wrapper that can deal with QNameMap objects directly
config.setObjectWrapper(qnameObjectWrapper);
// rethrow any exception so we can deal with them
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// set default template encoding
if (defaultEncoding != null)
{
config.setDefaultEncoding(defaultEncoding);
}
config.setIncompatibleImprovements(new Version(2, 3, 20));
config.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
return config;
}
示例10: 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;
}
示例11: 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;
}
示例12: loadTemplates
import freemarker.template.Configuration; //导入方法依赖的package包/类
@BeforeAll
public static void loadTemplates() {
loader = new ClassTemplateLoader(
BaseDocumentationTest.class,
"templates"
);
configuration = new Configuration(Configuration.getVersion());
configuration.setDefaultEncoding("UTF-8");
configuration.setTemplateLoader(loader);
configuration.setObjectWrapper(new BeansWrapper(Configuration.getVersion()));
}
示例13: showRollupEmail
import freemarker.template.Configuration; //导入方法依赖的package包/类
@GET
@Timed
@Path("/rollup")
@Produces(MediaType.TEXT_HTML)
public Response showRollupEmail(@Auth Person user, @QueryParam("startDate") Long start,
@QueryParam("endDate") Long end,
@QueryParam("orgType") OrganizationType orgType,
@QueryParam("advisorOrganizationId") Integer advisorOrgId,
@QueryParam("principalOrganizationId") Integer principalOrgId,
@QueryParam("showText") @DefaultValue("false") Boolean showReportText) {
DailyRollupEmail action = new DailyRollupEmail();
action.setStartDate(new DateTime(start));
action.setEndDate(new DateTime(end));
action.setChartOrgType(orgType);
action.setAdvisorOrganizationId(advisorOrgId);
action.setPrincipalOrganizationId(principalOrgId);
Map<String,Object> context = action.execute();
context.put("serverUrl", config.getServerUrl());
context.put(AdminSettingKeys.SECURITY_BANNER_TEXT.name(), engine.getAdminSetting(AdminSettingKeys.SECURITY_BANNER_TEXT));
context.put(AdminSettingKeys.SECURITY_BANNER_COLOR.name(), engine.getAdminSetting(AdminSettingKeys.SECURITY_BANNER_COLOR));
context.put(DailyRollupEmail.SHOW_REPORT_TEXT_FLAG, showReportText);
try {
Configuration freemarkerConfig = new Configuration(Configuration.getVersion());
freemarkerConfig.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.getVersion()).build());
freemarkerConfig.loadBuiltInEncodingMap();
freemarkerConfig.setDefaultEncoding(StandardCharsets.UTF_8.name());
freemarkerConfig.setClassForTemplateLoading(this.getClass(), "/");
freemarkerConfig.setAPIBuiltinEnabled(true);
Template temp = freemarkerConfig.getTemplate(action.getTemplateName());
StringWriter writer = new StringWriter();
temp.process(context, writer);
return Response.ok(writer.toString(), MediaType.TEXT_HTML_TYPE).build();
} catch (Exception e) {
throw new WebApplicationException(e);
}
}
示例14: AnetEmailWorker
import freemarker.template.Configuration; //导入方法依赖的package包/类
public AnetEmailWorker(Handle dbHandle, AnetConfiguration config, ScheduledExecutorService scheduler) {
this.handle = dbHandle;
this.scheduler = scheduler;
this.mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
//mapper.enableDefaultTyping();
this.emailMapper = new AnetEmailMapper();
this.fromAddr = config.getEmailFromAddr();
this.serverUrl = config.getServerUrl();
instance = this;
SmtpConfiguration smtpConfig = config.getSmtp();
props = new Properties();
props.put("mail.smtp.starttls.enable", smtpConfig.getStartTls().toString());
props.put("mail.smtp.host", smtpConfig.getHostname());
props.put("mail.smtp.port", smtpConfig.getPort().toString());
auth = null;
if (smtpConfig.getUsername() != null && smtpConfig.getUsername().trim().length() > 0) {
props.put("mail.smtp.auth", "true");
auth = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(smtpConfig.getUsername(), smtpConfig.getPassword());
}
};
}
freemarkerConfig = new Configuration(Configuration.getVersion());
freemarkerConfig.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.getVersion()).build());
freemarkerConfig.loadBuiltInEncodingMap();
freemarkerConfig.setDefaultEncoding(StandardCharsets.UTF_8.name());
freemarkerConfig.setClassForTemplateLoading(this.getClass(), "/");
freemarkerConfig.setAPIBuiltinEnabled(true);
}
示例15: sendMail
import freemarker.template.Configuration; //导入方法依赖的package包/类
@Async
@Override
public void sendMail(String to, Map<String, String> parameters, String template, String subject) {
log.debug("sendMail() - to: " + to);
MimeMessage message = mailSender.createMimeMessage();
try {
String stringDir = MailServiceImpl.class.getResource("/templates/freemarker").getPath();
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg.setDefaultEncoding("UTF-8");
File dir = new File(stringDir);
cfg.setDirectoryForTemplateLoading(dir);
cfg.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_22));
StringBuffer content = new StringBuffer();
Template temp = cfg.getTemplate(template + ".ftl");
content.append(FreeMarkerTemplateUtils.processTemplateIntoString(temp, parameters));
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(content.toString(), "text/html;charset=\"UTF-8\"");
MimeMultipart multipart = new MimeMultipart("related");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
message.setFrom(new InternetAddress(platformMailConfigurationProperties.getUser().getUsername(), platformMailConfigurationProperties.getUser().getName()));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
mailSender.send(message);
log.info("Message has been sent to: " + to);
} catch (Exception e) {
e.printStackTrace();
}
}