# HG changeset patch # User Raimund Renkert # Date 1324395128 0 # Node ID c899a7ffdc8f1b4e026b3b1e1dc8ed0e12816243 # Parent 14ce1c2a9f6caf899ced4152ec783d71ab4cc1d3 Extract and parse the output settings from describe document and add settings objects to collection. flys-client/trunk@3503 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 14ce1c2a9f6c -r c899a7ffdc8f flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Dec 20 15:22:42 2011 +0000 +++ b/flys-client/ChangeLog Tue Dec 20 15:32:08 2011 +0000 @@ -1,3 +1,17 @@ +2011-12-20 Raimund Renkert + + * src/main/java/de/intevation/flys/client/shared/model/Collection.java: + Added setter for settings. + + * src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java: + Ensure the settings is not null. + + * src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java: + Ensure the categories object is not null. + + * src/main/java/de/intevation/flys/client/server/CollectionHelper.java: + Extract and parse the output settings. + 2011-12-20 Raimund Renkert * src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java, diff -r 14ce1c2a9f6c -r c899a7ffdc8f flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Tue Dec 20 15:22:42 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Tue Dec 20 15:32:08 2011 +0000 @@ -48,6 +48,9 @@ import de.intevation.flys.client.shared.model.PropertyGroup; import de.intevation.flys.client.shared.model.PropertySetting; import de.intevation.flys.client.shared.model.StringProperty; +import de.intevation.flys.client.shared.model.DoubleProperty; +import de.intevation.flys.client.shared.model.IntegerProperty; +import de.intevation.flys.client.shared.model.BooleanProperty; import de.intevation.flys.client.shared.model.OutputSettings; //temporary @@ -334,7 +337,6 @@ } List recommended = parseRecommendations(description); - Map outSettings = parseSettings(description); Map collectionItems = new HashMap(); @@ -370,6 +372,8 @@ Map themeLists = parseThemeLists(description, collectionItems); c.setThemeLists(themeLists); + Map outSettings = parseSettings(description); + c.setSettings(outSettings); logger.debug( "Found " + c.getItemLength() + " collection items " + "for the Collection '" + c.identifier() + "'."); @@ -479,9 +483,26 @@ * @return Map containing the settings. */ protected static Map parseSettings(Document description) { - //TODO Extract settings from output elements. logger.info("parseSettings"); - Map list = new HashMap(); + + NodeList lists = (NodeList) XMLUtils.xpath( + description, + "/art:artifact-collection/art:attribute/art:outputs/art:output", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int num = lists != null ? lists.getLength() : 0; + + Map list = new HashMap(num); + + String uri = ArtifactNamespaceContext.NAMESPACE_URI; + + for (int i = 0; i < num; i++) { + Element node = (Element)lists.item(i); + String outName = node.getAttribute("name"); + Settings s = parseSettings(outName, node); + list.put(outName, s); + } return list; } @@ -490,9 +511,18 @@ /** * */ - protected static Settings parseSettings(String outName, Element settings) { + protected static Settings parseSettings(String outName, Element node) { logger.info("parseSettings(String,Element)"); OutputSettings set = new OutputSettings(outName); + + NodeList elements = node.getElementsByTagName("settings"); + + if (elements.getLength() == 0 || elements.getLength() > 1) { + return set; + } + + Element settings = (Element)elements.item(0); + // get the categories NodeList catNodes = settings.getChildNodes(); for (int i = 0; i < catNodes.getLength(); i++) { @@ -505,9 +535,9 @@ NodeList list = catNode.getChildNodes(); // iterate through all properties or groups. - ArrayList props = new ArrayList (); + List props = new ArrayList (); for (int j = 0; j < list.getLength(); j++) { - Property p; + Property p = new PropertySetting(); Element e = (Element)list.item(j); if (e.hasChildNodes() && e.getFirstChild().getNodeType() != Node.TEXT_NODE) { @@ -528,6 +558,7 @@ * */ protected static Property parseSettingsGroup(Element group) { + logger.debug("parseSettingsGroup"); PropertyGroup p = new PropertyGroup(); p.setName(group.getTagName()); @@ -545,6 +576,7 @@ * */ protected static Property parseSetting(Element property){ + logger.debug("parseSetting"); NamedNodeMap attrMap = property.getAttributes(); int attrNum = attrMap != null ? attrMap.getLength() : 0; @@ -555,6 +587,15 @@ if(t.equals("string")) { ps = new StringProperty(); } + else if (t.equals("integer")) { + ps = new IntegerProperty(); + } + else if (t.equals("double")) { + ps = new DoubleProperty(); + } + else if (t.equals("boolean")) { + ps = new BooleanProperty(); + } ps.setName(property.getTagName()); ps.setValue(property.getTextContent()); diff -r 14ce1c2a9f6c -r c899a7ffdc8f flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java Tue Dec 20 15:22:42 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java Tue Dec 20 15:32:08 2011 +0000 @@ -40,6 +40,8 @@ public Settings getSettings(String outName); + public void setSettings(Map settings); + /** Sets mapping outputname to ThemeList. */ public void setThemeLists(Map map); diff -r 14ce1c2a9f6c -r c899a7ffdc8f flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java Tue Dec 20 15:22:42 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java Tue Dec 20 15:32:08 2011 +0000 @@ -229,6 +229,9 @@ public void addSettings(String outname, Settings settings) { + if (this.settings == null) { + this.settings = new HashMap(); + } this.settings.put(outname, settings); } diff -r 14ce1c2a9f6c -r c899a7ffdc8f flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java Tue Dec 20 15:22:42 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/OutputSettings.java Tue Dec 20 15:32:08 2011 +0000 @@ -16,7 +16,6 @@ protected HashMap > categories; - public OutputSettings() { this.categories = new HashMap >(); } @@ -39,6 +38,9 @@ public void setSettings(String category, List settings) { + if (this.categories == null) { + this.categories = new HashMap >(); + } this.categories.put(category, settings); }