+ Album parent = null;
+ if (parentId != null) {
+ parent = core.getAlbum(parentId, false);
+ if (parent == null) {
+ logger.log(Level.WARNING, String.format("Downloaded Sone %s has album with invalid parent!", sone));
+ return null;
+ }
+ }
+ Album album = core.getAlbum(id).setSone(sone).setTitle(title).setDescription(description);
+ if (parent != null) {
+ parent.addAlbum(album);
+ } else {
+ topLevelAlbums.add(album);
+ }
+ SimpleXML imagesXml = albumXml.getNode("images");
+ if (imagesXml != null) {
+ for (SimpleXML imageXml : imagesXml.getNodes("image")) {
+ String imageId = imageXml.getValue("id", null);
+ String imageCreationTimeString = imageXml.getValue("creation-time", null);
+ String imageKey = imageXml.getValue("key", null);
+ String imageTitle = imageXml.getValue("title", null);
+ String imageDescription = imageXml.getValue("description", "");
+ String imageWidthString = imageXml.getValue("width", null);
+ String imageHeightString = imageXml.getValue("height", null);
+ if ((imageId == null) || (imageCreationTimeString == null) || (imageKey == null) || (imageTitle == null) || (imageWidthString == null) || (imageHeightString == null)) {
+ logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid images!", sone));
+ return null;
+ }
+ long creationTime = Numbers.safeParseLong(imageCreationTimeString, 0L);
+ int imageWidth = Numbers.safeParseInteger(imageWidthString, 0);
+ int imageHeight = Numbers.safeParseInteger(imageHeightString, 0);
+ if ((imageWidth < 1) || (imageHeight < 1)) {
+ logger.log(Level.WARNING, String.format("Downloaded Sone %s contains image %s with invalid dimensions (%s, %s)!", sone, imageId, imageWidthString, imageHeightString));
+ return null;
+ }
+ Image image = core.getImage(imageId).setSone(sone).setKey(imageKey).setCreationTime(creationTime);
+ image.setTitle(imageTitle).setDescription(imageDescription);
+ image.setWidth(imageWidth).setHeight(imageHeight);
+ album.addImage(image);
+ }