All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aeontronix.genesis.ClasspathResourceLoader Maven / Gradle / Ivy

There is a newer version: 1.0-beta1
Show newest version
package com.aeontronix.genesis;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Set;

public class ClasspathResourceLoader implements ResourceLoader {
    public ClasspathResourceLoader() throws TemplateNotFoundException, IOException {
        Enumeration en = ClassLoader.getSystemResources("genesis-template.json");
        if( ! en.hasMoreElements() ) {
            throw new TemplateNotFoundException("No template in classpath found");
        }
        URL url = en.nextElement();
        if(en.hasMoreElements()) {
            throw new TemplateNotFoundException("More than one template found in classpath: "+url+" and "+en.nextElement());
        }
    }

    @Override
    public InputStream loadResource(String resourcePath) throws IOException {
        InputStream is = ClassLoader.getSystemResourceAsStream(resourcePath);
        if( is == null ) {
            is = getClass().getResourceAsStream(resourcePath);
        }
        return is;
    }

    @Override
    public Set listFiles(String resourcePath) throws IOException {
        return Collections.emptySet();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy