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