comparison flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 1464:c899a7ffdc8f

Extract and parse the output settings from describe document and add settings objects to collection. flys-client/trunk@3503 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 20 Dec 2011 15:32:08 +0000
parents 8da36efc839a
children 237e7450ae2e
comparison
equal deleted inserted replaced
1463:14ce1c2a9f6c 1464:c899a7ffdc8f
46 import de.intevation.flys.client.shared.model.Settings; 46 import de.intevation.flys.client.shared.model.Settings;
47 import de.intevation.flys.client.shared.model.Property; 47 import de.intevation.flys.client.shared.model.Property;
48 import de.intevation.flys.client.shared.model.PropertyGroup; 48 import de.intevation.flys.client.shared.model.PropertyGroup;
49 import de.intevation.flys.client.shared.model.PropertySetting; 49 import de.intevation.flys.client.shared.model.PropertySetting;
50 import de.intevation.flys.client.shared.model.StringProperty; 50 import de.intevation.flys.client.shared.model.StringProperty;
51 import de.intevation.flys.client.shared.model.DoubleProperty;
52 import de.intevation.flys.client.shared.model.IntegerProperty;
53 import de.intevation.flys.client.shared.model.BooleanProperty;
51 import de.intevation.flys.client.shared.model.OutputSettings; 54 import de.intevation.flys.client.shared.model.OutputSettings;
52 55
53 //temporary 56 //temporary
54 57
55 /** 58 /**
332 catch (NumberFormatException nfe) { 335 catch (NumberFormatException nfe) {
333 // do nothing 336 // do nothing
334 } 337 }
335 338
336 List<Recommendation> recommended = parseRecommendations(description); 339 List<Recommendation> recommended = parseRecommendations(description);
337 Map<String, Settings> outSettings = parseSettings(description);
338 Map<String, CollectionItem> collectionItems = 340 Map<String, CollectionItem> collectionItems =
339 new HashMap<String, CollectionItem>(); 341 new HashMap<String, CollectionItem>();
340 342
341 name = (name != null && name.length() > 0) ? name : uuid; 343 name = (name != null && name.length() > 0) ? name : uuid;
342 344
368 } 370 }
369 371
370 Map<String, ThemeList> themeLists = parseThemeLists(description, collectionItems); 372 Map<String, ThemeList> themeLists = parseThemeLists(description, collectionItems);
371 c.setThemeLists(themeLists); 373 c.setThemeLists(themeLists);
372 374
375 Map<String, Settings> outSettings = parseSettings(description);
376 c.setSettings(outSettings);
373 logger.debug( 377 logger.debug(
374 "Found " + c.getItemLength() + " collection items " + 378 "Found " + c.getItemLength() + " collection items " +
375 "for the Collection '" + c.identifier() + "'."); 379 "for the Collection '" + c.identifier() + "'.");
376 380
377 return c; 381 return c;
477 * @param description The collection description. 481 * @param description The collection description.
478 * 482 *
479 * @return Map containing the settings. 483 * @return Map containing the settings.
480 */ 484 */
481 protected static Map<String, Settings> parseSettings(Document description) { 485 protected static Map<String, Settings> parseSettings(Document description) {
482 //TODO Extract settings from output elements.
483 logger.info("parseSettings"); 486 logger.info("parseSettings");
484 Map<String, Settings> list = new HashMap<String, Settings>(); 487
488 NodeList lists = (NodeList) XMLUtils.xpath(
489 description,
490 "/art:artifact-collection/art:attribute/art:outputs/art:output",
491 XPathConstants.NODESET,
492 ArtifactNamespaceContext.INSTANCE);
493
494 int num = lists != null ? lists.getLength() : 0;
495
496 Map<String, Settings> list = new HashMap<String, Settings>(num);
497
498 String uri = ArtifactNamespaceContext.NAMESPACE_URI;
499
500 for (int i = 0; i < num; i++) {
501 Element node = (Element)lists.item(i);
502 String outName = node.getAttribute("name");
503 Settings s = parseSettings(outName, node);
504 list.put(outName, s);
505 }
485 506
486 return list; 507 return list;
487 } 508 }
488 509
489 510
490 /** 511 /**
491 * 512 *
492 */ 513 */
493 protected static Settings parseSettings(String outName, Element settings) { 514 protected static Settings parseSettings(String outName, Element node) {
494 logger.info("parseSettings(String,Element)"); 515 logger.info("parseSettings(String,Element)");
495 OutputSettings set = new OutputSettings(outName); 516 OutputSettings set = new OutputSettings(outName);
517
518 NodeList elements = node.getElementsByTagName("settings");
519
520 if (elements.getLength() == 0 || elements.getLength() > 1) {
521 return set;
522 }
523
524 Element settings = (Element)elements.item(0);
525
496 // get the categories 526 // get the categories
497 NodeList catNodes = settings.getChildNodes(); 527 NodeList catNodes = settings.getChildNodes();
498 for (int i = 0; i < catNodes.getLength(); i++) { 528 for (int i = 0; i < catNodes.getLength(); i++) {
499 Element catNode = (Element)catNodes.item(i); 529 Element catNode = (Element)catNodes.item(i);
500 530
503 533
504 // list of properties or groups (groups have child nodes). 534 // list of properties or groups (groups have child nodes).
505 NodeList list = catNode.getChildNodes(); 535 NodeList list = catNode.getChildNodes();
506 536
507 // iterate through all properties or groups. 537 // iterate through all properties or groups.
508 ArrayList<Property> props = new ArrayList<Property> (); 538 List<Property> props = new ArrayList<Property> ();
509 for (int j = 0; j < list.getLength(); j++) { 539 for (int j = 0; j < list.getLength(); j++) {
510 Property p; 540 Property p = new PropertySetting();
511 Element e = (Element)list.item(j); 541 Element e = (Element)list.item(j);
512 if (e.hasChildNodes() && 542 if (e.hasChildNodes() &&
513 e.getFirstChild().getNodeType() != Node.TEXT_NODE) { 543 e.getFirstChild().getNodeType() != Node.TEXT_NODE) {
514 p = parseSettingsGroup(e); 544 p = parseSettingsGroup(e);
515 } 545 }
526 556
527 /** 557 /**
528 * 558 *
529 */ 559 */
530 protected static Property parseSettingsGroup(Element group) { 560 protected static Property parseSettingsGroup(Element group) {
561 logger.debug("parseSettingsGroup");
531 PropertyGroup p = new PropertyGroup(); 562 PropertyGroup p = new PropertyGroup();
532 p.setName(group.getTagName()); 563 p.setName(group.getTagName());
533 564
534 NodeList list = group.getChildNodes(); 565 NodeList list = group.getChildNodes();
535 ArrayList<Property> props = new ArrayList<Property>(); 566 ArrayList<Property> props = new ArrayList<Property>();
543 574
544 /** 575 /**
545 * 576 *
546 */ 577 */
547 protected static Property parseSetting(Element property){ 578 protected static Property parseSetting(Element property){
579 logger.debug("parseSetting");
548 NamedNodeMap attrMap = property.getAttributes(); 580 NamedNodeMap attrMap = property.getAttributes();
549 int attrNum = attrMap != null ? attrMap.getLength() : 0; 581 int attrNum = attrMap != null ? attrMap.getLength() : 0;
550 582
551 Node type = attrMap.getNamedItem("type"); 583 Node type = attrMap.getNamedItem("type");
552 String t = type.getNodeValue(); 584 String t = type.getNodeValue();
553 PropertySetting ps = new PropertySetting(); 585 PropertySetting ps = new PropertySetting();
554 586
555 if(t.equals("string")) { 587 if(t.equals("string")) {
556 ps = new StringProperty(); 588 ps = new StringProperty();
589 }
590 else if (t.equals("integer")) {
591 ps = new IntegerProperty();
592 }
593 else if (t.equals("double")) {
594 ps = new DoubleProperty();
595 }
596 else if (t.equals("boolean")) {
597 ps = new BooleanProperty();
557 } 598 }
558 ps.setName(property.getTagName()); 599 ps.setName(property.getTagName());
559 ps.setValue(property.getTextContent()); 600 ps.setValue(property.getTextContent());
560 601
561 for (int i = 0; i < attrNum; i++) { 602 for (int i = 0; i < attrNum; i++) {

http://dive4elements.wald.intevation.org