diff gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java @ 320:18302372703f

Implemented pdf export of charts. gnv-artifacts/trunk@381 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 30 Nov 2009 09:51:59 +0000
parents 5f2820e821e0
children a4376fd23f99
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Fri Nov 27 13:00:00 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Mon Nov 30 09:51:59 2009 +0000
@@ -68,9 +68,12 @@
  */
 public class TimeSeriesOutputTransition extends OutputTransitionBase {
 
-    protected static final boolean CACHE_CHART = 
+    protected static final boolean CACHE_CHART =
         Boolean.parseBoolean(System.getProperty("cache.chart", "false"));
 
+    protected static final boolean PDF_FORMAT_LANDSCAPE =
+        Boolean.parseBoolean(System.getProperty("export.pdf.landscape","true"));
+
     protected static final String[] IMG_EXPORT_FORMAT = {
         "PNG", "JPEG", "GIF"
     };
@@ -241,6 +244,34 @@
                     chartHeight
                 );
             }
+            else if (outputMode.equalsIgnoreCase("pdf")) {
+                log.debug("Output mode == pdf");
+
+                Locale[] serverLocales    =
+                    RessourceFactory.getInstance().getLocales();
+                Locale locale             =
+                    callMeta.getPreferredLocale(serverLocales);
+
+                log.debug(
+                    "Best locale - regarding intersection of server and " +
+                    "browser locales -  is " + locale.toString()
+                );
+
+                createPDF(
+                    outputStream,
+                    getParameters(uuid),
+                    getMeasurements(uuid),
+                    getDates(uuid),
+                    new ChartLabels(
+                        this.getFisName(callMeta.getLanguages()) +
+                        " "+ getSelectedFeatureName(uuid),
+                        this.domainLable),
+                    uuid,
+                    "A4",
+                    true,
+                    locale
+                );
+            }
             else if (outputMode.equalsIgnoreCase("csv")) {
                 log.debug("CSV-File will be generated.");
                 Collection<Result> chartResult = this.getChartResult(uuid);
@@ -449,6 +480,42 @@
     }
 
 
+    protected void createPDF(
+        OutputStream outputStream,
+        Collection   parameters,
+        Collection   measurements,
+        Collection   dates,
+        ChartLabels  chartLables,
+        String       uuid,
+        String       exportFormat,
+        boolean      landscape,
+        Locale       locale
+    ) {
+        Chart chart = getChart(
+            chartLables,
+            parameters,
+            measurements,
+            dates,
+            getChartResult(uuid),
+            locale,
+            uuid
+        );
+
+        if (chart == null) {
+            log.error("Could not initialize chart.");
+            return;
+        }
+
+        ChartExportHelper.exportPDF(
+            outputStream,
+            chart.generateChart(),
+            "A4",
+            PDF_FORMAT_LANDSCAPE,
+            50F, 50F, 50F, 50F
+        );
+    }
+
+
     protected Chart getChart(
         ChartLabels  chartLables,
         Collection   parameters,
@@ -607,4 +674,4 @@
         return null;
     }
 }
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org