- private void updateSoneFromXml(Sone sone, FetchResult fetchResult) {
- logger.log(Level.FINEST, "Persing FetchResult (%d bytes, %s) for %s…", new Object[] { fetchResult.size(), fetchResult.getMimeType(), sone });
+ public Sone parseSone(Sone originalSone, FetchResult fetchResult, FreenetURI requestUri) {
+ 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 {
+ soneInputStream = soneBucket.getInputStream();
+ Sone parsedSone = parseSone(originalSone, soneInputStream);
+ if (parsedSone != null) {
+ parsedSone.setLatestEdition(requestUri.getEdition());
+ 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) {
+ logger.log(Level.WARNING, "Could not parse Sone from " + requestUri + "!", ioe1);
+ } finally {
+ Closer.close(soneInputStream);
+ soneBucket.free();
+ }
+ return null;
+ }
+
+ /**
+ * Parses a Sone from the given input stream and creates a new Sone from the
+ * parsed data.
+ *
+ * @param originalSone
+ * The Sone to update
+ * @param soneInputStream
+ * The input stream to parse the Sone from
+ * @return The parsed Sone
+ */
+ public Sone parseSone(Sone originalSone, InputStream soneInputStream) {