Allow for both magnet and download URIs to be null.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 10 Jan 2013 06:09:11 +0000 (07:09 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 10 Jan 2013 06:09:11 +0000 (07:09 +0100)
src/main/java/net/pterodactylus/reactor/states/TorrentState.java
src/main/java/net/pterodactylus/reactor/triggers/NewEpisodeTrigger.java
src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java

index f3b3546..f3479a2 100644 (file)
@@ -179,7 +179,8 @@ public class TorrentState extends AbstractState implements Iterable<TorrentFile>
                /**
                 * Returns the magnet URI of the file.
                 *
-                * @return The magnet URI of the file
+                * @return The magnet URI of the file, or {@code null} if there is no
+                *         magnet URI for this torrent file
                 */
                public String magnetUri() {
                        return magnetUri;
@@ -188,7 +189,8 @@ public class TorrentState extends AbstractState implements Iterable<TorrentFile>
                /**
                 * Returns the download URI of the file.
                 *
-                * @return The download URI of the file
+                * @return The download URI of the file, or {@code null} if there is no
+                *         download URI for this torrent file
                 */
                public String downloadUri() {
                        return downloadUri;
index 4504d60..04b6956 100644 (file)
@@ -152,8 +152,12 @@ public class NewEpisodeTrigger implements Trigger {
                                stringBuilder.append("- ").append(episode.identifier()).append("\n");
                                for (TorrentFile torrentFile : episode) {
                                        stringBuilder.append("  - ").append(torrentFile.name()).append(", ").append(torrentFile.size()).append("\n");
-                                       stringBuilder.append("    Magnet: ").append(torrentFile.magnetUri()).append("\n");
-                                       stringBuilder.append("    Download: ").append(torrentFile.downloadUri()).append("\n");
+                                       if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
+                                               stringBuilder.append("    Magnet: ").append(torrentFile.magnetUri()).append("\n");
+                                       }
+                                       if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
+                                               stringBuilder.append("    Download: ").append(torrentFile.downloadUri()).append("\n");
+                                       }
                                }
                        }
                }
@@ -163,8 +167,12 @@ public class NewEpisodeTrigger implements Trigger {
                                stringBuilder.append("- ").append(episode.identifier()).append("\n");
                                for (TorrentFile torrentFile : episode) {
                                        stringBuilder.append("  - ").append(torrentFile.name()).append(", ").append(torrentFile.size()).append("\n");
-                                       stringBuilder.append("    Magnet: ").append(torrentFile.magnetUri()).append("\n");
-                                       stringBuilder.append("    Download: ").append(torrentFile.downloadUri()).append("\n");
+                                       if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
+                                               stringBuilder.append("    Magnet: ").append(torrentFile.magnetUri()).append("\n");
+                                       }
+                                       if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
+                                               stringBuilder.append("    Download: ").append(torrentFile.downloadUri()).append("\n");
+                                       }
                                }
                        }
                }
@@ -199,8 +207,14 @@ public class NewEpisodeTrigger implements Trigger {
                                        htmlBuilder.append("<strong>").append(torrentFile.fileCount()).append("</strong> file(s), ");
                                        htmlBuilder.append("<strong>").append(torrentFile.seedCount()).append("</strong> seed(s), ");
                                        htmlBuilder.append("<strong>").append(torrentFile.leechCount()).append("</strong> leecher(s)</div>\n");
-                                       htmlBuilder.append("<div><a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())).append("\">Magnet</a> ");
-                                       htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())).append("\">Download</a></div>\n");
+                                       htmlBuilder.append("<div>");
+                                       if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
+                                               htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())).append("\">Magnet</a> ");
+                                       }
+                                       if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
+                                               htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())).append("\">Download</a>");
+                                       }
+                                       htmlBuilder.append("</div>\n");
                                }
                                htmlBuilder.append("</ul>\n");
                        }
@@ -219,8 +233,14 @@ public class NewEpisodeTrigger implements Trigger {
                                        htmlBuilder.append("<strong>").append(torrentFile.fileCount()).append("</strong> file(s), ");
                                        htmlBuilder.append("<strong>").append(torrentFile.seedCount()).append("</strong> seed(s), ");
                                        htmlBuilder.append("<strong>").append(torrentFile.leechCount()).append("</strong> leecher(s)</div>\n");
-                                       htmlBuilder.append("<div><a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())).append("\">Magnet</a> ");
-                                       htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())).append("\">Download</a></div>\n");
+                                       htmlBuilder.append("<div>");
+                                       if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
+                                               htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())).append("\">Magnet</a> ");
+                                       }
+                                       if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
+                                               htmlBuilder.append("<a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())).append("\">Download</a>");
+                                       }
+                                       htmlBuilder.append("</div>\n");
                                }
                                htmlBuilder.append("</ul>\n");
                        }
index ab640c6..64ff693 100644 (file)
@@ -96,8 +96,12 @@ public class NewTorrentTrigger implements Trigger {
                        plainText.append(torrentFile.name()).append('\n');
                        plainText.append('\t').append(torrentFile.size()).append(" in ").append(torrentFile.fileCount()).append(" file(s)\n");
                        plainText.append('\t').append(torrentFile.seedCount()).append(" seed(s), ").append(torrentFile.leechCount()).append(" leecher(s)\n");
-                       plainText.append('\t').append(torrentFile.magnetUri()).append('\n');
-                       plainText.append('\t').append(torrentFile.downloadUri()).append('\n');
+                       if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
+                               plainText.append('\t').append(torrentFile.magnetUri()).append('\n');
+                       }
+                       if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
+                               plainText.append('\t').append(torrentFile.downloadUri()).append('\n');
+                       }
                        plainText.append('\n');
                }
                return plainText.toString();
@@ -119,8 +123,12 @@ public class NewTorrentTrigger implements Trigger {
                        htmlText.append("<li><strong>").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("</strong></li>");
                        htmlText.append("<div>Size: <strong>").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append("</strong> in <strong>").append(torrentFile.fileCount()).append("</strong> file(s)</div>");
                        htmlText.append("<div><strong>").append(torrentFile.seedCount()).append("</strong> seed(s), <strong>").append(torrentFile.leechCount()).append("</strong> leecher(s)</div>");
-                       htmlText.append(String.format("<div><a href=\"%s\">Magnet URI</a></div>", StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())));
-                       htmlText.append(String.format("<div><a href=\"%s\">Download URI</a></div>", StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())));
+                       if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) {
+                               htmlText.append(String.format("<div><a href=\"%s\">Magnet URI</a></div>", StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())));
+                       }
+                       if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) {
+                               htmlText.append(String.format("<div><a href=\"%s\">Download URI</a></div>", StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())));
+                       }
                }
                htmlText.append("</ul>\n");
                htmlText.append("</body></html>\n");