Package io.dropwizard.views.mustache

Source Code of io.dropwizard.views.mustache.PerClassMustacheFactory

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<? extends View> klass;

    PerClassMustacheFactory(Class<? extends View> 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));
    }
}
TOP

Related Classes of io.dropwizard.views.mustache.PerClassMustacheFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.