当前位置: 首页>>代码示例>>Java>>正文


Java Configuration.setObjectWrapper方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:LocalFeedTaskProcessor.java

示例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;
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:28,代码来源:FreeMkKit.java

示例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;
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:21,代码来源:FreeMkKit.java

示例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;
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:29,代码来源:FreeMkKit.java

示例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;
}
 
开发者ID:bill1012,项目名称:AdminEAP,代码行数:28,代码来源:FreeMarkerUtil.java

示例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());
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:11,代码来源:FreemarkerTemplateEngine.java

示例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();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:SpeedTest.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:16,代码来源:FeedTaskProcessor.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:37,代码来源:FreeMarkerProcessor.java

示例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;
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:14,代码来源:TemplateUtils.java

示例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;
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:15,代码来源:WebserviceSteps.java

示例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()));
}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:13,代码来源:BaseDocumentationTest.java

示例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);
	}
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:41,代码来源:ReportResource.java

示例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);
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:35,代码来源:AnetEmailWorker.java

示例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();
    }
}
 
开发者ID:abixen,项目名称:abixen-platform,代码行数:36,代码来源:MailServiceImpl.java


注:本文中的freemarker.template.Configuration.setObjectWrapper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。