changeset 303:9ba2cf8cad8d

Export format of charts is related to mime-type. gnv-artifacts/trunk@358 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 20 Nov 2009 15:45:25 +0000 (2009-11-20)
parents dc2713a3eaa7
children a16d337c5678
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java
diffstat 4 files changed, 72 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Fri Nov 20 14:46:37 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Fri Nov 20 15:45:25 2009 +0000
@@ -1,3 +1,13 @@
+2009-11-20  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java:
+	  Export format of charts (png, jpeg, gif) depends on mime-type.
+
+	* src/main/java/de/intevation/gnv/chart/Chart.java,
+	  src/main/java/de/intevation/gnv/chart/AbstractChart.java: Renamed export
+	  method, because it doesn't export just png anymore, but jpeg or gif as
+	  well.
+
 2009-11-20  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_step_06_out_chart.xml,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java	Fri Nov 20 14:46:37 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java	Fri Nov 20 15:45:25 2009 +0000
@@ -31,7 +31,7 @@
 
     public abstract JFreeChart generateChart();
 
-    public BufferedImage exportPNG(int width, int height) {
+    public BufferedImage exportImage(int width, int height) {
         log.info("export chart as png");
 
         return chart.createBufferedImage(
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java	Fri Nov 20 14:46:37 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/Chart.java	Fri Nov 20 15:45:25 2009 +0000
@@ -13,7 +13,7 @@
     
     public JFreeChart generateChart();
     
-    public BufferedImage exportPNG(int width, int height)
+    public BufferedImage exportImage(int width, int height)
     throws IOException;
 
     public void exportSVG(); //TODO Change return value
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Fri Nov 20 14:46:37 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Fri Nov 20 15:45:25 2009 +0000
@@ -72,6 +72,10 @@
     protected static final boolean CACHE_CHART = 
         Boolean.parseBoolean(System.getProperty("cache.chart", "false"));
 
+    protected static final String[] IMG_EXPORT_FORMAT = {
+        "PNG", "JPEG", "GIF"
+    };
+
     /**
      * The UID of this Class
      */
@@ -163,15 +167,29 @@
      *      java.util.Collection, java.io.OutputStream, java.lang.String,
      *      de.intevation.artifacts.CallMeta)
      */
-    public void out(Document format, Collection<InputData> inputData,
-                    OutputStream outputStream, String uuid, CallMeta callMeta)
-                                                                              throws TransitionException {
+    public void out(
+        Document format,
+        Collection<InputData> inputData,
+        OutputStream outputStream,
+        String uuid,
+        CallMeta callMeta
+    ) throws TransitionException
+    {
         log.debug("TimeSeriesOutputTransition.out");
-        String outputMode = Config.getStringXPath(format, "action/out/@name");
+
+        String outputMode = Config.getStringXPath(
+            format,
+            "action/out/@name"
+        );
+        String mimeType   = Config.getStringXPath(
+            format,
+            "action/out/mime-type/@value"
+        );
+
         try {
 
             this.advance(uuid, callMeta); // TODO This hsould only be done if it is nessessary
-           
+
             if (outputMode.equalsIgnoreCase("chart")) {
                 log.debug("Chart will be generated.");
                 int chartWidth = 600;
@@ -199,8 +217,19 @@
                         .creatStyle(chartWidth, chartHeight);
                 ChartLabels chartLables = new ChartLabels(this.getFisName(callMeta.getLanguages())+" "+this
                         .getSelectedFeatureName(uuid), this.domainLable);
-                this.createChart(outputStream, parameters, measurements,dates,
-                        chartStyle, chartLables, uuid);
+
+                String exportFormat = getExportFormat(mimeType);
+
+                this.createChart(
+                    outputStream,
+                    parameters,
+                    measurements,
+                    dates,
+                    chartStyle,
+                    chartLables,
+                    uuid,
+                    exportFormat
+                );
             } else if (outputMode.equalsIgnoreCase("csv")) {
                 log.debug("CSV-File will be generated.");
                 Collection<Result> chartResult = this.getChartResult(uuid);
@@ -239,7 +268,18 @@
         }
     }
 
-    
+
+    protected String getExportFormat(String mime) {
+        for(int i = 0; i < IMG_EXPORT_FORMAT.length; i++) {
+            if (mime.trim().toUpperCase().indexOf(IMG_EXPORT_FORMAT[i]) > 0)
+                return IMG_EXPORT_FORMAT[i];
+        }
+
+        // no format found relating to mimeType, default export as PNG
+        return IMG_EXPORT_FORMAT[0];
+    }
+
+
     /**
      * @param outputStream
      * @param chartResult
@@ -360,7 +400,8 @@
         Collection   dates,
         ChartStyle   chartStyle,
         ChartLabels  chartLables,
-        String       uuid
+        String       uuid,
+        String       exportFormat
     )
     throws IOException, TechnicalChartException
     {
@@ -381,14 +422,20 @@
             return;
         }
 
-        // TODO generic format
         Dimension dim    = chartStyle.getChartSize();
-        String    format = "PNG";
         int       width  = new Double(dim.getWidth()).intValue();
         int       height = new Double(dim.getHeight()).intValue();
 
-        log.debug("export chart as " + format + " in " + width + "x" + height);
-        ImageIO.write(chart.exportPNG(width, height), format, outputStream);
+        log.debug(
+            "export chart as " + exportFormat +
+            " in " + width + "x" + height
+        );
+
+        ImageIO.write(
+            chart.exportImage(width, height),
+            exportFormat,
+            outputStream
+        );
     }
 
     protected Chart getChart(

http://dive4elements.wald.intevation.org