/*
- * 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;
/**
* This page lets the user view a post and all its replies.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, Template template) throws RedirectException {
- super.processTemplate(request, template);
+ protected String getPageTitle(FreenetRequest request) {
String postId = request.getHttpRequest().getParam("post");
- Post post = webInterface.getCore().getPost(postId);
- template.set("post", post);
+ Optional<Post> post = webInterface.getCore().getPost(postId);
+ String title = "";
+ 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;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+ String postId = request.getHttpRequest().getParam("post");
+ boolean raw = request.getHttpRequest().getParam("raw").equals("true");
+ 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;
}
}