Mercurial > projects > dwt-addons
annotate dwtx/jface/dialogs/DialogSettings.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 7ffeace6c47f |
children | 1470d66733fa |
rev | line source |
---|---|
19 | 1 /******************************************************************************* |
90 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
19 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.dialogs.DialogSettings; | |
14 | |
15 import dwtx.jface.dialogs.IDialogSettings; | |
16 | |
17 | |
18 static import tango.text.xml.Document; | |
19 static import tango.text.xml.SaxParser; | |
20 static import tango.text.xml.PullParser; | |
21 static import tango.text.xml.XmlPrinter; | |
22 | |
23 | |
24 import dwt.dwthelper.utils; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
25 import dwtx.dwtxhelper.Collection; |
19 | 26 static import dwt.dwthelper.OutputStream; |
27 static import tango.text.convert.Integer; | |
28 static import tango.text.convert.Float; | |
29 static import tango.text.Text; | |
30 static import tango.io.File; | |
31 static import tango.io.Print; | |
32 static import tango.io.model.IConduit; | |
33 static import tango.io.stream.FileStream; | |
34 static import tango.text.convert.Format; | |
35 import tango.core.Exception; | |
36 alias tango.text.Text.Text!(char) StringBuffer; | |
40
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
19
diff
changeset
|
37 import dwt.dwthelper.XmlTranscode; |
19 | 38 |
39 /** | |
40 * Concrete implementation of a dialog settings (<code>IDialogSettings</code>) | |
41 * using a hash table and XML. The dialog store can be read | |
42 * from and saved to a stream. All keys and values must be strings or array of | |
43 * strings. Primitive types are converted to strings. | |
44 * <p> | |
45 * This class was not designed to be subclassed. | |
46 * | |
47 * Here is an example of using a DialogSettings: | |
48 * </p> | |
49 * <pre> | |
50 * <code> | |
51 * DialogSettings settings = new DialogSettings("root"); | |
52 * settings.put("Boolean1",true); | |
53 * settings.put("Long1",100); | |
54 * settings.put("Array1",new String[]{"aaaa1","bbbb1","cccc1"}); | |
55 * DialogSettings section = new DialogSettings("sectionName"); | |
56 * settings.addSection(section); | |
57 * section.put("Int2",200); | |
58 * section.put("Float2",1.1); | |
59 * section.put("Array2",new String[]{"aaaa2","bbbb2","cccc2"}); | |
60 * settings.save("c:\\temp\\test\\dialog.xml"); | |
61 * </code> | |
62 * </pre> | |
90 | 63 * @noextend This class is not intended to be subclassed by clients. |
19 | 64 */ |
65 | |
66 public class DialogSettings : IDialogSettings { | |
67 alias tango.text.xml.Document.Document!(char) Document; | |
68 alias tango.text.xml.Document.Document!(char).Node Element; | |
69 alias tango.text.xml.XmlPrinter.XmlPrinter!(char) XmlPrinter; | |
70 // The name of the DialogSettings. | |
71 private String name; | |
72 | |
73 /* A Map of DialogSettings representing each sections in a DialogSettings. | |
74 It maps the DialogSettings' name to the DialogSettings */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
75 private Map sections; |
19 | 76 |
77 /* A Map with all the keys and values of this sections. | |
78 Either the keys an values are restricted to strings. */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
79 private Map items; |
19 | 80 |
81 // A Map with all the keys mapped to array of strings. | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
82 private Map arrayItems; |
19 | 83 |
84 private static const String TAG_SECTION = "section";//$NON-NLS-1$ | |
85 | |
86 private static const String TAG_NAME = "name";//$NON-NLS-1$ | |
87 | |
88 private static const String TAG_KEY = "key";//$NON-NLS-1$ | |
89 | |
90 private static const String TAG_VALUE = "value";//$NON-NLS-1$ | |
91 | |
92 private static const String TAG_LIST = "list";//$NON-NLS-1$ | |
93 | |
94 private static const String TAG_ITEM = "item";//$NON-NLS-1$ | |
95 | |
96 /** | |
97 * Create an empty dialog settings which loads and saves its | |
98 * content to a file. | |
99 * Use the methods <code>load(String)</code> and <code>store(String)</code> | |
100 * to load and store this dialog settings. | |
101 * | |
102 * @param sectionName the name of the section in the settings. | |
103 */ | |
104 public this(String sectionName) { | |
105 name = sectionName; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
106 items = new HashMap(); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
107 arrayItems = new HashMap(); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
108 sections = new HashMap(); |
19 | 109 } |
110 | |
111 /* (non-Javadoc) | |
112 * Method declared on IDialogSettings. | |
113 */ | |
114 public IDialogSettings addNewSection(String sectionName) { | |
115 DialogSettings section = new DialogSettings(sectionName); | |
116 addSection(section); | |
117 return section; | |
118 } | |
119 | |
120 /* (non-Javadoc) | |
121 * Method declared on IDialogSettings. | |
122 */ | |
123 public void addSection(IDialogSettings section) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
124 sections.put(stringcast(section.getName()), cast(Object)section); |
19 | 125 } |
126 | |
127 /* (non-Javadoc) | |
128 * Method declared on IDialogSettings. | |
129 */ | |
130 public String get(String key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
131 return stringcast(items.get(stringcast(key))); |
19 | 132 } |
133 | |
134 /* (non-Javadoc) | |
135 * Method declared on IDialogSettings. | |
136 */ | |
137 public String[] getArray(String key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
138 return stringArrayFromObject(arrayItems.get(stringcast(key))); |
19 | 139 } |
140 | |
141 /* (non-Javadoc) | |
142 * Method declared on IDialogSettings. | |
143 */ | |
144 public bool getBoolean(String key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
145 return stringcast(items.get(stringcast(key))) == "true"; |
19 | 146 } |
147 | |
148 /* (non-Javadoc) | |
149 * Method declared on IDialogSettings. | |
150 */ | |
151 public double getDouble(String key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
152 String setting = stringcast(items.get(stringcast(key))); |
19 | 153 if (setting is null) { |
154 throw new NumberFormatException( | |
155 "There is no setting associated with the key \"" ~ key ~ "\"");//$NON-NLS-1$ //$NON-NLS-2$ | |
156 } | |
157 | |
158 return tango.text.convert.Float.toFloat(setting); | |
159 } | |
160 | |
161 /* (non-Javadoc) | |
162 * Method declared on IDialogSettings. | |
163 */ | |
164 public float getFloat(String key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
165 String setting = stringcast(items.get(stringcast(key))); |
19 | 166 if (setting is null) { |
167 throw new NumberFormatException( | |
168 "There is no setting associated with the key \"" ~ key ~ "\"");//$NON-NLS-1$ //$NON-NLS-2$ | |
169 } | |
170 | |
171 return tango.text.convert.Float.toFloat(setting); | |
172 } | |
173 | |
174 /* (non-Javadoc) | |
175 * Method declared on IDialogSettings. | |
176 */ | |
177 public int getInt(String key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
178 String setting = stringcast(items.get(stringcast(key))); |
19 | 179 if (setting is null) { |
180 //new Integer(null) will throw a NumberFormatException and meet our spec, but this message | |
181 //is clearer. | |
182 throw new NumberFormatException( | |
183 "There is no setting associated with the key \"" ~ key ~ "\"");//$NON-NLS-1$ //$NON-NLS-2$ | |
184 } | |
185 | |
186 return tango.text.convert.Integer.toInt(setting); | |
187 } | |
188 | |
189 /* (non-Javadoc) | |
190 * Method declared on IDialogSettings. | |
191 */ | |
192 public long getLong(String key) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
193 String setting = stringcast(items.get(stringcast(key))); |
19 | 194 if (setting is null) { |
195 //new Long(null) will throw a NumberFormatException and meet our spec, but this message | |
196 //is clearer. | |
197 throw new NumberFormatException( | |
198 "There is no setting associated with the key \"" ~ key ~ "\"");//$NON-NLS-1$ //$NON-NLS-2$ | |
199 } | |
200 | |
201 return tango.text.convert.Integer.toLong(setting); | |
202 } | |
203 | |
204 /* (non-Javadoc) | |
205 * Method declared on IDialogSettings. | |
206 */ | |
207 public String getName() { | |
208 return name; | |
209 } | |
210 | |
211 /* (non-Javadoc) | |
212 * Method declared on IDialogSettings. | |
213 */ | |
214 public IDialogSettings getSection(String sectionName) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
215 return cast(IDialogSettings) sections.get(stringcast(sectionName)); |
19 | 216 } |
217 | |
218 /* (non-Javadoc) | |
219 * Method declared on IDialogSettings. | |
220 */ | |
221 public IDialogSettings[] getSections() { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
222 Collection values = sections.values(); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
223 IDialogSettings[] result = arraycast!(IDialogSettings)( values.toArray() ); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
224 return result; |
19 | 225 } |
226 | |
227 /* (non-Javadoc) | |
228 * Method declared on IDialogSettings. | |
229 */ | |
230 public void load( tango.io.model.IConduit.InputStream input) { | |
231 Document document = new Document(); | |
232 try { | |
233 char[] content; | |
234 char[1024] readbuf; | |
235 int chunksize = 0; | |
236 while( (chunksize=input.read(readbuf)) !is tango.io.model.IConduit.InputStream.Eof ){ | |
237 content ~= readbuf[ 0 .. chunksize ]; | |
238 } | |
239 document.parse( content ); | |
240 | |
241 //Strip out any comments first | |
242 foreach( n; document.query[].filter( delegate bool(Element n) { | |
243 return n.type is tango.text.xml.PullParser.XmlNodeType.Comment ; | |
244 })){ | |
245 //TODO: remove() was added after tango 0.99.5 | |
246 //n.remove(); | |
247 } | |
248 load(document, document.root.firstChild ); | |
249 } catch (IOException e) { | |
250 // ignore | |
251 } catch (TextException e) { | |
252 // ignore | |
253 } | |
254 } | |
255 | |
256 /* (non-Javadoc) | |
257 * Method declared on IDialogSettings. | |
258 */ | |
259 //TODO: solve overload load(char[]) | |
260 public void load(String fileName) { | |
261 auto f = new tango.io.stream.FileStream.FileInput( fileName ); | |
262 load( f.input ); | |
263 f.close; | |
264 } | |
265 | |
266 /* (non-Javadoc) | |
267 * Load the setting from the <code>document</code> | |
268 */ | |
269 private void load(Document document, Element root) { | |
270 | |
271 name = root.getAttribute(TAG_NAME).value(); | |
272 | |
273 foreach( n; root.query[TAG_ITEM] ){ | |
274 if( root is n.parent() ){ | |
275 String key = n.getAttribute(TAG_KEY).value().dup; | |
276 String value = n.getAttribute(TAG_VALUE).value().dup; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
277 items.put(stringcast(key), stringcast(value)); |
19 | 278 } |
279 } | |
280 foreach( n; root.query[TAG_LIST].dup ){ | |
281 if( root is n.parent() ){ | |
282 auto child = n; | |
283 String key = child.getAttribute(TAG_KEY).value().dup; | |
284 char[][] valueList; | |
285 foreach( node; root.query[TAG_ITEM].dup ){ | |
286 if (child is node.parent()) { | |
287 valueList ~= node.getAttribute(TAG_VALUE).value().dup; | |
288 } | |
289 } | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
290 arrayItems.put(stringcast(key), new ArrayWrapperString2(valueList) ); |
19 | 291 } |
292 } | |
293 foreach( n; root.query[TAG_SECTION].dup ){ | |
294 if( root is n.parent() ){ | |
295 DialogSettings s = new DialogSettings("NoName");//$NON-NLS-1$ | |
296 s.load(document, n); | |
297 addSection(s); | |
298 } | |
299 } | |
300 } | |
301 | |
302 /* (non-Javadoc) | |
303 * Method declared on IDialogSettings. | |
304 */ | |
305 public void put(String key, String[] value) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
306 arrayItems.put(stringcast(key), new ArrayWrapperString2(value)); |
19 | 307 } |
308 | |
309 /* (non-Javadoc) | |
310 * Method declared on IDialogSettings. | |
311 */ | |
312 public void put(String key, double value) { | |
313 put(key, tango.text.convert.Float.toString(value)); | |
314 } | |
315 | |
316 /* (non-Javadoc) | |
317 * Method declared on IDialogSettings. | |
318 */ | |
319 public void put(String key, float value) { | |
320 put(key, tango.text.convert.Float.toString(value)); | |
321 } | |
322 | |
323 /* (non-Javadoc) | |
324 * Method declared on IDialogSettings. | |
325 */ | |
326 public void put(String key, int value) { | |
327 put(key, tango.text.convert.Integer.toString(value)); | |
328 } | |
329 | |
330 /* (non-Javadoc) | |
331 * Method declared on IDialogSettings. | |
332 */ | |
333 public void put(String key, long value) { | |
334 put(key, tango.text.convert.Integer.toString(value)); | |
335 } | |
336 | |
337 /* (non-Javadoc) | |
338 * Method declared on IDialogSettings. | |
339 */ | |
340 public void put(String key, String value) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
341 items.put(stringcast(key), stringcast(value)); |
19 | 342 } |
343 | |
344 /* (non-Javadoc) | |
345 * Method declared on IDialogSettings. | |
346 */ | |
347 public void put(String key, bool value) { | |
348 put(key, value ? "true" : "false" ); | |
349 } | |
350 | |
351 /* (non-Javadoc) | |
352 * Method declared on IDialogSettings. | |
353 */ | |
354 public void save(tango.io.model.IConduit.OutputStream writer) { | |
355 save(new XMLWriter(writer)); | |
356 } | |
357 | |
358 | |
359 /* (non-Javadoc) | |
360 * Method declared on IDialogSettings. | |
361 */ | |
362 public void save(String fileName) { | |
363 auto stream = new tango.io.stream.FileStream.FileOutput(fileName); | |
364 XMLWriter writer = new XMLWriter(stream.output); | |
365 save(writer); | |
366 writer.close(); | |
367 } | |
368 | |
369 /* (non-Javadoc) | |
370 * Save the settings in the <code>document</code>. | |
371 */ | |
372 private void save(XMLWriter out_) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
373 HashMap attributes = new HashMap(2); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
374 attributes.put(stringcast(TAG_NAME), stringcast(name is null ? "" : name)); //$NON-NLS-1$ |
19 | 375 out_.startTag(TAG_SECTION, attributes); |
376 attributes.clear(); | |
377 | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
378 Object EMPTY_STR = new ArrayWrapperString(""); |
19 | 379 foreach( key,value; items ){ |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
380 attributes.put(stringcast(TAG_KEY), key is null ? EMPTY_STR : key); //$NON-NLS-1$ |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
381 String string = stringcast(value);//cast(String) items.get(stringcast(key)); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
382 attributes.put(stringcast(TAG_VALUE), stringcast(string is null ? "" : string)); //$NON-NLS-1$ |
19 | 383 out_.printTag(TAG_ITEM, attributes, true); |
384 } | |
385 | |
386 attributes.clear(); | |
387 foreach( key,value; arrayItems ){ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
388 attributes.put(stringcast(TAG_KEY), key is null ? EMPTY_STR : key); //$NON-NLS-1$ |
19 | 389 out_.startTag(TAG_LIST, attributes); |
390 attributes.clear(); | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
391 String[] strValues = stringArrayFromObject(value); |
19 | 392 if (value !is null) { |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
393 for (int index = 0; index < strValues.length; index++) { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
394 String string = strValues[index]; |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
395 attributes.put(stringcast(TAG_VALUE), stringcast(string is null ? "" : string)); //$NON-NLS-1$ |
19 | 396 out_.printTag(TAG_ITEM, attributes, true); |
397 } | |
398 } | |
399 out_.endTag(TAG_LIST); | |
400 attributes.clear(); | |
401 } | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
402 for (Iterator i = sections.values().iterator(); i.hasNext();) { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
403 (cast(DialogSettings) i.next()).save(out_); |
19 | 404 } |
405 out_.endTag(TAG_SECTION); | |
406 } | |
407 | |
408 | |
409 /** | |
410 * A simple XML writer. Using this instead of the javax.xml.transform classes allows | |
411 * compilation against JCL Foundation (bug 80059). | |
412 */ | |
413 private static class XMLWriter : tango.io.Print.Print!(char) { | |
414 /** current number of tabs to use for ident */ | |
415 protected int tab; | |
416 | |
417 /** the xml header */ | |
418 protected static const String XML_VERSION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$ | |
419 | |
420 /** | |
421 * Create a new XMLWriter | |
422 * @param output the write to used when writing to | |
423 */ | |
424 public this(tango.io.model.IConduit.OutputStream output) { | |
425 super( tango.text.convert.Format.Format, output); | |
426 tab = 0; | |
427 print(XML_VERSION); | |
428 newline; | |
429 } | |
430 | |
431 /** | |
432 * write the intended end tag | |
433 * @param name the name of the tag to end | |
434 */ | |
435 public void endTag(String name) { | |
436 tab--; | |
437 printTag("/" ~ name, null, false); //$NON-NLS-1$ | |
438 } | |
439 | |
440 private void printTabulation() { | |
441 for (int i = 0; i < tab; i++) { | |
442 super.print('\t'); | |
443 } | |
444 } | |
445 | |
446 /** | |
447 * write the tag to the stream and format it by itending it and add new line after the tag | |
448 * @param name the name of the tag | |
449 * @param parameters map of parameters | |
450 * @param close should the tag be ended automatically (=> empty tag) | |
451 */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
452 public void printTag(String name, HashMap parameters, bool close) { |
19 | 453 printTag(name, parameters, true, true, close); |
454 } | |
455 | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
456 private void printTag(String name, HashMap parameters, bool shouldTab, bool newLine, bool close) { |
19 | 457 StringBuffer sb = new StringBuffer(); |
458 sb.append('<'); | |
459 sb.append(name); | |
460 if (parameters !is null) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
461 for (Enumeration e = Collections.enumeration(parameters.keySet()); e.hasMoreElements();) { |
19 | 462 sb.append(" "); //$NON-NLS-1$ |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
463 String key = stringcast( e.nextElement()); |
19 | 464 sb.append(key); |
465 sb.append("=\""); //$NON-NLS-1$ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
466 //sb.append(getEscaped(String.valueOf(parameters.get(key)))); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
467 sb.append(xmlEscape(stringcast(parameters.get(stringcast(key))))); |
19 | 468 sb.append("\""); //$NON-NLS-1$ |
469 } | |
470 } | |
471 if (close) { | |
472 sb.append('/'); | |
473 } | |
474 sb.append('>'); | |
475 if (shouldTab) { | |
476 printTabulation(); | |
477 } | |
478 if (newLine) { | |
479 print(sb.toString()); | |
480 newline; | |
481 } else { | |
482 print(sb.toString()); | |
483 } | |
484 } | |
485 | |
486 /** | |
487 * start the tag | |
488 * @param name the name of the tag | |
489 * @param parameters map of parameters | |
490 */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
491 public void startTag(String name, HashMap parameters) { |
19 | 492 startTag(name, parameters, true); |
493 tab++; | |
494 } | |
495 | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
496 private void startTag(String name, HashMap parameters, bool newLine) { |
19 | 497 printTag(name, parameters, true, newLine, false); |
498 } | |
499 } | |
500 | |
501 } |