aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/musichub/business/Song.java
blob: 564b7c51e5694f1730454f5c94c195a2719b7144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package musichub.business;

import org.w3c.dom.Document;
import org.w3c.dom.Element;


public class Song extends AudioElement {
    private Genre genre;

    public Song(String title, String artist, int length, String uid, String content, String genre) {
        super(title, artist, length, uid, content);
        this.setGenre(genre);
    }

    public Song(String title, String artist, int length, String content, String genre) {
        super(title, artist, length, content);
        this.setGenre(genre);
    }

    public Song(Element xmlElement) {
        super(xmlElement);
        this.setGenre(xmlElement.getElementsByTagName("genre").item(0).getTextContent());
    }

    public String getGenre() {
        return genre.getGenre();
    }

    public void setGenre(String genre) {
        switch (genre.toLowerCase()) {
            default -> this.genre = Genre.JAZZ;
            case "classic" -> this.genre = Genre.CLASSIC;
            case "hiphop" -> this.genre = Genre.HIPHOP;
            case "rock" -> this.genre = Genre.ROCK;
            case "pop" -> this.genre = Genre.POP;
            case "rap" -> this.genre = Genre.RAP;
        }
    }

    public String toString() {
        return super.toString() + ", Genre = " + getGenre() + "\n";
    }

    public void createXMLElement(Document document, Element parentElement) {
        // song element
        Element song = document.createElement("song");

        super.createXMLElement(document, song);

        Element genreElement = document.createElement("genre");
        genreElement.appendChild(document.createTextNode(genre.getGenre()));
        song.appendChild(genreElement);

        parentElement.appendChild(song);
    }
    

}