Search in sources :

Example 1 with TemplateImpl

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);
    }
}
Also used : TemplateImpl(org.webpieces.templating.impl.TemplateImpl) VirtualFile(org.webpieces.util.file.VirtualFile) InputStream(java.io.InputStream) VirtualFileClasspath(org.webpieces.util.file.VirtualFileClasspath) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 TemplateImpl (org.webpieces.templating.impl.TemplateImpl)1 VirtualFile (org.webpieces.util.file.VirtualFile)1 VirtualFileClasspath (org.webpieces.util.file.VirtualFileClasspath)1