當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。