From: David ‘Bombe’ Roden Date: Mon, 9 Mar 2009 20:05:47 +0000 (+0100) Subject: Use HTMLEditorKit parser in URL fetcher. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0669aab9c004816d56a5e16c17b0492b53ddf9a8;p=arachne.git Use HTMLEditorKit parser in URL fetcher. --- diff --git a/src/net/pterodactylus/arachne/core/URLFetcher.java b/src/net/pterodactylus/arachne/core/URLFetcher.java index 8f8465d..df8180f 100644 --- a/src/net/pterodactylus/arachne/core/URLFetcher.java +++ b/src/net/pterodactylus/arachne/core/URLFetcher.java @@ -1,11 +1,14 @@ 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; /** @@ -14,7 +17,7 @@ import de.ina.util.validation.Validation; * * @author David ‘Bombe’ Roden */ -class URLFetcher implements Runnable { +class URLFetcher implements Runnable, ParserListener { /** The logger. */ private static final Logger logger = Logger.getLogger(URLFetcher.class.getName()); @@ -51,9 +54,29 @@ class URLFetcher implements Runnable { 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 + "”."); + } + }