aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/Errors.java
blob: 85ebf1a6061f5345b3f8eeeb511eb4452763311e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
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;

/**
 *
 * @author ugnich
 */
public class Errors {

    public static void doGet404(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
        response.setStatus(404);
        response.setContentType("text/html; charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            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);
        }
    }
}