Restrict access to methods.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneDownloader.java
index 8f4bf7d..b080549 100644 (file)
@@ -45,6 +45,7 @@ import net.pterodactylus.util.service.AbstractService;
 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;
@@ -105,18 +106,6 @@ public class SoneDownloader extends AbstractService {
        }
 
        /**
-        * 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)}.
         *
@@ -189,7 +178,7 @@ public class SoneDownloader extends AbstractService {
         *            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;
@@ -226,7 +215,8 @@ public class SoneDownloader extends AbstractService {
         * @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;
@@ -342,7 +332,7 @@ public class SoneDownloader extends AbstractService {
                                        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;
@@ -449,7 +439,7 @@ public class SoneDownloader extends AbstractService {
                                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;
                                }
@@ -548,4 +538,19 @@ public class SoneDownloader extends AbstractService {
 
        }
 
+       public class FetchSone implements Runnable {
+
+               private final Sone sone;
+
+               public FetchSone(Sone sone) {
+                       this.sone = sone;
+               }
+
+               @Override
+               public void run() {
+                       fetchSone(sone);
+               }
+
+       }
+
 }