comparison flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 1747:d2a17e990c70

Improved the Themes: we now support special themes for facets which need to match a given pattern string. flys-artifacts/trunk@3047 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 20 Oct 2011 13:45:45 +0000
parents 62efd1288e34
children 460374a08c44
comparison
equal deleted inserted replaced
1746:94faf08d143c 1747:d2a17e990c70
300 theme, 300 theme,
301 getFacetThemeFromAttribute( 301 getFacetThemeFromAttribute(
302 art, 302 art,
303 outName, 303 outName,
304 facetName, 304 facetName,
305 theme.getDescription(),
305 theme.getIndex(), 306 theme.getIndex(),
306 context), 307 context),
307 theme.getActive() == 1); 308 theme.getActive() == 1);
308 } 309 }
309 } 310 }
471 */ 472 */
472 protected Document getFacetThemeFromAttribute( 473 protected Document getFacetThemeFromAttribute(
473 String uuid, 474 String uuid,
474 String outName, 475 String outName,
475 String facet, 476 String facet,
477 String pattern,
476 int index, 478 int index,
477 CallContext context) 479 CallContext context)
478 throws ArtifactDatabaseException 480 throws ArtifactDatabaseException
479 { 481 {
480 log.debug("FLYSArtifactCollection.getFacetThemeFromAttribute"); 482 log.debug("FLYSArtifactCollection.getFacetThemeFromAttribute");
484 486
485 FLYSContext flysContext = context instanceof FLYSContext 487 FLYSContext flysContext = context instanceof FLYSContext
486 ? (FLYSContext) context 488 ? (FLYSContext) context
487 : (FLYSContext) context.globalContext(); 489 : (FLYSContext) context.globalContext();
488 490
489 Map<String, String> mappings = (Map<String, String>)
490 flysContext.get(FLYSContext.THEME_MAPPING);
491
492 String themeName = mappings.get(facet);
493
494 Document attr = db.getCollectionItemAttribute(identifier(), uuid, meta); 491 Document attr = db.getCollectionItemAttribute(identifier(), uuid, meta);
495 492
496 if (attr == null) { 493 if (attr == null) {
497 attr = initItemAttribute(uuid, facet, index, context); 494 attr = initItemAttribute(uuid, facet, pattern, index, context);
498 495
499 if (attr == null) { 496 if (attr == null) {
500 return null; 497 return null;
501 } 498 }
502 } 499 }
512 if (tmp == null) { 509 if (tmp == null) {
513 log.warn("No attribute found. Operation failed."); 510 log.warn("No attribute found. Operation failed.");
514 return null; 511 return null;
515 } 512 }
516 513
517 log.debug("Search theme '" + themeName + "' in attribute."); 514 log.debug("Search theme for facet '" + facet + "' in attribute.");
518 515
519 Node theme = (Node) XMLUtils.xpath( 516 Node theme = (Node) XMLUtils.xpath(
520 tmp, 517 tmp,
521 "art:themes/theme[@facet='" + facet + 518 "art:themes/theme[@facet='" + facet +
522 "' and @index='" + String.valueOf(index) + "']", 519 "' and @index='" + String.valueOf(index) + "']",
524 ArtifactNamespaceContext.INSTANCE); 521 ArtifactNamespaceContext.INSTANCE);
525 522
526 if (theme == null) { 523 if (theme == null) {
527 log.warn("Could not find the theme in attribute of: " + uuid); 524 log.warn("Could not find the theme in attribute of: " + uuid);
528 525
529 Theme t = getThemeForFacet(uuid, facet, index, context); 526 Theme t = getThemeForFacet(uuid, facet, pattern, index, context);
530 527
531 if (t == null) { 528 if (t == null) {
532 log.warn("No theme found for facet: " + facet); 529 log.warn("No theme found for facet: " + facet);
533 return null; 530 return null;
534 } 531 }
617 * @param the new attribute. 614 * @param the new attribute.
618 */ 615 */
619 protected Document initItemAttribute( 616 protected Document initItemAttribute(
620 String uuid, 617 String uuid,
621 String facet, 618 String facet,
619 String pattern,
622 int index, 620 int index,
623 CallContext context) 621 CallContext context)
624 { 622 {
625 log.info("FLYSArtifactCollection.initItemAttribute"); 623 log.info("FLYSArtifactCollection.initItemAttribute");
626 624
627 Theme t = getThemeForFacet(uuid, facet, index, context); 625 Theme t = getThemeForFacet(uuid, facet, pattern, index, context);
628 626
629 if (t == null) { 627 if (t == null) {
630 log.info("Could not find theme for facet. Cancel initialization."); 628 log.info("Could not find theme for facet. Cancel initialization.");
631 return null; 629 return null;
632 } 630 }
679 * @return the desired theme. 677 * @return the desired theme.
680 */ 678 */
681 protected Theme getThemeForFacet( 679 protected Theme getThemeForFacet(
682 String uuid, 680 String uuid,
683 String facet, 681 String facet,
682 String pattern,
684 int index, 683 int index,
685 CallContext context) 684 CallContext context)
686 { 685 {
687 log.info("FLYSArtifactCollection.getThemeForFacet: " + facet); 686 log.info("FLYSArtifactCollection.getThemeForFacet: " + facet);
688 687
689 FLYSContext flysContext = context instanceof FLYSContext 688 FLYSContext flysContext = context instanceof FLYSContext
690 ? (FLYSContext) context 689 ? (FLYSContext) context
691 : (FLYSContext) context.globalContext(); 690 : (FLYSContext) context.globalContext();
692 691
693 Theme t = ThemeFactory.getTheme(flysContext, facet); 692 Theme t = ThemeFactory.getTheme(flysContext, facet, pattern);
694 693
695 if (t != null) { 694 if (t != null) {
696 t.setFacet(facet); 695 t.setFacet(facet);
697 t.setIndex(index); 696 t.setIndex(index);
698 } 697 }

http://dive4elements.wald.intevation.org