View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.model.item;
17  
18  import org.fourthline.cling.support.model.Person;
19  import org.fourthline.cling.support.model.Res;
20  import org.fourthline.cling.support.model.container.Container;
21  
22  import java.net.URI;
23  import java.util.Arrays;
24  import java.util.List;
25  
26  import static org.fourthline.cling.support.model.DIDLObject.Property.DC;
27  import static org.fourthline.cling.support.model.DIDLObject.Property.UPNP;
28  
29  /**
30   * @author Christian Bauer
31   */
32  public class AudioItem extends Item {
33  
34      public static final Class CLASS = new Class("object.item.audioItem");
35  
36      public AudioItem() {
37          setClazz(CLASS);
38      }
39  
40      public AudioItem(Item other) {
41          super(other);
42      }
43  
44      public AudioItem(String id, Container parent, String title, String creator, Res... resource) {
45          this(id, parent.getId(), title, creator, resource);
46      }
47  
48      public AudioItem(String id, String parentID, String title, String creator, Res... resource) {
49          super(id, parentID, title, creator, CLASS);
50          if (resource != null) {
51              getResources().addAll(Arrays.asList(resource));
52          }
53      }
54  
55      public String getFirstGenre() {
56          return getFirstPropertyValue(UPNP.GENRE.class);
57      }
58  
59      public String[] getGenres() {
60          List<String> list = getPropertyValues(UPNP.GENRE.class);
61          return list.toArray(new String[list.size()]);
62      }
63  
64      public AudioItem setGenres(String[] genres) {
65          removeProperties(UPNP.GENRE.class);
66          for (String genre : genres) {
67              addProperty(new UPNP.GENRE(genre));
68          }
69          return this;
70      }
71  
72      public String getDescription() {
73          return getFirstPropertyValue(DC.DESCRIPTION.class);
74      }
75  
76      public AudioItem setDescription(String description) {
77          replaceFirstProperty(new DC.DESCRIPTION(description));
78          return this;
79      }
80  
81      public String getLongDescription() {
82          return getFirstPropertyValue(UPNP.LONG_DESCRIPTION.class);
83      }
84  
85      public AudioItem setLongDescription(String description) {
86          replaceFirstProperty(new UPNP.LONG_DESCRIPTION(description));
87          return this;
88      }
89  
90      public Person getFirstPublisher() {
91          return getFirstPropertyValue(DC.PUBLISHER.class);
92      }
93  
94      public Person[] getPublishers() {
95          List<Person> list = getPropertyValues(DC.PUBLISHER.class);
96          return list.toArray(new Person[list.size()]);
97      }
98  
99      public AudioItem setPublishers(Person[] publishers) {
100         removeProperties(DC.PUBLISHER.class);
101         for (Person publisher : publishers) {
102             addProperty(new DC.PUBLISHER(publisher));
103         }
104         return this;
105     }
106 
107     public URI getFirstRelation() {
108         return getFirstPropertyValue(DC.RELATION.class);
109     }
110 
111     public URI[] getRelations() {
112         List<URI> list = getPropertyValues(DC.RELATION.class);
113         return list.toArray(new URI[list.size()]);
114     }
115 
116     public AudioItem setRelations(URI[] relations) {
117         removeProperties(DC.RELATION.class);
118         for (URI relation : relations) {
119             addProperty(new DC.RELATION(relation));
120         }
121         return this;
122     }
123 
124     public String getLanguage() {
125         return getFirstPropertyValue(DC.LANGUAGE.class);
126     }
127 
128     public AudioItem setLanguage(String language) {
129         replaceFirstProperty(new DC.LANGUAGE(language));
130         return this;
131     }
132 
133     public String getFirstRights() {
134         return getFirstPropertyValue(DC.RIGHTS.class);
135     }
136 
137     public String[] getRights() {
138         List<String> list = getPropertyValues(DC.RIGHTS.class);
139         return list.toArray(new String[list.size()]);
140     }
141 
142     public AudioItem setRights(String[] rights) {
143         removeProperties(DC.RIGHTS.class);
144         for (String right : rights) {
145             addProperty(new DC.RIGHTS(right));
146         }
147         return this;
148     }
149 }
150