diff flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 2585:a71fc8f2030c

Issue 640. Remove all unnecessary output settings from attributes. flys-artifacts/trunk@4140 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 14 Mar 2012 15:00:30 +0000
parents 1fcaeced48f2
children 226c360febae 804088c2e23a
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Mar 09 12:57:23 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Wed Mar 14 15:00:30 2012 +0000
@@ -92,6 +92,10 @@
 
         try {
             String[]            aUUIDs  = getArtifactUUIDs(context);
+
+            oldAttrs = removeAttributes(oldAttrs, context);
+            parser   = new AttributeParser(oldAttrs);
+
             CollectionAttribute newAttr = mergeAttributes(
                 db, context, parser, aUUIDs);
 
@@ -144,6 +148,39 @@
     }
 
 
+    protected Document removeAttributes(Document attrs, 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);
+                }
+            }
+        }
+
+        return doc;
+    }
+
     /**
      * @param db The ArtifactDatabase which is required to save the attribute
      * into.

http://dive4elements.wald.intevation.org