changeset 7700:9211f8cafe8a

(issue1559) Improve Exception handling and allow null titles
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 16 Dec 2013 19:08:39 +0100 (2013-12-16)
parents 4daaf5e51dfb
children e47b1ea5baf4
files artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java
diffstat 1 files changed, 25 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java	Mon Dec 16 16:42:24 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java	Mon Dec 16 19:08:39 2013 +0100
@@ -240,42 +240,43 @@
         if (landscape) {
             document = new Document(page.rotate());
             log.debug("Create landscape pdf.");
+        } else {
+            document = new Document(page);
         }
-        else
-            document = new Document(page);
 
         try {
             PdfWriter writer = PdfWriter.getInstance(document, out);
 
-            document.addSubject(chart.getTitle().getText());
+            document.addSubject(chart.getTitle() != null ? chart.getTitle().getText() : "");
             document.addCreationDate();
             document.open();
 
-            PdfContentByte content  = writer.getDirectContent();
-
-            PdfTemplate template = content.createTemplate(width, height);
-            Graphics2D  graphics = template.createGraphics(width, height);
-
-            double[] origin = getCenteredAnchor(
-                marginLeft, marginRight, marginBottom, marginTop,
-                width, height,
-                size[0], size[1]);
+            try {
+                PdfContentByte content  = writer.getDirectContent();
 
-            Rectangle2D area = new Rectangle2D.Double(
-                origin[0], origin[1], size[0], size[1]);
-
-            ChartRenderingInfo info = new ChartRenderingInfo();
+                PdfTemplate template = content.createTemplate(width, height);
+                Graphics2D  graphics = template.createGraphics(width, height);
 
-            chart.draw(graphics, area, info);
-            graphics.dispose();
-            content.addTemplate(template, 0f, 0f);
-        }
-        catch (DocumentException de) {
+                double[] origin = getCenteredAnchor(
+                    marginLeft, marginRight, marginBottom, marginTop,
+                    width, height,
+                    size[0], size[1]);
+
+                Rectangle2D area = new Rectangle2D.Double(
+                    origin[0], origin[1], size[0], size[1]);
+
+                ChartRenderingInfo info = new ChartRenderingInfo();
+
+                chart.draw(graphics, area, info);
+                graphics.dispose();
+                content.addTemplate(template, 0f, 0f);
+            }
+            finally {
+                document.close();
+            }
+        } catch (DocumentException de) {
             log.error("Error while exporting chart to pdf.", de);
         }
-        finally {
-            document.close();
-        }
     }
 
 

http://dive4elements.wald.intevation.org