Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java @ 1994:3e703d134bbe
Parse the Settings of each Output during Collection's describe() operation.
flys-artifacts/trunk@3431 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 16 Dec 2011 09:56:32 +0000 |
parents | 5c1e7c1e9e09 |
children | 2ae0627f956e |
comparison
equal
deleted
inserted
replaced
1993:85132c9edd64 | 1994:3e703d134bbe |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | |
3 import javax.xml.xpath.XPathConstants; | |
4 | |
5 import org.w3c.dom.Node; | |
6 import org.w3c.dom.NodeList; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import de.intevation.artifacts.common.utils.XMLUtils; | |
2 | 11 |
3 import de.intevation.artifactdatabase.state.DefaultSection; | 12 import de.intevation.artifactdatabase.state.DefaultSection; |
4 import de.intevation.artifactdatabase.state.DefaultSettings; | 13 import de.intevation.artifactdatabase.state.DefaultSettings; |
5 import de.intevation.artifactdatabase.state.Section; | 14 import de.intevation.artifactdatabase.state.Section; |
6 | 15 |
8 /** | 17 /** |
9 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
10 */ | 19 */ |
11 public class ChartSettings extends DefaultSettings { | 20 public class ChartSettings extends DefaultSettings { |
12 | 21 |
22 private static final Logger logger = Logger.getLogger(ChartSettings.class); | |
23 | |
13 protected Section chartSection; | 24 protected Section chartSection; |
14 protected Section legendSection; | 25 protected Section legendSection; |
15 protected Section axesSection; | 26 protected Section axesSection; |
16 | 27 |
17 | 28 |
86 public void addAxisSection(Section axisSection) { | 97 public void addAxisSection(Section axisSection) { |
87 if (axisSection != null) { | 98 if (axisSection != null) { |
88 axesSection.addSubsection(axisSection); | 99 axesSection.addSubsection(axisSection); |
89 } | 100 } |
90 } | 101 } |
102 | |
103 | |
104 /** | |
105 * Parses the settings from <i>settings</i>. The result is a new | |
106 * ChartSettings instance. | |
107 * | |
108 * @param settings A <i>settings</i> node. | |
109 * | |
110 * @return a new <i>ChartSettings</i> instance. | |
111 */ | |
112 public static ChartSettings parse(Node settings) { | |
113 if (settings == null) { | |
114 logger.warn("Tried to parse ChartSettings from empty Node!"); | |
115 return null; | |
116 } | |
117 | |
118 ChartSettings chartSettings = new ChartSettings(); | |
119 | |
120 parseAxes(chartSettings, settings); | |
121 parseChart(chartSettings, settings); | |
122 parseLegend(chartSettings, settings); | |
123 | |
124 return chartSettings; | |
125 } | |
126 | |
127 | |
128 protected static void parseAxes(ChartSettings target, Node settings) { | |
129 NodeList axesList = (NodeList) XMLUtils.xpath( | |
130 settings, "axes/axis", XPathConstants.NODESET, null); | |
131 | |
132 int num = axesList != null ? axesList.getLength() : 0; | |
133 | |
134 if (num <= 0) { | |
135 logger.debug("No axis sections found."); | |
136 return; | |
137 } | |
138 | |
139 for (int i = 0; i < num; i++) { | |
140 parseAxis(target, axesList.item(i)); | |
141 } | |
142 } | |
143 | |
144 | |
145 protected static void parseAxis(ChartSettings target, Node axis) { | |
146 AxisSection section = new AxisSection(); | |
147 | |
148 String id = XMLUtils.xpathString(axis, "id", null); | |
149 String label = XMLUtils.xpathString(axis, "label", null); | |
150 String fSize = XMLUtils.xpathString(axis, "font-size", null); | |
151 String fixation = XMLUtils.xpathString(axis, "fixation", null); | |
152 String low = XMLUtils.xpathString(axis, "lower", null); | |
153 String up = XMLUtils.xpathString(axis, "upper", null); | |
154 | |
155 if (logger.isDebugEnabled()) { | |
156 logger.debug("Fount axis id: '" + id + "'"); | |
157 logger.debug("Fount axis label: '" + label + "'"); | |
158 logger.debug("Fount axis font size: '" + fSize + "'"); | |
159 logger.debug("Fount axis fixation: '" + fixation + "'"); | |
160 logger.debug("Fount axis lower: '" + low + "'"); | |
161 logger.debug("Fount axis upper: '" + up + "'"); | |
162 } | |
163 | |
164 section.setIdentifier(id); | |
165 section.setLabel(label); | |
166 section.setFontSize(Integer.valueOf(fSize.length() > 0 ? fSize : "-1")); | |
167 section.setFixed(Boolean.valueOf(fixation)); | |
168 section.setLowerRange(Double.valueOf(low.length() > 0 ? low : "0")); | |
169 section.setUpperRange(Double.valueOf(up.length() > 0 ? up : "0")); | |
170 | |
171 target.addAxisSection(section); | |
172 } | |
173 | |
174 | |
175 protected static void parseChart(ChartSettings target, Node chart) { | |
176 ChartSection chartSection = new ChartSection(); | |
177 | |
178 String title = XMLUtils.xpathString(chart, "chart/title", null); | |
179 String sub = XMLUtils.xpathString(chart, "chart/subtitle", null); | |
180 String grid = XMLUtils.xpathString(chart, "chart/display-grid", null); | |
181 | |
182 if (logger.isDebugEnabled()) { | |
183 logger.debug("Found chart title: '" + title + "'"); | |
184 logger.debug("Found chart subtitle: '" + sub + "'"); | |
185 logger.debug("Found chart grid: '" + grid + "'"); | |
186 } | |
187 | |
188 chartSection.setTitle(title); | |
189 chartSection.setSubtitle(sub); | |
190 chartSection.setDisplayGird(Boolean.valueOf(grid)); | |
191 | |
192 target.setChartSection(chartSection); | |
193 } | |
194 | |
195 | |
196 protected static void parseLegend(ChartSettings target, Node legend) { | |
197 LegendSection section = new LegendSection(); | |
198 | |
199 String vis = XMLUtils.xpathString(legend, "legend/visibility", null); | |
200 String fSize = XMLUtils.xpathString(legend, "legend/font-size", null); | |
201 | |
202 if (logger.isDebugEnabled()) { | |
203 logger.debug("Found legend visibility: '" + vis + "'"); | |
204 logger.debug("Found legend font size : '" + fSize + "'"); | |
205 } | |
206 | |
207 section.setVisibility(Boolean.valueOf(vis)); | |
208 section.setFontSize(Integer.valueOf(fSize.length() > 0 ? fSize : "-1")); | |
209 | |
210 target.setLegendSection(section); | |
211 } | |
91 } | 212 } |
92 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 213 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |