FreemarkerConfigurationComponentFactory extends AbstractComponentFactory { 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()]); }  @Override void init(ComponentRepository repo, final LinkedHashMap<String, String> configuration); static FreemarkerConfigurationComponentFactory.Meta meta(); @Override FreemarkerConfigurationComponentFactory.Meta metaBean(); String getTemplateLocations(); void setTemplateLocations(String templateLocations); final Property<String> templateLocations(); @Override FreemarkerConfigurationComponentFactory clone(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static final String SERVLET_CONTEXT; static final String FILE; }
@Test public void createLoaders() { String[] locations = {"servlet-context:WEB-INF/pages", "file:" + System.getProperty("java.io.tmpdir")}; TemplateLoader[] loaders = FreemarkerConfigurationComponentFactory.createLoaders(locations, mock(ServletContext.class)); assertNotNull(loaders); assertEquals(2, loaders.length); assertTrue(loaders[0] instanceof WebappTemplateLoader); assertTrue(loaders[1] instanceof FileTemplateLoader); }