changeset 2594:226c360febae

Remove unnecessary outputs from attributes instead of copying outs to new attribute element. flys-artifacts/trunk@4156 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 16 Mar 2012 09:32:29 +0000
parents fafc9247fe06
children b23c956c5aa2
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 2 files changed, 35 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Mar 16 07:12:40 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Mar 16 09:32:29 2012 +0000
@@ -1,3 +1,9 @@
+2012-03-16  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Remove unnecessary outputs from attributes instead of copying outs to
+	  new attribute element.
+
 2012-03-16  Ingo Weinzierl <ingo@intevation.de>
 
 	* Tagged module as 'pre2.7-2012-03-16'.
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Mar 16 07:12:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Mar 16 09:32:29 2012 +0000
@@ -149,36 +149,40 @@
 
 
     protected Document removeAttributes(Document attrs, CallContext context) {
+        Node outs = (Node) XMLUtils.xpath(
+            attrs,
+            "/art:attribute/art:outputs",
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        NodeList nodes = (NodeList) XMLUtils.xpath(
+            attrs,
+            "/art:attribute/art:outputs/art:output",
+            XPathConstants.NODESET,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (nodes != null) {
+            for (int i = 0; i < nodes.getLength(); i++) {
+                Element e = (Element)nodes.item(i);
+                if(!outputExists(e.getAttribute("name"), context)) {
+                    outs.removeChild(e);
+                }
+            }
+        }
+        return attrs;
+    }
+
+
+    protected boolean outputExists(String name, CallContext context) {
         FLYSArtifact master = getMasterArtifact(context);
         List<Output> outList = master.getOutputs(context);
 
-        Document doc = XMLUtils.newDocument();
-        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
-            doc,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
-
-        Element root = ec.create("attribute");
-        doc.appendChild(root);
-
-        if (outList.size() > 0) {
-            Element outs = ec.create("outputs");
-            root.appendChild(outs);
-
-            for (Output o : outList) {
-                Node n = (Node) XMLUtils.xpath(
-                    attrs,
-                    "/art:attribute/art:outputs/art:output[@name='" + o.getName() + "']",
-                    XPathConstants.NODE,
-                    ArtifactNamespaceContext.INSTANCE);
-                if (n != null) {
-                    Node clone = doc.importNode(n, true);
-                    outs.appendChild(clone);
-                }
+        for (Output o : outList) {
+            if (name.equals(o.getName())) {
+                return true;
             }
         }
-
-        return doc;
+        return false;
     }
 
     /**

http://dive4elements.wald.intevation.org