Merge branch 'release-0.9.6'
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ViewPostPage.java
index b62e19c..56bac8d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - ViewPostPage.java - Copyright © 2010 David Roden
+ * Sone - ViewPostPage.java - Copyright © 2010–2016 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 package net.pterodactylus.sone.web;
 
+import java.net.URI;
+
+import com.google.common.base.Optional;
+
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.template.SoneAccessor;
+import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 
@@ -49,13 +54,13 @@ public class ViewPostPage extends SoneTemplatePage {
         * {@inheritDoc}
         */
        @Override
-       protected String getPageTitle(Request request) {
+       protected String getPageTitle(FreenetRequest request) {
                String postId = request.getHttpRequest().getParam("post");
-               Post post = webInterface.getCore().getPost(postId, false);
+               Optional<Post> post = webInterface.getCore().getPost(postId);
                String title = "";
-               if ((post != null) && (post.getSone() != null)) {
-                       title = post.getText().substring(0, Math.min(20, post.getText().length())) + "…";
-                       title += " - " + SoneAccessor.getNiceName(post.getSone()) + " - ";
+               if (post.isPresent()) {
+                       title = post.get().getText().substring(0, Math.min(20, post.get().getText().length())) + "…";
+                       title += " - " + SoneAccessor.getNiceName(post.get().getSone()) + " - ";
                }
                title += webInterface.getL10n().getString("Page.ViewPost.Title");
                return title;
@@ -65,13 +70,20 @@ public class ViewPostPage extends SoneTemplatePage {
         * {@inheritDoc}
         */
        @Override
-       protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
-               super.processTemplate(request, templateContext);
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                String postId = request.getHttpRequest().getParam("post");
                boolean raw = request.getHttpRequest().getParam("raw").equals("true");
-               Post post = webInterface.getCore().getPost(postId);
-               templateContext.set("post", post);
+               Optional<Post> post = webInterface.getCore().getPost(postId);
+               templateContext.set("post", post.orNull());
                templateContext.set("raw", raw);
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean isLinkExcepted(URI link) {
+               return true;
+       }
+
 }