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


Java MultiTemplateLoader类代码示例

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


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

示例1: FreemarkerTemplateContext

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

import freemarker.cache.MultiTemplateLoader; //导入依赖的package包/类
@Override
public void addTemplateSource(TemplateProvider provider) {
	List<TemplateLocation> locations = provider.getTemplateLations();

	if (locations == null || locations.size() == 0) {
		return;
	}
	List<TemplateLocation> unlocations = new ArrayList<>();
	for (TemplateLocation tl : locations) {
		if (!templateLocations.contains(tl)) {
			unlocations.add(tl);
		}
	}
	if (unlocations.isEmpty()) {
		return;
	}

	lock.writeLock().lock();
	try {
		this.templateLocations.addAll(unlocations);
		this.multiTemplateLoader = new MultiTemplateLoader(reBuildTemplateLoader());
		this.cfg.setTemplateLoader(multiTemplateLoader);
	} finally {
		lock.writeLock().unlock();
	}
}
 
开发者ID:daileyet,项目名称:helpdesk,代码行数:27,代码来源:PageTemplateServiceImpl.java

示例3: init

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

示例4: configuration

import freemarker.cache.MultiTemplateLoader; //导入依赖的package包/类
@Singleton
@Provides
public static Configuration configuration(LinkHelper linkHelper, MultiTemplateLoader templateLoader) {
    try {
        freemarker.log.Logger.selectLoggerLibrary(Logger.LIBRARY_SLF4J);
        Configuration cfg = new freemarker.template.Configuration(Configuration.VERSION_2_3_25);
        cfg.setTagSyntax(freemarker.template.Configuration.SQUARE_BRACKET_TAG_SYNTAX);
        cfg.setLazyAutoImports(true);
        cfg.setLocale(Locale.GERMANY); // todo make configurable
        cfg.addAutoImport("saito", "saito.ftl");
        cfg.setSharedVariable("saitoLinkHelper", linkHelper);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setLogTemplateExceptions(false);
        cfg.setTemplateLoader(templateLoader);
        return cfg;
    } catch (TemplateModelException | ClassNotFoundException e) {
        log.error("Error creating config", e);
        throw new IllegalStateException(e);
    }
}
 
开发者ID:marcobehler,项目名称:saito,代码行数:21,代码来源:FreemarkerModule.java

示例5: getFreemarkerConfiguration

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

示例6: __doViewInit

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

示例7: getAggregateTemplateLoader

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

示例8: FlexibleConfiguration

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

示例9: setupFreemarkerConfig

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

示例10: setup

import freemarker.cache.MultiTemplateLoader; //导入依赖的package包/类
@Before
public void setup() throws IOException {
    // Add CommonWeb to the freemarker lookup path. In deployment the files will have been copied to local.
    TemplateLoader normalLoader = freemarkerConfig.getConfiguration().getTemplateLoader();
    freemarkerConfig.getConfiguration().setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[] {
            new FileTemplateLoader(new File("CommonWeb/web/WEB-INF/freemarker")),
            normalLoader
    }));

    // Setup Spring test in standalone mode
    this.mockMvc = MockMvcBuilders
            .webAppContextSetup(webApplicationContext)
            .build();

    // Setup user
    PublicSiteUser loggedInUser = mock(PublicSiteUser.class);
    when(loggedInUser.getId()).thenReturn(1);
    AbstractAuthenticatingTests.setupCurrentUser(loggedInUser);
}
 
开发者ID:SEEG-Oxford,项目名称:ABRAID-MP,代码行数:20,代码来源:CovariatesControllerIntegrationTest.java

示例11: newConfiguration

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

示例12: buildTemplateLoader

