use of org.webpieces.templating.impl.TemplateImpl in project webpieces by deanhiller.
the class DevTemplateService method loadTemplateImpl.
private Template loadTemplateImpl(OurGroovyClassLoader cl, String fullTemplatePath, String templateFullClassName) throws IOException, ClassNotFoundException {
if (config.isMustReadClassFromFileSystem()) {
//shortcut for tests that use PlatformOverridesForTest to ensure we test the production groovy class files AND
//it ensures we give code coverage numbers on those class files as well.
Class<?> compiledTemplate = DevTemplateService.class.getClassLoader().loadClass(templateFullClassName);
return new TemplateImpl(urlLookup, htmlTagLookup, compiledTemplate);
}
VirtualFile theResource = null;
List<VirtualFile> srcPaths = config.getSrcPaths();
for (VirtualFile f : srcPaths) {
//take off the leading '/' so it is a relative path
VirtualFile child = f.child(fullTemplatePath.substring(1));
if (child.exists()) {
theResource = child;
break;
}
}
if (theResource == null)
theResource = new VirtualFileClasspath(fullTemplatePath, DevTemplateService.class);
if (!theResource.exists())
throw new FileNotFoundException("resource=" + fullTemplatePath + " was not found in classpath");
try (InputStream resource = theResource.openInputStream()) {
String viewSource = IOUtils.toString(resource, config.getFileEncoding().name());
Class<?> compiledTemplate = createTemplate(cl, templateFullClassName, viewSource);
return new TemplateImpl(urlLookup, htmlTagLookup, compiledTemplate);
}
}
Aggregations