2 * Copyright (c) 2012, the Last.fm Java Project and Committers All rights
3 * reserved. Redistribution and use of this software in source and binary forms,
4 * with or without modification, are permitted provided that the following
5 * conditions are met: - Redistributions of source code must retain the above
6 * copyright notice, this list of conditions and the following disclaimer. -
7 * Redistributions in binary form must reproduce the above copyright notice,
8 * this list of conditions and the following disclaimer in the documentation
9 * and/or other materials provided with the distribution. THIS SOFTWARE IS
10 * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
11 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
13 * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
14 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
16 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
17 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 package com.cyanogenmod.eleven.lastfm;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.Locale;
31 * Abstract superclass for all items that may contain images (such as
32 * {@link Artist}s, {@link Album}s or {@link Track}s).
34 * @author Janni Kovacs
36 public abstract class ImageHolder {
38 protected Map<ImageSize, String> imageUrls = new HashMap<ImageSize, String>();
41 * Returns a Set of all {@link ImageSize}s available.
45 public Set<ImageSize> availableSizes() {
46 return imageUrls.keySet();
50 * Returns the URL of the image in the specified size, or <code>null</code>
53 * @param size The preferred size
54 * @return an image URL
56 public String getImageURL(final ImageSize size) {
57 return imageUrls.get(size);
64 protected static void loadImages(final ImageHolder holder, final DomElement element) {
65 final Collection<DomElement> images = element.getChildren("image");
66 for (final DomElement image : images) {
67 final String attribute = image.getAttribute("size");
68 ImageSize size = null;
69 if (attribute == null) {
70 size = ImageSize.UNKNOWN;
73 size = ImageSize.valueOf(attribute.toUpperCase(Locale.ENGLISH));
74 } catch (final IllegalArgumentException e) {
75 // if they suddenly again introduce a new image size
79 holder.imageUrls.put(size, image.getText());