summaryrefslogtreecommitdiff
path: root/orkbasecxx/serializers/DomSerializer.h
blob: 253fb0cff67fdd85d05e5590e5f91c6996f7fe6e (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
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

#ifndef __DOMSERIALIZER_H__
#define __DOMSERIALIZER_H__

#include "Serializer.h"
#include "Object.h"

#include "xercesc/dom/DOMNode.hpp"
#include "xercesc/util/XMLString.hpp"

using namespace XERCES_CPP_NAMESPACE;

/** Serializer class for Document Object Model.
	This class allows a nested object to be serialized or deserialized
	to or from a xerces DOM object.
*/
class DLL_IMPORT_EXPORT_ORKBASE DomSerializer : public Serializer
{
public:
	DomSerializer(Object* object) : Serializer(object){};

	void ObjectValue(const char* key, Object& value, bool required = false);
	void ListValue(const char* key, std::list<ObjectRef>& value, Object& model, bool required = false);


	void AddInt(const char* key, int value);
	void AddString(const char* key, CStdString& value);
	void AddObject(const char* key, Object& value);
	void AddList(const char* key, std::list<ObjectRef>& value);
	void Serialize(XERCES_CPP_NAMESPACE::DOMDocument* node);

	void GetString(const char* key, CStdString& value, bool required = false);
	void GetObject(const char* key, Object& value, bool required = false);
	void GetList(const char* key, std::list<ObjectRef>& value, Object& model, bool required = false);
	void DeSerialize(DOMNode* node);

	static CStdString XMLStringToLocal(const XMLCh* const toTranscode);
	static XMLCh* LocalStringToXML(CStdString& toTranscode);

	DOMNode* FindElementByName(DOMNode *node, CStdString name);

	static CStdString DomNodeToString(DOMNode *);
protected:
	DOMNode* m_node;
	XERCES_CPP_NAMESPACE::DOMDocument* m_document;
};

/** Container for xerces unicode string initialized with char* string */
class DLL_IMPORT_EXPORT_ORKBASE XStr
{
public :
    inline XStr(const char* const toTranscode)
    {
        fUnicodeForm = XMLString::transcode(toTranscode);
    }

    inline ~XStr()
    {
        XMLString::release(&fUnicodeForm);
    }

    inline const XMLCh* unicodeForm() const
    {
        return fUnicodeForm;
    }

private :
    XMLCh*   fUnicodeForm;
};


#endif