+ SimpleXML soneXml;
+ try {
+ soneXml = SimpleXML.fromDocument(document);
+ } catch (NullPointerException npe1) {
+ /* for some reason, invalid XML can cause NPEs. */
+ logger.log(Level.WARNING, String.format("XML for Sone %s can not be parsed!", sone), npe1);
+ return null;
+ }
+
+ Integer protocolVersion = null;
+ String soneProtocolVersion = soneXml.getValue("protocol-version", null);
+ if (soneProtocolVersion != null) {
+ protocolVersion = Numbers.safeParseInteger(soneProtocolVersion);
+ }
+ if (protocolVersion == null) {
+ logger.log(Level.INFO, "No protocol version found, assuming 0.");
+ protocolVersion = 0;
+ }
+
+ if (protocolVersion < 0) {
+ logger.log(Level.WARNING, String.format("Invalid protocol version: %d! Not parsing Sone.", protocolVersion));
+ return null;
+ }
+
+ /* check for valid versions. */
+ if (protocolVersion > MAX_PROTOCOL_VERSION) {
+ logger.log(Level.WARNING, String.format("Unknown protocol version: %d! Not parsing Sone.", protocolVersion));
+ return null;
+ }
+
+ String soneTime = soneXml.getValue("time", null);
+ if (soneTime == null) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, String.format("Downloaded time for Sone %s was null!", sone));
+ return null;
+ }
+ try {
+ sone.setTime(Long.parseLong(soneTime));
+ } catch (NumberFormatException nfe1) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, String.format("Downloaded Sone %s with invalid time: %s", sone, soneTime));
+ 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, String.format("Download Sone %s with client XML but missing name or version!", sone));