X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloader.java;h=0812f668110836d39287639d47b0e0699c43e0cc;hp=56c1e4a28f0f5444dbd077951b585bd4be49d8fe;hb=bb2c8cb2d47a77bcef2d299ad4bf8e16f22a6198;hpb=3c7c28dad396ea710bec838550ffd54718d7999a diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 56c1e4a..0812f66 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -25,7 +25,6 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import net.pterodactylus.sone.core.Core.Preferences; import net.pterodactylus.sone.core.Core.SoneStatus; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Post; @@ -124,8 +123,7 @@ public class SoneDownloader extends AbstractService { /** * Fetches the updated Sone. This method can be used to fetch a Sone from a - * specific URI (which happens when {@link Preferences#isSoneRescueMode() - * „Sone rescue mode“} is active). + * specific URI. * * @param sone * The Sone to fetch @@ -133,6 +131,23 @@ public class SoneDownloader extends AbstractService { * The URI to fetch the Sone from */ public void fetchSone(Sone sone, FreenetURI soneUri) { + fetchSone(sone, soneUri, false); + } + + /** + * Fetches the Sone from the given URI. + * + * @param sone + * The Sone to fetch + * @param soneUri + * The URI of the Sone to fetch + * @param fetchOnly + * {@code true} to only fetch and parse the Sone, {@code false} + * to {@link Core#updateSone(Sone) update} it in the core + * @return The downloaded Sone, or {@code null} if the Sone could not be + * downloaded + */ + public Sone fetchSone(Sone sone, FreenetURI soneUri, boolean fetchOnly) { logger.log(Level.FINE, "Starting fetch for Sone “%s” from %s…", new Object[] { sone, soneUri }); FreenetURI requestUri = soneUri.setMetaString(new String[] { "sone.xml" }); core.setSoneStatus(sone, SoneStatus.downloading); @@ -140,14 +155,17 @@ public class SoneDownloader extends AbstractService { Pair fetchResults = freenetInterface.fetchUri(requestUri); if (fetchResults == null) { /* TODO - mark Sone as bad. */ - return; + return null; } logger.log(Level.FINEST, "Got %d bytes back.", fetchResults.getRight().size()); Sone parsedSone = parseSone(sone, fetchResults.getRight(), fetchResults.getLeft()); if (parsedSone != null) { - addSone(parsedSone); - core.updateSone(parsedSone); + if (!fetchOnly) { + core.updateSone(parsedSone); + addSone(parsedSone); + } } + return parsedSone; } finally { core.setSoneStatus(sone, (sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle); }