Convert the URI a Sone was downloaded from to USK before setting it.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneDownloader.java
index 7133797..2310aca 100644 (file)
@@ -26,6 +26,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import net.pterodactylus.sone.core.Core.SoneStatus;
+import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Reply;
@@ -154,7 +155,11 @@ public class SoneDownloader extends AbstractService {
                        soneInputStream = soneBucket.getInputStream();
                        Sone parsedSone = parseSone(originalSone, soneInputStream);
                        if (parsedSone != null) {
-                               parsedSone.setRequestUri(requestUri.setMetaString(new String[0]));
+                               if (requestUri.getKeyType().equals("USK")) {
+                                       parsedSone.setRequestUri(requestUri.setMetaString(new String[0]));
+                               } else {
+                                       parsedSone.setRequestUri(requestUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]));
+                               }
                        }
                        return parsedSone;
                } catch (IOException ioe1) {
@@ -215,6 +220,17 @@ public class SoneDownloader extends AbstractService {
                        return null;
                }
 
+               SimpleXML clientXml = soneXml.getNode("client");
+               if (clientXml != null) {
+                       String clientName = clientXml.getValue("name", null);
+                       String clientVersion = clientXml.getValue("version", null);
+                       if ((clientName == null) || (clientVersion == null)) {
+                               logger.log(Level.WARNING, "Download Sone %s with client XML but missing name or version!", sone);
+                               return null;
+                       }
+                       sone.setClient(new Client(clientName, clientVersion));
+               }
+
                String soneRequestUri = soneXml.getValue("request-uri", null);
                if (soneRequestUri != null) {
                        try {