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