Some bugfixes
parent
7002ed7682
commit
8d3b72efee
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2020 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.mvc.freemarker;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import org.eclipse.krazo.engine.ViewEngineBase;
|
||||
import org.eclipse.krazo.engine.ViewEngineConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.mvc.engine.ViewEngine;
|
||||
import javax.mvc.engine.ViewEngineContext;
|
||||
import javax.mvc.engine.ViewEngineException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@Priority(ViewEngine.PRIORITY_APPLICATION)
|
||||
public class FreemarkerViewEngine extends ViewEngineBase {
|
||||
|
||||
@Inject
|
||||
@ViewEngineConfig
|
||||
private Configuration configuration;
|
||||
|
||||
@Override
|
||||
public boolean supports(String view) {
|
||||
return view.endsWith(".ftl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processView(final ViewEngineContext context)
|
||||
throws ViewEngineException {
|
||||
|
||||
final Charset charset = resolveCharsetAndSetContentType(context);
|
||||
|
||||
try (final Writer writer = new OutputStreamWriter(
|
||||
context.getOutputStream(), charset
|
||||
)) {
|
||||
final Template template = configuration.getTemplate(
|
||||
resolveView(context)
|
||||
);
|
||||
|
||||
final Map<String, Object> model = new HashMap<>(
|
||||
context.getModels().asMap()
|
||||
);
|
||||
model.put("request", context.getRequest(HttpServletRequest.class));
|
||||
|
||||
template.process(model, writer);
|
||||
} catch (TemplateException | IOException e) {
|
||||
throw new ViewEngineException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -53,7 +53,9 @@ class KrazoTemplateLoader implements TemplateLoader {
|
|||
|
||||
@Override
|
||||
public Object findTemplateSource(final String name) throws IOException {
|
||||
if (name.startsWith("@themes") || name.startsWith("/@themes")) {
|
||||
if (name.startsWith("@themes")
|
||||
|| name.startsWith("/@themes")
|
||||
|| name.startsWith("WEB-INF/views/@themes")) {
|
||||
return null;
|
||||
} else {
|
||||
// Freemarker drops "/"
|
||||
|
|
|
|||
|
|
@ -28,12 +28,11 @@ import org.eclipse.krazo.engine.ViewEngineConfig;
|
|||
import org.eclipse.krazo.ext.freemarker.DefaultConfigurationProducer;
|
||||
import org.libreccm.theming.Themes;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Alternative;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.enterprise.inject.Specializes;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
|
||||
/**
|
||||
* Extends the default configuration for Freemarker of Eclipse Krazo to
|
||||
|
|
@ -41,9 +40,10 @@ import javax.ws.rs.Produces;
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@Alternative
|
||||
@Specializes
|
||||
//@ApplicationScoped
|
||||
//@Alternative
|
||||
//@Specializes
|
||||
//@Priority(3000)
|
||||
public class MvcFreemarkerConfigurationProducer
|
||||
extends DefaultConfigurationProducer {
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ public class MvcFreemarkerConfigurationProducer
|
|||
|
||||
@Produces
|
||||
@ViewEngineConfig
|
||||
@Alternative
|
||||
// @Alternative
|
||||
@Specializes
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,9 @@ class ThemesTemplateLoader implements TemplateLoader {
|
|||
*/
|
||||
@Override
|
||||
public Object findTemplateSource(final String path) throws IOException {
|
||||
if (path.startsWith("@themes") || path.startsWith("/@themes")) {
|
||||
if (path.startsWith("@themes")
|
||||
|| path.startsWith("/@themes")
|
||||
|| path.startsWith("WEB-INF/views/@themes")) {
|
||||
final String[] tokens;
|
||||
if (path.startsWith("/")) {
|
||||
tokens = path.substring(1).split("/");
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@
|
|||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||
bean-discovery-mode="all">
|
||||
|
||||
<alternatives>
|
||||
<!-- <alternatives>
|
||||
<class>org.libreccm.mvc.freemarker.MvcFreemarkerConfigurationProducer</class>
|
||||
</alternatives>
|
||||
<class>org.eclipse.krazo.ext.freemarker.DefaultConfigurationProducer</class>
|
||||
</alternatives>-->
|
||||
|
||||
<interceptors>
|
||||
<class>org.libreccm.security.AuthorizationInterceptor</class>
|
||||
|
|
|
|||
Loading…
Reference in New Issue