Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java @ 549:e74bf6bfeeb6
Use the same code to create the attribute document for the chart creation in ChartOutputService and ChartInfoService.
flys-client/trunk@2060 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 07 Jun 2011 10:03:19 +0000 |
parents | |
children | 19f621663b7a |
comparison
equal
deleted
inserted
replaced
548:aff225e07720 | 549:e74bf6bfeeb6 |
---|---|
1 package de.intevation.flys.client.server; | |
2 | |
3 import java.util.Map; | |
4 | |
5 import org.w3c.dom.Document; | |
6 import org.w3c.dom.Element; | |
7 | |
8 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
9 import de.intevation.artifacts.common.utils.XMLUtils; | |
10 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
11 | |
12 | |
13 /** | |
14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
15 */ | |
16 public class ChartServiceHelper { | |
17 | |
18 /** The default chart width if no value is specified in the request.*/ | |
19 public static final int DEFAULT_CHART_WIDTH = 600; | |
20 | |
21 /** The default chart height if no value is specified in the request.*/ | |
22 public static final int DEFAULT_CHART_HEIGHT = 400; | |
23 | |
24 | |
25 private ChartServiceHelper() { | |
26 } | |
27 | |
28 /** | |
29 * This method returns a document which might contain parameters to adjust | |
30 * chart settings. The document is created using the information that are | |
31 * contained in the request object. | |
32 * | |
33 * @param req The request document. | |
34 * | |
35 * @return a document to adjust chart settings. | |
36 */ | |
37 protected static Document getChartAttributes(Map<String, String> req) { | |
38 System.out.println("ChartServiceHelper.getChartAttributes"); | |
39 | |
40 Document doc = XMLUtils.newDocument(); | |
41 | |
42 ElementCreator ec = new ElementCreator( | |
43 doc, | |
44 ArtifactNamespaceContext.NAMESPACE_URI, | |
45 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
46 | |
47 Element attributes = ec.create("attributes"); | |
48 | |
49 appendChartSize(req, attributes, ec); | |
50 appendXRange(req, attributes, ec); | |
51 appendYRange(req, attributes, ec); | |
52 | |
53 doc.appendChild(attributes); | |
54 | |
55 return doc; | |
56 } | |
57 | |
58 | |
59 /** | |
60 * This method extracts the size (width/height) of a chart from request | |
61 * object and append those values - if they exist - to the attribute | |
62 * document used to adjust chart settings. | |
63 * | |
64 * @param req The request object that might contain the chart size. | |
65 * @param attributes The attributes element used to adjust chart settings. | |
66 * @param ec The ElementCreator that might be used to create new Elements. | |
67 */ | |
68 protected static void appendChartSize( | |
69 Map<String, String> req, | |
70 Element attributes, | |
71 ElementCreator ec) | |
72 { | |
73 System.out.println("ChartServiceHelper.appendChartSize"); | |
74 | |
75 Element size = ec.create("size"); | |
76 | |
77 String width = req.get("width"); | |
78 String height = req.get("height"); | |
79 | |
80 if (width == null || height == null) { | |
81 width = String.valueOf(DEFAULT_CHART_WIDTH); | |
82 height = String.valueOf(DEFAULT_CHART_HEIGHT); | |
83 } | |
84 | |
85 ec.addAttr(size, "width", width, true); | |
86 ec.addAttr(size, "height", height, true); | |
87 | |
88 attributes.appendChild(size); | |
89 } | |
90 | |
91 | |
92 /** | |
93 * This method extracts the x range for the chart from request object and | |
94 * appends those range - if it exists - to the attribute document used to | |
95 * adjust the chart settings. | |
96 * | |
97 * @param req The request object that might contain the chart size. | |
98 * @param doc The attribute document used to adjust chart settings. | |
99 * @param ec The ElementCreator that might be used to create new Elements. | |
100 */ | |
101 protected static void appendXRange( | |
102 Map<String, String> req, | |
103 Element attributes, | |
104 ElementCreator ec) | |
105 { | |
106 System.out.println("ChartServiceHelper.appendXRange"); | |
107 | |
108 Element range = ec.create("xrange"); | |
109 | |
110 String from = req.get("minx"); | |
111 String to = req.get("maxx"); | |
112 | |
113 if (from != null && to != null) { | |
114 ec.addAttr(range, "from", from, true); | |
115 ec.addAttr(range, "to", to, true); | |
116 | |
117 attributes.appendChild(range); | |
118 } | |
119 } | |
120 | |
121 | |
122 /** | |
123 * This method extracts the x range for the chart from request object and | |
124 * appends those range - if it exists - to the attribute document used to | |
125 * adjust the chart settings. | |
126 * | |
127 * @param req The request object that might contain the chart size. | |
128 * @param doc The attribute document used to adjust chart settings. | |
129 * @param ec The ElementCreator that might be used to create new Elements. | |
130 */ | |
131 protected static void appendYRange( | |
132 Map<String, String> req, | |
133 Element attributes, | |
134 ElementCreator ec) | |
135 { | |
136 System.out.println("ChartServiceHelper.appendYRange"); | |
137 | |
138 Element range = ec.create("yrange"); | |
139 | |
140 String from = req.get("miny"); | |
141 String to = req.get("maxy"); | |
142 | |
143 if (from != null && to != null) { | |
144 ec.addAttr(range, "from", from, true); | |
145 ec.addAttr(range, "to", to, true); | |
146 | |
147 attributes.appendChild(range); | |
148 } | |
149 } | |
150 } | |
151 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |