Java 类freemarker.template.TemplateExceptionHandler 实例源码

项目:dremio-oss    文件:IndexServlet.java   
@Override
public void init(ServletConfig servletConfig) throws ServletException {
  this.servletConfig = servletConfig;

  //templateCfg.setClassForTemplateLoading(getClass(), "/");
  Resource baseResource;
  try {
    baseResource = Resource.newResource(servletConfig.getInitParameter("resourceBase"));
  } catch (MalformedURLException e) {
    throw new ServletException(e);
  }
  templateCfg.setTemplateLoader(new ResourceTemplateLoader(baseResource));
  templateCfg.setDefaultEncoding("UTF-8");

  // Sets how errors will appear.
  // During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER
  // is better.
  // cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  templateCfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
}
项目:nuclei-android    文件:Context.java   
public void render(String modelType) throws IOException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setClassLoaderForTemplateLoading(SimpleModel.class.getClassLoader(), "/");
    if (!outDir.getParentFile().exists())
        outDir.getParentFile().mkdirs();
    String modelTypeName = modelType.substring(0, 1).toUpperCase() + modelType.substring(1);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("packageName", packageName);
    params.put("models", models);
    writeFile(packageName, modelTypeName, getTemplate(cfg, modelType), params);

    for (SimpleModel model : models) {
        if (model.isRender()) {
            params = new HashMap<>();
            params.put("model", model);
            writeFile(model.getPackageName(), model.getName(), getModelTemplate(cfg), params);
        }
    }
}
项目:quota-limits-generator    文件:YamlTemplateProcessor.java   
public void init() throws IOException {
    ClassTemplateLoader ctl = new ClassTemplateLoader(Application.class, "/freemarker");
    MultiTemplateLoader mtl = new MultiTemplateLoader(new TemplateLoader[] {ctl});

    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    cfg.setTemplateLoader(mtl);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);

    Pair<String, Template> clusterResourceQuota = new ImmutablePair<String, Template>("ClusterResourceQuota-ForUser", cfg.getTemplate("ClusterResourceQuota-ForUser.ftlh"));
    Pair<String, Template> bestEffortResourceLimits = new ImmutablePair<String, Template>("LimitRange-BestEffortResourceLimits", cfg.getTemplate("LimitRange-BestEffortResourceLimits.ftlh"));
    Pair<String, Template> burstableResourceLimits = new ImmutablePair<String, Template>("LimitRange-BurstableResourceLimits", cfg.getTemplate("LimitRange-BurstableResourceLimits.ftlh"));
    Pair<String, Template> maxImageCounts = new ImmutablePair<String, Template>("LimitRange-MaxImageCounts", cfg.getTemplate("LimitRange-MaxImageCounts.ftlh"));
    Pair<String, Template> bestEffort = new ImmutablePair<String, Template>("ResourceQuota-BestEffort", cfg.getTemplate("ResourceQuota-BestEffort.ftlh"));
    Pair<String, Template> notTerminatingAndNotBestEffort = new ImmutablePair<String, Template>("ResourceQuota-NotTerminating-And-NotBestEffort",
                                                                              cfg.getTemplate("ResourceQuota-NotTerminating-And-NotBestEffort.ftlh"));
    Pair<String, Template> terminating = new ImmutablePair<String, Template>("ResourceQuota-Terminating", cfg.getTemplate("ResourceQuota-Terminating.ftlh"));

    templates = Arrays.asList(clusterResourceQuota, bestEffortResourceLimits, burstableResourceLimits, maxImageCounts, bestEffort, notTerminatingAndNotBestEffort, terminating);
}
项目:DarwinSPL    文件:DwFeatureModelSVGGenerator.java   
/**
 * Configures freemarker for usage.
 * @return
 * @throws URISyntaxException
 * @throws TemplateNotFoundException
 * @throws MalformedTemplateNameException
 * @throws ParseException
 * @throws IOException
 * @throws TemplateException
 */
private Configuration initializeConfiguration() throws URISyntaxException, TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
    cfg.setClassForTemplateLoading(DwFeatureModelSVGGenerator.class, "templates");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    Bundle bundle = Platform.getBundle("de.darwinspl.feature.graphical.editor");
    URL fileURL = bundle.getEntry("templates/");

    File file = new File(FileLocator.resolve(fileURL).toURI());
    cfg.setDirectoryForTemplateLoading(file);

    Map<String, TemplateNumberFormatFactory> customNumberFormats = new HashMap<String, TemplateNumberFormatFactory>();

    customNumberFormats.put("hex", DwHexTemplateNumberFormatFactory.INSTANCE);

    cfg.setCustomNumberFormats(customNumberFormats);

    return cfg;
}
项目:DarwinSPL    文件:DwFeatureModelOverviewGenerator.java   
private Configuration initializeConfiguration() throws URISyntaxException, TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
    cfg.setClassForTemplateLoading(DwFeatureModelOverviewGenerator.class, "templates");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    Map<String, TemplateDateFormatFactory> customDateFormats = new HashMap<String, TemplateDateFormatFactory>();
    customDateFormats.put("simple", DwSimpleTemplateDateFormatFactory.INSTANCE);

    cfg.setCustomDateFormats(customDateFormats);
    cfg.setDateTimeFormat("@simle");

    Bundle bundle = Platform.getBundle("eu.hyvar.feature.graphical.editor");
    URL fileURL = bundle.getEntry("templates/");

    File file = new File(FileLocator.resolve(fileURL).toURI());
    cfg.setDirectoryForTemplateLoading(file);

    return cfg;
}
项目: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;
}
项目:hugojoomla    文件:JoomlaHugoConverter.java   
public JoomlaHugoConverter(NastyContentChecker nastyContentChecker,
                           JdbcTemplate template, String pathToOutput, String dbExtension,
                           boolean buildTags) throws IOException {

    this.dbExtension = dbExtension;

    this.nastyContentChecker = nastyContentChecker;
    this.template = template;
    this.pathToOutput = pathToOutput;
    this.buildTags = buildTags;

    Configuration cfg = new Configuration(Configuration.getVersion());
    cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), "/");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);

    categoryTemplate = cfg.getTemplate("categoryPage.toml.ftl");
    contentTemplate = cfg.getTemplate("defaultPage.toml.ftl");

    buildTags();
}
项目:schedule    文件:TmplMarker.java   
private void init() {
    if (inited) {
        return;
    }
    lock.lock();
    try {
        if (!inited) {
            cfg = new Configuration(Configuration.VERSION_2_3_25);
            cfg.setDefaultEncoding(encode);
            cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
            cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), tmplPath);
        }
    } finally {
        lock.unlock();
    }
}
项目:robotframework-filelibrary    文件:TemplateService.java   
public TemplateService() {

        String templatePath = new File("").getAbsolutePath();
        System.out.println("Using template path '" + templatePath + "'.");

        try {
            config = new Configuration(Configuration.VERSION_2_3_25);
            config.setDirectoryForTemplateLoading(new File(templatePath));
            config.setDefaultEncoding("UTF-8");
            config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
            config.setLogTemplateExceptions(false);
        } catch (IOException e) {
            throw new FileLibraryException(e);
        }

    }
项目:raml-module-builder    文件:SchemaMaker.java   
/**
 * @param onTable
 */
