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;
* @return The parsed Sone, or {@code null} if the Sone could not be parsed
*/
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 });
+ logger.log(Level.FINEST, "Parsing FetchResult (%d bytes, %s) for %s…", new Object[] { fetchResult.size(), fetchResult.getMimeType(), originalSone });
Bucket soneBucket = fetchResult.asBucket();
InputStream soneInputStream = null;
try {
}
/**
- * Parses a Sone from the given input stream and updates the given Sone, or
- * creates a new Sone.
+ * Parses a Sone from the given input stream and creates a new Sone from the
+ * parsed data.
*
- * @param sone
+ * @param originalSone
* The Sone to update
* @param soneInputStream
* The input stream to parse the Sone from
* @return The parsed Sone
*/
- public Sone parseSone(Sone sone, InputStream soneInputStream) {
+ public Sone parseSone(Sone originalSone, InputStream soneInputStream) {
/* TODO - impose a size limit? */
Document document;
}
if (document == null) {
/* TODO - mark Sone as bad. */
- logger.log(Level.WARNING, "Could not parse XML for Sone %s!", new Object[] { sone });
+ logger.log(Level.WARNING, "Could not parse XML for Sone %s!", new Object[] { originalSone });
return null;
}
+
+ Sone sone = new Sone(originalSone.getId()).setIdentity(originalSone.getIdentity());
+
SimpleXML soneXml;
try {
soneXml = SimpleXML.fromDocument(document);
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 {
sone.setPosts(posts);
sone.setReplies(replies);
sone.setLikePostIds(likedPostIds);
- sone.setModificationCounter(0);
}
return sone;