2 * Copyright (c) 2012, the Last.fm Java Project and Committers
\r
3 * All rights reserved.
\r
5 * Redistribution and use of this software in source and binary forms, with or without modification, are
\r
6 * permitted provided that the following conditions are met:
\r
8 * - Redistributions of source code must retain the above
\r
9 * copyright notice, this list of conditions and the
\r
10 * following disclaimer.
\r
12 * - Redistributions in binary form must reproduce the above
\r
13 * copyright notice, this list of conditions and the
\r
14 * following disclaimer in the documentation and/or other
\r
15 * materials provided with the distribution.
\r
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
\r
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
\r
19 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
\r
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
\r
23 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
\r
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 package com.andrew.apollo.lastfm.api;
\r
29 import java.util.Locale;
\r
31 import com.andrew.apollo.utils.DomElement;
\r
34 * An <code>Image</code> contains metadata and URLs for an artist's image.
\r
35 * Metadata contains title, votes, format and other. Images are available in
\r
36 * various sizes, see {@link ImageSize} for all sizes.
\r
38 * @author Janni Kovacs
\r
40 * @see Artist#getImages(String, String)
\r
42 public class Image extends ImageHolder {
\r
44 static final ItemFactory<Image> FACTORY = new ImageFactory();
\r
51 public String getUrl() {
\r
55 private static class ImageFactory implements ItemFactory<Image> {
\r
57 public Image createItemFromElement(DomElement element) {
\r
58 Image i = new Image();
\r
59 i.url = element.getChildText("url");
\r
60 DomElement sizes = element.getChild("sizes");
\r
61 for (DomElement image : sizes.getChildren("size")) {
\r
62 // code copied from ImageHolder.loadImages
\r
63 String attribute = image.getAttribute("name");
\r
64 ImageSize size = null;
\r
65 if (attribute == null) {
\r
66 size = ImageSize.LARGESQUARE;
\r
69 size = ImageSize.valueOf(attribute.toUpperCase(Locale.ENGLISH));
\r
70 } catch (IllegalArgumentException e) {
\r
71 // if they suddenly again introduce a new image size
\r
75 i.imageUrls.put(size, image.getText());
\r