Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java @ 444:85f48e287fb3
Added configuration for vertical cross sections ("Profilschnitte")
gnv-artifacts/trunk@492 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 30 Dec 2009 10:35:19 +0000 |
parents | da21c256a0ba |
children | 07672838fa5f |
comparison
equal
deleted
inserted
replaced
443:da21c256a0ba | 444:85f48e287fb3 |
---|---|
10 import java.io.File; | 10 import java.io.File; |
11 | 11 |
12 import java.util.Properties; | 12 import java.util.Properties; |
13 import java.util.HashMap; | 13 import java.util.HashMap; |
14 import java.util.ArrayList; | 14 import java.util.ArrayList; |
15 import java.util.Collections; | |
16 | |
17 import java.awt.Dimension; | |
15 | 18 |
16 import org.apache.log4j.Logger; | 19 import org.apache.log4j.Logger; |
17 | 20 |
18 import org.w3c.dom.Document; | 21 import org.w3c.dom.Document; |
19 import org.w3c.dom.Element; | 22 import org.w3c.dom.Element; |
27 import de.intevation.gnv.chart.XMLChartTheme; | 30 import de.intevation.gnv.chart.XMLChartTheme; |
28 | 31 |
29 import de.intevation.gnv.artifacts.cache.CacheFactory; | 32 import de.intevation.gnv.artifacts.cache.CacheFactory; |
30 | 33 |
31 import de.intevation.gnv.raster.Palette; | 34 import de.intevation.gnv.raster.Palette; |
35 import de.intevation.gnv.raster.Filter; | |
32 import de.intevation.gnv.raster.PaletteManager; | 36 import de.intevation.gnv.raster.PaletteManager; |
33 | 37 |
34 import de.intevation.artifacts.ArtifactContextFactory; | 38 import de.intevation.artifacts.ArtifactContextFactory; |
35 | 39 |
36 import de.intevation.artifactdatabase.Config; | 40 import de.intevation.artifactdatabase.Config; |
65 public final static String PALETTE_ITEMS = | 69 public final static String PALETTE_ITEMS = |
66 "palette"; | 70 "palette"; |
67 | 71 |
68 public final static String HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES = | 72 public final static String HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES = |
69 "/artifact-database/gnv/horizontal-cross-section-profile/samples/@number"; | 73 "/artifact-database/gnv/horizontal-cross-section-profile/samples/@number"; |
74 | |
75 public final static String VERTICAL_CROSS_SECTION_SAMPLES = | |
76 "/artifact-database/gnv/vertical-cross-section/samples"; | |
77 | |
78 public final static String VERTICAL_CROSS_SECTION_FILTERS = | |
79 "/artifact-database/gnv/vertical-cross-section/filters/filter"; | |
70 | 80 |
71 /** | 81 /** |
72 * Constructor | 82 * Constructor |
73 */ | 83 */ |
74 public GNVArtifactContextFactory() { | 84 public GNVArtifactContextFactory() { |
118 | 128 |
119 configureChartTemplate(config, returnValue); | 129 configureChartTemplate(config, returnValue); |
120 | 130 |
121 configureHorizontalCrossSectionProfile(config, returnValue); | 131 configureHorizontalCrossSectionProfile(config, returnValue); |
122 | 132 |
133 configureVerticalCrossSection(config, returnValue); | |
134 | |
123 } catch (FileNotFoundException e) { | 135 } catch (FileNotFoundException e) { |
124 log.error(e, e); | 136 log.error(e, e); |
125 } catch (IOException e) { | 137 } catch (IOException e) { |
126 log.error(e, e); | 138 log.error(e, e); |
127 } catch (QueryContainerException e) { | 139 } catch (QueryContainerException e) { |
128 log.error(e, e); | 140 log.error(e, e); |
129 } | 141 } |
130 return returnValue; | 142 return returnValue; |
143 } | |
144 | |
145 protected void configureVerticalCrossSection( | |
146 Document config, | |
147 GNVArtifactContext context | |
148 ) { | |
149 log.info("configuration of vertical cross section"); | |
150 configureVerticalCrossSectionSamples(config, context); | |
151 configureVerticalCrossSectionFilters(config, context); | |
152 } | |
153 | |
154 protected void configureVerticalCrossSectionFilters( | |
155 Document config, | |
156 GNVArtifactContext context | |
157 ) { | |
158 log.info("configuration of vertical cross section filters"); | |
159 | |
160 NodeList filters = Config.getNodeSetXPath( | |
161 VERTICAL_CROSS_SECTION_FILTERS); | |
162 | |
163 ArrayList<Filter.Factory> filterFactories = | |
164 new ArrayList<Filter.Factory>(); | |
165 | |
166 if (filters == null) { | |
167 log.warn("no filters found"); | |
168 } | |
169 else { | |
170 for (int i = 0, N = filters.getLength(); i < N; ++i) { | |
171 Element filterElement = (Element)filters.item(i); | |
172 String factoryName = filterElement.getAttribute("factory"); | |
173 if ((factoryName = factoryName.trim()).length() > 0) { | |
174 try { | |
175 Class clazz = Class.forName(factoryName); | |
176 Filter.Factory filterFactory = | |
177 (Filter.Factory)clazz.newInstance(); | |
178 filterFactories.add(filterFactory); | |
179 } | |
180 catch (ClassNotFoundException cnfe) { | |
181 log.error("filter class not found", cnfe); | |
182 } | |
183 catch (InstantiationException ie) { | |
184 log.error("cannot instantiate filter factory", ie); | |
185 } | |
186 catch (IllegalAccessException iae) { | |
187 log.error("cannot access filter factory", iae); | |
188 } | |
189 catch (ClassCastException cce) { | |
190 log.error("not a filter factory class", cce); | |
191 } | |
192 } | |
193 else { | |
194 log.error("No factory name given"); | |
195 } | |
196 } | |
197 } | |
198 | |
199 log.info("number of filters: " + filterFactories.size()); | |
200 | |
201 context.put( | |
202 GNVArtifactContext.VERTICAL_CROSS_SECTION_FILTER_FACTORIES_KEY, | |
203 Collections.unmodifiableList(filterFactories)); | |
204 } | |
205 | |
206 protected void configureVerticalCrossSectionSamples( | |
207 Document config, | |
208 GNVArtifactContext context | |
209 ) { | |
210 log.info("configuration of vertical cross section samples"); | |
211 | |
212 Element samples = (Element)Config.getNodeXPath( | |
213 VERTICAL_CROSS_SECTION_SAMPLES); | |
214 | |
215 Dimension sampleSize = new Dimension( | |
216 GNVArtifactContext.DEFAULT_VERTICAL_CROSS_SECTION_SAMPLES); | |
217 | |
218 if (samples == null) { | |
219 log.warn("no samples found"); | |
220 } | |
221 else { | |
222 String widthString = samples.getAttribute("width"); | |
223 if ((widthString = widthString.trim()).length() > 0) { | |
224 try { | |
225 sampleSize.width = Math.max(1, Integer.parseInt(widthString)); | |
226 } | |
227 catch (NumberFormatException nfe) { | |
228 log.error("invalid value for width: '" + widthString + "'"); | |
229 } | |
230 } | |
231 String heightString = samples.getAttribute("height"); | |
232 if ((heightString = heightString.trim()).length() > 0) { | |
233 try { | |
234 sampleSize.height = Math.max(1, Integer.parseInt(heightString)); | |
235 } | |
236 catch (NumberFormatException nfe) { | |
237 log.error("invalid value for height: '" + heightString + "'"); | |
238 } | |
239 } | |
240 } | |
241 log.info("samples (width x height): " + | |
242 sampleSize.width + " x " + sampleSize.height); | |
243 | |
244 context.put( | |
245 GNVArtifactContext.VERTICAL_CROSS_SECTION_SAMPLES_KEY, | |
246 sampleSize); | |
247 | |
131 } | 248 } |
132 | 249 |
133 protected void configureHorizontalCrossSectionProfile( | 250 protected void configureHorizontalCrossSectionProfile( |
134 Document config, | 251 Document config, |
135 GNVArtifactContext context | 252 GNVArtifactContext context |