Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java @ 341:eca7892bf8ff
Added a first small theme configuration and code to read it.
flys-artifacts/trunk@1740 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 21 Apr 2011 08:47:39 +0000 |
parents | 53c155bfde07 |
children | 88a669785863 |
comparison
equal
deleted
inserted
replaced
340:b36fd8f21e6a | 341:eca7892bf8ff |
---|---|
25 import de.intevation.artifactdatabase.transition.Transition; | 25 import de.intevation.artifactdatabase.transition.Transition; |
26 import de.intevation.artifactdatabase.transition.TransitionEngine; | 26 import de.intevation.artifactdatabase.transition.TransitionEngine; |
27 | 27 |
28 import de.intevation.flys.artifacts.states.StateFactory; | 28 import de.intevation.flys.artifacts.states.StateFactory; |
29 import de.intevation.flys.artifacts.transitions.TransitionFactory; | 29 import de.intevation.flys.artifacts.transitions.TransitionFactory; |
30 import de.intevation.flys.themes.Theme; | |
31 import de.intevation.flys.themes.ThemeFactory; | |
30 | 32 |
31 | 33 |
32 /** | 34 /** |
33 * The ArtifactContextFactory is used to initialize basic components and put | 35 * The ArtifactContextFactory is used to initialize basic components and put |
34 * them into the global context of the application. | 36 * them into the global context of the application. |
59 "/artifact/states/state"; | 61 "/artifact/states/state"; |
60 | 62 |
61 public static final String XPATH_OUTPUT_GENERATORS = | 63 public static final String XPATH_OUTPUT_GENERATORS = |
62 "/artifact-database/output-generators/output-generator"; | 64 "/artifact-database/output-generators/output-generator"; |
63 | 65 |
66 public static final String XPATH_THEME_CONFIG = | |
67 "/artifact-database/flys/themes/configuration/text()"; | |
68 | |
69 public static final String XPATH_THEMES = | |
70 "/themes/theme"; | |
71 | |
64 /** | 72 /** |
65 * Creates a new FLYSArtifactContext object and initialize all | 73 * Creates a new FLYSArtifactContext object and initialize all |
66 * components required by the application. | 74 * components required by the application. |
67 * | 75 * |
68 * @param config The artifact server configuration. | 76 * @param config The artifact server configuration. |
72 FLYSContext context = new FLYSContext(config); | 80 FLYSContext context = new FLYSContext(config); |
73 | 81 |
74 configureTransitions(config, context); | 82 configureTransitions(config, context); |
75 configureStates(config, context); | 83 configureStates(config, context); |
76 configureOutGenerators(config, context); | 84 configureOutGenerators(config, context); |
85 configureThemes(config, context); | |
77 | 86 |
78 return context; | 87 return context; |
79 } | 88 } |
80 | 89 |
81 | 90 |
244 } | 253 } |
245 | 254 |
246 logger.info("Successfully loaded " + idx + " output generators."); | 255 logger.info("Successfully loaded " + idx + " output generators."); |
247 context.put(FLYSContext.OUTGENERATORS_KEY, generators); | 256 context.put(FLYSContext.OUTGENERATORS_KEY, generators); |
248 } | 257 } |
258 | |
259 | |
260 /** | |
261 * This methods reads the configured themes and puts them into the | |
262 * FLYSContext. | |
263 * | |
264 * @param config The global configuration. | |
265 * @param context The FLYSContext. | |
266 */ | |
267 protected void configureThemes(Document config, FLYSContext context) { | |
268 logger.debug("FLYSContextFactory.configureThemes"); | |
269 | |
270 Document cfg = getThemeConfig(config); | |
271 | |
272 NodeList themes = (NodeList) XMLUtils.xpath( | |
273 cfg, XPATH_THEMES, XPathConstants.NODESET); | |
274 | |
275 int num = themes != null ? themes.getLength() : 0; | |
276 | |
277 if (num == 0) { | |
278 logger.warn("There are no themes configured!"); | |
279 return; | |
280 } | |
281 | |
282 logger.debug("Found " + num + " configured themes."); | |
283 | |
284 Map<String, Theme> theThemes = new HashMap<String, Theme>(); | |
285 | |
286 for (int i = 0; i < num; i++) { | |
287 Node theme = themes.item(i); | |
288 | |
289 Theme theTheme = ThemeFactory.createTheme(cfg, theme); | |
290 | |
291 if (theme != null) { | |
292 theThemes.put(theTheme.getName(), theTheme); | |
293 } | |
294 } | |
295 | |
296 logger.debug("Initialized " + theThemes.size() + "/" + num + " themes"); | |
297 | |
298 context.put(FLYSContext.THEMES, theThemes); | |
299 } | |
300 | |
301 | |
302 /** | |
303 * This method is used to retrieve the theme configuration document. | |
304 * | |
305 * @param config The global configuration. | |
306 * | |
307 * @return the theme configuration. | |
308 */ | |
309 protected Document getThemeConfig(Document config) { | |
310 String themeConfig = (String) XMLUtils.xpath( | |
311 config, | |
312 XPATH_THEME_CONFIG, | |
313 XPathConstants.STRING); | |
314 | |
315 themeConfig = Config.replaceConfigDir(themeConfig); | |
316 | |
317 logger.debug("Parse theme cfg: " + themeConfig); | |
318 | |
319 return XMLUtils.parseDocument(new File(themeConfig)); | |
320 } | |
249 } | 321 } |
250 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 322 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |