[PATCH 2 of 3] Added new 'column' xpath function that allows to access a data-column via a name using variable replacement

Wald Commits scm-commit at wald.intevation.org
Wed Mar 28 14:35:09 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1522240495 -7200
# Node ID 66ce19d2c5f1366ba7c11e03124126ef0384f5d2
# Parent  175f113ed939f2556f480862f422279ce92314ab
Added new 'column' xpath function that allows to access a data-column via a name using variable replacement.

diff -r 175f113ed939 -r 66ce19d2c5f1 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Wed Mar 28 14:34:20 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Wed Mar 28 14:34:55 2018 +0200
@@ -221,6 +221,12 @@
             }
         });
 
+        addFunction("column", 1, new XPathFunction() {
+            @Override
+            public Object evaluate(List args) throws XPathFunctionException {
+                return column(args.get(0));
+            }
+        });
     }
 
     /**
@@ -578,5 +584,17 @@
         }
         return StackFrames.NULL;
     }
+
+    private Object column(Object argument) {
+        
+        if( !(argument instanceof String) )
+            throw new IllegalArgumentException("Argument of 'column' function must be a string");
+        
+        String columnName = (String) argument;
+
+        StackFrames frms = buildHelper.frames;
+        
+        return frms.getNull(columnName);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4Elements-commits mailing list