package net.pterodactylus.arachne.core;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;
+import net.pterodactylus.arachne.parser.HtmlEditorKitParser;
+import net.pterodactylus.arachne.parser.ParserListener;
import de.ina.util.validation.Validation;
/**
*
* @author David ‘Bombe’ Roden <bombe@pterodactylus.net>
*/
-class URLFetcher implements Runnable {
+class URLFetcher implements Runnable, ParserListener {
/** The logger. */
private static final Logger logger = Logger.getLogger(URLFetcher.class.getName());
long contentLength = urlConnection.getContentLength();
String contentType = urlConnection.getContentType();
logger.log(Level.INFO, "Type is “" + contentType + "”, length is " + contentLength + ".");
+ HtmlEditorKitParser htmlEditorKitParser = new HtmlEditorKitParser();
+ htmlEditorKitParser.parse(this, urlConnection.getInputStream(), "UTF-8");
} catch (IOException ioe1) {
logger.log(Level.WARNING, "Could not fetch “" + url + "”.", ioe1);
}
}
+ //
+ // INTERFACE ParserListener
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ public void parsedLink(InputStream inputStream, String linkTarget, String linkTitle, String linkText) {
+ System.out.println("Found link to “" + linkTarget + "” named “" + linkText + "” or “" + linkTitle + "”.");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void parsedTitle(InputStream inputStream, String title) {
+ System.out.println("Found title “" + title + "”.");
+ }
+
}