diff options
author | Vitaly Takmazov | 2016-09-15 00:24:58 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-09-15 00:24:58 +0300 |
commit | 8e4fa6480f9392da50b82c59672b74f3c553f843 (patch) | |
tree | be0687bae373cdf018cf6a739196b3b13f823d9f /juick-www/src/main/java/com/juick/www | |
parent | c410bf67edd2fb7590b813871d2a45843584aa32 (diff) |
404 page -> pebble
Diffstat (limited to 'juick-www/src/main/java/com/juick/www')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/Errors.java | 29 |
1 files changed, 11 insertions, 18 deletions
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("<section id=\"content\">"); - out.println("<h1>Страница не найдена</h1>"); - out.println("<p>Сожалеем, но страницу с этим адресом удалил её автор, либо её никогда не существовало.</p>"); - out.println("</section>"); - - PageTemplates.pageFooter(request, out, visitor, false); - PageTemplates.pageEnd(out); + PebbleTemplate template = Utils.getEngine().getTemplate("views/404.html"); + Map<String, Object> context = new HashMap<>(); + context.put("title", "404 Страница не найдена"); + context.put("visitor", visitor); + template.evaluate(out, context); + } catch (PebbleException e) { + // log("pebble exception", e); } } } |