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 |
|
//---PACKAGE DECLARATION--- |
21 |
|
|
22 |
|
//---IMPORTS--- |
24 |
|
|
25 |
|
/** |
26 |
|
* Formats data into valid XML |
27 |
< |
* By calling either addElement() or addNest() you can use this |
28 |
< |
* class to create valid xml. When all elements have been added |
29 |
< |
* calling returnXML() will return a string containing the xml. |
27 |
> |
* By calling either addElement() or addNest() you can use |
28 |
> |
* this class to create valid xml. When all elements have |
29 |
> |
* been added calling returnXML() will return a string |
30 |
> |
* containing the xml. |
31 |
|
* |
32 |
|
* |
33 |
|
* @author $Author$ |
51 |
|
* Takes in one arguement which can contain any valid non xml character ( "<",">" ) |
52 |
|
* an example for rootInfo would be "Host" |
53 |
|
*/ |
54 |
< |
public XMLFormatter(String rootInfo){ |
54 |
> |
public XMLFormatter(String rootInfo, String attributes){ |
55 |
|
|
56 |
|
myStack = new Stack(); |
57 |
|
xmlData = new String(); |
58 |
+ |
xmlData = "<"+rootInfo+" "+attributes+">"; |
59 |
+ |
hostInfo = rootInfo; |
60 |
+ |
} |
61 |
+ |
|
62 |
+ |
/** |
63 |
+ |
* Public Constructor for the class |
64 |
+ |
* Takes in one arguement which can contain any valid non xml character ( "<",">" ) |
65 |
+ |
* an example for rootInfo would be "Host" |
66 |
+ |
*/ |
67 |
+ |
public XMLFormatter(String rootInfo){ |
68 |
+ |
myStack = new Stack(); |
69 |
+ |
xmlData = new String(); |
70 |
|
xmlData = "<"+rootInfo+">"; |
71 |
|
hostInfo = rootInfo; |
72 |
|
} |
81 |
|
hostInfo = null; |
82 |
|
} |
83 |
|
|
52 |
– |
|
84 |
|
//---PUBLIC METHODS--- |
85 |
+ |
|
86 |
+ |
/** |
87 |
+ |
* addEement, adds an element to the XML string with attributes |
88 |
+ |
* |
89 |
+ |
*/ |
90 |
+ |
public void addElement(String name, String attributes, String value){ |
91 |
+ |
// check that the strings contain valid data first |
92 |
+ |
if (( name.length() != 0 ) && ( value.length() != 0 )){ |
93 |
+ |
xmlData += "<"+name+" "+attributes+">"+value+"</"+name+">"; |
94 |
+ |
} |
95 |
+ |
} |
96 |
|
|
97 |
|
/** |
98 |
|
* addEement, adds an element to the XML string |