public SchemaMaker(String tenant, String module, TenantOperation mode, String previousVersion, String rmbVersion){
  if(SchemaMaker.cfg == null){
    //do this ONLY ONCE
    SchemaMaker.cfg = new Configuration(new Version(2, 3, 26));
    // Where do we load the templates from:
    cfg.setClassForTemplateLoading(SchemaMaker.class, "/templates/db_scripts");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  }
  this.tenant = tenant;
  this.module = module;
  this.mode = mode;
  this.previousVersion = previousVersion;
  this.rmbVersion = rmbVersion;
}
项目:ymate-platform-v2    文件:FreemarkerView.java   
@Override
protected void __doViewInit(IWebMvc owner) {
    super.__doViewInit(owner);
    // 初始化Freemarker模板引擎配置
    if (__freemarkerConfig == null) {
        __freemarkerConfig = new Configuration(Configuration.VERSION_2_3_22);
        __freemarkerConfig.setDefaultEncoding(owner.getModuleCfg().getDefaultCharsetEncoding());
        __freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        //
        List<TemplateLoader> _tmpLoaders = new ArrayList<TemplateLoader>();
        try {
            if (__baseViewPath.startsWith("/WEB-INF")) {
                _tmpLoaders.add(new FileTemplateLoader(new File(RuntimeUtils.getRootPath(), StringUtils.substringAfter(__baseViewPath, "/WEB-INF/"))));
            } else {
                _tmpLoaders.add(new FileTemplateLoader(new File(__baseViewPath)));
            }
            //
            __freemarkerConfig.setTemplateLoader(new MultiTemplateLoader(_tmpLoaders.toArray(new TemplateLoader[_tmpLoaders.size()])));
        } catch (IOException e) {
            throw new Error(RuntimeUtils.unwrapThrow(e));
        }
    }
}
项目:nifty-flow    文件:FreemarkerConfiguration.java   
Configuration createConfiguration() throws IOException {
        // Create your Configuration instance, and specify if up to what FreeMarker
// version (here 2.3.22) do you want to apply the fixes that are not 100%
// backward-compatible. See the Configuration JavaDoc for details.
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);

// Specify the source where the template files come from. Here I set a
// plain directory for it, but non-file-system sources are possible too:
        cfg.setDirectoryForTemplateLoading(new File("/"));

// Set the preferred charset template files are stored in. UTF-8 is
// a good choice in most applications:
        cfg.setDefaultEncoding("UTF-8");

// Sets how errors will appear.
// During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER is better.
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

        cfg.setTemplateLoader(new ClassTemplateLoader());

        return cfg;
    }
