[Dive4elements-commits] [PATCH] Handle NULL elements in datacage xml

Wald Commits scm-commit at wald.intevation.org
Wed Apr 10 10:59:32 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1365584369 -7200
# Node ID 142ed3c6276557b06a2e789ab68a1bf0c6bacfc6
# Parent  2d9eb188fa51b1842a0275ab83f43a27b2d41a1f
Handle NULL elements in datacage xml

    Patch provided by Sascha Teichmann

diff -r 2d9eb188fa51 -r 142ed3c62765 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/StackFrames.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/StackFrames.java	Wed Apr 10 10:25:33 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/StackFrames.java	Wed Apr 10 10:59:29 2013 +0200
@@ -23,6 +23,8 @@
 {
     private static Logger log = Logger.getLogger(StackFrames.class);
 
+    public static final Object NULL = new Object();
+
     /** The frames (used like a stack). */
     protected List<Map<String, Object>> frames;
 
@@ -115,12 +117,32 @@
         return def;
     }
 
+    public Object getNull(String key) {
+        return getNull(key, null);
+    }
+
+    public Object getNull(String key, Object def) {
+
+        key = key.toUpperCase();
+
+        for (int i = frames.size()-1; i >= 0; --i) {
+            Map<String, Object> frame = frames.get(i);
+            if (frame.containsKey(key)) {
+                Object value = frame.get(key);
+                return value != null ? value : NULL;
+            }
+        }
+
+        return def;
+    }
+
     @Override
     public Object resolveVariable(QName variableName) {
         if (log.isDebugEnabled()) {
             log.debug("resolve var: " + variableName);
         }
-        return get(variableName.getLocalPart());
+
+        return getNull(variableName.getLocalPart());
     }
 
     public String dump() {


More information about the Dive4elements-commits mailing list