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.5 by ab11, Fri Mar 23 14:07:11 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";
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 += " ";
# Line 30 | Line 52 | XMLFormatter::XMLFormatter( string newHostInfo, string
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){
49        // std::cout << "DEBUG: Adding Nest: " << nest << "\n";
50        xmlData += "<";
51        xmlData += nest;
52        xmlData += ">";
53        
54        // now add the nest to the stack
55        stack[stackPointer] = nest;
56        stackPointer++;
57        return;
58 }
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 <        if ( value != "" ){
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 < }
113 >    
114 > } // addElement
115  
76 void XMLFormatter::addElement(string element, string value){
77        // std::cout << "DEBUG: Add Element: " << element << ":" << value << "\n";
78        xmlData += "<";
79        xmlData += element;
80        xmlData += ">";
81        xmlData += value;
82        xmlData += "</";
83        xmlData += element;
84        xmlData += ">";
85        return;
86 }
116  
88
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 <        }
123 >        } // if
124          
125          if ( hostInfo.length() > 0 ){
126              xmlData += "</";
127                  xmlData += hostInfo;
128                  xmlData += ">";
129 <        }
129 >        } // if
130          
131          stackPointer = 0;
132          
105        // std::cout << "DEBUG: returning XML: " << xmlData;
133          return xmlData;
134 < }
134 >        
135 > } // returnXML

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines