Add new links to core.
[arachne.git] / src / net / pterodactylus / arachne / core / URLFetcher.java
index df8180f..0b4cb47 100644 (file)
@@ -2,6 +2,7 @@ package net.pterodactylus.arachne.core;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.logging.Level;
@@ -69,14 +70,21 @@ class URLFetcher implements Runnable, ParserListener {
         * {@inheritDoc}
         */
        public void parsedLink(InputStream inputStream, String linkTarget, String linkTitle, String linkText) {
-               System.out.println("Found link to “" + linkTarget + "” named “" + linkText + "” or “" + linkTitle + "”.");
+               URL newLink = null;
+               try {
+                       newLink = new URL(url, linkTarget);
+                       core.addPage(newLink);
+               } catch (MalformedURLException mue1) {
+                       logger.log(Level.WARNING, "Could not create URL from “" + url + "” and “" + linkTarget + "”.", mue1);
+               } catch (IllegalArgumentException iae1) {
+                       logger.log(Level.WARNING, "Could not add “" + newLink + "” to core queue.", iae1);
+               }
        }
 
        /**
         * {@inheritDoc}
         */
        public void parsedTitle(InputStream inputStream, String title) {
-               System.out.println("Found title “" + title + "”.");
        }
 
 }