comparison artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java @ 9104:07d51fd4864c

Added metadata subtitle to all chart export
author gernotbelger
date Tue, 29 May 2018 11:35:44 +0200
parents
children 1cc7653ca84f
comparison
equal deleted inserted replaced
9103:e68d4a10c308 9104:07d51fd4864c
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10 package org.dive4elements.river.exports;
11
12 import javax.xml.xpath.XPathConstants;
13
14 import org.dive4elements.artifacts.ArtifactNamespaceContext;
15 import org.dive4elements.artifacts.CallContext;
16 import org.dive4elements.artifacts.common.utils.XMLUtils;
17 import org.dive4elements.river.artifacts.D4EArtifact;
18 import org.dive4elements.river.artifacts.access.RangeAccess;
19 import org.dive4elements.river.artifacts.access.RiverAccess;
20 import org.jfree.chart.JFreeChart;
21 import org.jfree.chart.title.TextTitle;
22 import org.w3c.dom.Document;
23
24 /**
25 * @author Gernot Belger
26 */
27 // FIXME: this class is intended to contain all duplicate code from ChartGenerator and ChartGenerator2; who will clean
28 // up this mess...?
29 abstract class AbstractChartGenerator implements OutGenerator {
30 private static final String XPATH_CHART_EXPORT = "/art:action/art:attributes/art:export/@art:value";
31
32 // TODO: move real code here
33 protected abstract D4EArtifact getArtifact();
34
35 /** The CallContext object. */
36 // TODO: move real code here
37 protected abstract CallContext getContext();
38
39 /** The document of the incoming out() request. */
40 // TODO: move real code here
41 protected abstract Document getRequest();
42
43 /**
44 * Adds a metadata sub-title to the chart if it gets exported
45 */
46 protected final void addMetadataSubtitle(final JFreeChart chart) {
47 if (isExport()) {
48 final String text = ChartExportHelper.createMetadataSubtitle(getArtifact(), getContext(), getRiverName());
49 chart.addSubtitle(new TextTitle(text));
50 }
51 }
52
53 /**
54 * This method returns the export flag specified in the <i>request</i> document
55 * or <i>false</i> if no export is specified in <i>request</i>.
56 */
57 protected final boolean isExport() {
58 final Boolean export = (Boolean) XMLUtils.xpath(getRequest(), XPATH_CHART_EXPORT, XPathConstants.BOOLEAN, ArtifactNamespaceContext.INSTANCE);
59
60 return export == null ? false : export;
61 }
62
63 protected final String getRiverName() {
64 return new RiverAccess(getArtifact()).getRiver().getName();
65 }
66
67 protected final String getRiverUnit() {
68 return new RiverAccess(getArtifact()).getRiver().getWstUnit().getName();
69 }
70
71 protected final double[] getRange() {
72 final D4EArtifact flys = getArtifact();
73
74 final RangeAccess rangeAccess = new RangeAccess(flys);
75 return rangeAccess.getKmRange();
76 }
77 }

http://dive4elements.wald.intevation.org