import freemarker.cache.MultiTemplateLoader; //导入依赖的package包/类
private TemplateLoader buildTemplateLoader(Site site) {
    try {
        List<TemplateLoader> loaders = new ArrayList<TemplateLoader>();
        loaders.add(new FileTemplateLoader(workingTemplateDir));
        loaders.add(new FileTemplateLoader(templateDir));
        loaders.add(new ClassTemplateLoader(AbstractFreeMarkerRenderer.class, "/org/opoo/press/templates"));

        //template registered by plugins
        List<TemplateLoader> instances = site.getFactory().getPluginManager().getObjectList(TemplateLoader.class);
        if (instances != null && !instances.isEmpty()) {
            loaders.addAll(instances);
        }

        TemplateLoader[] loadersArray = loaders.toArray(new TemplateLoader[loaders.size()]);
        return new MultiTemplateLoader(loadersArray);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:opoo,项目名称:opoopress,代码行数:20,代码来源:FreeMarkerRenderer.java

示例13: commonConstruct

import freemarker.cache.MultiTemplateLoader; //导入依赖的package包/类
@PostConstruct
public void commonConstruct() {
    // Just look for files in the class path
    fmConfig.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[]{
    		new ViewableResourceTemplateLoader(),
    		new ClassTemplateLoader(getClass(), "/"),
    		}));
    fmConfig.setNumberFormat("0");
    fmConfig.setLocalizedLookup(false);
    fmConfig.setTemplateUpdateDelay(0);

    try {
        if (manager != null) {
            fmConfig.setSharedVariable("Global", manager.getGlobalModel());
            fmConfig.setSharedVariable("Explorers", manager);
        }
        fmConfig.setSharedVariable("toJson", new ToJsonMethod());
    } catch (TemplateModelException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Netflix,项目名称:karyon,代码行数:22,代码来源:AdminFreemarkerTemplateProvider.java

示例14: postNotification

import freemarker.cache.MultiTemplateLoader; //导入依赖的package包/类
@Override
public boolean postNotification(String trigger, Map executionData, Map config) {

    ClassTemplateLoader builtInTemplate = new ClassTemplateLoader(DingtalkNotificationPlugin.class, "/templates");
    TemplateLoader[] loaders = new TemplateLoader[]{builtInTemplate};
    MultiTemplateLoader mtl = new MultiTemplateLoader(loaders);
    FREEMARKER_CFG.setTemplateLoader(mtl);

    try {
        FREEMARKER_CFG.setSetting(Configuration.CACHE_STORAGE_KEY, "strong:20, soft:250");
    } catch (Exception e) {
        System.err.printf("Got and exception from Freemarker: %s", e.getMessage());
    }

    String webhookUrl = this.dingtalkHookUrl + "?access_token=" + this.dingtalkToken;

    String message = generateMessage(trigger, executionData, config);
    String dingtalkResponse = invokeDingtalkAPIMethod(webhookUrl, message);

    if ("{\"errmsg\":\"ok\",\"errcode\":0}".equals(dingtalkResponse)) {
        return true;
    } else {
        // Unfortunately there seems to be no way to obtain a reference to the plugin logger within notification plugins,
        // but throwing an exception will result in its message being logged.
        throw new DingtalkNotificationPluginException("Unknown status returned from Dingtalk API: [" + dingtalkResponse + "].");
    }
}
 
开发者ID:nongfenqi,项目名称:dingtalk-incoming-webhoot-plugin,代码行数:28,代码来源:DingtalkNotificationPlugin.java

示例15: getAggregateTemplateLoader

import freemarker.cache.MultiTemplateLoader; //导入依赖的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(List<TemplateLoader> templateLoaders) {
	int loaderCount = templateLoaders.size();
	switch (loaderCount) {
		case 0:
			logger.info("No FreeMarker TemplateLoaders specified");
			return null;
		case 1:
			return templateLoaders.get(0);
		default:
			TemplateLoader[] loaders = templateLoaders.toArray(new TemplateLoader[loaderCount]);
			return new MultiTemplateLoader(loaders);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:FreeMarkerConfigurationFactory.java


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