1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // Document.cc
4 // -----------
5 // XML document class implementation
6 //
7 // Design and Implementation by Bjoern Lemke
8 //
9 // (C)opyright 2000-2016 Bjoern Lemke
10 //
11 // IMPLEMENTATION MODULE
12 //
13 // Class: Document
14 //
15 // Description: XML document container class
16 //
17 // Status: CLEAN
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20 
21 // INCLUDES
22 #include "Document.h"
23 
Document()24 Document::Document()
25 {
26     _pRootElement = 0;
27 }
28 
Document(const Chain & docName)29 Document::Document(const Chain& docName)
30 {
31     _docName = docName;
32     _pRootElement = 0;
33 }
34 
Document(Element * pRootElement)35 Document::Document(Element* pRootElement)
36 {
37     _pRootElement = pRootElement;
38     _pRootElement->incRef();
39 }
40 
~Document()41 Document::~Document()
42 {
43     if ( _pRootElement )
44     {
45 	if ( _pRootElement->getRef() == 1 )
46 	    delete _pRootElement;
47 	else
48 	    _pRootElement->decRef();
49     }
50 }
51 
clear()52 void Document::clear()
53 {
54     if ( _pRootElement )
55     {
56 	_pRootElement->clear();
57 	delete _pRootElement;
58 	_pRootElement = 0;
59     }
60 }
61 
getName()62 const Chain& Document::getName()
63 {
64     return _docName;
65 }
66 
setRootElement(Element * pRootElement)67 void Document::setRootElement(Element* pRootElement)
68 {
69     _pRootElement = pRootElement;
70     if ( _pRootElement )
71 	_pRootElement->incRef();
72 }
73 
getRootElement()74 Element* Document::getRootElement()
75 {
76     return _pRootElement;
77 }
78 
setDocType(const Chain & docType)79 void Document::setDocType(const Chain& docType)
80 {
81     _docType = docType;
82 }
83 
getDocType() const84 const Chain& Document::getDocType() const
85 {
86     return _docType;
87 }
88 
setAttributeList(const ListT<Attribute> & attrList)89 void Document::setAttributeList(const ListT<Attribute>& attrList)
90 {
91     _attrList = attrList;
92 }
93 
getAttributeList() const94 const ListT<Attribute>& Document::getAttributeList() const
95 {
96     return _attrList;
97 }
98 
setAttribute(const Chain & attr,const Chain & value)99 void Document::setAttribute(const Chain& attr, const Chain& value)
100 {
101     Attribute* pAttr = _attrList.Find( Attribute( attr ) );
102     if ( pAttr )
103     {
104 	pAttr->setValue(value);
105     }
106     else
107     {
108 	_attrList.Insert ( Attribute ( attr, value ) );
109     }
110 }
111 
getAttributeValue(const Chain & attr) const112 Chain Document::getAttributeValue(const Chain& attr) const
113 {
114     Attribute* pAttr = _attrList.Find( Attribute( attr ) );
115     if ( pAttr )
116     {
117 	return pAttr->getValue();
118     }
119     return Chain("");
120 }
121 
operator =(const Document & doc)122 Document& Document::operator=(const Document& doc)
123 {
124     _pRootElement = doc._pRootElement;
125     _attrList = doc._attrList;
126     _docName = doc._docName;
127     _docType = doc._docType;
128     return (*this);
129 }
130 
operator ==(const Document & d) const131 bool Document::operator==(const Document& d) const
132 {
133     if ( (Chain)_docName == (Chain)d._docName)
134 	return true;
135     return false;
136 }
137