comparison flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 1439:4df2d9a4b9b4

Added interfaces and container for output settings. Added settings container to collection. Extract settings from describe collection document. flys-client/trunk@3420 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 15 Dec 2011 08:29:04 +0000
parents f6fbfdc813f0
children 8da36efc839a
comparison
equal deleted inserted replaced
1438:432180235caf 1439:4df2d9a4b9b4
41 import de.intevation.flys.client.shared.model.OutputMode; 41 import de.intevation.flys.client.shared.model.OutputMode;
42 import de.intevation.flys.client.shared.model.ReportMode; 42 import de.intevation.flys.client.shared.model.ReportMode;
43 import de.intevation.flys.client.shared.model.Recommendation; 43 import de.intevation.flys.client.shared.model.Recommendation;
44 import de.intevation.flys.client.shared.model.Theme; 44 import de.intevation.flys.client.shared.model.Theme;
45 import de.intevation.flys.client.shared.model.ThemeList; 45 import de.intevation.flys.client.shared.model.ThemeList;
46 46 import de.intevation.flys.client.shared.model.Settings;
47 import de.intevation.flys.client.shared.model.Property;
48 import de.intevation.flys.client.shared.model.PropertyGroup;
49 import de.intevation.flys.client.shared.model.PropertySetting;
50 import de.intevation.flys.client.shared.model.StringProperty;
51 import de.intevation.flys.client.shared.model.OutputSettings;
52
53 //temporary
54 import javax.xml.parsers.DocumentBuilderFactory;
55 import javax.xml.parsers.DocumentBuilder;
56 import org.xml.sax.InputSource;
57 import java.io.StringReader;
47 58
48 /** 59 /**
49 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 60 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
50 */ 61 */
51 public class CollectionHelper { 62 public class CollectionHelper {
325 catch (NumberFormatException nfe) { 336 catch (NumberFormatException nfe) {
326 // do nothing 337 // do nothing
327 } 338 }
328 339
329 List<Recommendation> recommended = parseRecommendations(description); 340 List<Recommendation> recommended = parseRecommendations(description);
341 Map<String, Settings> outSettings = parseSettings(description);
330 Map<String, CollectionItem> collectionItems = 342 Map<String, CollectionItem> collectionItems =
331 new HashMap<String, CollectionItem>(); 343 new HashMap<String, CollectionItem>();
332 344
333 name = (name != null && name.length() > 0) ? name : uuid; 345 name = (name != null && name.length() > 0) ? name : uuid;
334 346
458 470
459 t.addAttr(name, value); 471 t.addAttr(name, value);
460 } 472 }
461 473
462 return t; 474 return t;
475 }
476
477
478 /**
479 * Parse Settings elements.
480 *
481 * @param description The collection description.
482 *
483 * @return Map containing the settings.
484 */
485 protected static Map<String, Settings> parseSettings(Document description) {
486 //TODO Extract settings from output elements.
487 logger.info("parseSettings");
488 Map<String, Settings> list = new HashMap<String, Settings>();
489
490 return list;
491 }
492
493
494 /**
495 *
496 */
497 protected static Settings parseSettings(String outName, Element settings) {
498 logger.info("parseSettings(String,Element)");
499 OutputSettings set = new OutputSettings(outName);
500 // get the categories
501 NodeList catNodes = settings.getChildNodes();
502 for (int i = 0; i < catNodes.getLength(); i++) {
503 Element catNode = (Element)catNodes.item(i);
504
505 // The category name
506 String category = catNode.getTagName();
507
508 // list of properties or groups (groups have child nodes).
509 NodeList list = catNode.getChildNodes();
510
511 // iterate through all properties or groups.
512 ArrayList<Property> props = new ArrayList<Property> ();
513 for (int j = 0; j < list.getLength(); j++) {
514 Property p;
515 Element e = (Element)list.item(j);
516 if (e.hasChildNodes() &&
517 e.getFirstChild().getNodeType() != Node.TEXT_NODE) {
518 p = parseSettingsGroup(e);
519 }
520 else {
521 p = parseSetting(e);
522 }
523 props.add(p);
524 }
525 set.setSettings(category, props);
526 }
527 return set;
528 }
529
530
531 /**
532 *
533 */
534 protected static Property parseSettingsGroup(Element group) {
535 PropertyGroup p = new PropertyGroup();
536 p.setName(group.getTagName());
537
538 NodeList list = group.getChildNodes();
539 ArrayList<Property> props = new ArrayList<Property>();
540 for (int i = 0; i < list.getLength(); i++) {
541 props.add(parseSetting((Element)list.item(i)));
542 }
543 p.setProperties(props);
544 return p;
545 }
546
547
548 /**
549 *
550 */
551 protected static Property parseSetting(Element property){
552 NamedNodeMap attrMap = property.getAttributes();
553 int attrNum = attrMap != null ? attrMap.getLength() : 0;
554
555 Node type = attrMap.getNamedItem("type");
556 String t = type.getNodeValue();
557 PropertySetting ps = new PropertySetting();
558
559 if(t.equals("string")) {
560 ps = new StringProperty();
561 }
562 ps.setName(property.getTagName());
563 ps.setValue(property.getTextContent());
564
565 for (int i = 0; i < attrNum; i++) {
566 Node attr = attrMap.item(i);
567
568 String name = attr.getNodeName();
569 String value = attr.getNodeValue();
570 if(name.equals("type")) {
571 continue;
572 }
573 ps.setAttribute(name, value);
574 }
575 return ps;
463 } 576 }
464 577
465 578
466 /** 579 /**
467 * This method extracts the CollectionItem from <i>node</i> with its output 580 * This method extracts the CollectionItem from <i>node</i> with its output

http://dive4elements.wald.intevation.org