Use provider interfaces instead of core.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 9 Jun 2011 08:37:14 +0000 (10:37 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 9 Jun 2011 08:37:14 +0000 (10:37 +0200)
This will allow creating a test case without creating a core.

src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index 98bb800..2787d52 100644 (file)
@@ -26,7 +26,8 @@ import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.logging.Logging;
@@ -78,17 +79,23 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
 
        }
 
 
        }
 
-       /** The core. */
-       private final Core core;
+       /** The Sone provider. */
+       private final SoneProvider soneProvider;
+
+       /** The post provider. */
+       private final PostProvider postProvider;
 
        /**
         * Creates a new freenet link parser.
         *
 
        /**
         * Creates a new freenet link parser.
         *
-        * @param core
-        *            The core
+        * @param soneProvider
+        *            The Sone provider
+        * @param postProvider
+        *            The post provider
         */
         */
-       public SoneTextParser(Core core) {
-               this.core = core;
+       public SoneTextParser(SoneProvider soneProvider, PostProvider postProvider) {
+               this.soneProvider = soneProvider;
+               this.postProvider = postProvider;
        }
 
        //
        }
 
        //
@@ -174,7 +181,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                        }
                                        if (line.length() >= (next + 7 + 43)) {
                                                String soneId = line.substring(next + 7, next + 50);
                                        }
                                        if (line.length() >= (next + 7 + 43)) {
                                                String soneId = line.substring(next + 7, next + 50);
-                                               Sone sone = core.getSone(soneId, false);
+                                               Sone sone = soneProvider.getSone(soneId, false);
                                                if (sone != null) {
                                                        parts.add(new SonePart(sone));
                                                } else {
                                                if (sone != null) {
                                                        parts.add(new SonePart(sone));
                                                } else {
@@ -193,7 +200,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                        }
                                        if (line.length() >= (next + 7 + 36)) {
                                                String postId = line.substring(next + 7, next + 43);
                                        }
                                        if (line.length() >= (next + 7 + 36)) {
                                                String postId = line.substring(next + 7, next + 43);
-                                               Post post = core.getPost(postId, false);
+                                               Post post = postProvider.getPost(postId, false);
                                                if ((post != null) && (post.getSone() != null)) {
                                                        String postText = post.getText();
                                                        postText = postText.substring(0, Math.min(postText.length(), 20)) + "…";
                                                if ((post != null) && (post.getSone() != null)) {
                                                        String postText = post.getText();
                                                        postText = postText.substring(0, Math.min(postText.length(), 20)) + "…";
index 8eb0122..d0034dd 100644 (file)
@@ -196,7 +196,7 @@ public class WebInterface implements CoreListener {
        public WebInterface(SonePlugin sonePlugin) {
                this.sonePlugin = sonePlugin;
                formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
        public WebInterface(SonePlugin sonePlugin) {
                this.sonePlugin = sonePlugin;
                formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
-               soneTextParser = new SoneTextParser(getCore());
+               soneTextParser = new SoneTextParser(getCore(), getCore());
 
                templateContextFactory = new TemplateContextFactory();
                templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
 
                templateContextFactory = new TemplateContextFactory();
                templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());