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


Java TemplateLoader类代码示例

本文整理汇总了Java中freemarker.cache.TemplateLoader的典型用法代码示例。如果您正苦于以下问题:Java TemplateLoader类的具体用法?Java TemplateLoader怎么用?Java TemplateLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: buildFreemarkerHelper

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
private FreemarkerHelper buildFreemarkerHelper(File templateBaseDir) {
    Configuration configuration = new Configuration(new Version(2, 3, 0));
    try {
        TemplateLoader templateLoader = new FileTemplateLoader(templateBaseDir);
        configuration.setTemplateLoader(templateLoader);
    } catch (IOException e) {
        throw new GeneratorException("构建模板助手出错:" + e.getMessage());
    }
    configuration.setNumberFormat("###############");
    configuration.setBooleanFormat("true,false");
    configuration.setDefaultEncoding("UTF-8");

    // 自动导入公共文件,用于支持灵活变量
    if (autoIncludeFile.exists()) {
        List<String> autoIncludeList = new ArrayList<>();
        autoIncludeList.add(FREEMARKER_AUTO_INCLUDE_SUFFIX);
        configuration.setAutoIncludes(autoIncludeList);
    }
    return new FreemarkerHelper(configuration);
}
 
开发者ID:sgota,项目名称:tkcg,代码行数:21,代码来源:Generator.java

示例2: FreemarkerTemplateContext

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
public FreemarkerTemplateContext(File path)
{
    config = new Configuration(VERSION);
    config.setDefaultEncoding("UTF-8");
    config.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);

    try
    {
        //Web site location resources
        FileTemplateLoader fileLoader = new FileTemplateLoader(path);
        //Core common resources
        ClassTemplateLoader classLoader = new ClassTemplateLoader(WebSite.class, "/");

        config.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[]
        {
            fileLoader, classLoader
        }));
    }
    catch (IOException ex)
    {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
 
开发者ID:touwolf,项目名称:kasije,代码行数:24,代码来源:FreemarkerTemplateContext.java

示例3: freemarkerConfig

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
@Bean
public FreeMarkerConfigurer freemarkerConfig() throws IOException, TemplateException {
	final FreeMarkerConfigurationFactory factory = new FreeMarkerConfigurationFactory();

	// If overwritten use path of user
	if (isNotBlank(uaaProperties.getTemplatePath())) {
		final TemplateLoader templateLoader = getTemplateLoader(uaaProperties.getTemplatePath());
		factory.setPreTemplateLoaders(templateLoader);
	}

	// Default configurations
	factory.setPostTemplateLoaders(getTemplateLoader("classpath:/templates/"));
	factory.setDefaultEncoding("UTF-8");

	final FreeMarkerConfigurer result = new FreeMarkerConfigurer();
	result.setConfiguration(factory.createConfiguration());
	return result;
}
 
开发者ID:JanLoebel,项目名称:uaa-service,代码行数:19,代码来源:TemplateConfig.java

示例4: init

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
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);
}
 
开发者ID:garethahealy,项目名称:quota-limits-generator,代码行数:22,代码来源:YamlTemplateProcessor.java

示例5: __processTemplate

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
protected static String __processTemplate(TemplateLoader templateLoader, String templateName,
                                          Map<String, ?> parameterValues) {
    Map<String, Object> params = prepareParams(parameterValues);

    final StringWriter writer = new StringWriter();

    try {
        final Configuration configuration = new Configuration();
        configuration.setTemplateLoader(templateLoader);
        final Template template = configuration.getTemplate(templateName);
        template.process(params, writer);

        return writer.toString();
    } catch (Throwable e) {
        throw new RuntimeException("Unable to process template", e);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:18,代码来源:TemplateHelper.java

示例6: getFreemarkerConfiguration

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:24,代码来源:DrillRestServer.java

示例7: createLoaders

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
static TemplateLoader[] createLoaders(String[] locations, ServletContext servletContext) {
  Collection<TemplateLoader> templateLoaders = new ArrayList<TemplateLoader>();
  for (String location : locations) {
    String[] prefixAndBase = StringUtils.split(location, ":", 2);
    if (prefixAndBase.length != 2) {
      throw new OpenGammaRuntimeException("Invalid Freemarker template location: " + location);
    }
    String prefix = prefixAndBase[0].trim();
    String base = prefixAndBase[1].trim();
    if (SERVLET_CONTEXT.equals(prefix)) {
      templateLoaders.add(new WebappTemplateLoader(servletContext, base));
    } else if (FILE.equals(prefix)) {
      try {
        templateLoaders.add(new FileTemplateLoader(new File(base)));
      } catch (IOException e) {
        throw new OpenGammaRuntimeException("Unable to load Freemarker templates from " + base, e);
      }
    } else {
      throw new OpenGammaRuntimeException("Invalid Freemarker template location: " + location);
    }
  }
  return templateLoaders.toArray(new TemplateLoader[templateLoaders.size()]);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:FreemarkerConfigurationComponentFactory.java

示例8: __doViewInit

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
@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));
        }
    }
}
 
开发者ID:suninformation,项目名称:ymate-platform-v2,代码行数:24,代码来源:FreemarkerView.java

示例9: createFreeMarkerConfiguration

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
/**
 * Creates the {@link freemarker.template.Configuration} instance
 * and sets it up. If you want to change it (set another props, for
 * example), you can override it in inherited class and use your own
 * class in @Lang directive.
 */
