From 358a9a2ab0ead0cc4dd86e3b97fa387ec958ec01 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 16 Oct 2010 04:59:53 +0200 Subject: [PATCH] Store request URI in yet unknown Sones when parsing. --- src/main/java/net/pterodactylus/sone/core/Core.java | 5 +++-- .../java/net/pterodactylus/sone/core/SoneDownloader.java | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index ccd5aff..b838216 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -310,8 +310,9 @@ public class Core extends AbstractService { */ public void loadSone(String requestUri) { try { - FetchResult fetchResult = freenetInterface.fetchUri(new FreenetURI(requestUri).setMetaString(new String[] { "sone.xml" })); - soneDownloader.parseSone(null, fetchResult); + FreenetURI realRequestUri = new FreenetURI(requestUri).setMetaString(new String[] { "sone.xml" }); + FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri); + soneDownloader.parseSone(null, fetchResult, realRequestUri); } catch (MalformedURLException mue1) { logger.log(Level.INFO, "Could not create URI from “" + requestUri + "”.", mue1); } diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 9f6ce5e..a8d7deb 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -37,6 +37,7 @@ import net.pterodactylus.util.xml.XML; import org.w3c.dom.Document; import freenet.client.FetchResult; +import freenet.keys.FreenetURI; import freenet.support.api.Bucket; /** @@ -109,9 +110,10 @@ public class SoneDownloader extends AbstractService { */ public void fetchSone(Sone sone) { logger.log(Level.FINE, "Starting fetch for Sone “%s” from %s…", new Object[] { sone, sone.getRequestUri().setMetaString(new String[] { "sone.xml" }) }); - FetchResult fetchResult = freenetInterface.fetchUri(sone.getRequestUri().setMetaString(new String[] { "sone.xml" })); + FreenetURI requestUri = sone.getRequestUri().setMetaString(new String[] { "sone.xml" }); + FetchResult fetchResult = freenetInterface.fetchUri(requestUri); logger.log(Level.FINEST, "Got %d bytes back.", fetchResult.size()); - Sone parsedSone = parseSone(sone, fetchResult); + Sone parsedSone = parseSone(sone, fetchResult, requestUri); if (parsedSone != null) { core.addSone(parsedSone); } @@ -124,9 +126,11 @@ public class SoneDownloader extends AbstractService { * The sone to parse, or {@code null} if the Sone is yet unknown * @param fetchResult * The fetch result + * @param requestUri + * The requested URI * @return The parsed Sone, or {@code null} if the Sone could not be parsed */ - public Sone parseSone(Sone originalSone, FetchResult fetchResult) { + public Sone parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI requestUri) { logger.log(Level.FINEST, "Persing FetchResult (%d bytes, %s) for %s…", new Object[] { fetchResult.size(), fetchResult.getMimeType(), originalSone }); /* TODO - impose a size limit? */ InputStream xmlInputStream = null; @@ -156,7 +160,7 @@ public class SoneDownloader extends AbstractService { /* load Sone from core. */ sone = originalSone; if (sone == null) { - sone = core.getSone(soneId); + sone = core.getSone(soneId).setRequestUri(requestUri.setMetaString(new String[] {})); } String soneName = soneXml.getValue("name", null); -- 2.7.4