项目:ogham    文件:AbstractFreemarkerBuilder.java   
private Configuration buildConfiguration() {
    Configuration builtConfiguration;
    if (this.configuration != null) {
        builtConfiguration = this.configuration;
    } else if (configurationBuilder != null) {
        builtConfiguration = configurationBuilder.build();
    } else {
        builtConfiguration = new Configuration(DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        builtConfiguration.setDefaultEncoding("UTF-8");
        builtConfiguration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    }
    FirstSupportingResourceResolver builtResolver = buildResolver();
    FirstSupportingResolverAdapter builtAdapter = buildAdapter();
    builtConfiguration.setTemplateLoader(new FreeMarkerFirstSupportingTemplateLoader(builtResolver, builtAdapter));
    builtConfiguration.setTemplateLookupStrategy(new SkipLocaleForStringContentTemplateLookupStrategy(builtConfiguration.getTemplateLookupStrategy(), builtResolver, builtAdapter));
    return builtConfiguration;
}
项目:Improve    文件:FreemarkerRender.java   
/**
 * 初始化freemarker配置
 * 
 */
public void initialize() {
    try {
        if (templateconfig == null) {
            templateconfig = new Configuration();
            templateconfig
                    .setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
            templateconfig.setObjectWrapper(ObjectWrapper.DEFAULT_WRAPPER);
            templateconfig.setTemplateLoader(new ClassTemplateLoader(this
                    .getClass(), "/"));
            templateconfig.setTemplateUpdateDelay(1200);
            templateconfig.setDefaultEncoding("gb2312");
            templateconfig.setLocale(new java.util.Locale("zh_CN"));
            templateconfig.setNumberFormat("0.##########");
        }
    } catch (Exception e) {
    }
}
项目:Improve    文件:FreemarkerRender.java   
/**
 * 初始化freemarker配置
 *
 */
public void initialize()
{
    try
    {
        if (templateconfig==null)
        {
            templateconfig = new Configuration();
            templateconfig.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
            templateconfig.setObjectWrapper(ObjectWrapper.DEFAULT_WRAPPER);
            templateconfig.setTemplateLoader(new ClassTemplateLoader(this.getClass(),"/"));
            templateconfig.setTemplateUpdateDelay(1200);
            templateconfig.setDefaultEncoding("gb2312");
            templateconfig.setLocale(new java.util.Locale("zh_CN"));
            templateconfig.setNumberFormat("0.##########");
        }
    }
    catch (Exception e)
    {}
}
项目:contribution    文件:TemplateProcessor.java   
/**
 * Generates output file with release notes using FreeMarker.
 * @param variables the map which represents template variables.
 * @param outputFile output file.
 * @param templateFilename template name.
 * @throws IOException if I/O error occurs.
 * @throws TemplateException if an error occurs while generating freemarker template.
 */
public static void generateWithFreemarker(Map<String, Object> variables, String outputFile,
        String templateFilename) throws IOException, TemplateException {

    final Configuration configuration = new Configuration(Configuration.VERSION_2_3_22);
    configuration.setDefaultEncoding("UTF-8");
    configuration.setLocale(Locale.US);
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setNumberFormat("0.######");
    configuration.setClassForTemplateLoading(Main.class, "/" + TEMPLATE_FOLDER_PATH);

    final Template template = configuration.getTemplate(templateFilename);
    try (Writer fileWriter = new OutputStreamWriter(
            new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
        template.process(variables, fileWriter);
    }
}
项目:WebSphere-Deployment-Xml-Tool    文件:DeploymentXmlWriter.java   
public void save() throws Exception {
    genTime = new Date().getTime();
    deploymentXmlFile.getParentFile().mkdirs();

    Configuration cfg = new Configuration(new Version(2, 3, 22));
    cfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), "templates");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    Template template = cfg.getTemplate("parent_last.ftl");

    FileOutputStream outputStream = new FileOutputStream(deploymentXmlFile);
    Writer out = new OutputStreamWriter(outputStream);
    template.process(this, out);
    outputStream.flush();
    outputStream.close();
}
项目:private-freemarker    文件:FreemarkerConfiguration.java   
public static Template getTemplate(String name) {
    Template template = null;
    try {
        Version version = new Version("2.3.0");
        Configuration cfg = new Configuration(version);
        // 读取ftl模板
        cfg.setClassForTemplateLoading(FreemarkerConfiguration.class, "/ftl");
        cfg.setClassicCompatible(true);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        cfg.setObjectWrapper(new SaicObjectWrapper(cfg.getIncompatibleImprovements()));
        template = cfg.getTemplate(name);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return template;
}
项目:freemarker-dynamic-ql-builder    文件:ParamMethodTest.java   
@Before
public void setUp() throws Exception {
    freemarkerConfiguration = new Configuration(Configuration.VERSION_2_3_23);

    templateLoader = new StringTemplateLoader();

    freemarkerConfiguration.setTemplateLoader(templateLoader);
    freemarkerConfiguration.setDefaultEncoding("UTF-8");
    freemarkerConfiguration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    freemarkerConfiguration.setNumberFormat("0.######");

    parameterConverters = new HashMap<String, ParameterConverter>();
    parameterConverters.put("booleanToYn", booleanToYn);
    parameterConverters.put("dateToTime", dateToTime);

    unwrapper = new TemplateModelObjectUnwrapperDefaultImpl();
    paramMethod = new ParamMethod(unwrapper, parameterConverters, withPositionalIndex);

    dataModel = new HashMap<String, Object>();
}
项目:JobHunter    文件:FreeMarkerRenderer.java   
public FreeMarkerRenderer() {
    cfg = new Configuration();

    if(ApplicationState.isDevelopment()){
        try {
            cfg.setDirectoryForTemplateLoading(new File("src/main/resources/templates/"));
        } catch (IOException e) {
            l.error("Failed to access path", e);
        }
    }else{
        cfg.setClassForTemplateLoading(this.getClass(), "/templates/");
    }

    cfg.setObjectWrapper(new DefaultObjectWrapper());
       cfg.setDefaultEncoding("UTF-8");
       cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
}
项目:ofexport2    文件:FreeMarkerFormatter.java   
public FreeMarkerFormatter(String templateName) throws IOException {
    // If the resource doesn't exist abort so we can look elsewhere
    try (
        InputStream in = this.getClass().getResourceAsStream(TEMPLATES + "/" + templateName)) {
        if (in == null) {
            throw new IOException("Resource not found:" + templateName);
        }
    }

    this.templateName = templateName;

    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), TEMPLATES);
    cfg.setTemplateLoader(templateLoader);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    // This is fatal - bomb out of application
    try {
        template = cfg.getTemplate(templateName);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
项目:private-freemarker    文件:FreemarkerConfiguration.java   
public static Template getTemplate(String name) {
    Template template = null;
    try {
        Version version = new Version("2.3.0");
        Configuration cfg = new Configuration(version);
        // 读取ftl模板
        cfg.setClassForTemplateLoading(FreemarkerConfiguration.class, "/ftl");
        cfg.setClassicCompatible(true);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        cfg.setObjectWrapper(new SaicObjectWrapper(cfg.getIncompatibleImprovements()));
        template = cfg.getTemplate(name);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return template;
}
项目:pinot    文件:AnomalyReportGenerator.java   
void buildEmailTemplateAndSendAlert(Map<String, Object> paramMap,
    SmtpConfiguration smtpConfiguration, String subject, String emailRecipients,
    String fromEmail, HtmlEmail email) {
  if (Strings.isNullOrEmpty(fromEmail)) {
    throw new IllegalArgumentException("Invalid sender's email");
  }

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try (Writer out = new OutputStreamWriter(baos, AlertTaskRunnerV2.CHARSET)) {
    Configuration freemarkerConfig = new Configuration(Configuration.VERSION_2_3_21);
    freemarkerConfig.setClassForTemplateLoading(getClass(), "/com/linkedin/thirdeye/detector");
    freemarkerConfig.setDefaultEncoding(AlertTaskRunnerV2.CHARSET);
    freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    Template template = freemarkerConfig.getTemplate(MULTIPLE_ANOMALIES_EMAIL_TEMPLATE);

    template.process(paramMap, out);

    String alertEmailHtml = new String(baos.toByteArray(), AlertTaskRunnerV2.CHARSET);
    EmailHelper.sendEmailWithHtml(email, smtpConfiguration, subject, alertEmailHtml, fromEmail,
        emailRecipients);
  } catch (Exception e) {
    Throwables.propagate(e);
  }
}
项目:ToughRadius    文件:Freemarker.java   
public  void start() {
    try {
        cfg = new Configuration();
        cfg.setDirectoryForTemplateLoading(new File("templates"));
        cfg.setTemplateUpdateDelay(0);
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        cfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
        cfg.setDefaultEncoding("utf-8");
        cfg.setLocale(Locale.CHINESE);
        cfg.setSharedVariable("sitename", config.getString("radius.version"));
        cfg.setSharedVariable("context", context);

    } catch (Exception e) {
        log.error("freemarker init error", e);
    }

}
项目:log-synth    文件:HeaderSampler.java   
private void setupTemplate() throws IOException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setTemplateLoader(new ClassTemplateLoader(getClass(), "/web-headers"));
    String templateName = "header";
    switch (headerType) {
        case MAL3:
            templateName = "mal3";
            break;
        case ABABIL:
            templateName = "ababil";
            break;
        default:
            break;
    }
    template = cfg.getTemplate(templateName);
}
项目:kubernetes-elastic-agents    文件:PluginStatusReportViewBuilder.java   
private PluginStatusReportViewBuilder() throws IOException {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setLogTemplateExceptions(false);
    configuration.setDateTimeFormat("iso");
}
项目:incubator-netbeans    文件:ProcessorTest.java   
static void apply(FileObject template, Writer w, Map<String,? extends Object> values, TemplateExceptionHandler teh) throws Exception {
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine eng = mgr.getEngineByName("freemarker");
    assertNotNull("We do have such engine", eng);
    eng.getContext().setWriter(w);
    eng.getContext().setAttribute(FileObject.class.getName(), template, ScriptContext.ENGINE_SCOPE);
    eng.getContext().getBindings(ScriptContext.ENGINE_SCOPE).putAll(values);
    if (teh != null) {
        eng.getContext().setAttribute("org.netbeans.libs.freemarker.exceptionHandler", teh, ScriptContext.ENGINE_SCOPE);
    }
    eng.eval(new InputStreamReader(template.getInputStream()));
}
项目:solo-spring    文件:Skins.java   
/**
 * Sets the directory for template loading with the specified skin directory
 * name, and sets the directory for mobile request template loading.
 *
 * @param skinDirName
 *            the specified skin directory name
 */
public static void setDirectoryForTemplateLoading(final String skinDirName) {
    final ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();

    Templates.MAIN_CFG.setServletContextForTemplateLoading(servletContext, "/skins/" + skinDirName);
    Templates.MAIN_CFG.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    Templates.MAIN_CFG.setLogTemplateExceptions(false);

    Templates.MOBILE_CFG.setServletContextForTemplateLoading(servletContext, "/skins/mobile");
    Templates.MOBILE_CFG.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    Templates.MOBILE_CFG.setLogTemplateExceptions(false);
}
项目:springboot-jsp-generator    文件:ApplicationContext.java   
@Bean(name="freeMarkerCfg")
    public freemarker.template.Configuration freemarkerConfig() throws IOException { 
        freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_25);
        cfg.setDirectoryForTemplateLoading(new File(templateFolder));
//        cfg.setClassForTemplateLoading(this.getClass(), "templates");
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        cfg.setLogTemplateExceptions(false);
        return cfg; 
    }
