From: David ‘Bombe’ Roden Date: Thu, 10 Jan 2013 06:09:11 +0000 (+0100) Subject: Allow for both magnet and download URIs to be null. X-Git-Tag: 0.1~38^2~1 X-Git-Url: https://git.pterodactylus.net/?p=rhynodge.git;a=commitdiff_plain;h=a6e8911302a7482787136ef41d1fdb0448d81c1f Allow for both magnet and download URIs to be null. --- diff --git a/src/main/java/net/pterodactylus/reactor/states/TorrentState.java b/src/main/java/net/pterodactylus/reactor/states/TorrentState.java index f3b3546..f3479a2 100644 --- a/src/main/java/net/pterodactylus/reactor/states/TorrentState.java +++ b/src/main/java/net/pterodactylus/reactor/states/TorrentState.java @@ -179,7 +179,8 @@ public class TorrentState extends AbstractState implements Iterable /** * 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 /** * 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; diff --git a/src/main/java/net/pterodactylus/reactor/triggers/NewEpisodeTrigger.java b/src/main/java/net/pterodactylus/reactor/triggers/NewEpisodeTrigger.java index 4504d60..04b6956 100644 --- a/src/main/java/net/pterodactylus/reactor/triggers/NewEpisodeTrigger.java +++ b/src/main/java/net/pterodactylus/reactor/triggers/NewEpisodeTrigger.java @@ -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("").append(torrentFile.fileCount()).append(" file(s), "); htmlBuilder.append("").append(torrentFile.seedCount()).append(" seed(s), "); htmlBuilder.append("").append(torrentFile.leechCount()).append(" leecher(s)\n"); - htmlBuilder.append("
Magnet "); - htmlBuilder.append("Download
\n"); + htmlBuilder.append("
"); + if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) { + htmlBuilder.append("Magnet "); + } + if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) { + htmlBuilder.append("Download"); + } + htmlBuilder.append("
\n"); } htmlBuilder.append("\n"); } @@ -219,8 +233,14 @@ public class NewEpisodeTrigger implements Trigger { htmlBuilder.append("").append(torrentFile.fileCount()).append(" file(s), "); htmlBuilder.append("").append(torrentFile.seedCount()).append(" seed(s), "); htmlBuilder.append("").append(torrentFile.leechCount()).append(" leecher(s)\n"); - htmlBuilder.append("
Magnet "); - htmlBuilder.append("Download
\n"); + htmlBuilder.append("
"); + if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) { + htmlBuilder.append("Magnet "); + } + if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) { + htmlBuilder.append("Download"); + } + htmlBuilder.append("
\n"); } htmlBuilder.append("\n"); } diff --git a/src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java b/src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java index ab640c6..64ff693 100644 --- a/src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java +++ b/src/main/java/net/pterodactylus/reactor/triggers/NewTorrentTrigger.java @@ -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("
  • ").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("
  • "); htmlText.append("
    Size: ").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append(" in ").append(torrentFile.fileCount()).append(" file(s)
    "); htmlText.append("
    ").append(torrentFile.seedCount()).append(" seed(s), ").append(torrentFile.leechCount()).append(" leecher(s)
    "); - htmlText.append(String.format("
    Magnet URI
    ", StringEscapeUtils.escapeHtml4(torrentFile.magnetUri()))); - htmlText.append(String.format("
    Download URI
    ", StringEscapeUtils.escapeHtml4(torrentFile.downloadUri()))); + if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) { + htmlText.append(String.format("
    Magnet URI
    ", StringEscapeUtils.escapeHtml4(torrentFile.magnetUri()))); + } + if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) { + htmlText.append(String.format("
    Download URI
    ", StringEscapeUtils.escapeHtml4(torrentFile.downloadUri()))); + } } htmlText.append("\n"); htmlText.append("\n");