Java Code Examples for freemarker.template.Configuration#VERSION_2_3_26

The following examples show how to use freemarker.template.Configuration#VERSION_2_3_26 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrillRestServer.java    From Bats with Apache License 2.0 7 votes vote down vote up
/**
 * Creates freemarker configuration settings,
 * default output format to trigger auto-escaping policy
 * and template loaders.
 *
 * @param servletContext servlet context
 * @return freemarker configuration settings
 */
private Configuration getFreemarkerConfiguration(ServletContext servletContext) {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);

  List<TemplateLoader> loaders = new ArrayList<>();
  loaders.add(new WebappTemplateLoader(servletContext));
  loaders.add(new ClassTemplateLoader(DrillRestServer.class, "/"));
  try {
    loaders.add(new FileTemplateLoader(new File("/")));
  } catch (IOException e) {
    logger.error("Could not set up file template loader.", e);
  }
  configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
  return configuration;
}
 
Example 2
Source File: ClinicalNoteExporter.java    From synthea with Apache License 2.0 6 votes vote down vote up
private static Configuration templateConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setDefaultEncoding("UTF-8");
  configuration.setLogTemplateExceptions(false);
  try {
    configuration.setSetting("object_wrapper",
        "DefaultObjectWrapper(2.3.26, forceLegacyNonListCollections=false, "
            + "iterableSupport=true, exposeFields=true)");
  } catch (TemplateException e) {
    e.printStackTrace();
  }
  configuration.setAPIBuiltinEnabled(true);
  configuration.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(),
      "templates/notes");
  return configuration;
}
 
Example 3
Source File: CCDAExporter.java    From synthea with Apache License 2.0 6 votes vote down vote up
private static Configuration templateConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setDefaultEncoding("UTF-8");
  configuration.setLogTemplateExceptions(false);
  try {
    configuration.setSetting("object_wrapper",
        "DefaultObjectWrapper(2.3.26, forceLegacyNonListCollections=false, "
            + "iterableSupport=true, exposeFields=true)");
  } catch (TemplateException e) {
    e.printStackTrace();
  }
  configuration.setAPIBuiltinEnabled(true);
  configuration.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(),
      "templates/ccda");
  return configuration;
}
 
Example 4
Source File: DetectBootFactory.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
public Configuration createConfiguration() {
    final Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
    configuration.setClassForTemplateLoading(Application.class, "/");
    configuration.setDefaultEncoding("UTF-8");
    configuration.setLogTemplateExceptions(true);

    return configuration;
}
 
Example 5
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 构造函数
 * @param context
 * @param templatePath  模板路径
 */
public TemplateCommentGenerator(Context context, String templatePath) {
    try {
        Document doc = null;
        File file = new File(templatePath);
        if (file.exists()) {
            doc = new SAXReader().read(file);
        } else {
            logger.error("没有找到对应注释模板:" + templatePath);
        }

        // 遍历comment 节点
        if (doc != null) {
            for (EnumNode node : EnumNode.values()) {
                Element element = doc.getRootElement().elementByID(node.value());
                if (element != null) {
                    Configuration cfg = new Configuration(Configuration.VERSION_2_3_26);
                    // 字符串清理
                    Template template = new Template(node.value(), element.getText(), cfg);
                    templates.put(node, template);
                }
            }
        }

        // 解析mybatis generator 注释配置
        CommentGeneratorConfiguration config = context.getCommentGeneratorConfiguration();
        if (config != null) {
            this.addConfigurationProperties(config.getProperties());
        }
    } catch (Exception e) {
        logger.error("注释模板XML解析失败!", e);
    }
}
 
Example 6
Source File: BootFactory.java    From hub-detect with Apache License 2.0 5 votes vote down vote up
public Configuration createConfiguration() {
    final Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
    configuration.setClassForTemplateLoading(Application.class, "/");
    configuration.setDefaultEncoding("UTF-8");
    configuration.setLogTemplateExceptions(true);

    return configuration;
}
 
Example 7
Source File: FreeMarkerEngine.java    From requirementsascode with Apache License 2.0 5 votes vote down vote up
private void createConfiguration(String basePackagePath) {
  cfg = new Configuration(Configuration.VERSION_2_3_26);
  cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), basePackagePath);
  cfg.setLogTemplateExceptions(false);
  setDefaultEncoding("UTF-8");
  setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
}
 
Example 8
Source File: FreeMarkerUtil.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: BatteryFiles.java    From synopsys-detect with Apache License 2.0 4 votes vote down vote up
public static Template asTemplate(final File fullPath) throws IOException {
    final Configuration templates = new Configuration(Configuration.VERSION_2_3_26);
    return new Template(fullPath.getName(), FileUtils.readFileToString(fullPath), templates);
}
 
Example 10
Source File: RestServerV2.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private Configuration getFreemarkerConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);
  configuration.setClassForTemplateLoading(getClass(), "/");
  return configuration;
}