+ * Throws a
+ * {@link net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException}
+ * if the given object is not {@code null}, appending the object to the
+ * given target URL.
+ *
+ * @param object
+ * The object on which to redirect
+ * @param target
+ * The target of the redirect
+ * @throws RedirectException
+ * if {@code object} is not {@code null}
+ */
+ private static void redirectIfNotNull(String object, String target) throws RedirectException {
+ if (object != null) {
+ throw new RedirectException(target + object);
+ }
+ }
+
+ /**
+ * If the given phrase contains a Sone ID (optionally prefixed by
+ * “sone://”), returns said Sone ID, otherwise return {@code null}.
+ *
+ * @param phrase
+ * The phrase that maybe is a Sone ID
+ * @return The Sone ID, or {@code null}
+ */
+ private String getSoneId(String phrase) {
+ String soneId = phrase.startsWith("sone://") ? phrase.substring(7) : phrase;
+ return (webInterface.getCore().getSone(soneId).isPresent()) ? soneId : null;
+ }
+
+ /**
+ * If the given phrase contains a post ID (optionally prefixed by
+ * “post://”), returns said post ID, otherwise return {@code null}.
+ *
+ * @param phrase
+ * The phrase that maybe is a post ID
+ * @return The post ID, or {@code null}
+ */
+ private String getPostId(String phrase) {
+ String postId = phrase.startsWith("post://") ? phrase.substring(7) : phrase;
+ return (webInterface.getCore().getPost(postId).isPresent()) ? postId : null;
+ }
+
+ /**
+ * If the given phrase contains a reply ID (optionally prefixed by
+ * “reply://”), returns the ID of the post the reply belongs to, otherwise
+ * return {@code null}.
+ *
+ * @param phrase
+ * The phrase that maybe is a reply ID
+ * @return The reply’s post ID, or {@code null}
+ */
+ private String getReplyPostId(String phrase) {
+ String replyId = phrase.startsWith("reply://") ? phrase.substring(8) : phrase;
+ Optional<PostReply> postReply = webInterface.getCore().getPostReply(replyId);
+ if (!postReply.isPresent()) {
+ return null;
+ }
+ return postReply.get().getPostId();
+ }
+
+ /**
+ * If the given phrase contains an album ID (optionally prefixed by
+ * “album://”), returns said album ID, otherwise return {@code null}.
+ *
+ * @param phrase
+ * The phrase that maybe is an album ID
+ * @return The album ID, or {@code null}
+ */
+ private String getAlbumId(String phrase) {
+ String albumId = phrase.startsWith("album://") ? phrase.substring(8) : phrase;
+ return (webInterface.getCore().getAlbum(albumId) != null) ? albumId : null;
+ }
+
+ /**
+ * If the given phrase contains an image ID (optionally prefixed by
+ * “image://”), returns said image ID, otherwise return {@code null}.
+ *
+ * @param phrase
+ * The phrase that maybe is an image ID
+ * @return The image ID, or {@code null}
+ */
+ private String getImageId(String phrase) {
+ String imageId = phrase.startsWith("image://") ? phrase.substring(8) : phrase;
+ return (webInterface.getCore().getImage(imageId, false) != null) ? imageId : null;
+ }
+
+ /**