當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。