protected freemarker.template.Configuration createFreeMarkerConfiguration() {
  freemarker.template.Configuration cfg = new freemarker.template.Configuration(
      freemarker.template.Configuration.VERSION_2_3_22);

  TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass().getClassLoader(), basePackage);
  cfg.setTemplateLoader(templateLoader);

  // To avoid formatting numbers using spaces and commas in SQL
  cfg.setNumberFormat("computer");

  // Because it defaults to default system encoding, we should set it always explicitly
  cfg.setDefaultEncoding(StandardCharsets.UTF_8.name());

  return cfg;
}
 
开发者ID:mybatis,项目名称:freemarker-scripting,代码行数:22,代码来源:FreeMarkerLanguageDriver.java

示例10: getAggregateTemplateLoader

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
/**
 * Return a TemplateLoader based on the given TemplateLoader list.
 * If more than one TemplateLoader has been registered, a FreeMarker
 * MultiTemplateLoader needs to be created.
 *
 * @param templateLoaders the final List of TemplateLoader instances
 * @return the aggregate TemplateLoader
 */
protected TemplateLoader getAggregateTemplateLoader(TemplateLoader[] templateLoaders) {
    int loaderCount = (templateLoaders != null ? templateLoaders.length : 0);
    switch (loaderCount) {
        case 0:
            if (log.isDebugEnabled()) {
                log.debug("No FreeMarker TemplateLoaders specified. Can be used only inner template source");
            }
            return null;
        case 1:
            if (log.isDebugEnabled()) {
                log.debug("One FreeMarker TemplateLoader registered: " + templateLoaders[0]);
            }
            return templateLoaders[0];
        default:
            TemplateLoader loader = new MultiTemplateLoader(templateLoaders);
            if (log.isDebugEnabled()) {
                log.debug("Multiple FreeMarker TemplateLoader registered: " + loader);
            }
            return loader;
    }
}
 
开发者ID:aspectran,项目名称:aspectran,代码行数:30,代码来源:FreeMarkerConfigurationFactory.java

示例11: getTemplateLoaderForPath

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
public static TemplateLoader getTemplateLoaderForPath(ResourceLoader resourceLoader, String templateLoaderPath) {
	try {
		Resource path = resourceLoader.getResource(templateLoaderPath);
		File file = path.getFile();  // will fail if not resolvable in the file system
		if (logger.isDebugEnabled()) {
			logger.debug(
					"Template loader path [" + path + "] resolved to file path [" + file.getAbsolutePath() + "]");
		}
		return new FileTemplateLoader(file);
	}
	catch (IOException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("Cannot resolve template loader path [" + templateLoaderPath +
					"] to [java.io.File]: using SpringTemplateLoader as fallback", ex);
		}
		return new SpringTemplateLoader(resourceLoader, templateLoaderPath);
	}
	
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:20,代码来源:FtlUtils.java

示例12: main

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
public static void main(String[] args){
	PluginTemplateLoader j = new PluginTemplateLoader(new TemplateLoader[]{}, null);
	System.out.println(j.pluginNameParser.getPluginName("lib/test/test.ftl"));
	String path = "[codegen]/lib/test/test.ftl";
	String pname = j.pluginNameParser.getPluginName(path);
	System.out.println(pname);
	System.out.println(path.substring(pname.length()+j.pluginNameParser.getLength()));
	
	path = "[codegen]/test.ftl";
	pname = j.pluginNameParser.getPluginName(path);
	System.out.println(pname);
	System.out.println(path.substring(pname.length()+j.pluginNameParser.getLength()));
	
	path = "[[codegen-test";
	pname = j.pluginNameParser.getPluginName(path);
	System.out.println("[["+pname);
	System.out.println("[["+path.substring(pname.length()+j.pluginNameParser.getLength()));
	

}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:21,代码来源:PluginTemplateLoader.java

示例13: lookup

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
@Override
public TemplateLookupResult lookup(TemplateLookupContext ctx) throws IOException {
	try {
		ResourceResolver matchingResolver = resolverRegistry.getSupportingResolver(ctx.getTemplateName());
		// no match, delegate to let delegate decide
		if (matchingResolver == null) {
			return delegate.lookup(ctx);
		}
		TemplateLoader matchingAdapter = adapter.adapt(matchingResolver);
		// if it is a template content (directly a string)
		// => skip locale resolution
		if (matchingAdapter instanceof StringContentTemplateLoader) {
			return ctx.lookupWithLocalizedThenAcquisitionStrategy(ctx.getTemplateName(), null);
		}
		// standard Freemarker behavior
		return delegate.lookup(ctx);
	} catch (ResolverAdapterException e) {
		LOG.debug("Failed to determine which Freemarker adapter to use for template name " + ctx.getTemplateName(), e);
		return delegate.lookup(ctx);
	}
}
 
开发者ID:groupe-sii,项目名称:ogham,代码行数:22,代码来源:SkipLocaleForStringContentTemplateLookupStrategy.java

示例14: FlexibleConfiguration

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
@Inject
public FlexibleConfiguration(final javax.ws.rs.core.Configuration config, @Optional final ServletContext servletContext) {
    super();

    final List<TemplateLoader> loaders = new ArrayList<>();
    if (servletContext != null) {
        loaders.add(new WebappTemplateLoader(servletContext));
    }
    loaders.add(new ClassTemplateLoader(FlexibleConfiguration.class, "/"));

    // Create Factory.
    this.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
    try {
        settingConfiguration(config);
    } catch (TemplateException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:19,代码来源:FlexibleConfiguration.java

示例15: FreeMarkerFormatter

import freemarker.cache.TemplateLoader; //导入依赖的package包/类
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);
    }
}
 
开发者ID:psidnell,项目名称:ofexport2,代码行数:25,代码来源:FreeMarkerFormatter.java


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