Make post reply returned by provider optional.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / SearchPage.java
index 3e68f51..b937b2f 100644 (file)
@@ -37,6 +37,7 @@ import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.collection.Pagination;
 import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.number.Numbers;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 import net.pterodactylus.util.text.StringEscaper;
@@ -51,7 +52,6 @@ import com.google.common.cache.LoadingCache;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.Ordering;
-import com.google.common.primitives.Ints;
 
 /**
  * This page lets the user search for posts and replies that contain certain
@@ -149,8 +149,8 @@ public class SearchPage extends SoneTemplatePage {
                List<Post> resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper<Post>()).toList();
 
                /* pagination. */
-               Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("sonePage"))).or(0));
-               Pagination<Post> postPagination = new Pagination<Post>(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("postPage"))).or(0));
+               Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("sonePage"), 0));
+               Pagination<Post> postPagination = new Pagination<Post>(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0));
 
                templateContext.set("sonePagination", sonePagination);
                templateContext.set("soneHits", sonePagination.getItems());
@@ -323,7 +323,7 @@ public class SearchPage extends SoneTemplatePage {
         */
        private String getPostId(String phrase) {
                String postId = phrase.startsWith("post://") ? phrase.substring(7) : phrase;
-               return (webInterface.getCore().getPost(postId, false) != null) ? postId : null;
+               return (webInterface.getCore().getPost(postId) != null) ? postId : null;
        }
 
        /**
@@ -337,7 +337,11 @@ public class SearchPage extends SoneTemplatePage {
         */
        private String getReplyPostId(String phrase) {
                String replyId = phrase.startsWith("reply://") ? phrase.substring(8) : phrase;
-               return (webInterface.getCore().getPostReply(replyId, false) != null) ? webInterface.getCore().getPostReply(replyId, false).getPost().getId() : null;
+               Optional<PostReply> postReply = webInterface.getCore().getPostReply(replyId);
+               if (!postReply.isPresent()) {
+                       return null;
+               }
+               return postReply.get().getPost().getId();
        }
 
        /**