import net.pterodactylus.util.xml.SimpleXML;
import net.pterodactylus.util.xml.XML;
+import com.google.common.annotations.VisibleForTesting;
import org.w3c.dom.Document;
import freenet.client.FetchResult;
}
/**
- * Removes the given Sone from the downloader.
- *
- * @param sone
- * The Sone to stop watching
- */
- public void removeSone(Sone sone) {
- if (sones.remove(sone)) {
- freenetInterface.unregisterUsk(sone);
- }
- }
-
- /**
* Fetches the updated Sone. This method is a callback method for
* {@link FreenetInterface#registerUsk(Sone, SoneDownloader)}.
*
* The requested URI
* @return The parsed Sone, or {@code null} if the Sone could not be parsed
*/
- public Sone parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI requestUri) {
+ private Sone parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI requestUri) {
logger.log(Level.FINEST, String.format("Parsing FetchResult (%d bytes, %s) for %s…", fetchResult.size(), fetchResult.getMimeType(), originalSone));
Bucket soneBucket = fetchResult.asBucket();
InputStream soneInputStream = null;
* @throws SoneException
* if a parse error occurs, or the protocol is invalid
*/
- public Sone parseSone(Sone originalSone, InputStream soneInputStream) throws SoneException {
+ @VisibleForTesting
+ protected Sone parseSone(Sone originalSone, InputStream soneInputStream) throws SoneException {
/* TODO - impose a size limit? */
Document document;
return null;
}
try {
- profile.addField(fieldName).setValue(fieldValue);
+ profile.addField(fieldName.trim()).setValue(fieldValue);
} catch (IllegalArgumentException iae1) {
logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName), iae1);
return null;
String title = albumXml.getValue("title", null);
String description = albumXml.getValue("description", "");
String albumImageId = albumXml.getValue("album-image", null);
- if ((id == null) || (title == null) || (description == null)) {
+ if ((id == null) || (title == null)) {
logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid album!", sone));
return null;
}
}
}
+ public class FetchSoneWithUri implements Runnable {
+
+ private final Sone sone;
+
+ public FetchSoneWithUri(Sone sone) {
+ this.sone = sone;
+ }
+
+ @Override
+ public void run() {
+ fetchSone(sone, sone.getRequestUri());
+ }
+
+ }
+
+ public class FetchSone implements Runnable {
+
+ private final Sone sone;
+
+ public FetchSone(Sone sone) {
+ this.sone = sone;
+ }
+
+ @Override
+ public void run() {
+ fetchSone(sone);
+ }
+
+ }
+
}