ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
Revision: 1.10
Committed: Mon Jun 10 14:10:43 2002 UTC (22 years, 3 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +0 -0 lines
State: FILE REMOVED
Log Message:
Tidy up of files. These are all old things that are not only no longer used
but are also probably useless to anyone other than us. This saves checking
them out all the time, and makes the "cms/source" tree contain only current
stuff. They'll still exist in the attic's though :)

File Contents

# User Rev Content
1 tdb 1.8 /*
2     * i-scream central monitoring system
3 tdb 1.9 * http://www.i-scream.org.uk
4 tdb 1.8 * Copyright (C) 2000-2002 i-scream
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21 ab11 1.2 #include "XMLFormatter.h"
22 ab11 1.1
23 ab11 1.2 XMLFormatter::XMLFormatter( string newHostInfo ){
24 ab11 1.7
25 ab11 1.6 if ( newHostInfo != "" ){
26 ab11 1.2
27 ab11 1.6 xmlData += "<";
28     xmlData += newHostInfo;
29     xmlData += ">";
30 ab11 1.7 hostInfo = newHostInfo;
31 ab11 1.6
32 ab11 1.7 } // if
33 ab11 1.2 stackPointer = 0;
34 ab11 1.7
35     } // XMLFormatter
36 ab11 1.2
37 ab11 1.5 XMLFormatter::XMLFormatter(){
38 ab11 1.7
39 ab11 1.2 hostInfo = ""; // null
40 ab11 1.5 xmlData = "";
41 ab11 1.2 stackPointer = 0;
42 ab11 1.7
43     } // XMLFormatter
44 ab11 1.2
45     XMLFormatter::XMLFormatter( string newHostInfo, string attributes){
46 ab11 1.7
47 ab11 1.2 xmlData += "<";
48     xmlData += newHostInfo;
49 ab11 1.4 xmlData += " ";
50     xmlData += attributes;
51 ab11 1.2 xmlData += ">";
52    
53     hostInfo = newHostInfo;
54    
55     stackPointer = 0;
56 ab11 1.7 } // XMLFormatter
57 ab11 1.1
58     void XMLFormatter::closeNest(){
59 ab11 1.7
60 ab11 1.5 if ( stackPointer >= 0 ){
61    
62     stackPointer--;
63     xmlData += "</";
64     xmlData += stack[stackPointer];
65     xmlData += ">";
66 ab11 1.7 } // if
67 ab11 1.2
68 ab11 1.1 return;
69 ab11 1.7 } // closeNest
70 ab11 1.1
71 ab11 1.2 void XMLFormatter::addNest(string nest){
72 ab11 1.7
73 ab11 1.6 // check it is not empty
74     if ( nest != "" ){
75     xmlData += "<";
76     xmlData += nest;
77     xmlData += ">";
78    
79     // now add the nest to the stack
80     stack[stackPointer] = nest;
81     stackPointer++;
82     } // if
83    
84     return;
85 ab11 1.7 } // addNest
86 ab11 1.1
87 ab11 1.2 void XMLFormatter::addElement(string element, string attributes, string value){
88 ab11 1.7
89 ab11 1.2 xmlData += "<";
90     xmlData += element;
91     xmlData += " ";
92     xmlData += attributes;
93     xmlData += ">";
94 ab11 1.6 xmlData += value;
95     xmlData += "</";
96     xmlData += element;
97     xmlData += ">";
98    
99     return;
100 ab11 1.7 } // addElement
101 ab11 1.6
102     void XMLFormatter::addElement(string element, string value){
103 ab11 1.7
104 ab11 1.6 if (( element != "" ) && ( value != "" )){
105     xmlData += "<";
106     xmlData += element;
107     xmlData += ">";
108 ab11 1.5 xmlData += value;
109     xmlData += "</";
110     xmlData += element;
111     xmlData += ">";
112     } // if
113     return;
114 ab11 1.7
115     } // addElement
116 ab11 1.2
117    
118     string XMLFormatter::returnXML(){
119     // close as many nests as we have open, could (but shouldn't) cause
120     // some arraylist out of bounds errors.
121     for ( int count= stackPointer; count > 0; count-- ){
122     // close nest
123     closeNest();
124 ab11 1.7 } // if
125 ab11 1.2
126 ab11 1.5 if ( hostInfo.length() > 0 ){
127     xmlData += "</";
128 ab11 1.2 xmlData += hostInfo;
129     xmlData += ">";
130 ab11 1.7 } // if
131 ab11 1.5
132     stackPointer = 0;
133 ab11 1.2
134     return xmlData;
135 ab11 1.7
136     } // returnXML