changeset 1831:490ab097f58c

Prevent empty output-nodes in flyscollections attributes. flys-artifacts/trunk@3167 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 04 Nov 2011 11:59:08 +0000
parents 7bb5bfd3b51f
children a8910c1c82fb
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java
diffstat 2 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Nov 04 10:58:44 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Nov 04 11:59:08 2011 +0000
@@ -1,3 +1,14 @@
+2011-11-04  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	For a Flys-Collection, add outputt to attributes-part of describe
+	document only if they contain facets.  -> Prevent empty output nodes
+	in flys-collections outputs.
+
+	* src/main/java/de/intevation/flys/collections/AttributeWriter.java:
+	  (writeFacets): Added return type to indicate whether any facet was
+	  written. Decide whether to add an output-node depending on this
+	  return value.
+
 2011-11-04  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/utils/MapfileGenerator.java: Create
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Fri Nov 04 10:58:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Fri Nov 04 11:59:08 2011 +0000
@@ -134,11 +134,16 @@
         Element output = cr.create("output");
         cr.addAttr(output, "name", outputName);
 
-        outs.appendChild(output);
 
         List<String> compatibleFacets = this.compatibilities.get(outputName);
         try {
-            writeFacets(doc, cr, output, newOutFacets, oldOutFacets, compatibleFacets);
+            if (writeFacets(
+                    doc, cr, output, newOutFacets, oldOutFacets,
+                    compatibleFacets))
+            {
+                // Add output element only if it contains facets.
+                outs.appendChild(output);
+            }
         }
         catch (ArtifactDatabaseException ade) {
             logger.error(ade, ade);
@@ -153,8 +158,9 @@
      * @param newFacets the new facets
      * @param oldFacets the old facets
      * @param compatibleFacets List of facets to accept
+     * @return true if any facets are written to the out.
      */
-    protected void writeFacets(
+    protected boolean writeFacets(
         Document       doc,
         ElementCreator cr,
         Element        output,
@@ -165,7 +171,7 @@
     {
         if (compatibleFacets == null) {
             logger.warn("No compatible facets, not generating out.");
-            return;
+            return false;
         }
 
         int num = newFacets.size();
@@ -253,6 +259,8 @@
                 output.appendChild(node);
             }
         }
+
+        return currentFacets.size() > 0;
     }
 
 

http://dive4elements.wald.intevation.org