aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/Help.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-09-15 00:13:35 +0300
committerGravatar Vitaly Takmazov2016-09-15 00:13:35 +0300
commit4db3d0d9c7625b6d1b521158e7b9e900c667f286 (patch)
treeeb374abaeb62e2fdf3bbd7d0d6fa38463e631e5f /juick-www/src/main/java/com/juick/www/Help.java
parent5a14a313d6bc70f821e1bd513d025109a5c15906 (diff)
rendering help using pebble
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/Help.java')
-rw-r--r--juick-www/src/main/java/com/juick/www/Help.java49
1 files changed, 22 insertions, 27 deletions
diff --git a/juick-www/src/main/java/com/juick/www/Help.java b/juick-www/src/main/java/com/juick/www/Help.java
index a8bfaf3f..301d2edc 100644
--- a/juick-www/src/main/java/com/juick/www/Help.java
+++ b/juick-www/src/main/java/com/juick/www/Help.java
@@ -17,12 +17,22 @@
*/
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.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
/**
*
@@ -34,7 +44,7 @@ public class Help {
Utils.sendTemporaryRedirect(response, "/help/ru/");
}
- protected void doGetHelp(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGetHelp(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, PebbleException, URISyntaxException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
String path[] = request.getRequestURI().split("/");
@@ -54,37 +64,22 @@ public class Help {
page = "index";
}
- File f = new File("/var/www/juick.com/help/" + path[2] + "/" + page);
- if (!f.isFile()) {
+ URL f = getClass().getResource("/help/" + path[2] + "/" + page);
+ if (f == null) {
Errors.doGet404(sql, request, response);
return;
}
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
- PageTemplates.pageHead(out, visitor, "Помощь", null);
- PageTemplates.pageNavigation(out, visitor, null);
-
- out.println("<aside id=\"column\">");
- printFile(out, new File("/var/www/juick.com/help/" + path[2] + "/navigation"));
- out.println("</aside>");
-
- out.println("<section id=\"content\">");
- out.println("<article>");
- printFile(out, f);
- out.println("</article>");
- out.println("</section>");
-
- PageTemplates.pageFooter(request, out, visitor, false);
- PageTemplates.pageEnd(out);
- }
- }
-
- private void printFile(PrintWriter out, File f) throws IOException {
- BufferedReader br = new BufferedReader(new FileReader(f));
- String str;
- while ((str = br.readLine()) != null) {
- out.println(str);
+ PebbleTemplate template = Utils.getEngine().getTemplate("views/help.html");
+ Map<String, Object> context = new HashMap<>();
+ context.put("title", "Помощь");
+ context.put("visitor", visitor);
+ context.put("content", new String(Files.readAllBytes(Paths.get(f.toURI()))));
+ context.put("navigation", new String(Files.readAllBytes(
+ new File(getClass().getResource("/help/" + path[2] + "/navigation").toURI()).toPath())));
+ template.evaluate(out, context);
}
}
}