X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FSearchPage.java;h=b937b2f97d45c0c13a0b2d4ef3ac32d244831b8c;hp=ffde2a46b4111c50bca051e0b376b7a408dbc3a4;hb=93fdf9e218d808f65f618abbddce183191d8c15b;hpb=d5efb086bee8f103cbe90c7a953ffbb7ff27b689 diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index ffde2a4..b937b2f 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -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 @@ -98,6 +98,7 @@ public class SearchPage extends SoneTemplatePage { * {@inheritDoc} */ @Override + @SuppressWarnings("synthetic-access") protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String query = request.getHttpRequest().getParam("query").trim(); @@ -148,8 +149,8 @@ public class SearchPage extends SoneTemplatePage { List resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper()).toList(); /* pagination. */ - Pagination sonePagination = new Pagination(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("sonePage"))).or(0)); - Pagination postPagination = new Pagination(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("postPage"))).or(0)); + Pagination sonePagination = new Pagination(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("sonePage"), 0)); + Pagination postPagination = new Pagination(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0)); templateContext.set("sonePagination", sonePagination); templateContext.set("soneHits", sonePagination.getItems()); @@ -322,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; } /** @@ -336,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 = webInterface.getCore().getPostReply(replyId); + if (!postReply.isPresent()) { + return null; + } + return postReply.get().getPost().getId(); } /**