[PATCH 1 of 2] (issue1559) Improve Exception handling and allow null titles
Wald Commits
scm-commit at wald.intevation.org
Mon Dec 16 19:10:48 CET 2013
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1387217319 -3600
# Node ID 9211f8cafe8a16ae874f6d4cdca0fc88e196e0e5
# Parent 4daaf5e51dfb666fa35aaee2c4b54e3645112f50
(issue1559) Improve Exception handling and allow null titles
diff -r 4daaf5e51dfb -r 9211f8cafe8a artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java
--- 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();
+ try {
+ PdfContentByte content = writer.getDirectContent();
- PdfTemplate template = content.createTemplate(width, height);
- Graphics2D graphics = template.createGraphics(width, height);
+ 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]);
+ 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]);
+ Rectangle2D area = new Rectangle2D.Double(
+ origin[0], origin[1], size[0], size[1]);
- ChartRenderingInfo info = new ChartRenderingInfo();
+ ChartRenderingInfo info = new ChartRenderingInfo();
- chart.draw(graphics, area, info);
- graphics.dispose();
- content.addTemplate(template, 0f, 0f);
- }
- catch (DocumentException de) {
+ 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();
- }
}
More information about the Dive4elements-commits
mailing list