Mercurial > dive4elements > gnv-client
changeset 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
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/ChangeLog Tue Dec 15 15:30:25 2009 +0000 @@ -1,3 +1,32 @@ +2009-12-15 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue106 + + * doc/conf/conf.xml: Added charttemplate to global configuration. + + * src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java: Made + method static to call it without initiating an object of its class. + + * src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java: + Create ChartTheme at startup of artifact server and put it into global + context. The theme is created one time on this way. + + * src/main/java/de/intevation/gnv/state/OutputState.jav, + src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: Changed + signature of 'out'-method. Call 'out' with CallContext instead of + CallMeta, which is contained in CallContext. CallContext is needed to + fetch the ChartTheme out of it. + + * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java, + src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java, + src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java, + src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java: + Changed signature of 'getChart'-method which now gets the CallContext + containing the ChartTheme. + + * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java: + Get ChartTheme from CallContext instead of reading the XML file here. + 2009-12-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java:
--- a/gnv-artifacts/doc/conf/conf.xml Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/doc/conf/conf.xml Tue Dec 15 15:30:25 2009 +0000 @@ -414,4 +414,9 @@ <driver>org.h2.Driver</driver> <sql></sql> --> </database> + <charttemplate> + <!-- This section configures the path to the template used to create + charts. --> + <configuration>${artifacts.config.dir}/charttemplate.xml</configuration> + </charttemplate> </artifact-database>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Tue Dec 15 15:30:25 2009 +0000 @@ -498,7 +498,7 @@ ((OutputState) current) .out(format, this.parseInputData( format, "/action/out/params/input"), - outputStream, super.identifier, context.getMeta()); + outputStream, super.identifier, context); } } catch (StateException e) { log.error(e, e);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Tue Dec 15 15:30:25 2009 +0000 @@ -18,6 +18,8 @@ import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory; import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory; import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException; +import de.intevation.gnv.chart.XMLChartTheme; +import de.intevation.gnv.utils.ArtifactXMLUtilities; /** * @author Tim Englich <tim.englich@intevation.de> @@ -35,6 +37,10 @@ private final static String CACHECONFIGNODEPATH = "/artifact-database/ehcache/configuration"; + private final static String CHARTCONFIGNODEPATH = "/artifact-database/charttemplate/configuration"; + + public final static String CHARTTEMPLATE = "template"; + /** * Constructor */ @@ -47,7 +53,7 @@ * @see de.intevation.artifacts.ArtifactContextFactory#createArtifactContext(org.w3c.dom.Document) */ public Object createArtifactContext(Document config) { - Object returnValue = null; + GNVArtifactContext returnValue = null; try { log.debug("GNVArtifactContextFactory.createArtifactContext"); log.info("Initialisation of the Geo-BackendConnectionPool"); @@ -75,7 +81,20 @@ CacheFactory cf = CacheFactory.getInstance(); cf.initializeCache(cacheConfigurationFile); + log.info("Initialisation of chart template"); + String chartConfigFile = Config.getStringXPath( + config, CHARTCONFIGNODEPATH + ); + chartConfigFile = Config.replaceConfigDir(chartConfigFile); + log.debug("Parse xml configuration of " + chartConfigFile); + InputStream is = new FileInputStream(chartConfigFile); + Document template = ArtifactXMLUtilities.readDocument(is); + XMLChartTheme theme = new XMLChartTheme("XMLChartTheme"); + theme.applyXMLConfiguration(template); + returnValue = new GNVArtifactContext(config); + + returnValue.put(CHARTTEMPLATE, theme); } catch (FileNotFoundException e) { log.error(e, e); } catch (IOException e) {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputState.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputState.java Tue Dec 15 15:30:25 2009 +0000 @@ -8,7 +8,7 @@ import org.w3c.dom.Document; -import de.intevation.artifacts.CallMeta; +import de.intevation.artifacts.CallContext; import de.intevation.gnv.state.exception.StateException; /** @@ -25,9 +25,13 @@ * @return The Bytecode of the Result * @throws StateException */ - public void out(Document format, Collection<InputData> inputData, - OutputStream outputStream, String uuid, CallMeta callMeta) - throws StateException; + public void out( + Document format, + Collection<InputData> inputData, + OutputStream outputStream, + String uuid, + CallContext callContext + ) throws StateException; /** * Delivers the provided OutputModes of an State
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java Tue Dec 15 15:30:25 2009 +0000 @@ -18,6 +18,8 @@ import org.apache.log4j.Logger; +import org.jfree.chart.ChartTheme; + import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.HorizontalProfileChart; @@ -91,6 +93,7 @@ @Override protected Chart getChart( ChartLabels chartLables, + ChartTheme theme, Collection parameters, Collection measurements, Collection dates, @@ -113,7 +116,7 @@ log.info("Chart not in cache yet."); chart = new HorizontalProfileChart( chartLables, - createStyle(), + theme, parameters, measurements, dates,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Tue Dec 15 15:30:25 2009 +0000 @@ -13,6 +13,8 @@ import org.apache.log4j.Logger; +import org.jfree.chart.ChartTheme; + import au.com.bytecode.opencsv.CSVWriter; import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; @@ -47,6 +49,7 @@ @Override protected Chart getChart( ChartLabels chartLables, + ChartTheme theme, Collection parameters, Collection measurements, Collection dates,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java Tue Dec 15 15:30:25 2009 +0000 @@ -8,6 +8,8 @@ import org.apache.log4j.Logger; +import org.jfree.chart.ChartTheme; + import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.VerticalProfileChart; @@ -40,6 +42,7 @@ @Override protected Chart getChart( ChartLabels chartLables, + ChartTheme theme, Collection parameters, Collection measurements, Collection dates, @@ -62,7 +65,7 @@ log.info("Chart not in cache yet."); chart = new VerticalProfileChart( chartLables, - this.createStyle(), + theme, parameters, measurements, dates,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Tue Dec 15 15:30:25 2009 +0000 @@ -13,6 +13,8 @@ import org.apache.log4j.Logger; +import org.jfree.chart.ChartTheme; + import au.com.bytecode.opencsv.CSVWriter; import com.vividsolutions.jts.geom.Point; @@ -56,6 +58,7 @@ @Override protected Chart getChart( ChartLabels chartLables, + ChartTheme theme, Collection parameters, Collection measurements, Collection dates,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Tue Dec 15 15:30:25 2009 +0000 @@ -35,7 +35,10 @@ import de.intevation.artifactdatabase.Config; import de.intevation.artifactdatabase.XMLUtils; import de.intevation.artifacts.CallMeta; +import de.intevation.artifacts.CallContext; import de.intevation.artifacts.PreferredLocale; +import de.intevation.gnv.artifacts.context.GNVArtifactContext; +import de.intevation.gnv.artifacts.context.GNVArtifactContextFactory; import de.intevation.gnv.artifacts.ressource.RessourceFactory; import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; @@ -176,7 +179,7 @@ Collection<InputData> inputData, OutputStream outputStream, String uuid, - CallMeta callMeta + CallContext callContext ) throws StateException { log.debug("TimeSeriesOutputTransition.out"); @@ -190,6 +193,8 @@ "action/out/mime-type/@value" ); + CallMeta callMeta = callContext.getMeta(); + try { if (outputMode.equalsIgnoreCase("chart")) { log.debug("Chart will be generated."); @@ -249,6 +254,7 @@ measurements, dates, chartLables, + callContext, uuid, exportFormat, locale, @@ -292,9 +298,10 @@ uuid, "A4", true, + linesVisible, + shapesVisible, locale, - linesVisible, - shapesVisible + callContext ); } else if (outputMode.equalsIgnoreCase("svg")) { @@ -335,7 +342,8 @@ width, height, linesVisible, - shapesVisible + shapesVisible, + callContext ); } else if (outputMode.equalsIgnoreCase("csv")) { @@ -529,6 +537,7 @@ Collection measurements, Collection dates, ChartLabels chartLables, + CallContext context, String uuid, String exportFormat, Locale locale, @@ -542,6 +551,7 @@ log.debug("Create chart."); Chart chart = getChart( chartLables, + createStyle(context), parameters, measurements, dates, @@ -581,12 +591,14 @@ String uuid, String exportFormat, boolean landscape, + boolean linesVisible, + boolean shapesVisible, Locale locale, - boolean linesVisible, - boolean shapesVisible + CallContext context ) { Chart chart = getChart( chartLables, + createStyle(context), parameters, measurements, dates, @@ -636,10 +648,12 @@ int width, int height, boolean linesVisible, - boolean shapesVisible + boolean shapesVisible, + CallContext callContext ) { Chart chart = getChart( chartLables, + createStyle(callContext), parameters, measurements, dates, @@ -668,6 +682,7 @@ protected Chart getChart( ChartLabels chartLables, + ChartTheme theme, Collection parameters, Collection measurements, Collection dates, @@ -690,7 +705,7 @@ log.info("Chart not in cache yet."); chart = new TimeSeriesChart( chartLables, - createStyle(), + theme, parameters, measurements, dates, @@ -710,18 +725,16 @@ return chart; } - protected ChartTheme createStyle() { - XMLChartTheme theme = null; + protected ChartTheme createStyle(CallContext callContext) { + log.debug("Fetch chart theme from global context"); - Document template = Config.getChartTemplate(); - String name = Config.getStringXPath( - template, - "theme/name/@value" + GNVArtifactContext context = + (GNVArtifactContext) callContext.globalContext(); + + XMLChartTheme theme = (XMLChartTheme) context.get( + GNVArtifactContextFactory.CHARTTEMPLATE ); - theme = new XMLChartTheme(name); - theme.applyXMLConfiguration(template); - return theme; }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Tue Dec 15 15:14:21 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Tue Dec 15 15:30:25 2009 +0000 @@ -85,7 +85,7 @@ return null; } - public Document readDocument(InputStream inputStream) { + public static Document readDocument(InputStream inputStream) { Document returnValue = null; try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory