1 | package nu.fw.jeti.backend; |
---|
2 | |
---|
3 | import java.util.Map; |
---|
4 | |
---|
5 | /* |
---|
6 | * Jeti, a Java Jabber client, Copyright (C) 2002 E.S. de Boer |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
21 | * |
---|
22 | * For questions, comments etc, |
---|
23 | * use the website at http://jeti.jabberstudio.org |
---|
24 | * or mail/IM me at jeti@jabber.org |
---|
25 | */ |
---|
26 | |
---|
27 | public abstract class XMLDataFile |
---|
28 | { |
---|
29 | int tabDepth=0; |
---|
30 | |
---|
31 | public XMLDataFile() |
---|
32 | { |
---|
33 | } |
---|
34 | |
---|
35 | private void addTabs(StringBuffer xml) |
---|
36 | { |
---|
37 | xml.append("\r\n"); |
---|
38 | for(int i =0;i<tabDepth;i++) |
---|
39 | { |
---|
40 | xml.append(" "); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * <code>toString</code> is a serializer for the data contained in the |
---|
46 | * object to an equivalent snippet of XML stream. |
---|
47 | * |
---|
48 | * @return a <code>String</code> value which contains the XML |
---|
49 | * representation of this object |
---|
50 | */ |
---|
51 | public String toString() |
---|
52 | { |
---|
53 | StringBuffer retval=new StringBuffer(); |
---|
54 | appendToXML(retval); |
---|
55 | return new String(retval); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * <code>appendToXML</code> appends the XML representation of the |
---|
60 | * current packet data to the specified <code>StringBuffer</code>. |
---|
61 | * |
---|
62 | * @param xml The <code>StringBuffer</code> to append to |
---|
63 | */ |
---|
64 | public abstract void appendToXML(StringBuffer xml); |
---|
65 | |
---|
66 | protected final void appendHeader(StringBuffer xml) |
---|
67 | { |
---|
68 | xml.append("<?xml version=\"1.0\"?>"); |
---|
69 | } |
---|
70 | |
---|
71 | protected final void appendOpenTag(StringBuffer xml,String name) |
---|
72 | { |
---|
73 | //xml.append("\r\n"); |
---|
74 | addTabs(xml); |
---|
75 | tabDepth++; |
---|
76 | xml.append(name); |
---|
77 | } |
---|
78 | |
---|
79 | protected final void appendCloseTag(StringBuffer xml,String name) |
---|
80 | { |
---|
81 | //xml.append("\r\n"); |
---|
82 | tabDepth--; |
---|
83 | addTabs(xml); |
---|
84 | xml.append(name); |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | protected final void appendCloseSymbol(StringBuffer xml) |
---|
89 | { |
---|
90 | tabDepth--; |
---|
91 | xml.append("/>"); |
---|
92 | } |
---|
93 | |
---|
94 | protected final boolean appendElement(StringBuffer xml,String name,String value) |
---|
95 | { |
---|
96 | //xml.append("\r\n"); |
---|
97 | addTabs(xml); |
---|
98 | boolean result = HelpXMLData.appendElement(xml,name,value); |
---|
99 | //xml.append('\n'); |
---|
100 | return result; |
---|
101 | } |
---|
102 | |
---|
103 | protected final boolean appendElement(StringBuffer xml,String name,boolean value) |
---|
104 | { |
---|
105 | //xml.append("\r\n"); |
---|
106 | addTabs(xml); |
---|
107 | return HelpXMLData.appendElement(xml,name,value); |
---|
108 | } |
---|
109 | |
---|
110 | protected final boolean appendElement(StringBuffer xml,Map map) |
---|
111 | { |
---|
112 | //xml.append("\r\n"); |
---|
113 | addTabs(xml); |
---|
114 | return HelpXMLData.appendElement(xml,map); |
---|
115 | } |
---|
116 | |
---|
117 | protected final boolean appendAttribute(StringBuffer xml,String name,String value) |
---|
118 | { |
---|
119 | return HelpXMLData.appendAttribute(xml,name,value); |
---|
120 | } |
---|
121 | |
---|
122 | protected final boolean appendAttribute(StringBuffer xml,String name,Object value) |
---|
123 | { |
---|
124 | return HelpXMLData.appendAttribute(xml,name,value); |
---|
125 | } |
---|
126 | |
---|
127 | abstract static class HelpXMLData extends XMLData |
---|
128 | { |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | } |
---|
133 | /* |
---|
134 | * Overrides for emacs |
---|
135 | * Local variables: |
---|
136 | * tab-width: 4 |
---|
137 | * End: |
---|
138 | */ |
---|