diff artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java @ 9402:e511eb935ccd

Changed hard coded standard vegetation zone table to fetching it from the database, i18n for the standard zone names
author mschaefer
date Tue, 14 Aug 2018 14:04:01 +0200
parents 4a6cc7c6716a
children e2da9c8a7c57
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java	Tue Aug 14 14:02:26 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/DefaultVegetationZoneXPathFunction.java	Tue Aug 14 14:04:01 2018 +0200
@@ -10,15 +10,19 @@
 package org.dive4elements.river.artifacts.datacage.templating;
 
 import java.util.List;
+import java.util.UUID;
 
 import javax.xml.xpath.XPathFunction;
 import javax.xml.xpath.XPathFunctionException;
 
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RiverAccess;
 import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZone;
+import org.dive4elements.river.utils.RiverUtils;
 
 /**
- * Very specialized function the resolves the 'year' (als middle of all used events) from a fix-analysis-vollmer
- * artifact).
+ * Very specialized function that fetches the default vegetation zones for the river specified by an artifact
  *
  * @author Gernot Belger
  */
@@ -26,10 +30,25 @@
 
     public static final String ID = "defaultvegetationzone";
 
-    public static final int ARITY = 0;
+    public static final int ARITY = 1;
+
+    private final CallContext context;
+
+    public DefaultVegetationZoneXPathFunction(final CallContext context) {
+        this.context = context;
+    }
 
     @Override
     public Object evaluate(final List args) throws XPathFunctionException {
-        return VegetationZone.parseListToDataString(VegetationZone.getStandardList());
+
+        final UUID uuid = (UUID) args.get(0);
+        if (uuid == null)
+            return null;
+
+        final D4EArtifact artifact = RiverUtils.getArtifact(uuid.toString(), this.context);
+
+        final RiverAccess access = new RiverAccess(artifact);
+
+        return VegetationZone.parseListToDataString(VegetationZone.getStandardList(access.getRiver(), this.context));
     }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org