summaryrefslogtreecommitdiff
path: root/XmlObject.cpp
blob: 923d2d1cc9406e8f4e011daecc2852e135320321 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "XmlObject.h"

namespace plexclient
{

XmlObject::XmlObject()
{
}

XmlObject::~XmlObject()
{
}

std::string XmlObject::GetNodeValue(Poco::XML::Node* pNode)
{
	std::string value;
	if(pNode != 0) {
		value = pNode->getNodeValue();
	}
	return value;
}

int XmlObject::GetNodeValueAsInt(Poco::XML::Node* pNode)
{
	int value = 0;
	if(pNode != 0) {
		try {
			value = atoi(pNode->getNodeValue().c_str());
		} catch(Poco::Exception) {}
	}
	return value;
}

long XmlObject::GetNodeValueAsLong(Poco::XML::Node* pNode)
{
	long value = 0;
	if(pNode != 0) {
		try {
			value = atol(pNode->getNodeValue().c_str());
		} catch(Poco::Exception) {}
	}
	return value;
}

bool XmlObject::GetNodeValueAsBool(Poco::XML::Node* pNode)
{
	bool value = false;
	if(pNode != 0) {
		value = pNode->getNodeValue() == "1";
	}
	return value;
}

Poco::Timestamp XmlObject::GetNodeValueAsTimeStamp(Poco::XML::Node* pNode)
{
	Poco::Timestamp value;
	if(pNode != 0) {
		try {
			long lValue = atol(pNode->nodeValue().c_str());
			value = Poco::Timestamp(lValue);
		} catch (Poco::Exception) {}
	}
	return value;
}

MediaType XmlObject::GetNodeValueAsMediaType(Poco::XML::Node* pNode)
{
	MediaType type = UNDEF;

	if(pNode != 0) {
		std::string sType = pNode->nodeValue();
		if (Poco::icompare(sType, "photo") == 0) {
			type = PHOTO;
		} else if (Poco::icompare(sType, "movie") == 0) {
			type = MOVIE;
		} else if (Poco::icompare(sType, "music") == 0) {
			type = MUSIC;
		} else if (Poco::icompare(sType, "show") == 0) {
			type = SHOW;
		} else if (Poco::icompare(sType, "season") == 0) {
			type = SHOW;
		}
	}
	return type;
}

}