projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Process Sone templates in their own method
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
web
/
ViewSonePage.java
diff --git
a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
index
f216431
..
14268a0
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
@@
-17,6
+17,8
@@
package net.pterodactylus.sone.web;
package net.pterodactylus.sone.web;
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
@@
-32,10
+34,11
@@
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.template.SoneAccessor;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.collection.Pagination;
import net.pterodactylus.sone.template.SoneAccessor;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Optional;
+
/**
* Lets the user browser another Sone.
*
/**
* Lets the user browser another Sone.
*
@@
-65,9
+68,9
@@
public class ViewSonePage extends SoneTemplatePage {
@Override
protected String getPageTitle(FreenetRequest request) {
String soneId = request.getHttpRequest().getParam("sone");
@Override
protected String getPageTitle(FreenetRequest request) {
String soneId = request.getHttpRequest().getParam("sone");
-
Sone
sone = webInterface.getCore().getSone(soneId);
- if (
(sone != null) && (sone.getTime() > 0
)) {
- String soneName = SoneAccessor.getNiceName(sone);
+
Optional<Sone>
sone = webInterface.getCore().getSone(soneId);
+ if (
sone.isPresent(
)) {
+ String soneName = SoneAccessor.getNiceName(sone
.get()
);
return soneName + " - " + webInterface.getL10n().getString("Page.ViewSone.Title");
}
return webInterface.getL10n().getString("Page.ViewSone.Page.TitleWithoutSone");
return soneName + " - " + webInterface.getL10n().getString("Page.ViewSone.Title");
}
return webInterface.getL10n().getString("Page.ViewSone.Page.TitleWithoutSone");
@@
-77,29
+80,28
@@
public class ViewSonePage extends SoneTemplatePage {
* {@inheritDoc}
*/
@Override
* {@inheritDoc}
*/
@Override
- protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
- super.processTemplate(request, templateContext);
+ protected void processSonePage(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
String soneId = request.getHttpRequest().getParam("sone");
String soneId = request.getHttpRequest().getParam("sone");
-
Sone
sone = webInterface.getCore().getSone(soneId);
- templateContext.set("sone", sone);
+
Optional<Sone>
sone = webInterface.getCore().getSone(soneId);
+ templateContext.set("sone", sone
.orNull()
);
templateContext.set("soneId", soneId);
templateContext.set("soneId", soneId);
- if (
sone == null
) {
+ if (
!sone.isPresent()
) {
return;
}
return;
}
- List<Post> sonePosts = sone.getPosts();
- sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.getId()));
+ List<Post> sonePosts = sone.get
().get
Posts();
+ sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.get
().get
Id()));
Collections.sort(sonePosts, Post.TIME_COMPARATOR);
Collections.sort(sonePosts, Post.TIME_COMPARATOR);
- Pagination<Post> postPagination = new Pagination<Post>(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(
Numbers.safeParseInteger
(request.getHttpRequest().getParam("postPage"), 0));
+ Pagination<Post> postPagination = new Pagination<Post>(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(
parseInt
(request.getHttpRequest().getParam("postPage"), 0));
templateContext.set("postPagination", postPagination);
templateContext.set("posts", postPagination.getItems());
templateContext.set("postPagination", postPagination);
templateContext.set("posts", postPagination.getItems());
- Set<PostReply> replies = sone.getReplies();
+ Set<PostReply> replies = sone.get
().get
Replies();
final Map<Post, List<PostReply>> repliedPosts = new HashMap<Post, List<PostReply>>();
for (PostReply reply : replies) {
final Map<Post, List<PostReply>> repliedPosts = new HashMap<Post, List<PostReply>>();
for (PostReply reply : replies) {
-
Post
post = reply.getPost();
- if (
repliedPosts.containsKey(post) || sone.equals(post.getSone()) || (sone.equals(post.getRecipient
()))) {
+
Optional<Post>
post = reply.getPost();
+ if (
!post.isPresent() || repliedPosts.containsKey(post.get()) || sone.get().equals(post.get().getSone()) || (sone.get().getId().equals(post.get().getRecipientId().orNull
()))) {
continue;
}
continue;
}
- repliedPosts.put(post
, webInterface.getCore().getReplies(post
));
+ repliedPosts.put(post
.get(), webInterface.getCore().getReplies(post.get().getId()
));
}
List<Post> posts = new ArrayList<Post>(repliedPosts.keySet());
Collections.sort(posts, new Comparator<Post>() {
}
List<Post> posts = new ArrayList<Post>(repliedPosts.keySet());
Collections.sort(posts, new Comparator<Post>() {
@@
-111,7
+113,7
@@
public class ViewSonePage extends SoneTemplatePage {
});
});
- Pagination<Post> repliedPostPagination = new Pagination<Post>(posts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(
Numbers.safeParseInteger
(request.getHttpRequest().getParam("repliedPostPage"), 0));
+ Pagination<Post> repliedPostPagination = new Pagination<Post>(posts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(
parseInt
(request.getHttpRequest().getParam("repliedPostPage"), 0));
templateContext.set("repliedPostPagination", repliedPostPagination);
templateContext.set("repliedPosts", repliedPostPagination.getItems());
}
templateContext.set("repliedPostPagination", repliedPostPagination);
templateContext.set("repliedPosts", repliedPostPagination.getItems());
}