Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/AbstractChartService.java @ 4507:976ff4b74b96
QSectorFacet: Guard access to curentKm in context.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 14 Nov 2012 12:26:45 +0100 |
parents | 0674d89210f5 |
children | 61f4d4164a30 |
rev | line source |
---|---|
4213
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.services; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.awt.Dimension; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.awt.Transparency; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.awt.image.BufferedImage; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import java.io.ByteArrayOutputStream; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import java.io.IOException; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import javax.imageio.ImageIO; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.apache.log4j.Logger; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import org.jfree.chart.JFreeChart; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import org.w3c.dom.Document; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import org.w3c.dom.Element; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import org.w3c.dom.NodeList; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.artifactdatabase.DefaultService; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.artifacts.CallMeta; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifacts.GlobalContext; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.artifacts.Service; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 public abstract class AbstractChartService extends DefaultService { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 public static final int DEFAULT_WIDTH = 240; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 public static final int DEFAULT_HEIGHT = 180; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 public static final String DEFAULT_FORMAT = "png"; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 private static final Logger log = Logger |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 .getLogger(AbstractChartService.class); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 // TODO: Load fancy image from resources. |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 public static final byte[] EMPTY = { (byte) 0x89, (byte) 0x50, (byte) 0x4e, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 (byte) 0x47, (byte) 0x0d, (byte) 0x0a, (byte) 0x1a, (byte) 0x0a, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0d, (byte) 0x49, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 (byte) 0x48, (byte) 0x44, (byte) 0x52, (byte) 0x00, (byte) 0x00, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 (byte) 0x00, (byte) 0x3a, (byte) 0x7e, (byte) 0x9b, (byte) 0x55, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x73, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 (byte) 0x52, (byte) 0x47, (byte) 0x42, (byte) 0x00, (byte) 0xae, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 (byte) 0xce, (byte) 0x1c, (byte) 0xe9, (byte) 0x00, (byte) 0x00, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 (byte) 0x00, (byte) 0x09, (byte) 0x70, (byte) 0x48, (byte) 0x59, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 (byte) 0x73, (byte) 0x00, (byte) 0x00, (byte) 0x0b, (byte) 0x13, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 (byte) 0x00, (byte) 0x00, (byte) 0x0b, (byte) 0x13, (byte) 0x01, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 (byte) 0x00, (byte) 0x9a, (byte) 0x9c, (byte) 0x18, (byte) 0x00, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 (byte) 0x00, (byte) 0x00, (byte) 0x07, (byte) 0x74, (byte) 0x49, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 (byte) 0x4d, (byte) 0x45, (byte) 0x07, (byte) 0xdc, (byte) 0x04, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 (byte) 0x04, (byte) 0x10, (byte) 0x30, (byte) 0x15, (byte) 0x7d, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 (byte) 0x77, (byte) 0x36, (byte) 0x0b, (byte) 0x00, (byte) 0x00, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 (byte) 0x00, (byte) 0x08, (byte) 0x74, (byte) 0x45, (byte) 0x58, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 (byte) 0x74, (byte) 0x43, (byte) 0x6f, (byte) 0x6d, (byte) 0x6d, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x00, (byte) 0xf6, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 (byte) 0xcc, (byte) 0x96, (byte) 0xbf, (byte) 0x00, (byte) 0x00, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 (byte) 0x00, (byte) 0x0a, (byte) 0x49, (byte) 0x44, (byte) 0x41, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 (byte) 0x54, (byte) 0x08, (byte) 0xd7, (byte) 0x63, (byte) 0xf8, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 (byte) 0x0f, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 (byte) 0x00, (byte) 0x1b, (byte) 0xb6, (byte) 0xee, (byte) 0x56, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x49, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 (byte) 0x45, (byte) 0x4e, (byte) 0x44, (byte) 0xae, (byte) 0x42, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 (byte) 0x60, (byte) 0x82 }; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 private static final Output empty() { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 return new Output(EMPTY, "image/png"); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 protected abstract JFreeChart createChart(Document data, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 GlobalContext globalContext, CallMeta callMeta); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 protected void init() { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 }; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 protected void finish() { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 }; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 @Override |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 public Service.Output process(Document data, GlobalContext globalContext, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 CallMeta callMeta) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 log.debug("process"); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 init(); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 try { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 JFreeChart chart = createChart(data, globalContext, callMeta); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 if (chart == null) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 return empty(); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 Dimension extent = getExtent(data); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 String format = getFormat(data); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 return encode(chart, extent, format); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 finally { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 finish(); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 protected static Output encode(JFreeChart chart, Dimension extent, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 String format) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 BufferedImage image = chart.createBufferedImage(extent.width, |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 extent.height, Transparency.BITMASK, null); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 try { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 ImageIO.write(image, format, out); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
110 catch (IOException ioe) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
111 log.warn("writing image failed", ioe); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 return empty(); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 return new Output(out.toByteArray(), "image/" + format); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
117 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 protected static Dimension getExtent(Document input) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 int width = DEFAULT_WIDTH; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 int height = DEFAULT_HEIGHT; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
122 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 NodeList extents = input.getElementsByTagName("extent"); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
124 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
125 if (extents.getLength() > 0) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
126 Element element = (Element) extents.item(0); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
127 String w = element.getAttribute("width"); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 String h = element.getAttribute("height"); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
130 try { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
131 width = Math.max(1, Integer.parseInt(w)); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
132 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 catch (NumberFormatException nfe) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 log.warn("width '" + w + "' is not a valid."); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
135 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 try { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
138 height = Math.max(1, Integer.parseInt(h)); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
139 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
140 catch (NumberFormatException nfe) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 log.warn("height '" + h + "' is not a valid"); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
143 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
144 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
145 return new Dimension(width, height); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
146 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
147 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
148 protected static String getFormat(Document input) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
149 String format = DEFAULT_FORMAT; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
150 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 NodeList formats = input.getElementsByTagName("format"); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 if (formats.getLength() > 0) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
154 String type = ((Element) formats.item(0)).getAttribute("type"); |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
155 if (type.length() > 0) { |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
156 format = type; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
157 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
158 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
159 |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
160 return format; |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
161 } |
0674d89210f5
Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
162 } |