mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 10:41:06 +01:00
use mustache template engine to render index and error page
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.template;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -38,6 +39,9 @@ import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
@@ -63,9 +67,18 @@ import javax.servlet.http.HttpServletResponse;
|
||||
public class ErrorServlet extends HttpServlet
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String TEMPALTE = "/error.html";
|
||||
|
||||
/** Field description */
|
||||
private static final long serialVersionUID = -3289076078469757874L;
|
||||
|
||||
/**
|
||||
* the logger for ErrorServlet
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(ErrorServlet.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -74,12 +87,14 @@ public class ErrorServlet extends HttpServlet
|
||||
*
|
||||
* @param context
|
||||
* @param handler
|
||||
* @param templateEngineFactory
|
||||
*/
|
||||
@Inject
|
||||
public ErrorServlet(SCMContextProvider context, TemplateHandler handler)
|
||||
public ErrorServlet(SCMContextProvider context,
|
||||
TemplateEngineFactory templateEngineFactory)
|
||||
{
|
||||
this.context = context;
|
||||
this.handler = handler;
|
||||
this.templateEngineFactory = templateEngineFactory;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -96,7 +111,7 @@ public class ErrorServlet extends HttpServlet
|
||||
*/
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
throws ServletException, IOException
|
||||
{
|
||||
processRequest(request, response);
|
||||
}
|
||||
@@ -113,8 +128,8 @@ public class ErrorServlet extends HttpServlet
|
||||
*/
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
processRequest(request, response);
|
||||
}
|
||||
@@ -130,8 +145,8 @@ public class ErrorServlet extends HttpServlet
|
||||
* @throws ServletException
|
||||
*/
|
||||
private void processRequest(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
PrintWriter writer = null;
|
||||
|
||||
@@ -148,7 +163,18 @@ public class ErrorServlet extends HttpServlet
|
||||
}
|
||||
|
||||
env.put("error", error);
|
||||
handler.render("/error.html", writer, env);
|
||||
|
||||
TemplateEngine engine = templateEngineFactory.getDefaultEngine();
|
||||
Template template = engine.getTemplate(TEMPALTE);
|
||||
|
||||
if (template != null)
|
||||
{
|
||||
template.execute(writer, env);
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("could not find template {}", TEMPALTE);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -162,5 +188,5 @@ public class ErrorServlet extends HttpServlet
|
||||
private SCMContextProvider context;
|
||||
|
||||
/** Field description */
|
||||
private TemplateHandler handler;
|
||||
private TemplateEngineFactory templateEngineFactory;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user