OSDN Git Service

6ffc63509e0ac339983596f34a7c3caf48c9c0ee
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / lastfm / MusicEntry.java
1 /*
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.
20  */
21
22 package com.cyanogenmod.eleven.lastfm;
23
24 /**
25  * <code>MusicEntry</code> is the abstract superclass for {@link Track},
26  * {@link Artist} and {@link Album}. It encapsulates data and provides methods
27  * used in all subclasses, for example: name, playcount, images and more.
28  * 
29  * @author Janni Kovacs
30  */
31 public abstract class MusicEntry extends ImageHolder {
32
33     protected String name;
34
35     protected String url;
36
37     private String wikiSummary;
38
39     protected MusicEntry(final String name, final String url) {
40         this.name = name;
41         this.url = url;
42     }
43
44     public String getName() {
45         return name;
46     }
47
48     public String getUrl() {
49         return url;
50     }
51
52     public String getWikiSummary() {
53         return wikiSummary;
54     }
55
56     @Override
57     public String toString() {
58         return this.getClass().getSimpleName() + "[" + "name='" + name + '\'' + ", url='" + url
59                 + '\'' + ']';
60     }
61
62     /**
63      * Loads all generic information from an XML <code>DomElement</code> into
64      * the given <code>MusicEntry</code> instance, i.e. the following tags:<br/>
65      * <ul>
66      * <li>playcount/plays</li>
67      * <li>listeners</li>
68      * <li>streamable</li>
69      * <li>name</li>
70      * <li>url</li>
71      * <li>mbid</li>
72      * <li>image</li>
73      * <li>tags</li>
74      * </ul>
75      * 
76      * @param entry An entry
77      * @param element XML source element
78      */
79     protected static void loadStandardInfo(final MusicEntry entry, final DomElement element) {
80         // copy
81         entry.name = element.getChildText("name");
82         entry.url = element.getChildText("url");
83         // wiki
84         DomElement wiki = element.getChild("bio");
85         if (wiki == null) {
86             wiki = element.getChild("wiki");
87         }
88         if (wiki != null) {
89             entry.wikiSummary = wiki.getChildText("summary");
90         }
91         // images
92         ImageHolder.loadImages(entry, element);
93     }
94 }