
sitemesh-examples-javalin.3.2.2.source-code.HelloWorld Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sitemesh-examples-javalin Show documentation
Show all versions of sitemesh-examples-javalin Show documentation
SiteMesh is a web-page layout and decoration framework and web- application integration framework to aid in creating sites consisting of many pages for which a consistent look/feel, navigation and layout scheme is required.
The newest version!
import io.javalin.Javalin;
import io.javalin.http.staticfiles.Location;
import jakarta.servlet.DispatcherType;
import org.eclipse.jetty.servlet.FilterHolder;
import org.sitemesh.config.ConfigurableSiteMeshFilter;
import io.javalin.rendering.template.JavalinFreemarker;
import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.TemplateExceptionHandler;
import java.util.Collections;
import java.util.EnumSet;
public class HelloWorld {
public static void main(String[] args) {
JavalinFreemarker.init(configureFreemarker("/templates"));
var app = Javalin.create(config -> {
config.staticFiles.add(staticFiles -> {
staticFiles.hostedPath = "/static";
staticFiles.directory = "/";
staticFiles.location = Location.CLASSPATH;
});
config.jetty.contextHandlerConfig(sch -> {
sch.addFilter(new FilterHolder(ConfigurableSiteMeshFilter.create(b ->
b.setMimeTypes("text/html", "text/plain")
.setDecoratorPrefix("")
.addDecoratorPath("/*", "/decorators/default")
.addExcludedPath("/static/*")
.addExcludedPath("/decorators/*")
)), "/*", EnumSet.of(DispatcherType.REQUEST));
});
})
.get("/", ctx -> ctx.render("/hello.ftl", Collections.singletonMap("user", "Scott")))
.get("/decorators/default", ctx -> ctx.render("/decorators/default.ftl"))
.start(7070);
}
public static Configuration configureFreemarker(String templatePath) {
Configuration conf = new Configuration(Configuration.VERSION_2_3_23);
conf.setTemplateLoader(new ClassTemplateLoader(HelloWorld.class, templatePath));
conf.setDefaultEncoding("UTF-8");
conf.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
return conf;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy