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