项目:support-rulesengine    文件:RuleCreator.java   
@PostConstruct
public void init() throws IOException {
  try {
    cfg = new Configuration(Configuration.getVersion());
    cfg.setDirectoryForTemplateLoading(new File(templateLocation));
    cfg.setDefaultEncoding(templateEncoding);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  } catch (IOException e) {
    logger.error("Problem getting rule template location." + e.getMessage());
    throw e;
  }
}
项目:magic-beanstalk    文件:FileGenerator.java   
private static Configuration initializeTemplateConfiguration() throws IOException {
  Configuration cfg = new Configuration(Configuration.getVersion());
  cfg.setDefaultEncoding("UTF-8");
  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  cfg.setLogTemplateExceptions(false);
  return cfg;
}
项目:tscfg-docgen    文件:FreemarkerDocGenerator.java   
private void initFreeMarkerConfig() {
  freeMarkerConfig = new freemarker.template.Configuration(
      freemarker.template.Configuration.VERSION_2_3_26);
  freeMarkerConfig.setDefaultEncoding(StandardCharsets.UTF_8.name());
  freeMarkerConfig.setTemplateExceptionHandler(
      TemplateExceptionHandler.RETHROW_HANDLER);
  freeMarkerConfig.setLogTemplateExceptions(false);
}
项目:alfresco-repository    文件:FreeMarkerProcessor.java   
/**
 * 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;
}
项目:tck    文件:Reporter.java   
private static Configuration createFreemarkerConfiguration() {
    Configuration cfg = new Configuration();
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler( TemplateExceptionHandler.RETHROW_HANDLER );
    cfg.setClassForTemplateLoading( Reporter.class, "/" );
    return cfg;
}
项目:dotwebstack-framework    文件:TemplateProcessor.java   
private static Configuration prepareConfiguration() {
  Configuration result = new Configuration(Configuration.VERSION_2_3_26);

  result.setNumberFormat("computer");
  result.setDefaultEncoding(StandardCharsets.UTF_8.name());
  result.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  result.setLogTemplateExceptions(false);

  return result;
}
项目:mensa-api    文件:FreemarkerConfig.java   
@Bean
public freemarker.template.Configuration configuration() {
    freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_26);
    cfg.setClassForTemplateLoading(this.getClass(), "/templates");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    return cfg;
}
项目:helpdesk    文件:PageTemplateServiceImpl.java   
public PageTemplateServiceImpl() {
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.CHINESE);
    cfg.setNumberFormat("0.######"); // now it will print 1000000
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
    cfg.setLogTemplateExceptions(false);
}