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