Store in link type whether a link is an internet link.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Nov 2013 21:47:51 +0000 (22:47 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:56 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java

index 396c660..6086918 100644 (file)
@@ -58,32 +58,33 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
        private enum LinkType {
 
                /** Link is a KSK. */
-               KSK("KSK@", true),
+               KSK("KSK@", true, false),
 
                /** Link is a CHK. */
-               CHK("CHK@", true),
+               CHK("CHK@", true, false),
 
                /** Link is an SSK. */
-               SSK("SSK@", true),
+               SSK("SSK@", true, false),
 
                /** Link is a USK. */
-               USK("USK@", true),
+               USK("USK@", true, false),
 
                /** Link is HTTP. */
-               HTTP("http://", false),
+               HTTP("http://", false, true),
 
                /** Link is HTTPS. */
-               HTTPS("https://", false),
+               HTTPS("https://", false, true),
 
                /** Link is a Sone. */
-               SONE("sone://", false),
+               SONE("sone://", false, false),
 
                /** Link is a post. */
-               POST("post://", false);
+               POST("post://", false, false);
 
                /** The scheme identifying this link type. */
                private final String scheme;
                private final boolean freenetLink;
+               private final boolean internetLink;
 
                /**
                 * Creates a new link type identified by the given scheme.
@@ -92,9 +93,10 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                 *            The scheme of the link type
                 * @param freenetLink
                 */
-               private LinkType(String scheme, boolean freenetLink) {
+               private LinkType(String scheme, boolean freenetLink, boolean internetLink) {
                        this.scheme = scheme;
                        this.freenetLink = freenetLink;
+                       this.internetLink = internetLink;
                }
 
                /**
@@ -110,6 +112,10 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                        return freenetLink;
                }
 
+               public boolean isInternetLink() {
+                       return internetLink;
+               }
+
        }
 
        private final Database database;
@@ -299,7 +305,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                                        /* oh, and these, too. */
                                                        parts.add(new PlainTextPart(link));
                                                }
-                                       } else if ((linkType == LinkType.HTTP) || (linkType == LinkType.HTTPS)) {
+                                       } else if (linkType.isInternetLink()) {
                                                name = link.substring(linkType == LinkType.HTTP ? 7 : 8);
                                                int firstSlash = name.indexOf('/');
                                                int lastSlash = name.lastIndexOf('/');