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


Java ClassTemplateLoader类代码示例

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


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

示例1: FreemarkerTemplateContext

import freemarker.cache.ClassTemplateLoader; //导入依赖的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

示例2: init

import freemarker.cache.ClassTemplateLoader; //导入依赖的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

示例3: simpleCfg

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
/**
 * 创建默认配置的{@link Configuration}实例
 * @return
 */
public static Configuration simpleCfg() throws TemplateException {
	Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
	cfg.setDefaultEncoding("UTF-8");
	cfg.setSetting("locale", "zh_CN");
	//cfg.setSetting("template_update_delay", "3600");
	cfg.setSetting("classic_compatible", "true");
	cfg.setSetting("number_format", "#.##");
	cfg.setSetting("tag_syntax", "auto_detect");
	cfg.setTemplateLoader(new ClassTemplateLoader(Freemarkers.class, "/"));
	
	//因classic_compatible=true且对象的Date类型属性为null时,表达式${obj.birth?datetime}会抛异常,所以自定义格式化
	Map<String, TemplateDateFormatFactory> customDateFormats = new HashMap<>();
	customDateFormats.put("date", JavaTemplateDateFormatFactory.INSTANCE);
	cfg.setCustomDateFormats(customDateFormats);
	
	cfg.setSetting("datetime_format", "@date yyyy-MM-dd HH:mm:ss");
	cfg.setSetting("date_format", "@date yyyy-MM-dd");
	cfg.setSetting("time_format", "@date HH:mm:ss");
	return cfg;
}
 
开发者ID:easycodebox,项目名称:easycode,代码行数:25,代码来源:Freemarkers.java

示例4: getFreemarkerConfiguration

import freemarker.cache.ClassTemplateLoader; //导入依赖的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

示例5: createRouteBuilder

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        public void configure() throws Exception {
            FreemarkerEndpoint endpoint = new FreemarkerEndpoint();
            endpoint.setCamelContext(context);
            endpoint.setResourceUri("org/apache/camel/component/freemarker/example.ftl");

            Configuration configuraiton = new Configuration();
            configuraiton.setTemplateLoader(new ClassTemplateLoader(Resource.class, "/"));
            endpoint.setConfiguration(configuraiton);

            context.addEndpoint("free", endpoint);

            from("direct:a").to("free");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:FreemarkerEndpointTest.java

示例6: createFreeMarkerConfiguration

import freemarker.cache.ClassTemplateLoader; //导入依赖的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

示例7: createConfiguration

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
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;
    }
 
开发者ID:albertonavarro,项目名称:nifty-flow,代码行数:23,代码来源:FreemarkerConfiguration.java

示例8: initialize

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
/**
 * 初始化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) {
	}
}
 
开发者ID:RayleighChen,项目名称:Improve,代码行数:22,代码来源:FreemarkerRender.java

示例9: initialize

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
/**
 * 初始化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)
	{}
}
 
开发者ID:RayleighChen,项目名称:Improve,代码行数:24,代码来源:FreemarkerRender.java

示例10: setupTemplateLoader

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
protected void setupTemplateLoader() {
	if (ddlTemplateFileDir != null) {
		try {
			FileTemplateLoader templateLoader = new FileTemplateLoader(new File("./" + ddlTemplateFileDir));
			templateLoaderList.add(templateLoader);
		} catch (IOException e) {
			// configurationが設定されているにも関わらず到達できない
			throw new IllegalArgumentException("failed to reach project resource", e);
		}
	}

	if (url != null) {
		String[] urlTokens = StringUtils.split(url, ':');
		if(urlTokens.length < 3) {
			throw new IllegalArgumentException("url isn't jdbc url format.");
		}
		templateLoaderList.add(
				new ClassTemplateLoader(Erd.class, "/jp/co/tis/gsp/tools/db/template/"
						+urlTokens[1]+"/")
		);
	}

	templateLoaderList.add(
			new ClassTemplateLoader(AbstractDbObjectParser.class, "/jp/co/tis/gsp/tools/db/template/"));
}
 
开发者ID:coastland,项目名称:gsp-dba-maven-plugin,代码行数:26,代码来源:AbstractDbObjectParser.java

示例11: FlexibleConfiguration

import freemarker.cache.ClassTemplateLoader; //导入依赖的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

示例12: FreeMarkerFormatter

import freemarker.cache.ClassTemplateLoader; //导入依赖的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

示例13: AbstractPrintGeneratingTest

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
AbstractPrintGeneratingTest() {
  targetDirectory.mkdirs();

  try {
    freeMarkerConfiguration = new Configuration();
    freeMarkerConfiguration.setTemplateLoader(new ClassTemplateLoader(Class.class, "/"));
    //freeMarkerConfiguration.setDirectoryForTemplateLoading(new File(templateDirectory).getAbsoluteFile());
    freeMarkerConfiguration.setObjectWrapper(new DefaultObjectWrapper());
    freeMarkerConfiguration.setDefaultEncoding("UTF-8");
    freeMarkerConfiguration.setTemplateExceptionHandler(HTML_DEBUG_HANDLER);
    freeMarkerConfiguration.setIncompatibleImprovements(new Version(2, 3, 20));

    printsRendererService.setFreeMarkerConfiguration(freeMarkerConfiguration);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:tunguski,项目名称:matsuo-core,代码行数:18,代码来源:AbstractPrintGeneratingTest.java

示例14: setupFreemarkerConfig

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
private static Configuration setupFreemarkerConfig(Class[] classTemplateLookupPaths, File[] fileTemplateLookupPaths)
        throws IOException {
    Configuration config = new Configuration();

    TemplateLoader[] loaders = new TemplateLoader[classTemplateLookupPaths.length + fileTemplateLookupPaths.length];

    for (int i = 0; i < classTemplateLookupPaths.length; i++) {
        loaders[i] = new ClassTemplateLoader(classTemplateLookupPaths[i], "");
    }

    for (int i = 0; i < fileTemplateLookupPaths.length; i++) {
        loaders[classTemplateLookupPaths.length + i] = new FileTemplateLoader(fileTemplateLookupPaths[i]);
    }

    config.setTemplateLoader(new MultiTemplateLoader(loaders));

    return config;
}
 
开发者ID:SEEG-Oxford,项目名称:ABRAID-MP,代码行数:19,代码来源:EmailServiceImpl.java

示例15: newConfiguration

import freemarker.cache.ClassTemplateLoader; //导入依赖的package包/类
@Override
protected Configuration newConfiguration() throws IOException, TemplateException {
    configuration = new Configuration(Configuration.VERSION_2_3_25);
    configuration.setDefaultEncoding("UTF-8");
    try {
        List<TemplateLoader> loaders = new ArrayList<>();
        File i18nFolder = new File(FileUtils.getUserFolder(), "i18n");
        File confFolder1 = new File(FileUtils.getUserFolder(), "config");
        File confFolder2 = new File(FileUtils.getUserFolder(), "src/main/config");
        if (i18nFolder.exists()) {
            loaders.add(new FileTemplateLoader(i18nFolder));
        }
        if (confFolder1.exists()) {
            loaders.add(new FileTemplateLoader(confFolder1));
        }
        if (confFolder2.exists()) {
            loaders.add(new FileTemplateLoader(confFolder2));
        }
        loaders.add(new ClassTemplateLoader(SiteConfiguration.class.getClassLoader(), ""));
        configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
    } catch (Exception e) {
        LOG.error("Can not configure freemarker", e);
        System.exit(-1);
    }
    return configuration;
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:27,代码来源:FreeMarkerConfiguration.java


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