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

io.dropwizard.views.mustache.PerClassMustacheFactory Maven / Gradle / Ivy

package io.dropwizard.views.mustache;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.MustacheException;
import com.google.common.base.Charsets;
import io.dropwizard.views.View;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

/**
 * A class-specific Mustache factory which caches the parsed/compiled templates.
 */
class PerClassMustacheFactory extends DefaultMustacheFactory {
    private final Class klass;

    PerClassMustacheFactory(Class klass) {
        this.klass = klass;
    }

    @Override
    public Reader getReader(String resourceName) {
        final InputStream is = klass.getResourceAsStream(resourceName);
        if (is == null) {
            throw new MustacheException("Template " + resourceName + " not found");
        }
        return new BufferedReader(new InputStreamReader(is, Charsets.UTF_8));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy