From 8e4fa6480f9392da50b82c59672b74f3c553f843 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 15 Sep 2016 00:24:58 +0300 Subject: 404 page -> pebble --- juick-www/src/main/java/com/juick/www/Errors.java | 29 +++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'juick-www/src/main/java/com/juick') diff --git a/juick-www/src/main/java/com/juick/www/Errors.java b/juick-www/src/main/java/com/juick/www/Errors.java index 4ab10229..85ebf1a6 100644 --- a/juick-www/src/main/java/com/juick/www/Errors.java +++ b/juick-www/src/main/java/com/juick/www/Errors.java @@ -1,5 +1,7 @@ package com.juick.www; +import com.mitchellbosecke.pebble.error.PebbleException; +import com.mitchellbosecke.pebble.template.PebbleTemplate; import org.springframework.jdbc.core.JdbcTemplate; import javax.servlet.ServletException; @@ -7,6 +9,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; /** * @@ -14,29 +18,18 @@ import java.io.PrintWriter; */ public class Errors { - public static String tagsHTML = null; - public static void doGet404(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - - if (tagsHTML == null) { - tagsHTML = PageTemplates.formatPopularTags(sql, 80); - } - response.setStatus(404); response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()) { - PageTemplates.pageHead(out, visitor, "404 Страница не найдена", null); - PageTemplates.pageNavigation(out, visitor, null); - PageTemplates.pageHomeColumn(out, sql, visitor); - - out.println("
"); - out.println("

Страница не найдена

"); - out.println("

Сожалеем, но страницу с этим адресом удалил её автор, либо её никогда не существовало.

"); - out.println("
"); - - PageTemplates.pageFooter(request, out, visitor, false); - PageTemplates.pageEnd(out); + PebbleTemplate template = Utils.getEngine().getTemplate("views/404.html"); + Map context = new HashMap<>(); + context.put("title", "404 Страница не найдена"); + context.put("visitor", visitor); + template.evaluate(out, context); + } catch (PebbleException e) { + // log("pebble exception", e); } } } -- cgit v1.2.3