1 31 32 package org.opencms.frontend.photoalbum; 33 34 import com.alkacon.simapi.Simapi; 35 36 import org.opencms.file.CmsFile; 37 import org.opencms.file.CmsObject; 38 import org.opencms.jsp.CmsJspActionElement; 39 import org.opencms.loader.CmsImageScaler; 40 import org.opencms.main.CmsException; 41 import org.opencms.util.CmsStringUtil; 42 import org.opencms.xml.content.CmsXmlContent; 43 import org.opencms.xml.content.CmsXmlContentFactory; 44 import org.opencms.xml.types.CmsXmlHtmlValue; 45 46 import java.awt.Color ; 47 import java.util.List ; 48 import java.util.Locale ; 49 50 59 public class CmsPhotoAlbumConfiguration { 60 61 62 public static final String FILTER_DELIMITER = "."; 63 64 65 public static final String FILTER_NONE = "none"; 66 67 68 public static final String NAVPOS_BOTTOM_ABOVE = "b_a"; 69 70 71 public static final String NAVPOS_BOTTOM_BELOW = "b_b"; 72 73 74 public static final String NAVPOS_TOP_ABOVE = "t_a"; 75 76 77 public static final String NAVPOS_TOP_BELOW = "t_b"; 78 79 80 public static final String NODE_ALIGN_NAVIGATION = "AlignNavigation"; 81 82 83 public static final String NODE_ALIGN_TITLE = "AlignTitle"; 84 85 86 public static final String NODE_BACKGROUND = "Background"; 87 88 89 public static final String NODE_COLS = "Cols"; 90 91 92 public static final String NODE_DETAIL = "Details"; 93 94 95 public static final String NODE_FILTER = "Filter"; 96 97 98 public static final String NODE_HIGHQUALITY = "HighQuality"; 99 100 101 public static final String NODE_NAVIGATION_POSITION = "NavigationPosition"; 102 103 104 public static final String NODE_ROWS = "Rows"; 105 106 107 public static final String NODE_SHOWDESCRIPTION = "ShowDescription"; 108 109 110 public static final String NODE_SHOWLINKORIGINAL = "ShowLinkOriginal"; 111 112 113 public static final String NODE_SHOWRESOURCENAMEASTITLE = "ShowResourceNameAsTitle"; 114 115 116 public static final String NODE_SHOWTITLE = "ShowTitle"; 117 118 119 public static final String NODE_SIZE = "Size"; 120 121 122 public static final String NODE_TEXTBOTTOM = "TextBottom"; 123 124 125 public static final String NODE_TEXTTOP = "TextTop"; 126 127 128 public static final String NODE_THUMBS = "Thumbs"; 129 130 131 public static final String NODE_TITLE = "Title"; 132 133 134 public static final String NODE_VFSFOLDER = "VfsFolder"; 135 136 137 private String m_albumTitle; 138 139 140 private String m_alignNavigation; 141 142 143 private String m_detailAlignTitle; 144 145 146 private CmsImageScaler m_detailImageScaler; 147 148 149 private String m_navigationPosition; 150 151 152 private boolean m_showDetailDescription; 153 154 155 private boolean m_showDetailOriginalLink; 156 157 158 private boolean m_showDetailTitle; 159 160 161 private boolean m_showResourceNameAsTitle; 162 163 164 private boolean m_showThumbTitle; 165 166 167 private String m_thumbAlignTitle; 168 169 170 private int m_thumbCols; 171 172 173 private CmsImageScaler m_thumbNailScaler; 174 175 176 private int m_thumbRows; 177 178 179 private String m_thumbTextBottom; 180 181 182 private String m_thumbTextTop; 183 184 185 private String m_vfsPathGallery; 186 187 190 public CmsPhotoAlbumConfiguration() { 191 192 initMembers(); 194 } 195 196 202 public CmsPhotoAlbumConfiguration(CmsJspActionElement jsp) 203 throws Exception { 204 205 init(jsp, null); 206 } 207 208 215 public CmsPhotoAlbumConfiguration(CmsJspActionElement jsp, String configUri) 216 throws Exception { 217 218 init(jsp, configUri); 219 } 220 221 226 public String getAlbumTitle() { 227 228 return m_albumTitle; 229 } 230 231 236 public String getAlignNavigation() { 237 238 return m_alignNavigation; 239 } 240 241 246 public String getDetailAlignTitle() { 247 248 return m_detailAlignTitle; 249 } 250 251 256 public CmsImageScaler getDetailImageScaler() { 257 258 return m_detailImageScaler; 259 } 260 261 266 public String getNavigationPosition() { 267 268 return m_navigationPosition; 269 } 270 271 276 public String getThumbAlignTitle() { 277 278 return m_thumbAlignTitle; 279 } 280 281 286 public int getThumbCols() { 287 288 return m_thumbCols; 289 } 290 291 296 public CmsImageScaler getThumbNailScaler() { 297 298 return m_thumbNailScaler; 299 } 300 301 306 public int getThumbRows() { 307 308 return m_thumbRows; 309 } 310 311 316 public String getThumbTextBottom() { 317 318 return m_thumbTextBottom; 319 } 320 321 326 public String getThumbTextTop() { 327 328 return m_thumbTextTop; 329 } 330 331 336 public String getVfsPathGallery() { 337 338 return m_vfsPathGallery; 339 } 340 341 349 public void init(CmsJspActionElement jsp, String configUri) throws Exception { 350 351 initMembers(); 353 354 if (CmsStringUtil.isEmpty(configUri)) { 356 configUri = jsp.getRequestContext().getUri(); 357 } 358 CmsFile file = jsp.getCmsObject().readFile(configUri); 359 CmsXmlContent content = CmsXmlContentFactory.unmarshal(jsp.getCmsObject(), file); 360 361 Locale locale = jsp.getRequestContext().getLocale(); 363 CmsObject cms = jsp.getCmsObject(); 365 366 String stringValue = content.getStringValue(cms, NODE_TITLE, locale); 368 setAlbumTitle(getConfigurationValue(stringValue, "")); 369 370 stringValue = content.getStringValue(cms, NODE_VFSFOLDER, locale); 372 setVfsPathGallery(getConfigurationValue(stringValue, "")); 373 374 stringValue = content.getStringValue(cms, NODE_ALIGN_NAVIGATION, locale); 376 setAlignNavigation(getConfigurationValue(stringValue, "left")); 377 378 stringValue = content.getStringValue(cms, NODE_NAVIGATION_POSITION, locale); 380 setNavigationPosition(getConfigurationValue(stringValue, NAVPOS_BOTTOM_BELOW)); 381 382 stringValue = content.getStringValue(cms, NODE_SHOWRESOURCENAMEASTITLE, locale); 384 setShowResourceNameAsTitle(Boolean.valueOf(stringValue).booleanValue()); 385 386 String nodePrefix = NODE_THUMBS + "/"; 388 389 stringValue = content.getStringValue(cms, nodePrefix + NODE_SHOWTITLE, locale); 391 setShowThumbTitle(Boolean.valueOf(stringValue).booleanValue()); 392 393 stringValue = content.getStringValue(cms, nodePrefix + NODE_ALIGN_TITLE, locale); 395 setThumbAlignTitle(getConfigurationValue(stringValue, "left")); 396 397 stringValue = content.getStringValue(cms, nodePrefix + NODE_COLS, locale); 399 setThumbCols(Integer.parseInt(getConfigurationValue(stringValue, "1"))); 400 401 stringValue = content.getStringValue(cms, nodePrefix + NODE_ROWS, locale); 403 setThumbRows(Integer.parseInt(getConfigurationValue(stringValue, "-1"))); 404 405 stringValue = content.getStringValue(cms, nodePrefix + NODE_BACKGROUND, locale); 407 stringValue = getConfigurationValue(stringValue, "#FFFFFF"); 408 Color color = Color.WHITE; 409 try { 410 color = Color.decode(stringValue); 411 } catch (NumberFormatException e) { 412 throw new CmsException(Messages.get().container(Messages.LOG_ERR_WRONG_THUMB_BGCOLOR_1, stringValue)); 413 } 414 getThumbNailScaler().setColor(color); 415 416 stringValue = content.getStringValue(cms, nodePrefix + NODE_HIGHQUALITY, locale); 418 if (Boolean.valueOf(stringValue).booleanValue()) { 419 getThumbNailScaler().setQuality(85); 421 } else { 422 getThumbNailScaler().setQuality(50); 424 getThumbNailScaler().setRenderMode(Simapi.RENDER_SPEED); 425 } 426 427 stringValue = content.getStringValue(cms, nodePrefix + NODE_SIZE, locale); 429 setImageSize(stringValue, true); 430 431 stringValue = content.getStringValue(cms, nodePrefix + NODE_FILTER, locale); 433 setImageFilter(stringValue, true); 434 435 CmsXmlHtmlValue textValue = (CmsXmlHtmlValue)content.getValue(nodePrefix + NODE_TEXTTOP, locale); 437 if (textValue != null) { 438 stringValue = textValue.getStringValue(cms); 440 setThumbTextTop(getConfigurationValue(stringValue, "")); 441 } else { 442 setThumbTextTop(""); 443 } 444 textValue = (CmsXmlHtmlValue)content.getValue(nodePrefix + NODE_TEXTBOTTOM, locale); 445 if (textValue != null) { 446 stringValue = textValue.getStringValue(cms); 448 setThumbTextBottom(getConfigurationValue(stringValue, "")); 449 } else { 450 setThumbTextBottom(""); 451 } 452 453 nodePrefix = NODE_DETAIL + "/"; 455 456 stringValue = content.getStringValue(cms, nodePrefix + NODE_SHOWTITLE, locale); 458 setShowDetailTitle(Boolean.valueOf(stringValue).booleanValue()); 459 460 stringValue = content.getStringValue(cms, nodePrefix + NODE_SHOWDESCRIPTION, locale); 462 setShowDetailDescription(Boolean.valueOf(stringValue).booleanValue()); 463 464 stringValue = content.getStringValue(cms, nodePrefix + NODE_ALIGN_TITLE, locale); 466 setDetailAlignTitle(getConfigurationValue(stringValue, "left")); 467 468 stringValue = content.getStringValue(cms, nodePrefix + NODE_SHOWLINKORIGINAL, locale); 470 setShowDetailOriginalLink(Boolean.valueOf(stringValue).booleanValue()); 471 472 stringValue = content.getStringValue(cms, nodePrefix + NODE_SIZE, locale); 474 setImageSize(stringValue, false); 475 476 stringValue = content.getStringValue(cms, nodePrefix + NODE_FILTER, locale); 478 setImageFilter(stringValue, false); 479 480 stringValue = content.getStringValue(cms, nodePrefix + NODE_BACKGROUND, locale); 482 stringValue = getConfigurationValue(stringValue, "#FFFFFF"); 483 color = Color.WHITE; 484 try { 485 color = Color.decode(stringValue); 486 } catch (NumberFormatException e) { 487 throw new CmsException(Messages.get().container(Messages.LOG_ERR_WRONG_DETAIL_BGCOLOR_1, stringValue)); 488 } 489 getDetailImageScaler().setColor(color); 490 } 491 492 497 public boolean showDetailDescription() { 498 499 return m_showDetailDescription; 500 } 501 502 507 public boolean showDetailOriginalLink() { 508 509 return m_showDetailOriginalLink; 510 } 511 512 517 public boolean showDetailTitle() { 518 519 return m_showDetailTitle; 520 } 521 522 527 public boolean showPageNavigation() { 528 529 return getThumbRows() > 0; 530 } 531 532 537 public boolean showResourceNameAsTitle() { 538 539 return m_showResourceNameAsTitle; 540 } 541 542 547 public boolean showThumbTextBottom() { 548 549 return CmsStringUtil.isNotEmpty(getThumbTextBottom()); 550 } 551 552 557 public boolean showThumbTextTop() { 558 559 return CmsStringUtil.isNotEmpty(getThumbTextTop()); 560 } 561 562 567 public boolean showThumbTitle() { 568 569 return m_showThumbTitle; 570 } 571 572 578 protected String getStyleAlignAttribute(String alignment) { 579 580 StringBuffer result = new StringBuffer (32); 581 result.append(" style=\"text-align: "); 582 result.append(alignment); 583 result.append(";\""); 584 return result.toString(); 585 } 586 587 590 protected void initMembers() { 591 592 setDetailImageScaler(new CmsImageScaler()); 594 setThumbNailScaler(new CmsImageScaler()); 595 596 setVfsPathGallery("/"); 598 setThumbCols(3); 599 setThumbRows(3); 600 setNavigationPosition(NAVPOS_TOP_BELOW); 601 602 } 603 604 609 protected void setAlbumTitle(String albumTitle) { 610 611 m_albumTitle = albumTitle; 612 } 613 614 619 protected void setAlignNavigation(String alignNavigation) { 620 621 m_alignNavigation = alignNavigation; 622 } 623 624 629 protected void setDetailAlignTitle(String detailAlignTitle) { 630 631 m_detailAlignTitle = detailAlignTitle; 632 } 633 634 639 protected void setDetailImageScaler(CmsImageScaler detailImageScaler) { 640 641 m_detailImageScaler = detailImageScaler; 642 } 643 644 649 protected void setNavigationPosition(String navigationPosition) { 650 651 m_navigationPosition = navigationPosition; 652 } 653 654 659 protected void setShowDetailDescription(boolean showDetailDescription) { 660 661 m_showDetailDescription = showDetailDescription; 662 } 663 664 669 protected void setShowDetailOriginalLink(boolean showDetailOriginalLink) { 670 671 m_showDetailOriginalLink = showDetailOriginalLink; 672 } 673 674 679 protected void setShowDetailTitle(boolean showDetailTitle) { 680 681 m_showDetailTitle = showDetailTitle; 682 } 683 684 689 protected void setShowResourceNameAsTitle(boolean showResourceNameAsTitle) { 690 691 m_showResourceNameAsTitle = showResourceNameAsTitle; 692 } 693 694 699 protected void setShowThumbTitle(boolean showThumbTitle) { 700 701 m_showThumbTitle = showThumbTitle; 702 } 703 704 709 protected void setThumbAlignTitle(String thumbAlignTitle) { 710 711 m_thumbAlignTitle = thumbAlignTitle; 712 } 713 714 719 protected void setThumbCols(int thumbCols) { 720 721 m_thumbCols = thumbCols; 722 } 723 724 729 protected void setThumbNailScaler(CmsImageScaler thumbNailScaler) { 730 731 m_thumbNailScaler = thumbNailScaler; 732 } 733 734 739 protected void setThumbRows(int thumbRows) { 740 741 if (thumbRows < 1) { 742 m_thumbRows = -1; 743 } else { 744 m_thumbRows = thumbRows; 745 } 746 } 747 748 753 protected void setThumbTextBottom(String thumbTextBottom) { 754 755 m_thumbTextBottom = thumbTextBottom; 756 } 757 758 763 protected void setThumbTextTop(String thumbTextTop) { 764 765 m_thumbTextTop = thumbTextTop; 766 } 767 768 773 protected void setVfsPathGallery(String vfsPathGallery) { 774 775 m_vfsPathGallery = vfsPathGallery; 776 } 777 778 785 private String getConfigurationValue(String value, String defaultValue) { 786 787 if (CmsStringUtil.isNotEmpty(value)) { 788 return value; 789 } 790 return defaultValue; 791 } 792 793 800 private void setImageFilter(String configValue, boolean isThumbNail) throws Exception { 801 802 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configValue) && !FILTER_NONE.equals(configValue)) { 803 List filter = CmsStringUtil.splitAsList(configValue, FILTER_DELIMITER); 805 for (int i=0; i<filter.size(); i++) { 806 String currentFilter = (String )filter.get(i); 807 if (isThumbNail) { 808 getThumbNailScaler().addFilter(currentFilter); 810 } else { 811 getDetailImageScaler().addFilter(currentFilter); 813 } 814 } 815 816 } 817 } 818 819 826 private void setImageSize(String configValue, boolean isThumbNail) throws Exception { 827 828 List sizes = CmsStringUtil.splitAsList(getConfigurationValue(configValue, "200x150"), 'x', true); 829 int width = Integer.parseInt((String )sizes.get(0)); 830 int height = Integer.parseInt((String )sizes.get(1)); 831 if (isThumbNail) { 832 getThumbNailScaler().setWidth(width); 833 getThumbNailScaler().setHeight(height); 834 } else { 835 getDetailImageScaler().setWidth(width); 836 getDetailImageScaler().setHeight(height); 837 } 838 } 839 840 } | Popular Tags |