changeset 8074:bd0dfa57b1fe

flys/issue1262: Introduce variable $RADIUS to be used in user defined chart sub titles.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 07 Aug 2014 17:24:33 +0200
parents 6e6506ec0ae0
children 1cae4fc6bdd7
files artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java artifacts/src/main/java/org/dive4elements/river/exports/process/WDiffProcessor.java
diffstat 2 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java	Tue Aug 05 18:28:04 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java	Thu Aug 07 17:24:33 2014 +0200
@@ -131,6 +131,8 @@
     public static final String XPATH_CHART_Y_RANGE =
         "/art:action/art:attributes/art:yrange";
 
+    public static final String I18N_SUBTITLE_RADIUS =
+        "chart.subtitle.radius";
 
     /** The document of the incoming out() request.*/
     protected Document request;
@@ -672,6 +674,20 @@
         return getDefaultChartTitle();
     }
 
+    protected String interpolateVariables(String s) {
+
+        Object radius = context.getContextValue("radius");
+        if (radius instanceof Double) {
+            String txt = Resources.getMsg(
+                context.getMeta(),
+                I18N_SUBTITLE_RADIUS,
+                new Object[] { radius });
+
+            return s.replace("$RADIUS", txt);
+
+        }
+        return s;
+    }
 
     /**
      * Returns the subtitle of a chart. The return value depends on the
@@ -689,9 +705,13 @@
             if (subTitle == null) {
                 return getDefaultChartSubtitle();
             }
-            else {
-                return subTitle;
+            String defSubTitle = getDefaultChartSubtitle();
+            if (defSubTitle != null
+            && !defSubTitle.isEmpty()
+            && !subTitle.equals(defSubTitle)) {
+                return interpolateVariables(defSubTitle);
             }
+            return subTitle;
         }
 
         return getDefaultChartSubtitle();
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/WDiffProcessor.java	Tue Aug 05 18:28:04 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/WDiffProcessor.java	Thu Aug 07 17:24:33 2014 +0200
@@ -45,8 +45,9 @@
             ZoomScale scales = (ZoomScale)fc.get("zoomscale");
             RiverAccess access = new RiverAccess((D4EArtifact)artifact);
             String river = access.getRiverName();
+            double radius = scales.getRadius(river, start, end);
+            context.putContextValue("radius", radius);
 
-            double radius = scales.getRadius(river, start, end);
             generator.addSubtitle(Resources.getMsg(
                 context.getMeta(),
                 I18N_SUBTITLE_RADIUS,

http://dive4elements.wald.intevation.org