X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloader.java;h=da33b0b80435bf79ee2c28e212924975666a43cd;hb=c28a1233dc8daf4713b53f688110e0332e7a7340;hp=9f6ce5ea298c9e9b17851560a84fb587ecbb2a42;hpb=314be56fa3e4ac53dac18ae0282439559209f4b3;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 9f6ce5e..da33b0b 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); @@ -165,6 +169,7 @@ public class SoneDownloader extends AbstractService { logger.log(Level.WARNING, "Downloaded name for Sone %s was null!", new Object[] { sone }); return null; } + sone.setName(soneName); SimpleXML profileXml = soneXml.getNode("profile"); if (profileXml == null) {