summaryrefslogtreecommitdiffstats
blob: bb299e44eae7152fbdb66e9682d453387b3e7fa8 (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
59
/*
 * Copyright (c) 2014 Remko Tronçon
 * Licensed under the GNU General Public License.
 * See the COPYING file for more information.
 */

#include <Swiften/Parser/PayloadParsers/UserTuneParser.h>

#include <boost/lexical_cast.hpp>

using namespace Swift;

UserTuneParser::UserTuneParser() : level(0) {
}

UserTuneParser::~UserTuneParser() {
}

void UserTuneParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) {
	if (level == 1) {
		currentText = "";
	}
	++level;
}

void UserTuneParser::handleEndElement(const std::string& element, const std::string&) {
	--level;
	if (level == 1) {
		try {
			if (element == "artist") {
				getPayloadInternal()->setArtist(currentText);
			}
			else if (element == "length") {
				getPayloadInternal()->setLength(boost::lexical_cast<unsigned int>(currentText));
			}
			else if (element == "rating") {
				getPayloadInternal()->setRating(boost::lexical_cast<unsigned int>(currentText));
			}
			else if (element == "source") {
				getPayloadInternal()->setSource(currentText);
			}
			else if (element == "title") {
				getPayloadInternal()->setTitle(currentText);
			}
			else if (element == "track") {
				getPayloadInternal()->setTrack(currentText);
			}
			else if (element == "URI") {
				getPayloadInternal()->setURI(currentText);
			}
		}
		catch (const boost::bad_lexical_cast&) {
		}
	}
}

void UserTuneParser::handleCharacterData(const std::string& data) {
	currentText += data;
}