changeset 5628:142ed3c62765

Handle NULL elements in datacage xml Patch provided by Sascha Teichmann
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 10 Apr 2013 10:59:29 +0200
parents 2d9eb188fa51
children ce982943ab46
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/StackFrames.java
diffstat 1 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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() {

http://dive4elements.wald.intevation.org