From 6ea4235635c296991bbae3689d0b7dd735b17480 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 26 Aug 2016 14:13:37 +0300 Subject: pebble WIP --- juick-www/build.gradle | 1 + juick-www/src/main/java/com/juick/www/Main.java | 8 +- juick-www/src/main/java/com/juick/www/PM.java | 67 +++----------- .../src/main/java/com/juick/www/PageTemplates.java | 98 +------------------- juick-www/src/main/java/com/juick/www/RSS.java | 2 +- .../src/main/java/com/juick/www/UserThread.java | 9 +- juick-www/src/main/java/com/juick/www/Utils.java | 100 +++++++++++++++++++++ juick-www/src/main/resources/layouts/content.html | 29 ++++++ .../main/resources/views/partial/homecolumn.html | 6 ++ .../main/resources/views/partial/navigation.html | 37 ++++++++ .../src/main/resources/views/partial/tags.html | 7 ++ juick-www/src/main/resources/views/pm_inbox.html | 36 ++++++++ 12 files changed, 245 insertions(+), 155 deletions(-) create mode 100644 juick-www/src/main/resources/layouts/content.html create mode 100644 juick-www/src/main/resources/views/partial/homecolumn.html create mode 100644 juick-www/src/main/resources/views/partial/navigation.html create mode 100644 juick-www/src/main/resources/views/partial/tags.html create mode 100644 juick-www/src/main/resources/views/pm_inbox.html (limited to 'juick-www') diff --git a/juick-www/build.gradle b/juick-www/build.gradle index 27c3bc1a..891ee8f6 100644 --- a/juick-www/build.gradle +++ b/juick-www/build.gradle @@ -37,6 +37,7 @@ dependencies { compile 'net.coobird:thumbnailator:0.4.8' compile 'com.github.ooxi:serialized-php-parser:0.5.0' compile 'net.jodah:failsafe:0.9.2' + compile 'com.mitchellbosecke:pebble:2.2.2' providedCompile 'javax.servlet:javax.servlet-api:3.1.0' providedRuntime 'mysql:mysql-connector-java:5.1.39' } diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java index c249995f..1e755ca3 100644 --- a/juick-www/src/main/java/com/juick/www/Main.java +++ b/juick-www/src/main/java/com/juick/www/Main.java @@ -21,6 +21,7 @@ import com.juick.server.UserQueries; import com.juick.xmpp.JID; import com.juick.xmpp.Stream; import com.juick.xmpp.StreamComponent; +import com.mitchellbosecke.pebble.error.PebbleException; import net.jodah.failsafe.Execution; import net.jodah.failsafe.RetryPolicy; import org.apache.commons.dbcp2.BasicDataSource; @@ -181,7 +182,12 @@ public class Main extends HttpServlet implements Stream.StreamListener { } else { switch (uri) { case "/pm/inbox": - pm.doGetInbox(sql, request, response, visitor); + try { + pm.doGetInbox(sql, request, response, visitor); + } catch (PebbleException e) { + log("pebble exception", e); + response.sendError(500); + } break; case "/pm/sent": pm.doGetSent(sql, request, response, visitor); diff --git a/juick-www/src/main/java/com/juick/www/PM.java b/juick-www/src/main/java/com/juick/www/PM.java index 9d7da65b..ac2cbb76 100644 --- a/juick-www/src/main/java/com/juick/www/PM.java +++ b/juick-www/src/main/java/com/juick/www/PM.java @@ -18,11 +18,14 @@ package com.juick.www; import com.juick.server.PMQueries; +import com.juick.server.TagQueries; import com.juick.server.UserQueries; import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Stream; import com.juick.xmpp.extensions.JuickMessage; +import com.mitchellbosecke.pebble.error.PebbleException; +import com.mitchellbosecke.pebble.template.PebbleTemplate; import org.springframework.jdbc.core.JdbcTemplate; import javax.servlet.ServletException; @@ -30,7 +33,9 @@ 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.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -41,64 +46,20 @@ import java.util.logging.Logger; public class PM { private static final Logger logger = Logger.getLogger(PM.class.getName()); - protected void doGetInbox(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException { - /* - int paramBefore = 0; - String paramBeforeStr = request.getParameter("before"); - if (paramBeforeStr != null) { - try { - paramBefore = Integer.parseInt(paramBeforeStr); - } catch (NumberFormatException e) { - } - } - */ + protected void doGetInbox(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException, PebbleException { String title = "PM: Inbox"; List msgs = PMQueries.getLastPMInbox(sql, visitor.getUID()); response.setContentType("text/html; charset=UTF-8"); try (PrintWriter out = response.getWriter()) { - PageTemplates.pageHead(out, visitor, title, null); - PageTemplates.pageNavigation(out, visitor, null); - - out.println("
"); - - if (!msgs.isEmpty()) { - out.println(""); - } - - /* - if (msgs.size() >= 20) { - String nextpage = "?before=" + msgs.get(msgs.size() - 1); - out.println("

Читать дальше →

"); - } - */ - - out.println("
"); - - PageTemplates.pageHomeColumn(out, sql, visitor); - - PageTemplates.pageFooter(request, out, visitor, false); - PageTemplates.pageEnd(out); + PebbleTemplate template = Utils.getEngine().getTemplate("views/pm_inbox.html"); + Map context = new HashMap<>(); + context.put("title", title); + context.put("visitor", visitor); + context.put("msgs", msgs); + context.put("tags", TagQueries.getPopularTags(sql)); + template.evaluate(out, context); } } @@ -142,7 +103,7 @@ public class PM { out.println("