Store request URI in yet unknown Sones when parsing.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 16 Oct 2010 02:59:53 +0000 (04:59 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 16 Oct 2010 02:59:53 +0000 (04:59 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java

index ccd5aff..b838216 100644 (file)
@@ -310,8 +310,9 @@ public class Core extends AbstractService {
         */
        public void loadSone(String requestUri) {
                try {
         */
        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);
                }
                } catch (MalformedURLException mue1) {
                        logger.log(Level.INFO, "Could not create URI from “" + requestUri + "”.", mue1);
                }
index 9f6ce5e..a8d7deb 100644 (file)
@@ -37,6 +37,7 @@ import net.pterodactylus.util.xml.XML;
 import org.w3c.dom.Document;
 
 import freenet.client.FetchResult;
 import org.w3c.dom.Document;
 
 import freenet.client.FetchResult;
+import freenet.keys.FreenetURI;
 import freenet.support.api.Bucket;
 
 /**
 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" }) });
         */
        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());
                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);
                }
                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
         *            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
         */
         * @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;
                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) {
                        /* 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);
                        }
 
                        String soneName = soneXml.getValue("name", null);