ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/XMLFormatter.cpp
(Generate patch)

Comparing projects/cms/source/host/c++/XMLFormatter.cpp (file contents):
Revision 1.4 by ab11, Mon Feb 26 14:54:13 2001 UTC vs.
Revision 1.8 by tdb, Sat May 18 18:15:56 2002 UTC

# Line 1 | Line 1
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 ){
4        // std::cout << "DEBUG: " << newHostInfo << "\n";
5        xmlData += "<";
6        xmlData += newHostInfo;
7        xmlData += ">";
23          
24 <        hostInfo = newHostInfo;
10 <        // std::cout << "DEBUG: xmldata: " << xmlData << "\n";
24 >        if ( newHostInfo != "" ){
25          
26 +        xmlData += "<";
27 +        xmlData += newHostInfo;
28 +        xmlData += ">";
29 +        hostInfo = newHostInfo;
30 +        
31 +        } // if
32          stackPointer = 0;
33 < }
33 >        
34 > } // XMLFormatter
35  
36 < XMLFormatter::XMLFormatter( ){
37 <        // std::cout << "DEBUG: " << "No Root info" << "\n";
36 > XMLFormatter::XMLFormatter(){
37 >        
38          hostInfo = ""; // null
39 <        xmlData = hostInfo;
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 += " ";
# Line 30 | Line 52 | XMLFormatter::XMLFormatter( string newHostInfo, string
52          hostInfo = newHostInfo;
53          
54          stackPointer = 0;
55 < }
55 > } // XMLFormatter
56  
57   void XMLFormatter::closeNest(){
36        // std::cout << "DEBUG: Closing Nest: " << stackPointer << ":" << stack[stackPointer] << "\n";
37        stackPointer--;
38        xmlData += "</";
39        xmlData += stack[stackPointer];
40        xmlData += ">";
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(string nest){
46        // std::cout << "DEBUG: Adding Nest: " << nest << "\n";
47        xmlData += "<";
48        xmlData += nest;
49        xmlData += ">";
50        
51        // now add the nest to the stack
52        stack[stackPointer] = nest;
53        stackPointer++;
54        return;
55 }
71  
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   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 += " ";
91          xmlData += attributes;
92          xmlData += ">";
93 <        xmlData += value;
94 <        xmlData += "</";
95 <        xmlData += element;
96 <        xmlData += ">";
68 <        return;
69 < }
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 <        // std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n";
103 <        xmlData += "<";
104 <        xmlData += element;
105 <        xmlData += ">";
106 <        xmlData += value;
107 <        xmlData += "</";
108 <        xmlData += element;
109 <        xmlData += ">";
110 <        return;
111 < }
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(){
# Line 87 | Line 120 | 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 += "</";
125 >        if ( hostInfo.length() > 0 ){
126 >            xmlData += "</";
127                  xmlData += hostInfo;
128                  xmlData += ">";
129 <        }
129 >        } // if
130          
131 <        // std::cout << "DEBUG: returning XML: " << xmlData;
131 >        stackPointer = 0;
132 >        
133          return xmlData;
134 < }
134 >        
135 > } // returnXML

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines