comparison flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 1478:237e7450ae2e

Save output settings in chart properties dialog. flys-client/trunk@3524 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 22 Dec 2011 12:46:23 +0000
parents c899a7ffdc8f
children c21d14e48040
comparison
equal deleted inserted replaced
1477:6e694603cde1 1478:237e7450ae2e
176 if (t != null) { 176 if (t != null) {
177 out.appendChild(t); 177 out.appendChild(t);
178 } 178 }
179 } 179 }
180 180
181 Document doc = out.getOwnerDocument();
182
183 ElementCreator settingscr = new ElementCreator(doc, "", "");
184
185 Settings settings = collection.getSettings(mode.getName());
186 if (settings == null ||
187 settings.getCategories().size() == 0)
188 {
189 logger.debug("No settings for output mode: " + mode.getName());
190 return null;
191 }
192 Element s = createSettingsElement(settingscr, collection, settings);
193 if (s != null) {
194 out.appendChild(s);
195 }
196 logger.info(XMLUtils.toString(out));
181 return out; 197 return out;
182 } 198 }
183 199
184 200
185 /** 201 /**
283 return recommendation; 299 return recommendation;
284 } 300 }
285 301
286 302
287 /** 303 /**
304 *
305 */
306 protected static Element createSettingsElement(
307 ElementCreator cr,
308 Collection c,
309 Settings s)
310 {
311 logger.debug("CollectionHelper.createSettingsElement");
312 Element settings = cr.create("settings");
313
314 List<String> categories = s.getCategories();
315
316 for (String category: categories) {
317 Element cat =cr.create(category);
318 settings.appendChild(cat);
319 List<Property> props = s.getSettings(category);
320 for (Property p: props) {
321 if (p instanceof PropertyGroup) {
322 Element prop = createPropertyGroupElement(cr,
323 (PropertyGroup)p);
324 cat.appendChild(prop);
325 }
326 else if (p instanceof PropertySetting) {
327 Element prop = createPropertyElement (cr,
328 (PropertySetting)p);
329 cat.appendChild(prop);
330 }
331 }
332 }
333 return settings;
334 }
335
336
337 /**
338 *
339 */
340 protected static Element createPropertyGroupElement(
341 ElementCreator cr,
342 PropertyGroup pg)
343 {
344 Element e = cr.create(pg.getName());
345
346 List<Property> list = pg.getProperties();
347 for (Property p: list) {
348 Element pe = createPropertyElement(cr, (PropertySetting)p);
349 e.appendChild(pe);
350 }
351 return e;
352 }
353
354
355 /**
356 *
357 */
358 protected static Element createPropertyElement(
359 ElementCreator cr,
360 PropertySetting p)
361 {
362 Element e = cr.create(p.getName());
363
364 if(p instanceof BooleanProperty) {
365 cr.addAttr(e, "type", "boolean", false);
366 }
367 else if(p instanceof DoubleProperty) {
368 cr.addAttr(e, "type", "double", false);
369 }
370 else if(p instanceof IntegerProperty) {
371 cr.addAttr(e, "type", "integer", false);
372 }
373 else if(p instanceof StringProperty) {
374 cr.addAttr(e, "type", "string", false);
375 }
376
377 e.setTextContent(p.getValue());
378 cr.addAttr(e, "display", p.getAttribute("display"), false);
379 return e;
380 }
381
382
383 /**
288 * Take the DESCRIBE document of the Collections describe() 384 * Take the DESCRIBE document of the Collections describe()
289 * operation and extracts the information about the collection itself and 385 * operation and extracts the information about the collection itself and
290 * the collection items. 386 * the collection items.
291 * 387 *
292 * @param description The DESCRIBE document of the Collections describe() 388 * @param description The DESCRIBE document of the Collections describe()
510 606
511 /** 607 /**
512 * 608 *
513 */ 609 */
514 protected static Settings parseSettings(String outName, Element node) { 610 protected static Settings parseSettings(String outName, Element node) {
515 logger.info("parseSettings(String,Element)");
516 OutputSettings set = new OutputSettings(outName); 611 OutputSettings set = new OutputSettings(outName);
517 612
518 NodeList elements = node.getElementsByTagName("settings"); 613 NodeList elements = node.getElementsByTagName("settings");
519 614
520 if (elements.getLength() == 0 || elements.getLength() > 1) { 615 if (elements.getLength() == 0 || elements.getLength() > 1) {
556 651
557 /** 652 /**
558 * 653 *
559 */ 654 */
560 protected static Property parseSettingsGroup(Element group) { 655 protected static Property parseSettingsGroup(Element group) {
561 logger.debug("parseSettingsGroup");
562 PropertyGroup p = new PropertyGroup(); 656 PropertyGroup p = new PropertyGroup();
563 p.setName(group.getTagName()); 657 p.setName(group.getTagName());
564 658
565 NodeList list = group.getChildNodes(); 659 NodeList list = group.getChildNodes();
566 ArrayList<Property> props = new ArrayList<Property>(); 660 ArrayList<Property> props = new ArrayList<Property>();
574 668
575 /** 669 /**
576 * 670 *
577 */ 671 */
578 protected static Property parseSetting(Element property){ 672 protected static Property parseSetting(Element property){
579 logger.debug("parseSetting");
580 NamedNodeMap attrMap = property.getAttributes(); 673 NamedNodeMap attrMap = property.getAttributes();
581 int attrNum = attrMap != null ? attrMap.getLength() : 0; 674 int attrNum = attrMap != null ? attrMap.getLength() : 0;
582 675
583 Node type = attrMap.getNamedItem("type"); 676 Node type = attrMap.getNamedItem("type");
584 String t = type.getNodeValue(); 677 String t = type.getNodeValue();

http://dive4elements.wald.intevation.org