Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java @ 423:bab867fb37e8
Charts are generated using the size defined in the incoming request document.
flys-artifacts/trunk@1908 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 12 May 2011 09:11:16 +0000 |
parents | 046bd86ae41d |
children | 8fa4c5c9cd1a |
comparison
equal
deleted
inserted
replaced
422:3b83341e0cf4 | 423:bab867fb37e8 |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.io.OutputStream; | 4 import java.io.OutputStream; |
5 | 5 |
6 import javax.xml.xpath.XPathConstants; | |
7 | |
6 import org.apache.log4j.Logger; | 8 import org.apache.log4j.Logger; |
7 | 9 |
8 import org.w3c.dom.Document; | 10 import org.w3c.dom.Document; |
11 import org.w3c.dom.Node; | |
9 | 12 |
10 import de.intevation.artifacts.Artifact; | 13 import de.intevation.artifacts.Artifact; |
11 import de.intevation.artifacts.CallContext; | 14 import de.intevation.artifacts.CallContext; |
15 | |
16 import de.intevation.artifacts.ArtifactNamespaceContext; | |
17 import de.intevation.artifacts.common.utils.XMLUtils; | |
12 | 18 |
13 import de.intevation.flys.model.River; | 19 import de.intevation.flys.model.River; |
14 | 20 |
15 import de.intevation.flys.artifacts.FLYSArtifact; | 21 import de.intevation.flys.artifacts.FLYSArtifact; |
16 import de.intevation.flys.artifacts.resources.Resources; | 22 import de.intevation.flys.artifacts.resources.Resources; |
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
24 */ | 30 */ |
25 public abstract class ChartGenerator implements OutGenerator { | 31 public abstract class ChartGenerator implements OutGenerator { |
26 | 32 |
27 private static Logger logger = Logger.getLogger(ChartGenerator.class); | 33 private static Logger logger = Logger.getLogger(ChartGenerator.class); |
34 | |
35 | |
36 /** The default chart width, if no other width is set.*/ | |
37 public static final int DEFAULT_CHART_WIDTH = 600; | |
38 | |
39 /** The default chart height, if no other height is set.*/ | |
40 public static final int DEFAULT_CHART_HEIGHT = 400; | |
41 | |
42 /** The XPath that points to the chart size of the incoming request | |
43 * document.*/ | |
44 public static final String XPATH_CHART_SIZE = | |
45 "/art:action/art:attributes/art:size"; | |
28 | 46 |
29 | 47 |
30 /** The document of the incoming out() request.*/ | 48 /** The document of the incoming out() request.*/ |
31 protected Document request; | 49 protected Document request; |
32 | 50 |
77 | 95 |
78 return flys.getDistance(); | 96 return flys.getDistance(); |
79 } | 97 } |
80 | 98 |
81 | 99 |
100 /** | |
101 * Returns the size of a chart export as array which has been specified by | |
102 * the incoming request document. | |
103 * | |
104 * @return the size of a chart as [width, height] or the result of | |
105 * getDefaultSize() if no width or height are given in the request document. | |
106 */ | |
107 protected int[] getSize() { | |
108 int[] size = new int[2]; | |
109 | |
110 Node sizeEl = (Node) XMLUtils.xpath( | |
111 request, | |
112 XPATH_CHART_SIZE, | |
113 XPathConstants.NODE, | |
114 ArtifactNamespaceContext.INSTANCE); | |
115 | |
116 if (sizeEl != null) { | |
117 String w = XMLUtils.xpathString( | |
118 sizeEl, "@art:width", ArtifactNamespaceContext.INSTANCE); | |
119 | |
120 String h = XMLUtils.xpathString( | |
121 sizeEl, "@art:height", ArtifactNamespaceContext.INSTANCE); | |
122 | |
123 if (w != null && w.length() > 0 && h != null && h.length() > 0) { | |
124 try { | |
125 size[0] = Integer.parseInt(w); | |
126 size[1] = Integer.parseInt(h); | |
127 } | |
128 catch (NumberFormatException nfe) { | |
129 logger.warn("Wrong values for chart width/height."); | |
130 } | |
131 } | |
132 } | |
133 | |
134 return size[0] > 0 && size[1] > 0 ? size : getDefaultSize(); | |
135 } | |
136 | |
137 | |
138 /** | |
139 * Returns the default size of a chart export as array. | |
140 * | |
141 * @return the default size of a chart as [width, height]. | |
142 */ | |
143 protected int[] getDefaultSize() { | |
144 return new int[] { DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT }; | |
145 } | |
146 | |
147 | |
82 public abstract void doOut(Artifact artifact, String facet, Document attr); | 148 public abstract void doOut(Artifact artifact, String facet, Document attr); |
83 | 149 |
84 public abstract void generate() throws IOException; | 150 public abstract void generate() throws IOException; |
85 } | 151 } |
86 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 152 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |