+
+ private Optional<Integer> parseProtocolVersion(SimpleXML soneXml) {
+ String soneProtocolVersion = soneXml.getValue("protocol-version", null);
+ if (soneProtocolVersion == null) {
+ logger.log(Level.INFO, "No protocol version found, assuming 0.");
+ return absent();
+ }
+ return fromNullable(Ints.tryParse(soneProtocolVersion));
+ }
+
+ private Optional<SimpleXML> parseXml(Sone originalSone, Document document) {
+ try {
+ return fromNullable(SimpleXML.fromDocument(document));
+ } catch (NullPointerException npe1) {
+ /* for some reason, invalid XML can cause NPEs. */
+ return absent();
+ }
+ }
+
+ private Optional<Client> parseClient(Sone sone, SimpleXML soneXml) {
+ SimpleXML clientXml = soneXml.getNode("client");
+ if (clientXml == null) {
+ return absent();
+ }
+ String clientName = clientXml.getValue("name", null);
+ String clientVersion = clientXml.getValue("version", null);
+ if ((clientName == null) || (clientVersion == null)) {
+ logger.log(Level.WARNING, String.format("Download Sone %s with client XML but missing name or version!", sone));
+ return null;
+ }
+ return of(new Client(clientName, clientVersion));
+ }
+