ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
Revision: 1.8
Committed: Sat May 18 18:15:56 2002 UTC (22 years, 4 months ago) by tdb
Branch: MAIN
Changes since 1.7: +19 -0 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.8 /*
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 ab11 1.2 #include "XMLFormatter.h"
21 ab11 1.1
22 ab11 1.2 XMLFormatter::XMLFormatter( string newHostInfo ){
23 ab11 1.7
24 ab11 1.6 if ( newHostInfo != "" ){
25 ab11 1.2
26 ab11 1.6 xmlData += "<";
27     xmlData += newHostInfo;
28     xmlData += ">";
29 ab11 1.7 hostInfo = newHostInfo;
30 ab11 1.6
31 ab11 1.7 } // if
32 ab11 1.2 stackPointer = 0;
33 ab11 1.7
34     } // XMLFormatter
35 ab11 1.2
36 ab11 1.5 XMLFormatter::XMLFormatter(){
37 ab11 1.7
38 ab11 1.2 hostInfo = ""; // null
39 ab11 1.5 xmlData = "";
40 ab11 1.2 stackPointer = 0;
41 ab11 1.7
42     } // XMLFormatter
43 ab11 1.2
44     XMLFormatter::XMLFormatter( string newHostInfo, string attributes){
45 ab11 1.7
46 ab11 1.2 xmlData += "<";
47     xmlData += newHostInfo;
48 ab11 1.4 xmlData += " ";
49     xmlData += attributes;
50 ab11 1.2 xmlData += ">";
51    
52     hostInfo = newHostInfo;
53    
54     stackPointer = 0;
55 ab11 1.7 } // XMLFormatter
56 ab11 1.1
57     void XMLFormatter::closeNest(){
58 ab11 1.7
59 ab11 1.5 if ( stackPointer >= 0 ){
60    
61     stackPointer--;
62     xmlData += "</";
63     xmlData += stack[stackPointer];
64     xmlData += ">";
65 ab11 1.7 } // if
66 ab11 1.2
67 ab11 1.1 return;
68 ab11 1.7 } // closeNest
69 ab11 1.1
70 ab11 1.2 void XMLFormatter::addNest(string nest){
71 ab11 1.7
72 ab11 1.6 // 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 ab11 1.7 } // addNest
85 ab11 1.1
86 ab11 1.2 void XMLFormatter::addElement(string element, string attributes, string value){
87 ab11 1.7
88 ab11 1.2 xmlData += "<";
89     xmlData += element;
90     xmlData += " ";
91     xmlData += attributes;
92     xmlData += ">";
93 ab11 1.6 xmlData += value;
94     xmlData += "</";
95     xmlData += element;
96     xmlData += ">";
97    
98     return;
99 ab11 1.7 } // addElement
100 ab11 1.6
101     void XMLFormatter::addElement(string element, string value){
102 ab11 1.7
103 ab11 1.6 if (( element != "" ) && ( value != "" )){
104     xmlData += "<";
105     xmlData += element;
106     xmlData += ">";
107 ab11 1.5 xmlData += value;
108     xmlData += "</";
109     xmlData += element;
110     xmlData += ">";
111     } // if
112     return;
113 ab11 1.7
114     } // addElement
115 ab11 1.2
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 ab11 1.7 } // if
124 ab11 1.2
125 ab11 1.5 if ( hostInfo.length() > 0 ){
126     xmlData += "</";
127 ab11 1.2 xmlData += hostInfo;
128     xmlData += ">";
129 ab11 1.7 } // if
130 ab11 1.5
131     stackPointer = 0;
132 ab11 1.2
133     return xmlData;
134 ab11 1.7
135     } // returnXML