Java 类freemarker.template.DefaultObjectWrapperBuilder 实例源码

项目:kit    文件:FreeMkKit.java   
/**
 * 根据根路径的类,获取配置文件
 * @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;
}
项目:kit    文件:FreeMkKit.java   
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;
}
项目:dynamicreports-jasper    文件:GenerateClasspath.java   
public static void main(String[] args) throws Exception {
    Project project = new Project();
    Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
    cfg.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build());
    Template temp = cfg.getTemplate("src/assemblies/eclipse_classpath.ftl");
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("project", project);
    Writer out = new FileWriter(project.getOutputDirectory() + "/eclipse_classpath");
    temp.process(root, out);
    out.flush();

    project = new Project();
    cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
    cfg.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build());
    temp = cfg.getTemplate("src/assemblies/netbeans_classpath.ftl");
    root = new HashMap<String, Object>();
    root.put("project", project);
    out = new FileWriter(project.getOutputDirectory() + "/netbeans_classpath");
    temp.process(root, out);
    out.flush();
}
项目:anet    文件:ReportResource.java   
@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);
    }
}
项目:anet    文件:AnetEmailWorker.java   
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);
}
项目:revapi    文件:TextReporter.java   
/**
 * Creates a new FreeMarker configuration.
 * By default, it is configured as follows:
 * <ul>
 * <li>compatibility level is set to 2.3.23
 * <li>the object wrapper is configured to expose fields
 * <li>API builtins are enabled
 * <li>there are 2 template loaders - 1 for loading templates from /META-INF using a classloader and a second
 *     one to load templates from files.
 * </ul>
 * @return
 */
protected Configuration createFreeMarkerConfiguration() {
    DefaultObjectWrapperBuilder bld = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23);
    bld.setExposeFields(true);

    Configuration freeMarker = new Configuration(Configuration.VERSION_2_3_23);

    freeMarker.setObjectWrapper(bld.build());
    freeMarker.setAPIBuiltinEnabled(true);
    freeMarker.setTemplateLoader(new MultiTemplateLoader(
            new TemplateLoader[]{new ClassTemplateLoader(getClass(), "/META-INF"),
                    new NaiveFileTemplateLoader()}));

    return freeMarker;
}
项目:hsac-fitnesse-fixtures    文件:Environment.java   
private Environment() {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
    // Specify the data source where the template files come from.
    cfg.setClassForTemplateLoading(getClass(), "/templates/");
    DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23);
    builder.setExposeFields(true);
    cfg.setObjectWrapper(builder.build());
    freemarkerConfig = cfg;

    fmHelper = new FreeMarkerHelper();
    templateCache = new ConcurrentHashMap<String, Template>();

    symbols = new ConcurrentHashMap<String, String>();

    textFormatter = new TextFormatter();

    xmlFormatter = new XMLFormatter();
    nsContext = new NamespaceContextImpl();
    fillNamespaceContext();
    xPathHelper = new XPathHelper();

    jsonPathHelper = new JsonPathHelper();
    jsonHelper = new JsonHelper();

    htmlCleaner = new HtmlCleaner();

    httpClient = new HttpClient();

    programHelper = new ProgramHelper();
    programHelper.setTimeoutHelper(timeoutHelper);
    configDatesHelper();

    driverManager = new DriverManager();
    cookieConverter = new CookieConverter();
}
项目:windup    文件:FreeMarkerUtil.java   
/**
 * Gets the default configuration for Freemarker within Windup.
 */
public static Configuration getDefaultFreemarkerConfiguration()
{
    freemarker.template.Configuration configuration = new freemarker.template.Configuration(Configuration.VERSION_2_3_26);
    DefaultObjectWrapperBuilder objectWrapperBuilder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_26);
    objectWrapperBuilder.setUseAdaptersForContainers(true);
    objectWrapperBuilder.setIterableSupport(true);
    configuration.setObjectWrapper(objectWrapperBuilder.build());
    configuration.setAPIBuiltinEnabled(true);

    configuration.setTemplateLoader(new FurnaceFreeMarkerTemplateLoader());
    configuration.setTemplateUpdateDelayMilliseconds(3600);
    return configuration;
}
项目:FatJar    文件:FreemarkerTemplate.java   
public FreemarkerTemplate() {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23).build());
}