comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java @ 358:2f7a28f211c7

Fetch ChartTheme from CallContext instead of creating it each time before creating a chart. gnv-artifacts/trunk@431 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 15 Dec 2009 15:30:25 +0000
parents bb1afbbd93e4
children 6491000407dd
comparison
equal deleted inserted replaced
357:25e4724aa504 358:2f7a28f211c7
33 33
34 import au.com.bytecode.opencsv.CSVWriter; 34 import au.com.bytecode.opencsv.CSVWriter;
35 import de.intevation.artifactdatabase.Config; 35 import de.intevation.artifactdatabase.Config;
36 import de.intevation.artifactdatabase.XMLUtils; 36 import de.intevation.artifactdatabase.XMLUtils;
37 import de.intevation.artifacts.CallMeta; 37 import de.intevation.artifacts.CallMeta;
38 import de.intevation.artifacts.CallContext;
38 import de.intevation.artifacts.PreferredLocale; 39 import de.intevation.artifacts.PreferredLocale;
40 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
41 import de.intevation.gnv.artifacts.context.GNVArtifactContextFactory;
39 import de.intevation.gnv.artifacts.ressource.RessourceFactory; 42 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
40 import de.intevation.gnv.chart.Chart; 43 import de.intevation.gnv.chart.Chart;
41 import de.intevation.gnv.chart.ChartLabels; 44 import de.intevation.gnv.chart.ChartLabels;
42 import de.intevation.gnv.chart.TimeSeriesChart; 45 import de.intevation.gnv.chart.TimeSeriesChart;
43 import de.intevation.gnv.chart.XMLChartTheme; 46 import de.intevation.gnv.chart.XMLChartTheme;
174 public void out( 177 public void out(
175 Document format, 178 Document format,
176 Collection<InputData> inputData, 179 Collection<InputData> inputData,
177 OutputStream outputStream, 180 OutputStream outputStream,
178 String uuid, 181 String uuid,
179 CallMeta callMeta 182 CallContext callContext
180 ) throws StateException 183 ) throws StateException
181 { 184 {
182 log.debug("TimeSeriesOutputTransition.out"); 185 log.debug("TimeSeriesOutputTransition.out");
183 186
184 String outputMode = Config.getStringXPath( 187 String outputMode = Config.getStringXPath(
187 ); 190 );
188 String mimeType = Config.getStringXPath( 191 String mimeType = Config.getStringXPath(
189 format, 192 format,
190 "action/out/mime-type/@value" 193 "action/out/mime-type/@value"
191 ); 194 );
195
196 CallMeta callMeta = callContext.getMeta();
192 197
193 try { 198 try {
194 if (outputMode.equalsIgnoreCase("chart")) { 199 if (outputMode.equalsIgnoreCase("chart")) {
195 log.debug("Chart will be generated."); 200 log.debug("Chart will be generated.");
196 int chartWidth = 600; 201 int chartWidth = 600;
247 outputStream, 252 outputStream,
248 parameters, 253 parameters,
249 measurements, 254 measurements,
250 dates, 255 dates,
251 chartLables, 256 chartLables,
257 callContext,
252 uuid, 258 uuid,
253 exportFormat, 259 exportFormat,
254 locale, 260 locale,
255 chartWidth, 261 chartWidth,
256 chartHeight, 262 chartHeight,
290 ) 296 )
291 ), 297 ),
292 uuid, 298 uuid,
293 "A4", 299 "A4",
294 true, 300 true,
301 linesVisible,
302 shapesVisible,
295 locale, 303 locale,
296 linesVisible, 304 callContext
297 shapesVisible
298 ); 305 );
299 } 306 }
300 else if (outputMode.equalsIgnoreCase("svg")) { 307 else if (outputMode.equalsIgnoreCase("svg")) {
301 log.debug("Output mode == svg"); 308 log.debug("Output mode == svg");
302 int width = 600; 309 int width = 600;
333 uuid, 340 uuid,
334 locale, 341 locale,
335 width, 342 width,
336 height, 343 height,
337 linesVisible, 344 linesVisible,
338 shapesVisible 345 shapesVisible,
346 callContext
339 ); 347 );
340 } 348 }
341 else if (outputMode.equalsIgnoreCase("csv")) { 349 else if (outputMode.equalsIgnoreCase("csv")) {
342 log.debug("CSV-File will be generated."); 350 log.debug("CSV-File will be generated.");
343 Collection<Result> chartResult = this.getChartResult(uuid); 351 Collection<Result> chartResult = this.getChartResult(uuid);
527 OutputStream outputStream, 535 OutputStream outputStream,
528 Collection parameters, 536 Collection parameters,
529 Collection measurements, 537 Collection measurements,
530 Collection dates, 538 Collection dates,
531 ChartLabels chartLables, 539 ChartLabels chartLables,
540 CallContext context,
532 String uuid, 541 String uuid,
533 String exportFormat, 542 String exportFormat,
534 Locale locale, 543 Locale locale,
535 int width, 544 int width,
536 int height, 545 int height,
540 throws IOException, TechnicalChartException 549 throws IOException, TechnicalChartException
541 { 550 {
542 log.debug("Create chart."); 551 log.debug("Create chart.");
543 Chart chart = getChart( 552 Chart chart = getChart(
544 chartLables, 553 chartLables,
554 createStyle(context),
545 parameters, 555 parameters,
546 measurements, 556 measurements,
547 dates, 557 dates,
548 getChartResult(uuid), 558 getChartResult(uuid),
549 locale, // Locale 559 locale, // Locale
579 Collection dates, 589 Collection dates,
580 ChartLabels chartLables, 590 ChartLabels chartLables,
581 String uuid, 591 String uuid,
582 String exportFormat, 592 String exportFormat,
583 boolean landscape, 593 boolean landscape,
594 boolean linesVisible,
595 boolean shapesVisible,
584 Locale locale, 596 Locale locale,
585 boolean linesVisible, 597 CallContext context
586 boolean shapesVisible
587 ) { 598 ) {
588 Chart chart = getChart( 599 Chart chart = getChart(
589 chartLables, 600 chartLables,
601 createStyle(context),
590 parameters, 602 parameters,
591 measurements, 603 measurements,
592 dates, 604 dates,
593 getChartResult(uuid), 605 getChartResult(uuid),
594 locale, 606 locale,
634 String uuid, 646 String uuid,
635 Locale locale, 647 Locale locale,
636 int width, 648 int width,
637 int height, 649 int height,
638 boolean linesVisible, 650 boolean linesVisible,
639 boolean shapesVisible 651 boolean shapesVisible,
652 CallContext callContext
640 ) { 653 ) {
641 Chart chart = getChart( 654 Chart chart = getChart(
642 chartLables, 655 chartLables,
656 createStyle(callContext),
643 parameters, 657 parameters,
644 measurements, 658 measurements,
645 dates, 659 dates,
646 getChartResult(uuid), 660 getChartResult(uuid),
647 locale, 661 locale,
666 } 680 }
667 681
668 682
669 protected Chart getChart( 683 protected Chart getChart(
670 ChartLabels chartLables, 684 ChartLabels chartLables,
685 ChartTheme theme,
671 Collection parameters, 686 Collection parameters,
672 Collection measurements, 687 Collection measurements,
673 Collection dates, 688 Collection dates,
674 Collection result, 689 Collection result,
675 Locale locale, 690 Locale locale,
688 return chart; 703 return chart;
689 704
690 log.info("Chart not in cache yet."); 705 log.info("Chart not in cache yet.");
691 chart = new TimeSeriesChart( 706 chart = new TimeSeriesChart(
692 chartLables, 707 chartLables,
693 createStyle(), 708 theme,
694 parameters, 709 parameters,
695 measurements, 710 measurements,
696 dates, 711 dates,
697 result, 712 result,
698 timeGapDefinitions, 713 timeGapDefinitions,
708 } 723 }
709 724
710 return chart; 725 return chart;
711 } 726 }
712 727
713 protected ChartTheme createStyle() { 728 protected ChartTheme createStyle(CallContext callContext) {
714 XMLChartTheme theme = null; 729 log.debug("Fetch chart theme from global context");
715 730
716 Document template = Config.getChartTemplate(); 731 GNVArtifactContext context =
717 String name = Config.getStringXPath( 732 (GNVArtifactContext) callContext.globalContext();
718 template, 733
719 "theme/name/@value" 734 XMLChartTheme theme = (XMLChartTheme) context.get(
720 ); 735 GNVArtifactContextFactory.CHARTTEMPLATE
721 736 );
722 theme = new XMLChartTheme(name);
723 theme.applyXMLConfiguration(template);
724 737
725 return theme; 738 return theme;
726 } 739 }
727 740
728 741

http://dive4elements.wald.intevation.org