From 0669aab9c004816d56a5e16c17b0492b53ddf9a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 9 Mar 2009 21:05:47 +0100 Subject: [PATCH] Use HTMLEditorKit parser in URL fetcher. --- src/net/pterodactylus/arachne/core/URLFetcher.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 + "”."); + } + } -- 2.7.4