comparison artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents 1ccbd7f81c7d
children 9667900536b6
comparison
equal deleted inserted replaced
8201:4b8c5a08de04 8202:e4606eae8ea5
60 * 60 *
61 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 61 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
62 */ 62 */
63 public class RiverContextFactory implements ArtifactContextFactory { 63 public class RiverContextFactory implements ArtifactContextFactory {
64 64
65 /** The logger that is used in this class. */ 65 /** The log that is used in this class. */
66 private static Logger logger = Logger.getLogger(RiverContextFactory.class); 66 private static Logger log = Logger.getLogger(RiverContextFactory.class);
67 67
68 /** The XPath to the artifacts configured in the configuration. */ 68 /** The XPath to the artifacts configured in the configuration. */
69 public static final String XPATH_ARTIFACTS = 69 public static final String XPATH_ARTIFACTS =
70 "/artifact-database/artifacts/artifact"; 70 "/artifact-database/artifacts/artifact";
71 71
205 */ 205 */
206 protected void configureTransitions(Document config, RiverContext context) { 206 protected void configureTransitions(Document config, RiverContext context) {
207 TransitionEngine engine = new TransitionEngine(); 207 TransitionEngine engine = new TransitionEngine();
208 208
209 List<Document> artifacts = getArtifactConfigurations(config); 209 List<Document> artifacts = getArtifactConfigurations(config);
210 logger.info("Found " + artifacts.size() + " artifacts in the config."); 210 log.info("Found " + artifacts.size() + " artifacts in the config.");
211 211
212 for (Document doc: artifacts) { 212 for (Document doc: artifacts) {
213 213
214 String artName = (String) XMLUtils.xpath( 214 String artName = (String) XMLUtils.xpath(
215 doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING); 215 doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING);
216 216
217 NodeList list = (NodeList) XMLUtils.xpath( 217 NodeList list = (NodeList) XMLUtils.xpath(
218 doc, XPATH_TRANSITIONS, XPathConstants.NODESET); 218 doc, XPATH_TRANSITIONS, XPathConstants.NODESET);
219 219
220 if (list == null) { 220 if (list == null) {
221 logger.warn("The artifact " + artName + 221 log.warn("The artifact " + artName +
222 " has no transitions configured."); 222 " has no transitions configured.");
223 continue; 223 continue;
224 } 224 }
225 225
226 int trans = list.getLength(); 226 int trans = list.getLength();
227 227
228 logger.info( 228 log.info(
229 "Artifact '" + artName + "' has " + trans + " transitions."); 229 "Artifact '" + artName + "' has " + trans + " transitions.");
230 230
231 for (int i = 0; i < trans; i++) { 231 for (int i = 0; i < trans; i++) {
232 Transition t = TransitionFactory.createTransition(list.item(i)); 232 Transition t = TransitionFactory.createTransition(list.item(i));
233 String s = t.getFrom(); 233 String s = t.getFrom();
262 String xlink = tmp.getAttribute(XPATH_XLINK); 262 String xlink = tmp.getAttribute(XPATH_XLINK);
263 xlink = Config.replaceConfigDir(xlink); 263 xlink = Config.replaceConfigDir(xlink);
264 264
265 File file = new File(xlink); 265 File file = new File(xlink);
266 if (!file.isFile() || !file.canRead()) { 266 if (!file.isFile() || !file.canRead()) {
267 logger.warn("Artifact configuration '" + file + "' not found."); 267 log.warn("Artifact configuration '" + file + "' not found.");
268 continue; 268 continue;
269 } 269 }
270 270
271 Document doc = XMLUtils.parseDocument(file); 271 Document doc = XMLUtils.parseDocument(file);
272 if (doc != null) { 272 if (doc != null) {
285 */ 285 */
286 protected void configureStates(Document config, RiverContext context) { 286 protected void configureStates(Document config, RiverContext context) {
287 StateEngine engine = new StateEngine(); 287 StateEngine engine = new StateEngine();
288 288
289 List<Document> artifacts = getArtifactConfigurations(config); 289 List<Document> artifacts = getArtifactConfigurations(config);
290 logger.info("Found " + artifacts.size() + " artifacts in the config."); 290 log.info("Found " + artifacts.size() + " artifacts in the config.");
291 291
292 for (Document doc: artifacts) { 292 for (Document doc: artifacts) {
293 List<State> states = new ArrayList<State>(); 293 List<State> states = new ArrayList<State>();
294 294
295 String artName = (String) XMLUtils.xpath( 295 String artName = (String) XMLUtils.xpath(
297 297
298 NodeList stateList = (NodeList) XMLUtils.xpath( 298 NodeList stateList = (NodeList) XMLUtils.xpath(
299 doc, XPATH_STATES, XPathConstants.NODESET); 299 doc, XPATH_STATES, XPathConstants.NODESET);
300 300
301 if (stateList == null) { 301 if (stateList == null) {
302 logger.warn("The artifact " + artName + 302 log.warn("The artifact " + artName +
303 " has no states configured."); 303 " has no states configured.");
304 continue; 304 continue;
305 } 305 }
306 306
307 int count = stateList.getLength(); 307 int count = stateList.getLength();
308 308
309 logger.info( 309 log.info(
310 "Artifact '" + artName + "' has " + count + " states."); 310 "Artifact '" + artName + "' has " + count + " states.");
311 311
312 for (int i = 0; i < count; i++) { 312 for (int i = 0; i < count; i++) {
313 states.add(StateFactory.createState( 313 states.add(StateFactory.createState(
314 stateList.item(i))); 314 stateList.item(i)));
335 XPathConstants.NODESET); 335 XPathConstants.NODESET);
336 336
337 int num = outGenerators == null ? 0 : outGenerators.getLength(); 337 int num = outGenerators == null ? 0 : outGenerators.getLength();
338 338
339 if (num == 0) { 339 if (num == 0) {
340 logger.warn("No output generators configured in this application."); 340 log.warn("No output generators configured in this application.");
341 return; 341 return;
342 } 342 }
343 343
344 logger.info("Found " + num + " configured output generators."); 344 log.info("Found " + num + " configured output generators.");
345 345
346 GeneratorLookup generators = new GeneratorLookup(); 346 GeneratorLookup generators = new GeneratorLookup();
347 347
348 int idx = 0; 348 int idx = 0;
349 349
362 362
363 try { 363 try {
364 generatorClass = (Class<OutGenerator>)Class.forName(clazz); 364 generatorClass = (Class<OutGenerator>)Class.forName(clazz);
365 } 365 }
366 catch (ClassNotFoundException cnfe) { 366 catch (ClassNotFoundException cnfe) {
367 logger.error(cnfe, cnfe); 367 log.error(cnfe, cnfe);
368 continue; 368 continue;
369 } 369 }
370 370
371 Object cfg = null; 371 Object cfg = null;
372 372
376 (ElementConverter)Class.forName(converter) 376 (ElementConverter)Class.forName(converter)
377 .newInstance(); 377 .newInstance();
378 cfg = ec.convert(item); 378 cfg = ec.convert(item);
379 } 379 }
380 catch (ClassNotFoundException cnfe) { 380 catch (ClassNotFoundException cnfe) {
381 logger.error(cnfe, cnfe); 381 log.error(cnfe, cnfe);
382 } 382 }
383 catch (InstantiationException ie) { 383 catch (InstantiationException ie) {
384 logger.error(ie); 384 log.error(ie);
385 } 385 }
386 catch (IllegalAccessException iae) { 386 catch (IllegalAccessException iae) {
387 logger.error(iae); 387 log.error(iae);
388 } 388 }
389 } 389 }
390 390
391 for (String key: names.split("[\\s,]")) { 391 for (String key: names.split("[\\s,]")) {
392 if (!(key = key.trim()).isEmpty()) { 392 if (!(key = key.trim()).isEmpty()) {
394 idx++; 394 idx++;
395 } 395 }
396 } 396 }
397 } 397 }
398 398
399 logger.info("Successfully loaded " + idx + " output generators."); 399 log.info("Successfully loaded " + idx + " output generators.");
400 context.put(RiverContext.OUTGENERATORS_KEY, generators); 400 context.put(RiverContext.OUTGENERATORS_KEY, generators);
401 context.put(RiverContext.FACETFILTER_KEY, generators); 401 context.put(RiverContext.FACETFILTER_KEY, generators);
402 } 402 }
403 403
404 404
408 * 408 *
409 * @param config The global configuration. 409 * @param config The global configuration.
410 * @param context The RiverContext. 410 * @param context The RiverContext.
411 */ 411 */
412 protected void configureThemes(Document config, RiverContext context) { 412 protected void configureThemes(Document config, RiverContext context) {
413 logger.debug("RiverContextFactory.configureThemes"); 413 log.debug("RiverContextFactory.configureThemes");
414 414
415 Document cfg = getThemeConfig(config); 415 Document cfg = getThemeConfig(config);
416 416
417 NodeList themeGroups = (NodeList) XMLUtils.xpath( 417 NodeList themeGroups = (NodeList) XMLUtils.xpath(
418 cfg, XPATH_THEME_GROUPS, XPathConstants.NODESET); 418 cfg, XPATH_THEME_GROUPS, XPathConstants.NODESET);
419 419
420 int groupNum = themeGroups != null ? themeGroups.getLength() : 0; 420 int groupNum = themeGroups != null ? themeGroups.getLength() : 0;
421 421
422 if (groupNum == 0) { 422 if (groupNum == 0) {
423 logger.warn("There are no theme groups configured!"); 423 log.warn("There are no theme groups configured!");
424 } 424 }
425 425
426 logger.info("Found " + groupNum + " theme groups in configuration"); 426 log.info("Found " + groupNum + " theme groups in configuration");
427 427
428 List<ThemeGroup> groups = new ArrayList<ThemeGroup>(); 428 List<ThemeGroup> groups = new ArrayList<ThemeGroup>();
429 429
430 for (int g = 0; g < groupNum; g++) { 430 for (int g = 0; g < groupNum; g++) {
431 Element themeGroup = (Element) themeGroups.item(g); 431 Element themeGroup = (Element) themeGroups.item(g);
433 themeGroup, XPATH_THEMES, XPathConstants.NODESET); 433 themeGroup, XPATH_THEMES, XPathConstants.NODESET);
434 434
435 int num = themes != null ? themes.getLength() : 0; 435 int num = themes != null ? themes.getLength() : 0;
436 436
437 if (num == 0) { 437 if (num == 0) {
438 logger.warn("There are no themes configured!"); 438 log.warn("There are no themes configured!");
439 return; 439 return;
440 } 440 }
441 441
442 logger.info("Theme group has " + num + " themes."); 442 log.info("Theme group has " + num + " themes.");
443 443
444 Map<String, Theme> theThemes = new HashMap<String, Theme>(); 444 Map<String, Theme> theThemes = new HashMap<String, Theme>();
445 445
446 for (int i = 0; i < num; i++) { 446 for (int i = 0; i < num; i++) {
447 Node theme = themes.item(i); 447 Node theme = themes.item(i);
453 } 453 }
454 } 454 }
455 String gName = themeGroup.getAttribute("name"); 455 String gName = themeGroup.getAttribute("name");
456 groups.add(new ThemeGroup(gName, theThemes)); 456 groups.add(new ThemeGroup(gName, theThemes));
457 457
458 logger.info( 458 log.info(
459 "Initialized " + theThemes.size() + "/" + num + " themes " + 459 "Initialized " + theThemes.size() + "/" + num + " themes " +
460 "of theme-group '" + gName + "'"); 460 "of theme-group '" + gName + "'");
461 } 461 }
462 context.put(RiverContext.THEMES, groups); 462 context.put(RiverContext.THEMES, groups);
463 } 463 }
475 XPATH_THEME_CONFIG, 475 XPATH_THEME_CONFIG,
476 XPathConstants.STRING); 476 XPathConstants.STRING);
477 477
478 themeConfig = Config.replaceConfigDir(themeConfig); 478 themeConfig = Config.replaceConfigDir(themeConfig);
479 479
480 logger.debug("Parse theme cfg: " + themeConfig); 480 log.debug("Parse theme cfg: " + themeConfig);
481 481
482 return XMLUtils.parseDocument(new File(themeConfig)); 482 return XMLUtils.parseDocument(new File(themeConfig));
483 } 483 }
484 484
485 485
486 protected void configureThemesMappings(Document cfg, RiverContext context) { 486 protected void configureThemesMappings(Document cfg, RiverContext context) {
487 logger.debug("RiverContextFactory.configureThemesMappings"); 487 log.debug("RiverContextFactory.configureThemesMappings");
488 488
489 Document config = getThemeConfig(cfg); 489 Document config = getThemeConfig(cfg);
490 490
491 NodeList mappings = (NodeList) XMLUtils.xpath( 491 NodeList mappings = (NodeList) XMLUtils.xpath(
492 config, XPATH_THEME_MAPPINGS, XPathConstants.NODESET); 492 config, XPATH_THEME_MAPPINGS, XPathConstants.NODESET);
493 493
494 int num = mappings != null ? mappings.getLength() : 0; 494 int num = mappings != null ? mappings.getLength() : 0;
495 495
496 if (num == 0) { 496 if (num == 0) {
497 logger.warn("No theme <--> facet mappins found!"); 497 log.warn("No theme <--> facet mappins found!");
498 return; 498 return;
499 } 499 }
500 500
501 Map<String, List<ThemeMapping>> mapping = 501 Map<String, List<ThemeMapping>> mapping =
502 new HashMap<String, List<ThemeMapping>>(); 502 new HashMap<String, List<ThemeMapping>>();
521 tm.add(new ThemeMapping( 521 tm.add(new ThemeMapping(
522 from, to, pattern, masterAttrPattern, outputPattern)); 522 from, to, pattern, masterAttrPattern, outputPattern));
523 } 523 }
524 } 524 }
525 525
526 logger.debug("Found " + mapping.size() + " theme mappings."); 526 log.debug("Found " + mapping.size() + " theme mappings.");
527 527
528 context.put(RiverContext.THEME_MAPPING, mapping); 528 context.put(RiverContext.THEME_MAPPING, mapping);
529 } 529 }
530 530
531 531
552 if (river != null && url != null) { 552 if (river != null && url != null) {
553 riverWMS.put(river, url); 553 riverWMS.put(river, url);
554 } 554 }
555 } 555 }
556 556
557 logger.debug("Found " + riverWMS.size() + " river WMS."); 557 log.debug("Found " + riverWMS.size() + " river WMS.");
558 558
559 context.put(RiverContext.RIVER_WMS, riverWMS); 559 context.put(RiverContext.RIVER_WMS, riverWMS);
560 } 560 }
561 561
562 562
577 Element e = (Element) modulenodes.item(i); 577 Element e = (Element) modulenodes.item(i);
578 String modulename = e.getAttribute("name"); 578 String modulename = e.getAttribute("name");
579 String attrselected = e.getAttribute("selected"); 579 String attrselected = e.getAttribute("selected");
580 boolean selected = attrselected == null ? false : 580 boolean selected = attrselected == null ? false :
581 attrselected.equalsIgnoreCase("true"); 581 attrselected.equalsIgnoreCase("true");
582 logger.debug("Loaded module " + modulename); 582 log.debug("Loaded module " + modulename);
583 NodeList children = e.getChildNodes(); 583 NodeList children = e.getChildNodes();
584 List<String> rivers = new ArrayList<String>(children.getLength()); 584 List<String> rivers = new ArrayList<String>(children.getLength());
585 for (int j = 0; j < children.getLength(); j++) { 585 for (int j = 0; j < children.getLength(); j++) {
586 if (children.item(j).getNodeType() != Node.ELEMENT_NODE) { 586 if (children.item(j).getNodeType() != Node.ELEMENT_NODE) {
587 continue; 587 continue;

http://dive4elements.wald.intevation.org