1 |
< |
#include <XMLFormatter.h> |
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 |
< |
void XMLFormatter::XMLFormatter( char* newHostInfo ){ |
4 |
< |
hostInfo = "<"+newHostInfo+">"; |
5 |
< |
} |
20 |
> |
#include "XMLFormatter.h" |
21 |
|
|
22 |
+ |
XMLFormatter::XMLFormatter( string newHostInfo ){ |
23 |
+ |
|
24 |
+ |
if ( newHostInfo != "" ){ |
25 |
+ |
|
26 |
+ |
xmlData += "<"; |
27 |
+ |
xmlData += newHostInfo; |
28 |
+ |
xmlData += ">"; |
29 |
+ |
hostInfo = newHostInfo; |
30 |
+ |
|
31 |
+ |
} // if |
32 |
+ |
stackPointer = 0; |
33 |
+ |
|
34 |
+ |
} // XMLFormatter |
35 |
+ |
|
36 |
+ |
XMLFormatter::XMLFormatter(){ |
37 |
+ |
|
38 |
+ |
hostInfo = ""; // null |
39 |
+ |
xmlData = ""; |
40 |
+ |
stackPointer = 0; |
41 |
+ |
|
42 |
+ |
} // XMLFormatter |
43 |
+ |
|
44 |
+ |
XMLFormatter::XMLFormatter( string newHostInfo, string attributes){ |
45 |
+ |
|
46 |
+ |
xmlData += "<"; |
47 |
+ |
xmlData += newHostInfo; |
48 |
+ |
xmlData += " "; |
49 |
+ |
xmlData += attributes; |
50 |
+ |
xmlData += ">"; |
51 |
+ |
|
52 |
+ |
hostInfo = newHostInfo; |
53 |
+ |
|
54 |
+ |
stackPointer = 0; |
55 |
+ |
} // XMLFormatter |
56 |
+ |
|
57 |
|
void XMLFormatter::closeNest(){ |
58 |
+ |
|
59 |
+ |
if ( stackPointer >= 0 ){ |
60 |
+ |
|
61 |
+ |
stackPointer--; |
62 |
+ |
xmlData += "</"; |
63 |
+ |
xmlData += stack[stackPointer]; |
64 |
+ |
xmlData += ">"; |
65 |
+ |
} // if |
66 |
+ |
|
67 |
|
return; |
68 |
< |
} |
68 |
> |
} // closeNest |
69 |
|
|
70 |
< |
void XMLFormatter::addNest(char* nest){ |
12 |
< |
return; |
13 |
< |
} |
70 |
> |
void XMLFormatter::addNest(string nest){ |
71 |
|
|
72 |
< |
void XMLFormatter::addElement(char* element){ |
73 |
< |
return; |
74 |
< |
} |
72 |
> |
// check it is not empty |
73 |
> |
if ( nest != "" ){ |
74 |
> |
xmlData += "<"; |
75 |
> |
xmlData += nest; |
76 |
> |
xmlData += ">"; |
77 |
> |
|
78 |
> |
// now add the nest to the stack |
79 |
> |
stack[stackPointer] = nest; |
80 |
> |
stackPointer++; |
81 |
> |
} // if |
82 |
> |
|
83 |
> |
return; |
84 |
> |
} // addNest |
85 |
|
|
86 |
< |
char* XMLFormatter::returnXML(){ |
87 |
< |
return "hellO"; |
88 |
< |
} |
86 |
> |
void XMLFormatter::addElement(string element, string attributes, string value){ |
87 |
> |
|
88 |
> |
xmlData += "<"; |
89 |
> |
xmlData += element; |
90 |
> |
xmlData += " "; |
91 |
> |
xmlData += attributes; |
92 |
> |
xmlData += ">"; |
93 |
> |
xmlData += value; |
94 |
> |
xmlData += "</"; |
95 |
> |
xmlData += element; |
96 |
> |
xmlData += ">"; |
97 |
> |
|
98 |
> |
return; |
99 |
> |
} // addElement |
100 |
> |
|
101 |
> |
void XMLFormatter::addElement(string element, string value){ |
102 |
> |
|
103 |
> |
if (( element != "" ) && ( value != "" )){ |
104 |
> |
xmlData += "<"; |
105 |
> |
xmlData += element; |
106 |
> |
xmlData += ">"; |
107 |
> |
xmlData += value; |
108 |
> |
xmlData += "</"; |
109 |
> |
xmlData += element; |
110 |
> |
xmlData += ">"; |
111 |
> |
} // if |
112 |
> |
return; |
113 |
> |
|
114 |
> |
} // addElement |
115 |
> |
|
116 |
> |
|
117 |
> |
string XMLFormatter::returnXML(){ |
118 |
> |
// close as many nests as we have open, could (but shouldn't) cause |
119 |
> |
// some arraylist out of bounds errors. |
120 |
> |
for ( int count= stackPointer; count > 0; count-- ){ |
121 |
> |
// close nest |
122 |
> |
closeNest(); |
123 |
> |
} // if |
124 |
> |
|
125 |
> |
if ( hostInfo.length() > 0 ){ |
126 |
> |
xmlData += "</"; |
127 |
> |
xmlData += hostInfo; |
128 |
> |
xmlData += ">"; |
129 |
> |
} // if |
130 |
> |
|
131 |
> |
stackPointer = 0; |
132 |
> |
|
133 |
> |
return xmlData; |
134 |
> |
|
135 |
> |
} // returnXML |