1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
#include "XMLFormatter.h" |
21 |
|
|
22 |
|
XMLFormatter::XMLFormatter( string newHostInfo ){ |
23 |
< |
// std::cout << "DEBUG: " << newHostInfo << "\n"; |
23 |
> |
|
24 |
|
if ( newHostInfo != "" ){ |
25 |
|
|
26 |
|
xmlData += "<"; |
27 |
|
xmlData += newHostInfo; |
28 |
|
xmlData += ">"; |
10 |
– |
|
29 |
|
hostInfo = newHostInfo; |
30 |
< |
// std::cout << "DEBUG: xmldata: " << xmlData << "\n"; |
31 |
< |
} |
30 |
> |
|
31 |
> |
} // if |
32 |
|
stackPointer = 0; |
33 |
< |
} |
33 |
> |
|
34 |
> |
} // XMLFormatter |
35 |
|
|
36 |
|
XMLFormatter::XMLFormatter(){ |
37 |
< |
// std::cout << "DEBUG: " << "No Root info" << "\n"; |
37 |
> |
|
38 |
|
hostInfo = ""; // null |
39 |
|
xmlData = ""; |
40 |
|
stackPointer = 0; |
41 |
< |
} |
41 |
> |
|
42 |
> |
} // XMLFormatter |
43 |
|
|
44 |
|
XMLFormatter::XMLFormatter( string newHostInfo, string attributes){ |
45 |
< |
// std::cout << "DEBUG: " << newHostInfo << ":" << attributes << "\n"; |
45 |
> |
|
46 |
|
xmlData += "<"; |
47 |
|
xmlData += newHostInfo; |
48 |
|
xmlData += " "; |
52 |
|
hostInfo = newHostInfo; |
53 |
|
|
54 |
|
stackPointer = 0; |
55 |
< |
} |
55 |
> |
} // XMLFormatter |
56 |
|
|
57 |
|
void XMLFormatter::closeNest(){ |
58 |
< |
// std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n"; |
58 |
> |
|
59 |
|
if ( stackPointer >= 0 ){ |
60 |
|
|
61 |
|
stackPointer--; |
62 |
|
xmlData += "</"; |
63 |
|
xmlData += stack[stackPointer]; |
64 |
|
xmlData += ">"; |
65 |
< |
} |
65 |
> |
} // if |
66 |
|
|
67 |
|
return; |
68 |
< |
} |
68 |
> |
} // closeNest |
69 |
|
|
70 |
|
void XMLFormatter::addNest(string nest){ |
71 |
< |
// std::cout << "DEBUG: Adding Nest: " << nest << "\n"; |
52 |
< |
|
71 |
> |
|
72 |
|
// check it is not empty |
73 |
|
if ( nest != "" ){ |
74 |
|
xmlData += "<"; |
81 |
|
} // if |
82 |
|
|
83 |
|
return; |
84 |
< |
} |
84 |
> |
} // addNest |
85 |
|
|
86 |
|
void XMLFormatter::addElement(string element, string attributes, string value){ |
87 |
< |
// std::cout << "DEBUG: Add Element: " << element << ":" << attributes << ":" << value << "\n"; |
87 |
> |
|
88 |
|
xmlData += "<"; |
89 |
|
xmlData += element; |
90 |
|
xmlData += " "; |
96 |
|
xmlData += ">"; |
97 |
|
|
98 |
|
return; |
99 |
< |
} |
99 |
> |
} // addElement |
100 |
|
|
101 |
|
void XMLFormatter::addElement(string element, string value){ |
102 |
< |
// std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n"; |
84 |
< |
|
102 |
> |
|
103 |
|
if (( element != "" ) && ( value != "" )){ |
104 |
|
xmlData += "<"; |
105 |
|
xmlData += element; |
110 |
|
xmlData += ">"; |
111 |
|
} // if |
112 |
|
return; |
113 |
< |
} |
113 |
> |
|
114 |
> |
} // addElement |
115 |
|
|
116 |
|
|
117 |
|
string XMLFormatter::returnXML(){ |
120 |
|
for ( int count= stackPointer; count > 0; count-- ){ |
121 |
|
// close nest |
122 |
|
closeNest(); |
123 |
< |
} |
123 |
> |
} // if |
124 |
|
|
125 |
|
if ( hostInfo.length() > 0 ){ |
126 |
|
xmlData += "</"; |
127 |
|
xmlData += hostInfo; |
128 |
|
xmlData += ">"; |
129 |
< |
} |
129 |
> |
} // if |
130 |
|
|
131 |
|
stackPointer = 0; |
132 |
|
|
114 |
– |
// std::cout << "DEBUG: returning XML: " << xmlData; |
133 |
|
return xmlData; |
134 |
< |
} |
134 |
> |
|
135 |
> |
} // returnXML |