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


Java Configuration.setClassLoaderForTemplateLoading方法代码示例

本文整理汇总了Java中freemarker.template.Configuration.setClassLoaderForTemplateLoading方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setClassLoaderForTemplateLoading方法的具体用法?Java Configuration.setClassLoaderForTemplateLoading怎么用?Java Configuration.setClassLoaderForTemplateLoading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在freemarker.template.Configuration的用法示例。


在下文中一共展示了Configuration.setClassLoaderForTemplateLoading方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: render

import freemarker.template.Configuration; //导入方法依赖的package包/类
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);
        }
    }
}
 
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:22,代码来源:Context.java

示例2: templateConfiguration

import freemarker.template.Configuration; //导入方法依赖的package包/类
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;
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:17,代码来源:CCDAExporter.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: JoomlaHugoConverter

import freemarker.template.Configuration; //导入方法依赖的package包/类
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();
}
 
开发者ID:davetcc,项目名称:hugojoomla,代码行数:23,代码来源:JoomlaHugoConverter.java

示例5: init

import freemarker.template.Configuration; //导入方法依赖的package包/类
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();
	}
}
 
开发者ID:kanven,项目名称:schedule,代码行数:17,代码来源:TmplMarker.java

示例6: processIndexPageTemplate

import freemarker.template.Configuration; //导入方法依赖的package包/类
private void processIndexPageTemplate(ProjectDescriptor projectDescriptor, CustomData customData) throws IOException, URISyntaxException, TemplateException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), "template");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("project", projectDescriptor);
    root.put("customData", customData);
    Template template = cfg.getTemplate("index.ftl");
    template.process(root, new FileWriter(new File(outputDir, "index.html")));
}
 
开发者ID:gradle-guides,项目名称:gradle-site-plugin,代码行数:13,代码来源:FreemarkerSiteGenerator.java

示例7: createConfiguration

import freemarker.template.Configuration; //导入方法依赖的package包/类
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);
}
 
开发者ID:bertilmuth,项目名称:requirementsascode,代码行数:8,代码来源:FreeMarkerEngine.java

示例8: render

import freemarker.template.Configuration; //导入方法依赖的package包/类
public void render() throws IOException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), "/");
    renderPersistence(cfg);
    renderContentProvider(cfg);
    renderDbHelper(cfg);
    renderModels(cfg);
    renderMappers(cfg);
}
 
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:12,代码来源:DbContext.java

示例9: init

import freemarker.template.Configuration; //导入方法依赖的package包/类
@PostConstruct
public void init()
{
  Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
  
  cfg.setDefaultEncoding("UTF-8");
  
  String templatePath = _config.get("view.freemarker.templates",
                                   "classpath:/templates");
  
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  
  if (templatePath.startsWith("classpath:")) {
    String path = templatePath.substring(("classpath:").length());
    
    cfg.setClassLoaderForTemplateLoading(loader, path);
  }
  else {
    throw new UnsupportedOperationException();
  }
  
  cfg.setAutoFlush(false);
  
  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
  
  _cfg = cfg;
}
 
开发者ID:baratine,项目名称:baratine,代码行数:28,代码来源:ViewFreemarker.java

示例10: createTemplateConfiguration

import freemarker.template.Configuration; //导入方法依赖的package包/类
private static Configuration createTemplateConfiguration() {
	// The templates rendered by this demo application are based on Apache Freemarker.
	
	Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
	cfg.setClassLoaderForTemplateLoading(TotpExample.class.getClassLoader(), ResourcesHome.class.getPackage().getName().replace(".", "/"));
	cfg.setDefaultEncoding("UTF-8");
	
	// SECURITY NOTE: You should use the TemplateExceptionHandler.RETHROW_HANDLER in production!
	cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
	return cfg;
}
 
开发者ID:rzwitserloot,项目名称:totp-example,代码行数:12,代码来源:TotpExample.java

示例11: renderModelBindings

import freemarker.template.Configuration; //导入方法依赖的package包/类
void renderModelBindings() throws Exception {
    if (bindings.size() == 0 && allModels.size() == 0)
        return;
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), "/");

    Template bindingTemplate = cfg.getTemplate("templates/java/binding.ftl");
    for (IntentBinding binding : bindings) {
        String name = (binding.getPackageName() != null ? binding.getPackageName() + "." : "")
                + binding.getName() + "Binding";
        JavaFileObject file = this.processingEnv.getFiler()
                .createSourceFile(name, binding.getElement());
        Writer writer = file.openWriter();
        try {
            Map<String, Object> model = new HashMap<>();
            model.put("binding", binding);
            model.put("cyto", "true".equals(processingEnv.getOptions().get(UI)));
            bindingTemplate.process(model, writer);
            writer.flush();
        } catch (TemplateException err) {
            throw new IOException(err);
        }
        writer.close();
    }

    if (allModels.size() > 0) {
        Element[] elements = new Element[allModels.size()];
        int ix = 0;
        for (SimpleModel simpleModel : allModels.values()) {
            elements[ix++] = simpleModel.getElement();
            if (simpleModel instanceof ArrayModel) {
                ArrayModel arrayModel = (ArrayModel) simpleModel;
                if (arrayModel.getModel() == null)
                    ((ArrayModel) simpleModel).setModel(allModels.get(arrayModel.getModelId()));
                continue;
            }
            if (simpleModel.getParentId() != null && simpleModel.getParent() == null) {
                simpleModel.setParent(allModels.get(simpleModel.getParentId()));
                simpleModel.getProperties().addAll(simpleModel.getParent().getProperties());
            }
            for (Property property : simpleModel.getProperties()) {
                if (property.getModelId() != null) {
                    property.setModel(allModels.get(property.getModelId()));
                    if (property.getModel() == null)
                        throw new Exception("Model (" + property.getModelId() + ") not found");
                }
            }
        }

        String modelTypes = processingEnv.getOptions().get(MODEL_TYPES);
        if (modelTypes != null) {
            for (String modelType : modelTypes.split(",")) {
                String packageName = processingEnv.getOptions().get(DEFAULT_PACKAGE);
                if (packageName == null)
                    packageName = "nuclei.data";
                Context context = new Context(allModels.values(), packageName, null);
                context.render(cfg, modelType, processingEnv.getFiler());
            }
        }
    }
}
 
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:64,代码来源:AptProcessor.java


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