Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java @ 335:e964a3d8f7bc
Some Refactoring work done.
Moved Transition to State
gnv-artifacts/trunk@401 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 08 Dec 2009 08:39:03 +0000 |
parents | |
children | bb1afbbd93e4 |
comparison
equal
deleted
inserted
replaced
334:e37930705daa | 335:e964a3d8f7bc |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.state.timeseries; | |
5 | |
6 import java.io.IOException; | |
7 import java.io.File; | |
8 import java.io.OutputStream; | |
9 import java.io.FileOutputStream; | |
10 import java.io.UnsupportedEncodingException; | |
11 import java.util.ArrayList; | |
12 import java.util.Collection; | |
13 import java.util.Iterator; | |
14 import java.util.List; | |
15 import java.util.Locale; | |
16 import java.util.Vector; | |
17 | |
18 import javax.xml.transform.Transformer; | |
19 import javax.xml.transform.TransformerConfigurationException; | |
20 import javax.xml.transform.TransformerException; | |
21 import javax.xml.transform.TransformerFactory; | |
22 import javax.xml.transform.TransformerFactoryConfigurationError; | |
23 import javax.xml.transform.dom.DOMSource; | |
24 import javax.xml.transform.stream.StreamResult; | |
25 | |
26 import org.apache.log4j.Logger; | |
27 import org.w3c.dom.Document; | |
28 import org.w3c.dom.Element; | |
29 import org.w3c.dom.Node; | |
30 import org.w3c.dom.NodeList; | |
31 | |
32 import org.jfree.chart.ChartTheme; | |
33 | |
34 import au.com.bytecode.opencsv.CSVWriter; | |
35 import de.intevation.artifactdatabase.Config; | |
36 import de.intevation.artifactdatabase.XMLUtils; | |
37 import de.intevation.artifacts.CallMeta; | |
38 import de.intevation.artifacts.PreferredLocale; | |
39 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | |
40 import de.intevation.gnv.chart.Chart; | |
41 import de.intevation.gnv.chart.ChartLabels; | |
42 import de.intevation.gnv.chart.TimeSeriesChart; | |
43 import de.intevation.gnv.chart.XMLChartTheme; | |
44 import de.intevation.gnv.chart.exception.TechnicalChartException; | |
45 import de.intevation.gnv.exports.ChartExportHelper; | |
46 import de.intevation.gnv.exports.DefaultExport; | |
47 import de.intevation.gnv.exports.DefaultDataCollector; | |
48 import de.intevation.gnv.exports.SimpleOdvDataCollector; | |
49 import de.intevation.gnv.exports.DefaultProfile; | |
50 import de.intevation.gnv.exports.Export.Profile; | |
51 import de.intevation.gnv.geobackend.base.Result; | |
52 import de.intevation.gnv.state.InputData; | |
53 import de.intevation.gnv.state.OutputStateBase; | |
54 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | |
55 import de.intevation.gnv.state.describedata.NamedCollection; | |
56 import de.intevation.gnv.state.exception.StateException; | |
57 import de.intevation.gnv.statistics.Statistic; | |
58 import de.intevation.gnv.statistics.StatisticSet; | |
59 import de.intevation.gnv.statistics.Statistics; | |
60 import de.intevation.gnv.statistics.TimeseriesStatistics; | |
61 import de.intevation.gnv.statistics.exception.StatisticsException; | |
62 import de.intevation.gnv.timeseries.gap.DefaultTimeGap; | |
63 import de.intevation.gnv.timeseries.gap.TimeGap; | |
64 import de.intevation.gnv.utils.ArtifactXMLUtilities; | |
65 | |
66 | |
67 /** | |
68 * @author Tim Englich <tim.englich@intevation.de> | |
69 * | |
70 */ | |
71 public class TimeSeriesOutputState extends OutputStateBase { | |
72 | |
73 protected static final boolean CACHE_CHART = | |
74 Boolean.parseBoolean(System.getProperty("cache.chart", "false")); | |
75 | |
76 protected static final boolean PDF_FORMAT_LANDSCAPE = | |
77 Boolean.parseBoolean(System.getProperty("export.pdf.landscape","true")); | |
78 | |
79 protected static final String[] IMG_EXPORT_FORMAT = { | |
80 "PNG", "JPEG", "GIF" | |
81 }; | |
82 | |
83 /** | |
84 * The UID of this Class | |
85 */ | |
86 private static final long serialVersionUID = 4178407570503098858L; | |
87 | |
88 /** | |
89 * the logger, used to log exceptions and additonaly information | |
90 */ | |
91 private static Logger log = Logger | |
92 .getLogger(TimeSeriesOutputState.class); | |
93 | |
94 private static List<TimeGap> timeGapDefinitions = null; | |
95 | |
96 protected String domainLable = "Zeit [UTC]"; | |
97 | |
98 protected String featureValuesName = "featureid"; | |
99 protected String parameterValuesName = "parameterid"; | |
100 protected String measuremenValueName = "measurementid"; | |
101 protected String dateValueName = "dateid"; | |
102 | |
103 public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { | |
104 "XORDINATE", | |
105 "YORDINATE", | |
106 "GROUP1", | |
107 "GROUP2", | |
108 "GROUP3" | |
109 }; | |
110 | |
111 public static final String [] TIMESERIES_ODV_PROFILE_NAMES = { | |
112 "CRUISE", | |
113 "STATION", | |
114 "TYPE", | |
115 "SHAPE", | |
116 "BOTDEPTH", | |
117 "DEPTH", | |
118 "TIMEVALUE", | |
119 "DATAVALUE", | |
120 "PARAMETER" | |
121 }; | |
122 | |
123 | |
124 public static final String [] ODV_COLUMN_HEADER = { | |
125 "Cruise", | |
126 "Station", | |
127 "Type", | |
128 "Longitude [deegrees_east]", | |
129 "Latitude [deegrees_north]", | |
130 "Bot. Depth [m]", | |
131 "Depth [m]", | |
132 "Date/Time", | |
133 "Value", | |
134 "Parameterid" | |
135 }; | |
136 | |
137 /** | |
138 * Profile for exporting data to cvs | |
139 */ | |
140 public static final Profile TIMESERIES_CSV_PROFILE = | |
141 new DefaultProfile( | |
142 null, | |
143 ',', | |
144 '"', | |
145 '"', | |
146 "CSV", | |
147 "ISO-8859-1"); | |
148 | |
149 /** | |
150 * Profile for exporting data to odv | |
151 * TODO Change TIMESERIES_PROFILE_NAMES, which belong to CSV exports | |
152 */ | |
153 public static final Profile TIMESERIES_ODV_PROFILE = | |
154 new DefaultProfile( | |
155 ODV_COLUMN_HEADER, | |
156 '\t', | |
157 CSVWriter.NO_QUOTE_CHARACTER, | |
158 CSVWriter.NO_ESCAPE_CHARACTER, | |
159 "ODV", | |
160 "ISO-8859-1"); | |
161 | |
162 /** | |
163 * Constructor | |
164 */ | |
165 public TimeSeriesOutputState() { | |
166 super(); | |
167 } | |
168 | |
169 /** | |
170 * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, | |
171 * java.util.Collection, java.io.OutputStream, java.lang.String, | |
172 * de.intevation.artifacts.CallMeta) | |
173 */ | |
174 public void out( | |
175 Document format, | |
176 Collection<InputData> inputData, | |
177 OutputStream outputStream, | |
178 String uuid, | |
179 CallMeta callMeta | |
180 ) throws StateException | |
181 { | |
182 log.debug("TimeSeriesOutputTransition.out"); | |
183 | |
184 String outputMode = Config.getStringXPath( | |
185 format, | |
186 "action/out/@name" | |
187 ); | |
188 String mimeType = Config.getStringXPath( | |
189 format, | |
190 "action/out/mime-type/@value" | |
191 ); | |
192 | |
193 try { | |
194 if (outputMode.equalsIgnoreCase("chart")) { | |
195 log.debug("Chart will be generated."); | |
196 int chartWidth = 600; | |
197 int chartHeight = 400; | |
198 try { | |
199 if (inputData != null) { | |
200 Iterator<InputData> it = inputData.iterator(); | |
201 while (it.hasNext()) { | |
202 InputData ip = it.next(); | |
203 if (ip.getName().equalsIgnoreCase("width")) { | |
204 chartWidth = Integer.parseInt(ip.getValue()); | |
205 } else if (ip.getName().equalsIgnoreCase("height")) { | |
206 chartHeight = Integer.parseInt(ip.getValue()); | |
207 } | |
208 } | |
209 } | |
210 } catch (NumberFormatException e) { | |
211 log.error(e, e); | |
212 throw new StateException(e); | |
213 } | |
214 | |
215 PreferredLocale[] locales = callMeta.getLanguages(); | |
216 Locale[] serverLocales = | |
217 RessourceFactory.getInstance().getLocales(); | |
218 Locale locale = | |
219 callMeta.getPreferredLocale(serverLocales); | |
220 | |
221 log.debug( | |
222 "Best locale - regarding intersection of server and " + | |
223 "browser locales - is " + locale.toString() | |
224 ); | |
225 | |
226 Collection parameters = this.getCleanedParameters(uuid); | |
227 Collection measurements = this.getMeasurements(uuid); | |
228 Collection dates = this.getDates(uuid); | |
229 | |
230 ChartLabels chartLables = new ChartLabels( | |
231 createChartTitle(locale, uuid), | |
232 createChartSubtitle(locale, uuid), | |
233 domainLable | |
234 ); | |
235 | |
236 String exportFormat = getExportFormat(mimeType); | |
237 | |
238 // TODO Remove this and parse input data | |
239 boolean linesVisible = true; | |
240 boolean shapesVisible = true; | |
241 | |
242 this.createChart( | |
243 outputStream, | |
244 parameters, | |
245 measurements, | |
246 dates, | |
247 chartLables, | |
248 uuid, | |
249 exportFormat, | |
250 locale, | |
251 chartWidth, | |
252 chartHeight, | |
253 linesVisible, | |
254 shapesVisible | |
255 ); | |
256 } | |
257 else if (outputMode.equalsIgnoreCase("pdf")) { | |
258 log.debug("Output mode == pdf"); | |
259 | |
260 Locale[] serverLocales = | |
261 RessourceFactory.getInstance().getLocales(); | |
262 Locale locale = | |
263 callMeta.getPreferredLocale(serverLocales); | |
264 | |
265 // TODO Remove this and parse input data | |
266 boolean linesVisible = true; | |
267 boolean shapesVisible = true; | |
268 | |
269 log.debug( | |
270 "Best locale - regarding intersection of server and " + | |
271 "browser locales - is " + locale.toString() | |
272 ); | |
273 | |
274 createPDF( | |
275 outputStream, | |
276 getCleanedParameters(uuid), | |
277 getMeasurements(uuid), | |
278 getDates(uuid), | |
279 new ChartLabels( | |
280 createChartTitle(locale, uuid), | |
281 createChartSubtitle(locale, uuid), | |
282 domainLable), | |
283 uuid, | |
284 "A4", | |
285 true, | |
286 locale, | |
287 linesVisible, | |
288 shapesVisible | |
289 ); | |
290 } | |
291 else if (outputMode.equalsIgnoreCase("svg")) { | |
292 log.debug("Output mode == svg"); | |
293 int width = 600; | |
294 int height = 400; | |
295 | |
296 // TODO Remove this and parse input data | |
297 boolean linesVisible = true; | |
298 boolean shapesVisible = true; | |
299 | |
300 Locale[] serverLocales = | |
301 RessourceFactory.getInstance().getLocales(); | |
302 Locale locale = | |
303 callMeta.getPreferredLocale(serverLocales); | |
304 | |
305 log.debug( | |
306 "Best locale - regarding intersection of server and " + | |
307 "browser locales - is " + locale.toString() | |
308 ); | |
309 | |
310 createSVG( | |
311 outputStream, | |
312 getCleanedParameters(uuid), | |
313 getMeasurements(uuid), | |
314 getDates(uuid), | |
315 new ChartLabels( | |
316 createChartTitle(locale, uuid), | |
317 createChartSubtitle(locale, uuid), | |
318 domainLable | |
319 ), | |
320 uuid, | |
321 locale, | |
322 width, | |
323 height, | |
324 linesVisible, | |
325 shapesVisible | |
326 ); | |
327 } | |
328 else if (outputMode.equalsIgnoreCase("csv")) { | |
329 log.debug("CSV-File will be generated."); | |
330 Collection<Result> chartResult = this.getChartResult(uuid); | |
331 this.createCSV(outputStream, chartResult); | |
332 } else if (outputMode.equalsIgnoreCase("statistics")) { | |
333 log.debug("Statistics will be generated."); | |
334 Statistics s = getStatisticsGenerator(); | |
335 Collection<Result> chartResult = this.getChartResult(uuid); | |
336 Collection<KeyValueDescibeData> parameters = | |
337 this.getParameters(uuid); | |
338 Collection<KeyValueDescibeData> measurements = | |
339 this.getMeasurements(uuid); | |
340 Collection<KeyValueDescibeData> dates = | |
341 this.getDates(uuid); | |
342 Collection<StatisticSet> statistics = | |
343 s.calculateStatistics(chartResult, | |
344 parameters, | |
345 measurements, | |
346 dates); | |
347 Document doc = this.writeStatistics2XML(statistics); | |
348 this.writeDocument2OutputStream(doc, outputStream); | |
349 } else if (outputMode.equalsIgnoreCase("odv")) { | |
350 | |
351 Collection<Result> odvResult = this.getODVResult(uuid); | |
352 this.createODV(outputStream, odvResult); | |
353 } | |
354 } catch (IOException e) { | |
355 log.error(e, e); | |
356 throw new StateException(e); | |
357 } catch (TechnicalChartException e) { | |
358 log.error(e, e); | |
359 throw new StateException(e); | |
360 } catch (StatisticsException e) { | |
361 log.error(e, e); | |
362 throw new StateException(e); | |
363 } | |
364 } | |
365 | |
366 | |
367 protected String getExportFormat(String mime) { | |
368 for(int i = 0; i < IMG_EXPORT_FORMAT.length; i++) { | |
369 if (mime.trim().toUpperCase().indexOf(IMG_EXPORT_FORMAT[i]) > 0) | |
370 return IMG_EXPORT_FORMAT[i]; | |
371 } | |
372 | |
373 // no format found relating to mimeType, default export as PNG | |
374 return IMG_EXPORT_FORMAT[0]; | |
375 } | |
376 | |
377 | |
378 protected Collection getCleanedParameters(Collection parameters) { | |
379 Iterator iter = parameters.iterator(); | |
380 Collection parameter = new Vector(parameters); | |
381 while (iter.hasNext()) { | |
382 KeyValueDescibeData data = (KeyValueDescibeData)iter.next(); | |
383 if (!data.isSelected()) | |
384 parameter.remove(data); | |
385 } | |
386 | |
387 return parameter; | |
388 } | |
389 | |
390 | |
391 protected Collection getCleanedParameters(String uuid) { | |
392 return getCleanedParameters(getParameters(uuid)); | |
393 } | |
394 | |
395 | |
396 /** | |
397 * @param outputStream | |
398 * @param chartResult | |
399 * @throws UnsupportedEncodingException | |
400 * @throws IOException | |
401 * @throws StateException | |
402 */ | |
403 protected void createCSV(OutputStream outputStream, | |
404 Collection<Result> chartResult) | |
405 throws UnsupportedEncodingException, | |
406 IOException, | |
407 StateException { | |
408 DefaultExport export = new DefaultExport(new DefaultDataCollector( | |
409 TIMESERIES_CSV_PROFILE_NAMES)); | |
410 | |
411 export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); | |
412 } | |
413 | |
414 /** | |
415 * TODO Result is not used at the moment. Change result with correct data. | |
416 */ | |
417 protected void createODV(OutputStream outputStream, Collection result) | |
418 throws IOException, StateException { | |
419 | |
420 DefaultExport export = new DefaultExport(new SimpleOdvDataCollector( | |
421 TIMESERIES_ODV_PROFILE_NAMES)); | |
422 | |
423 if (result == null) | |
424 log.error("#################### RESULT == NULL #################"); | |
425 export.create(TIMESERIES_ODV_PROFILE, outputStream, result); | |
426 } | |
427 | |
428 /** | |
429 * @return | |
430 */ | |
431 protected Statistics getStatisticsGenerator() { | |
432 Statistics s = new TimeseriesStatistics(); | |
433 return s; | |
434 } | |
435 | |
436 protected void writeDocument2OutputStream(Document document, OutputStream os) { | |
437 | |
438 try { | |
439 TransformerFactory transformerFactory = TransformerFactory | |
440 .newInstance(); | |
441 Transformer transformer = transformerFactory.newTransformer(); | |
442 DOMSource source = new DOMSource(document); | |
443 StreamResult result = new StreamResult(os); | |
444 transformer.transform(source, result); | |
445 } catch (TransformerConfigurationException e) { | |
446 log.error(e, e); | |
447 } catch (TransformerFactoryConfigurationError e) { | |
448 log.error(e, e); | |
449 } catch (TransformerException e) { | |
450 log.error(e, e); | |
451 } | |
452 } | |
453 | |
454 protected Document writeStatistics2XML( Collection<StatisticSet> statistic) { | |
455 ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities(); | |
456 Document doc = XMLUtils.newDocument(); | |
457 if (statistic != null) { | |
458 Node statisticResults = xmlUtilities.createArtifactElement(doc, | |
459 "statistics"); | |
460 doc.appendChild(statisticResults); | |
461 Iterator<StatisticSet> it = statistic.iterator(); | |
462 while (it.hasNext()) { | |
463 StatisticSet set = it.next(); | |
464 Element setElement = xmlUtilities.createArtifactElement(doc, | |
465 "statistic"); | |
466 setElement.setAttribute("name", set.getName()); | |
467 | |
468 Iterator<Statistic> sit = set.getStatistics().iterator(); | |
469 while (sit.hasNext()){ | |
470 Statistic s = sit.next(); | |
471 Element result = xmlUtilities.createArtifactElement(doc, | |
472 "statistic-value"); | |
473 result.setAttribute("name", s.getKey()); | |
474 result.setAttribute("value", s.getStringValue()); | |
475 setElement.appendChild(result); | |
476 } | |
477 statisticResults.appendChild(setElement); | |
478 } | |
479 | |
480 } | |
481 return doc; | |
482 } | |
483 | |
484 | |
485 protected String getSelectedFeatureName(String uuid) { | |
486 Collection values = getCollection(featureValuesName, uuid); | |
487 | |
488 if (values != null) { | |
489 Iterator it = values.iterator(); | |
490 | |
491 while (it.hasNext()) { | |
492 KeyValueDescibeData data = (KeyValueDescibeData) it.next(); | |
493 | |
494 if (data.isSelected()) { | |
495 return data.getValue(); | |
496 } | |
497 } | |
498 } | |
499 return null; | |
500 } | |
501 | |
502 | |
503 /** | |
504 * @param outputStream | |
505 * @param parameters | |
506 * @param measurements | |
507 * @param timeSeriesName | |
508 * @param chartStyle | |
509 * @param chartLables | |
510 * @throws IOException | |
511 * @throws TechnicalChartException | |
512 */ | |
513 protected void createChart( | |
514 OutputStream outputStream, | |
515 Collection parameters, | |
516 Collection measurements, | |
517 Collection dates, | |
518 ChartLabels chartLables, | |
519 String uuid, | |
520 String exportFormat, | |
521 Locale locale, | |
522 int width, | |
523 int height, | |
524 boolean linesVisible, | |
525 boolean shapesVisible | |
526 ) | |
527 throws IOException, TechnicalChartException | |
528 { | |
529 log.debug("Create chart."); | |
530 Chart chart = getChart( | |
531 chartLables, | |
532 parameters, | |
533 measurements, | |
534 dates, | |
535 getChartResult(uuid), | |
536 locale, // Locale | |
537 uuid, | |
538 linesVisible, | |
539 shapesVisible | |
540 ); | |
541 | |
542 if (chart == null) { | |
543 log.error("Could not initialize chart."); | |
544 return; | |
545 } | |
546 | |
547 log.debug( | |
548 "export chart as " + exportFormat + | |
549 " in " + width + "x" + height | |
550 ); | |
551 | |
552 ChartExportHelper.exportImage( | |
553 outputStream, | |
554 chart.generateChart(), | |
555 exportFormat, | |
556 width, | |
557 height | |
558 ); | |
559 } | |
560 | |
561 | |
562 protected void createPDF( | |
563 OutputStream outputStream, | |
564 Collection parameters, | |
565 Collection measurements, | |
566 Collection dates, | |
567 ChartLabels chartLables, | |
568 String uuid, | |
569 String exportFormat, | |
570 boolean landscape, | |
571 Locale locale, | |
572 boolean linesVisible, | |
573 boolean shapesVisible | |
574 ) { | |
575 Chart chart = getChart( | |
576 chartLables, | |
577 parameters, | |
578 measurements, | |
579 dates, | |
580 getChartResult(uuid), | |
581 locale, | |
582 uuid, | |
583 linesVisible, | |
584 shapesVisible | |
585 ); | |
586 | |
587 if (chart == null) { | |
588 log.error("Could not initialize chart."); | |
589 return; | |
590 } | |
591 | |
592 ChartExportHelper.exportPDF( | |
593 outputStream, | |
594 chart.generateChart(), | |
595 "A4", | |
596 PDF_FORMAT_LANDSCAPE, | |
597 50F, 50F, 50F, 50F | |
598 ); | |
599 | |
600 try { | |
601 OutputStream toFile = new FileOutputStream("/vol1/home/iweinzierl/tmp/test.svg"); | |
602 ChartExportHelper.exportSVG( | |
603 toFile, | |
604 chart.generateChart(), | |
605 null, | |
606 600, 400 | |
607 ); | |
608 toFile.flush(); | |
609 toFile.close(); | |
610 } | |
611 catch(Exception e) { log.debug("ERROR WHLILE TEST."); } | |
612 } | |
613 | |
614 | |
615 protected void createSVG( | |
616 OutputStream outputStream, | |
617 Collection parameters, | |
618 Collection measurements, | |
619 Collection dates, | |
620 ChartLabels chartLables, | |
621 String uuid, | |
622 Locale locale, | |
623 int width, | |
624 int height, | |
625 boolean linesVisible, | |
626 boolean shapesVisible | |
627 ) { | |
628 Chart chart = getChart( | |
629 chartLables, | |
630 parameters, | |
631 measurements, | |
632 dates, | |
633 getChartResult(uuid), | |
634 locale, | |
635 uuid, | |
636 linesVisible, | |
637 shapesVisible | |
638 ); | |
639 | |
640 if (chart == null) { | |
641 log.error("Could not initialize chart."); | |
642 return; | |
643 } | |
644 | |
645 ChartExportHelper.exportSVG( | |
646 outputStream, | |
647 chart.generateChart(), | |
648 null, | |
649 600, 400 | |
650 ); | |
651 | |
652 log.debug("svg export finished."); | |
653 } | |
654 | |
655 | |
656 protected Chart getChart( | |
657 ChartLabels chartLables, | |
658 Collection parameters, | |
659 Collection measurements, | |
660 Collection dates, | |
661 Collection result, | |
662 Locale locale, | |
663 String uuid, | |
664 boolean linesVisible, | |
665 boolean shapesVisible | |
666 ) { | |
667 Chart chart = null; | |
668 | |
669 if (CACHE_CHART) { | |
670 log.info("Try to get timeseries chart from cache."); | |
671 chart = (Chart) getChartFromCache(uuid); | |
672 } | |
673 | |
674 if (chart != null) | |
675 return chart; | |
676 | |
677 log.info("Chart not in cache yet."); | |
678 chart = new TimeSeriesChart( | |
679 chartLables, | |
680 createStyle(), | |
681 parameters, | |
682 measurements, | |
683 dates, | |
684 result, | |
685 timeGapDefinitions, | |
686 locale, | |
687 linesVisible, | |
688 shapesVisible | |
689 ); | |
690 chart.generateChart(); | |
691 | |
692 if (CACHE_CHART) { | |
693 log.info("Put chart into cache."); | |
694 purifyChart(chart, uuid); | |
695 } | |
696 | |
697 return chart; | |
698 } | |
699 | |
700 protected ChartTheme createStyle() { | |
701 XMLChartTheme theme = null; | |
702 | |
703 Document template = Config.getChartTemplate(); | |
704 String name = Config.getStringXPath( | |
705 template, | |
706 "theme/name/@value" | |
707 ); | |
708 | |
709 theme = new XMLChartTheme(name); | |
710 theme.applyXMLConfiguration(template); | |
711 | |
712 return theme; | |
713 } | |
714 | |
715 | |
716 protected String createChartTitle(Locale locale, String uuid) { | |
717 return getFisName(locale); | |
718 | |
719 } | |
720 | |
721 | |
722 protected String createChartSubtitle(Locale locale, String uuid) { | |
723 return getSelectedFeatureName(uuid); | |
724 } | |
725 | |
726 | |
727 protected String getFisName(Locale locale) { | |
728 String returnValue = ""; | |
729 InputData input = inputData.get("fisname"); | |
730 | |
731 if (input != null) { | |
732 String value = input.getValue(); | |
733 | |
734 returnValue = RessourceFactory.getInstance().getRessource( | |
735 locale, | |
736 value, | |
737 value | |
738 ); | |
739 } | |
740 return returnValue; | |
741 } | |
742 | |
743 | |
744 protected Collection<KeyValueDescibeData> getParameters(String uuid) { | |
745 return this.getCollection(parameterValuesName, uuid); | |
746 } | |
747 | |
748 protected Collection<KeyValueDescibeData> getMeasurements(String uuid) { | |
749 return this.getCollection(measuremenValueName, uuid); | |
750 } | |
751 protected Collection<KeyValueDescibeData> getDates(String uuid) { | |
752 return this.getCollection(dateValueName,uuid); | |
753 } | |
754 | |
755 @Override | |
756 public void setup(Node configuration) { | |
757 super.setup(configuration); | |
758 String featureNameValue = Config.getStringXPath(configuration, | |
759 "value-names/value-name[@name='feature']/@value"); | |
760 if (featureNameValue != null) { | |
761 this.featureValuesName = featureNameValue; | |
762 } | |
763 String parameterNameValue = Config.getStringXPath(configuration, | |
764 "value-names/value-name[@name='parameter']/@value"); | |
765 if (parameterNameValue != null) { | |
766 this.parameterValuesName = parameterNameValue; | |
767 } | |
768 String measurementNameValue = Config.getStringXPath(configuration, | |
769 "value-names/value-name[@name='measurement']/@value"); | |
770 if (measurementNameValue != null) { | |
771 this.measuremenValueName = measurementNameValue; | |
772 } | |
773 | |
774 String dateNameValue = Config.getStringXPath(configuration, | |
775 "value-names/value-name[@name='date']/@value"); | |
776 if (dateNameValue != null) { | |
777 this.dateValueName = dateNameValue; | |
778 } | |
779 if (timeGapDefinitions == null){ | |
780 Element gapDefinition = (Element)Config.getNodeXPath(configuration, | |
781 "time-gap-definition"); | |
782 synchronized (this.getClass()) { | |
783 if (gapDefinition != null){ | |
784 String link = gapDefinition.getAttribute("xlink:href"); | |
785 if (link != null ){ | |
786 String absolutFileName = Config.replaceConfigDir(link); | |
787 gapDefinition = (Element)new ArtifactXMLUtilities(). | |
788 readConfiguration(absolutFileName); | |
789 } | |
790 | |
791 NodeList gapDefinitions = Config.getNodeSetXPath(gapDefinition, | |
792 "/time-gaps/time-gap"); | |
793 if (gapDefinition != null){ | |
794 timeGapDefinitions = new ArrayList<TimeGap>(gapDefinitions. | |
795 getLength()); | |
796 for (int i = 0; i < gapDefinitions.getLength(); i++){ | |
797 Element gapNode = (Element)gapDefinitions.item(i); | |
798 String unit = gapNode.getAttribute("unit"); | |
799 int key = Integer.parseInt(gapNode.getAttribute("key")); | |
800 int value = Integer.parseInt(gapNode.getAttribute("gap")); | |
801 log.info("Add new Timegap: "+key+" "+value+" "+ unit); | |
802 timeGapDefinitions.add(new DefaultTimeGap(unit, | |
803 key, | |
804 value)); | |
805 } | |
806 } | |
807 | |
808 } | |
809 } | |
810 } | |
811 } | |
812 | |
813 /** | |
814 * @param collectionName | |
815 * @return | |
816 */ | |
817 protected Collection<KeyValueDescibeData> getCollection( | |
818 String collectionName, | |
819 String uuid) { | |
820 Iterator<Object> it = this.getDescibeData(uuid).iterator(); | |
821 while (it.hasNext()) { | |
822 | |
823 Object o = it.next(); | |
824 | |
825 if (o instanceof NamedCollection<?>) { | |
826 NamedCollection<KeyValueDescibeData> nc = (NamedCollection<KeyValueDescibeData>) o; | |
827 if (nc.getName().equals(collectionName)) { | |
828 return nc; | |
829 } | |
830 } | |
831 } | |
832 return null; | |
833 } | |
834 } | |
835 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |