1 31 32 package org.opencms.workplace.galleries; 33 34 import org.opencms.file.CmsProperty; 35 import org.opencms.file.CmsPropertyDefinition; 36 import org.opencms.file.CmsResource; 37 import org.opencms.file.CmsResourceFilter; 38 import org.opencms.file.types.CmsResourceTypeFolderExtended; 39 import org.opencms.i18n.CmsEncoder; 40 import org.opencms.i18n.CmsMessageContainer; 41 import org.opencms.jsp.CmsJspActionElement; 42 import org.opencms.loader.CmsLoaderException; 43 import org.opencms.lock.CmsLock; 44 import org.opencms.main.CmsException; 45 import org.opencms.main.CmsLog; 46 import org.opencms.main.CmsRuntimeException; 47 import org.opencms.main.OpenCms; 48 import org.opencms.security.CmsPermissionSet; 49 import org.opencms.util.CmsStringUtil; 50 import org.opencms.workplace.CmsDialog; 51 import org.opencms.workplace.CmsWorkplace; 52 import org.opencms.workplace.CmsWorkplaceManager; 53 import org.opencms.workplace.CmsWorkplaceSettings; 54 import org.opencms.workplace.explorer.CmsNewResource; 55 import org.opencms.workplace.explorer.CmsNewResourceUpload; 56 57 import java.util.ArrayList ; 58 import java.util.Iterator ; 59 import java.util.List ; 60 import java.util.Map ; 61 import java.util.TreeMap ; 62 63 import javax.servlet.http.HttpServletRequest ; 64 import javax.servlet.http.HttpSession ; 65 66 import org.apache.commons.logging.Log; 67 68 80 public abstract class A_CmsGallery extends CmsDialog implements Comparable { 81 82 83 public static final int ACTION_DELETE = 101; 84 85 86 public static final int ACTION_LIST = 102; 87 88 89 public static final int ACTION_SEARCH = 103; 90 91 92 public static final int ACTION_UPLOAD = 104; 93 94 95 public static final String CSS_FILENAME = "gallery.css"; 96 97 98 public static final String DIALOG_DELETE = "delete"; 99 100 101 public static final String DIALOG_EDITPROPERTY = "editproperty"; 102 103 104 public static final String DIALOG_LIST = "list"; 105 106 107 public static final String DIALOG_SEARCH = "search"; 108 109 110 public static final String DIALOG_TYPE = "gallery"; 111 112 113 public static final String DIALOG_UPLOAD = "upload"; 114 115 116 public static final String MODE_EDITOR = "editor"; 117 118 119 public static final String MODE_VIEW = "view"; 120 121 122 public static final String MODE_WIDGET = "widget"; 123 124 125 public static final String OPEN_URI_SUFFIX = "gallery_fs.jsp"; 126 127 128 public static final String PARAM_DIALOGMODE = "dialogmode"; 129 130 131 public static final String PARAM_FIELDID = "fieldid"; 132 133 134 public static final String PARAM_GALLERY_TYPENAME = "gallerytypename"; 135 136 137 public static final String PARAM_GALLERYPATH = "gallerypath"; 138 139 140 public static final String PARAM_PAGE = "page"; 141 142 143 public static final String PARAM_PROPERTYVALUE = "propertyvalue"; 144 145 146 public static final String PARAM_RESOURCEPATH = "resourcepath"; 147 148 149 public static final String PARAM_SEARCHWORD = "searchword"; 150 151 152 public static final String PATH_GALLERIES = CmsWorkplace.VFS_PATH_WORKPLACE + "galleries/"; 153 154 155 private static final Log LOG = CmsLog.getLog(A_CmsGallery.class); 156 157 158 private CmsResource m_currentResource; 159 160 161 private List m_galleryItems; 162 163 164 private int m_galleryTypeId; 165 166 167 private String m_galleryTypeName; 168 169 170 private String m_galleryTypeParams; 171 172 173 private String m_paramDialogMode; 174 175 176 private String m_paramFieldId; 177 178 179 private String m_paramGalleryPath; 180 181 182 private String m_paramPage; 183 184 185 private String m_paramPropertyValue; 186 187 188 private String m_paramResourcePath; 189 190 191 private String m_paramSearchWord; 192 193 194 private CmsResourceTypeFolderExtended m_resourceType; 195 196 199 public A_CmsGallery() { 200 201 this(null); 202 } 203 204 209 public A_CmsGallery(CmsJspActionElement jsp) { 210 211 super(jsp); 212 } 213 214 221 public static A_CmsGallery createInstance(CmsJspActionElement jsp) { 222 223 String galleryTypeName = null; 224 if (jsp != null) { 225 galleryTypeName = jsp.getRequest().getParameter(PARAM_GALLERY_TYPENAME); 227 } 228 return A_CmsGallery.createInstance(galleryTypeName, jsp); 229 } 230 231 239 public static A_CmsGallery createInstance(String galleryTypeName, CmsJspActionElement jsp) { 240 241 if (jsp != null) { 242 HttpSession session = jsp.getRequest().getSession(); 244 CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS); 246 if (CmsStringUtil.isEmpty(galleryTypeName)) { 247 galleryTypeName = settings.getGalleryType(); 249 } else { 250 settings.setGalleryType(galleryTypeName); 252 } 253 } 254 A_CmsGallery template = (A_CmsGallery)OpenCms.getWorkplaceManager().getGalleries().get(galleryTypeName); 256 257 if (template == null) { 258 CmsMessageContainer message; 260 if (jsp == null) { 261 message = Messages.get().container(Messages.LOG_UNKNOWN_GALLERY_TYPE_REQ_1, galleryTypeName); 262 } else { 263 message = Messages.get().container( 264 Messages.LOG_UNKNOWN_GALLERY_TYPE_REQ_JSP_2, 265 galleryTypeName, 266 jsp.info("opencms.request.element.uri")); 267 } 268 LOG.error(message.key()); 269 throw new CmsRuntimeException(message); 270 } 271 272 try { 273 Class galleryClass = Class.forName(template.getResourceType().getFolderClassName()); 275 A_CmsGallery galleryInstance = (A_CmsGallery)galleryClass.newInstance(); 277 galleryInstance.m_galleryTypeName = galleryTypeName; 279 galleryInstance.m_resourceType = template.getResourceType(); 280 galleryInstance.m_galleryTypeParams = template.getResourceType().getFolderClassParams(); 281 galleryInstance.m_galleryTypeId = template.getResourceType().getTypeId(); 282 galleryInstance.initWorkplaceMembers(jsp); 284 galleryInstance.init(); 286 return galleryInstance; 288 } catch (Exception e) { 289 CmsMessageContainer message; 291 if (jsp == null) { 292 message = Messages.get().container( 293 Messages.LOG_CREATE_GALLERY_INSTANCE_FAILED_2, 294 template.getResourceType().getFolderClassName(), 295 galleryTypeName); 296 } else { 297 message = Messages.get().container( 298 Messages.LOG_CREATE_GALLERY_INSTANCE_FAILED_JSP_3, 299 template.getResourceType().getFolderClassName(), 300 galleryTypeName, 301 jsp.info("opencms.request.element.uri")); 302 } 303 LOG.error(message.key()); 304 throw new CmsRuntimeException(message); 305 } 306 } 307 308 313 public static void initGallery(CmsDialog wp) { 314 315 String galleryTypeName = null; 317 if (wp.useNewStyle()) { 318 galleryTypeName = CmsResource.getName(CmsResource.getFolderPath(wp.getAdminTool().getHandler().getLink())); 319 } else { 320 galleryTypeName = CmsResource.getName(CmsResource.getFolderPath(wp.getJsp().getRequestContext().getUri())); 321 } 322 if (galleryTypeName.endsWith("/")) { 323 galleryTypeName = galleryTypeName.substring(0, galleryTypeName.length() - 1); 324 } 325 if (!galleryTypeName.equals("commons")) { 326 wp.getSettings().setGalleryType(galleryTypeName); 328 } 329 } 330 331 339 public String applyButton() { 340 341 if (MODE_VIEW.equals(getParamDialogMode())) { 342 return button(null, null, "apply_in.png", Messages.GUI_BUTTON_PASTE_0, 0); 344 } else { 345 String uri = getParamResourcePath(); 347 if (CmsStringUtil.isEmpty(getParamDialogMode())) { 348 uri = getJsp().link(uri); 349 } 350 return button( 351 "javascript:link('" + uri + "',document.form.title.value, document.form.title.value);", 352 null, 353 "apply.png", 354 Messages.GUI_BUTTON_PASTE_0, 355 0); 356 } 357 } 358 359 364 public String buildGalleryButtonBar() { 365 366 StringBuffer buttonBar = new StringBuffer (); 367 try { 368 if (CmsStringUtil.isNotEmpty(getParamResourcePath())) { 369 CmsResource res = getCms().readResource(getParamResourcePath()); 371 if (res != null) { 372 setCurrentResource(res); 373 if (hasWritePermissions() && DIALOG_EDITPROPERTY.equals(getParamAction())) { 375 writeTitleProperty(res); 377 } 378 String title = CmsEncoder.escapeXml(getPropertyValue(res, CmsPropertyDefinition.PROPERTY_TITLE)); 379 buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" "); 380 buttonBar.append("style=\"align: left; width:100%; background-color: ThreeDFace; margin: 0; border-right: 1px solid ThreeDShadow\">"); 381 buttonBar.append("<tr align=\"left\">"); 382 buttonBar.append(buttonBarStartTab(0, 0)); 383 buttonBar.append(applyButton()); 385 buttonBar.append(publishButton()); 387 buttonBar.append(deleteButton()); 389 buttonBar.append(buttonBarSeparator(5, 5)); 390 buttonBar.append("<td class=\"nowrap\"><b>"); 391 buttonBar.append(key(Messages.GUI_INPUT_TITLE_0)); 392 buttonBar.append("</b> </td>"); 393 buttonBar.append("<td class=\"maxwidth\">"); 394 buttonBar.append("<input name=\"title\" value=\""); 395 buttonBar.append(title); 396 buttonBar.append("\" style=\"width: 95%\">"); 397 buttonBar.append("</td>\r\n"); 398 buttonBar.append("<input type=\"hidden\" name=\""); 400 buttonBar.append(PARAM_PROPERTYVALUE); 401 buttonBar.append("\" value=\""); 402 buttonBar.append(title); 403 buttonBar.append("\">\r\n"); 404 buttonBar.append(editPropertyButton()); 406 buttonBar.append(targetSelectBox()); 408 buttonBar.append(previewButton()); 410 buttonBar.append(buttonBar(HTML_END)); 411 } 412 } else { 413 buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>"); 415 buttonBar.append("<img height=\"22\" border=\"0\" SRC=\""); 416 buttonBar.append(getJsp().link(CmsWorkplace.VFS_PATH_RESOURCES + "tree/empty.gif")); 417 buttonBar.append("\">"); 418 buttonBar.append("</td></tr></table>"); 419 } 420 } catch (CmsException e) { 421 buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>"); 423 buttonBar.append("<img height=\"22\" border=\"0\" SRC=\""); 424 buttonBar.append(getJsp().link(CmsWorkplace.VFS_PATH_RESOURCES + "tree/empty.gif")); 425 buttonBar.append("\">"); 426 buttonBar.append("</td></tr></table>"); 427 } 428 return buttonBar.toString(); 429 } 430 431 436 public abstract String buildGalleryItemPreview(); 437 438 443 public String buildGalleryItems() { 444 445 StringBuffer result = new StringBuffer (64); 446 result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\">"); 447 result.append(buildGalleryItemListHeadline()); 448 List items = getGalleryItems(); 449 String pageno = getParamPage(); 451 if (pageno == null) { 452 pageno = "1"; 453 } 454 if (items != null && items.size() > 0) { 455 int start = 0; 457 int end = getSettings().getUserSettings().getExplorerFileEntries(); 458 start = (Integer.parseInt(pageno) * end) - end; 459 end = (Integer.parseInt(pageno) * end); 460 if (end > items.size()) { 461 end = items.size(); 462 } 463 if (start > end) { 464 start = 0; 465 } 466 for (int i = start; i < end; i++) { 467 468 CmsResource res = (CmsResource)items.get(i); 469 int state = res.getState(); 470 String tdClass; 471 switch (state) { 472 case CmsResource.STATE_CHANGED: 473 tdClass = "fc"; 474 break; 475 case CmsResource.STATE_NEW: 476 tdClass = "fn"; 477 break; 478 default: 479 tdClass = "list"; 480 } 481 String resPath = getCms().getSitePath(res); 482 String resName = CmsResource.getName(resPath); 483 String title = getPropertyValue(res, CmsPropertyDefinition.PROPERTY_TITLE); 484 485 result.append("<tr>\n"); 486 487 result.append(buildGalleryItemListCustomStartCols(res, tdClass)); 489 490 result.append("\t<td class=\""); 492 result.append(tdClass); 493 result.append("\"><a class=\""); 494 result.append(tdClass); 495 result.append("\" HREF=\"javascript: preview(\'"); 496 result.append(resPath); 497 result.append("\');\" title=\""); 498 result.append(key(Messages.GUI_BUTTON_PREVIEW_0)); 499 result.append("\">"); 500 result.append(resName); 501 result.append("</a></td>\n"); 502 result.append("\t<td class=\""); 504 result.append(tdClass); 505 result.append("\">"); 506 result.append(CmsEncoder.escapeXml(title)); 507 result.append("</td>\n"); 508 509 result.append(buildGalleryItemListCustomEndCols(res, tdClass)); 511 512 result.append("</tr>\n"); 513 } 514 } 515 result.append("</table>"); 516 return result.toString(); 517 } 518 519 524 public String buildGallerySelectBox() { 525 526 List galleries = getGalleries(); 527 if (galleries != null && galleries.size() == 1) { 528 CmsResource res = (CmsResource)galleries.get(0); 530 StringBuffer result = new StringBuffer (128); 531 String path = getCms().getSitePath(res); 532 String title = ""; 533 try { 534 title = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue(""); 536 } catch (CmsException e) { 537 LOG.error(e); 539 } 540 result.append(title); 541 result.append(" ("); 542 result.append(path); 543 result.append(" )\r\n"); 544 result.append("<input type=\"hidden\" name=\""); 545 result.append(PARAM_GALLERYPATH); 546 result.append("\" value=\""); 547 result.append(path); 548 result.append("\">"); 549 return result.toString(); 550 } else if (galleries.size() > 1) { 551 int galleryCount = galleries.size(); 553 List options = new ArrayList (galleryCount); 554 List values = new ArrayList (galleryCount); 555 int selectedIndex = -1; 556 for (int i = 0; i < galleryCount; i++) { 557 CmsResource res = (CmsResource)galleries.get(i); 558 String path = getCms().getSitePath(res); 559 if (path.equals(getParamGalleryPath())) { 560 selectedIndex = i; 561 } 562 String title = ""; 563 try { 564 title = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue(""); 566 } catch (CmsException e) { 567 if (LOG.isErrorEnabled()) { 569 LOG.error(e); 570 } 571 } 572 options.add(title + " (" + path + ")"); 573 values.add(path); 574 575 } 576 selectedIndex = sortOptions(options, values); 577 String attrs = "name=\"" + PARAM_GALLERYPATH; 578 attrs += "\" size=\"1\" style=\"width: 100%;\" onchange=\"displayGallery();\""; 579 return buildSelect(attrs, options, values, selectedIndex); 580 } else { 581 StringBuffer result = new StringBuffer (128); 583 result.append(key(Messages.getGalleryNotFoundKey(getGalleryTypeName()))); 584 result.append("\r\n<input type=\"hidden\" name=\""); 585 result.append(PARAM_GALLERYPATH); 586 result.append("\">"); 587 return result.toString(); 588 } 589 } 590 591 596 public String buildPageSelectBox() { 597 598 StringBuffer html = new StringBuffer (16); 599 List items = getGalleryItems(); 600 String pageno = getParamPage(); 602 if (pageno == null) { 603 pageno = "1"; 604 } 605 int count = 0; 606 int pages = 1; 607 int rest = 0; 608 int maxentries = getSettings().getUserSettings().getExplorerFileEntries(); 610 611 if (items != null) { 612 count = items.size(); 613 } 614 if (count > maxentries) { 616 pages = count / maxentries; 617 rest = count % maxentries; 618 if (rest > 0) { 619 rest = 1; 620 } else { 621 rest = 0; 622 } 623 pages += rest; 624 } 625 if (pages > 1) { 627 html.append("<select name=\"page\" class=\"location\" onchange=\"displayGallery();\">"); 628 String selected = ""; 629 for (int i = 1; i < pages + 1; i++) { 630 if (i == Integer.parseInt(pageno)) { 631 selected = " selected=\"selected\""; 632 } 633 html.append("<option value='"); 634 html.append(i); 635 html.append("'"); 636 html.append(selected); 637 html.append(">"); 638 html.append(i); 639 html.append("</option>"); 640 selected = ""; 641 } 642 html.append("</select>"); 643 } 644 645 return html.toString(); 646 } 647 648 653 public int compareTo(Object o) { 654 655 if (!(o instanceof A_CmsGallery)) { 656 return 0; 658 } 659 660 return getOrder().compareTo(((A_CmsGallery)o).getOrder()); 662 } 663 664 673 public String deleteButton() { 674 675 try { 676 if (hasWritePermissions()) { 677 return button( 678 "javascript:deleteResource(\'" + getParamResourcePath() + "\');", 679 null, 680 "deletecontent.png", 681 Messages.GUI_TITLE_DELETE_0, 682 0); 683 } 684 } catch (CmsException e) { 685 if (LOG.isErrorEnabled()) { 687 LOG.error(e); 688 } 689 } 690 return button(null, null, "deletecontent_in.png", "", 0); 691 } 692 693 702 public String editPropertyButton() { 703 704 try { 705 if (hasWritePermissions()) { 706 return button( 707 "javascript:editProperty('" + getParamResourcePath() + "');", 708 null, 709 "edit.png", 710 Messages.GUI_INPUT_EDITPROPERTYINFO_0, 711 0); 712 } 713 } catch (CmsException e) { 714 LOG.error(e); 716 } 717 return button(null, null, "edit_in.png", "", 0); 718 } 719 720 725 public boolean galleriesExists() { 726 727 List galleries = getGalleries(); 728 if (galleries != null && galleries.size() > 0) { 729 return true; 731 } 732 return false; 733 } 734 735 740 public String getBodyOnload() { 741 742 StringBuffer onload = new StringBuffer (); 743 onload.append("self.focus();"); 744 if (CmsStringUtil.isEmpty(getParamGalleryPath())) { 745 onload.append("displayGallery();"); 746 } 747 748 return onload.toString(); 749 } 750 751 756 public String getCssPath() { 757 758 return getJsp().link(PATH_GALLERIES + CSS_FILENAME); 759 } 760 761 766 public CmsResource getCurrentResource() { 767 768 return m_currentResource; 769 } 770 771 776 public List getGalleries() { 777 778 List galleries = null; 779 int galleryTypeId = getGalleryTypeId(); 780 try { 781 galleries = getCms().readResources( 783 "/", 784 CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(galleryTypeId)); 785 } catch (CmsException e) { 786 LOG.error(e); 788 } 789 790 if (!getCms().getRequestContext().getSiteRoot().equals("")) { 792 List systemGalleries = null; 793 try { 794 systemGalleries = getCms().readResources( 796 CmsWorkplace.VFS_PATH_SYSTEM, 797 CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(galleryTypeId)); 798 } catch (CmsException e) { 799 LOG.error(e); 801 } 802 803 if (systemGalleries != null && systemGalleries.size() > 0) { 804 galleries.addAll(systemGalleries); 806 } 807 } 808 809 return galleries; 811 } 812 813 818 public List getGalleryItems() { 819 820 if (m_galleryItems == null) { 821 int resTypeId = getGalleryItemsTypeId(); 823 if (CmsStringUtil.isNotEmpty(getParamGalleryPath())) { 824 try { 825 getSettings().setLastUsedGallery(getGalleryTypeId(), getParamGalleryPath()); 827 CmsResourceFilter filter; 828 if (resTypeId == -1) { 829 filter = CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireFile(); 831 } else { 832 filter = CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(resTypeId); 834 } 835 m_galleryItems = getCms().readResources(getParamGalleryPath(), filter, false); 836 } catch (CmsException e) { 837 LOG.error(e); 839 } catch (NullPointerException e) { 840 } 842 } 843 } 844 List items = m_galleryItems; 845 if (CmsStringUtil.isNotEmpty(getParamSearchWord())) { 847 items = getSearchHits(m_galleryItems); 848 } 849 return items; 850 } 851 852 859 public abstract int getGalleryItemsTypeId(); 860 861 866 public int getGalleryTypeId() { 867 868 return m_galleryTypeId; 869 } 870 871 876 public String getGalleryTypeName() { 877 878 return m_galleryTypeName; 879 } 880 881 886 public String getGalleryTypeParams() { 887 888 return m_galleryTypeParams; 889 } 890 891 896 public String getHeadFrameSetHeight() { 897 898 return "280"; 899 } 900 901 906 public String getKeyTitle() { 907 908 return key(Messages.getTitleGalleryKey(getGalleryTypeName())); 909 } 910 911 916 public String getNoGalleryErrorMsg() { 917 918 return key(Messages.getGalleryNotFoundKey(getGalleryTypeName())); 919 } 920 921 926 public Integer getOrder() { 927 928 return new Integer (Integer.MAX_VALUE); 929 } 930 931 938 public String getParamDialogMode() { 939 940 if (m_paramDialogMode == null) { 941 return ""; 942 } 943 return m_paramDialogMode; 944 } 945 946 951 public String getParamFieldId() { 952 953 return m_paramFieldId; 954 } 955 956 961 public String getParamGalleryPath() { 962 963 if (CmsStringUtil.isEmpty(m_paramGalleryPath)) { 964 m_paramGalleryPath = ""; 965 } 966 return m_paramGalleryPath; 967 } 968 969 974 public String getParamPage() { 975 976 return m_paramPage; 977 } 978 979 984 public String getParamPropertyValue() { 985 986 return m_paramPropertyValue; 987 } 988 989 994 public String getParamResourcePath() { 995 996 return m_paramResourcePath; 997 } 998 999 1004 public String getParamSearchWord() { 1005 1006 if (CmsStringUtil.isEmpty(m_paramSearchWord)) { 1007 m_paramSearchWord = ""; 1008 } 1009 return m_paramSearchWord; 1010 } 1011 1012 1017 public String getPreviewBodyStyle() { 1018 1019 return new String (" class=\"dialog\" style=\"background-color: ThreeDFace;\" unselectable=\"on\""); 1020 } 1021 1022 1027 public String getPreviewDivStyle() { 1028 1029 return new String ("style=\"text-align: center; width: 100%; margin-top: 5px\""); 1030 } 1031 1032 1037 public CmsResourceTypeFolderExtended getResourceType() { 1038 1039 return m_resourceType; 1040 } 1041 1042 1047 public String getWizardUrl() { 1048 1049 StringBuffer wizardUrl = new StringBuffer (16); 1050 wizardUrl.append(getJsp().link( 1051 PATH_DIALOGS + OpenCms.getWorkplaceManager().getExplorerTypeSetting("upload").getNewResourceUri())); 1052 wizardUrl.append("?"); 1053 wizardUrl.append(CmsNewResourceUpload.PARAM_REDIRECTURL); 1054 wizardUrl.append("="); 1055 wizardUrl.append(PATH_GALLERIES); 1056 wizardUrl.append("gallery_list.jsp&"); 1057 wizardUrl.append(CmsNewResourceUpload.PARAM_TARGETFRAME); 1058 wizardUrl.append("=gallery_list&"); 1059 wizardUrl.append(CmsNewResource.PARAM_CURRENTFOLDER); 1060 wizardUrl.append("="); 1061 return wizardUrl.toString(); 1062 } 1063 1064 1067 public void init() { 1068 1069 } 1071 1072 1079 public String previewButton() { 1080 1081 StringBuffer previewButton = new StringBuffer (8); 1082 previewButton.append(buttonBarSeparator(5, 5)); 1083 previewButton.append(button( 1084 getJsp().link(getCms().getSitePath(getCurrentResource())), 1085 "_preview", 1086 "preview.png", 1087 Messages.GUI_BUTTON_PREVIEW_0, 1088 0)); 1089 return previewButton.toString(); 1090 } 1091 1092 1102 public String previewRow(String column1, String column2) { 1103 1104 StringBuffer previewRow = new StringBuffer (); 1105 previewRow.append("<tr align=\"left\">"); 1106 previewRow.append("<td><b>"); 1107 previewRow.append(column1); 1108 previewRow.append("</b></td>"); 1109 previewRow.append("<td>"); 1110 previewRow.append(column2); 1111 previewRow.append("</td>"); 1112 previewRow.append("</tr>"); 1113 1114 return previewRow.toString(); 1115 1116 } 1117 1118 1125 public String publishButton() { 1126 1127 if (getCms().hasPublishPermissions(getParamResourcePath())) { 1128 return button( 1129 "javascript:publishResource(\'" + getParamResourcePath() + "\');", 1130 null, 1131 "publish.png", 1132 Messages.GUI_MESSAGEBOX_TITLE_PUBLISHRESOURCE_0, 1133 0); 1134 } 1135 return button(null, null, "publish_in.png", "", 0); 1136 } 1137 1138 1143 public String searchButton() { 1144 1145 return button("javascript:displayGallery();", null, "search.png", Messages.GUI_INPUT_SEARCH_0, 0); 1146 } 1147 1148 1153 public void setCurrentResource(CmsResource currentResource) { 1154 1155 m_currentResource = currentResource; 1156 } 1157 1158 1165 public void setParamDialogMode(String dialogMode) { 1166 1167 m_paramDialogMode = dialogMode; 1168 } 1169 1170 1175 public void setParamFieldId(String fieldId) { 1176 1177 m_paramFieldId = fieldId; 1178 } 1179 1180 1185 public void setParamGalleryPath(String galleryPath) { 1186 1187 m_paramGalleryPath = galleryPath; 1188 } 1189 1190 1195 public void setParamPage(String page) { 1196 1197 m_paramPage = page; 1198 } 1199 1200 1205 public void setParamPropertyValue(String paramPropertyValue) { 1206 1207 m_paramPropertyValue = paramPropertyValue; 1208 } 1209 1210 1215 public void setParamResourcePath(String resourcePath) { 1216 1217 m_paramResourcePath = resourcePath; 1218 } 1219 1220 1225 public void setParamSearchWord(String searchWord) { 1226 1227 m_paramSearchWord = searchWord; 1228 } 1229 1230 1235 public void setResourceType(CmsResourceTypeFolderExtended type) { 1236 1237 m_resourceType = type; 1238 } 1239 1240 1245 public String targetSelectBox() { 1246 1247 StringBuffer targetSelectBox = new StringBuffer (32); 1248 targetSelectBox.append(buttonBarSpacer(5)); 1249 targetSelectBox.append("<td nowrap><b>"); 1250 targetSelectBox.append(key(Messages.GUI_INPUT_LINKTARGET_0)); 1251 targetSelectBox.append("</b> </td>"); 1252 targetSelectBox.append("<td>\r\n"); 1253 targetSelectBox.append("<select name=\"linktarget\" id=\"linktarget\" size=\"1\" style=\"width:150px\""); 1254 if (MODE_VIEW.equals(getParamDialogMode())) { 1255 targetSelectBox.append(" disabled=\"disabled\""); 1256 } 1257 targetSelectBox.append(">"); 1258 targetSelectBox.append(getTargetOptions()); 1259 targetSelectBox.append("</select>"); 1260 targetSelectBox.append("</td>"); 1261 1262 return targetSelectBox.toString(); 1263 } 1264 1265 1270 public String wizardButton() { 1271 1272 return button("javascript:wizard();", null, "upload.png", OpenCms.getWorkplaceManager().getExplorerTypeSetting( 1273 "upload").getKey(), 0); 1274 } 1275 1276 1284 protected String buildGalleryItemListCustomEndCols(CmsResource res, String tdClass) { 1285 1286 StringBuffer result = new StringBuffer (64); 1287 result.append("\t<td class=\""); 1288 result.append(tdClass); 1289 result.append("\" style=\"text-align: right;\">"); 1290 result.append(res.getLength() / 1024); 1291 result.append(" "); 1292 result.append(key(Messages.GUI_LABEL_KILOBYTES_0)); 1293 result.append("</td>\n"); 1294 return result.toString(); 1295 } 1296 1297 1305 protected String buildGalleryItemListCustomStartCols(CmsResource res, String tdClass) { 1306 1307 String resType; 1308 try { 1309 resType = OpenCms.getResourceManager().getResourceType(res.getTypeId()).getTypeName(); 1311 } catch (CmsLoaderException e) { 1312 resType = null; 1314 } 1315 StringBuffer result = new StringBuffer (64); 1316 result.append("\t<td>"); 1317 if ((resType != null) && (tdClass != null)) { 1318 result.append("<img SRC=\""); 1319 result.append(getSkinUri()); 1320 result.append("filetypes/"); 1321 result.append(resType); 1322 result.append(".gif\">"); 1323 } 1324 result.append("</td>\n"); 1325 return result.toString(); 1326 } 1327 1328 1333 protected String buildGalleryItemListHeadline() { 1334 1335 StringBuffer headline = new StringBuffer (32); 1336 headline.append("<tr>"); 1337 headline.append("<td class=\"headline\"> </td>"); 1338 headline.append("<td class=\"headline\" width=\"35%\">"); 1339 headline.append(key(Messages.GUI_LABEL_NAME_0)); 1340 headline.append("</td>"); 1341 headline.append("<td class=\"headline\" width=\"55%\">"); 1342 headline.append(key(Messages.GUI_LABEL_TITLE_0)); 1343 headline.append("</td>"); 1344 headline.append("<td class=\"headline\" style=\"text-align: right;\" width=\"10%\">"); 1345 headline.append(key(Messages.GUI_LABEL_SIZE_0)); 1346 headline.append("</td>"); 1347 headline.append("</tr>"); 1348 1349 return headline.toString(); 1350 } 1351 1352 1361 protected String getPropertyValue(CmsResource resource, String propertydefinition) { 1362 1363 String value = ""; 1364 if (resource != null) { 1365 String resPath = getCms().getSitePath(resource); 1366 String resName = CmsResource.getName(resPath); 1367 try { 1368 CmsProperty property = getCms().readPropertyObject(resPath, propertydefinition, false); 1369 value = property.getValue("[" + resName + "]"); 1371 } catch (CmsException e) { 1372 LOG.error(e); 1374 } 1375 } 1376 return value; 1377 } 1378 1379 1387 protected List getSearchHits(List items) { 1388 1389 String searchword = getParamSearchWord().toLowerCase(); 1390 List hitlist = new ArrayList (); 1391 if (items != null) { 1392 Iterator i = items.iterator(); 1393 while (i.hasNext()) { 1394 CmsResource res = (CmsResource)i.next(); 1395 String resname = res.getName().toLowerCase(); 1396 String restitle = getJsp().property( 1397 CmsPropertyDefinition.PROPERTY_TITLE, 1398 getCms().getSitePath(res), 1399 resname).toLowerCase(); 1400 if (restitle.indexOf(searchword) != -1 || resname.indexOf(searchword) != -1) { 1401 hitlist.add(res); 1403 } 1404 } 1405 } 1406 1407 return hitlist; 1408 } 1409 1410 1415 protected String getTargetOptions() { 1416 1417 StringBuffer options = new StringBuffer (); 1418 options.append("<option value=\"_self\">"); 1419 options.append(key(Messages.GUI_INPUT_LINKTARGETSELF_0)); 1420 options.append("</option>\r\n"); 1421 options.append("<option value=\"_blank\">"); 1422 options.append(key(Messages.GUI_INPUT_LINKTARGETBLANK_0)); 1423 options.append("</option>\r\n"); 1424 options.append("<option value=\"_top\">"); 1425 options.append(key(Messages.GUI_INPUT_LINKTARGETTOP_0)); 1426 options.append("</option>\r\n"); 1427 1428 return options.toString(); 1429 } 1430 1431 1437 protected boolean hasWritePermissions() throws CmsException { 1438 1439 return getCms().hasPermissions( 1440 getCurrentResource(), 1441 CmsPermissionSet.ACCESS_WRITE, 1442 false, 1443 CmsResourceFilter.ALL); 1444 } 1445 1446 1449 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 1450 1451 fillParamValues(request); 1453 setParamDialogtype(DIALOG_TYPE); 1455 if (CmsStringUtil.isEmpty(getParamGalleryPath())) { 1456 String lastUsedGallery = getSettings().getLastUsedGallery(getGalleryTypeId()); 1457 if (CmsStringUtil.isNotEmpty(lastUsedGallery)) { 1458 try { 1460 getCms().readResource(lastUsedGallery, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED); 1461 setParamGalleryPath(lastUsedGallery); 1462 } catch (CmsException e) { 1463 } 1465 } 1466 } 1467 } 1468 1469 1477 protected int sortOptions(List options, List values) { 1478 1479 int selectedIndex = -1; 1480 Map valuesByOption = new TreeMap (); 1481 1482 for (int i = 0, n = options.size(); i < n; i++) { 1484 1485 String option = (String )options.get(i); 1486 String value = (String )values.get(i); 1487 1488 if (CmsStringUtil.isNotEmpty(option) && CmsStringUtil.isNotEmpty(value)) { 1489 valuesByOption.put(option, value); 1490 } 1491 } 1492 1493 values.clear(); 1495 options.clear(); 1496 1497 Iterator it = valuesByOption.keySet().iterator(); 1499 while (it.hasNext()) { 1500 String option = (String )it.next(); 1501 String value = (String )valuesByOption.get(option); 1502 1503 if (value.equals(getParamGalleryPath())) { 1504 selectedIndex = options.size(); 1505 } 1506 1507 options.add(option); 1508 values.add(value); 1509 } 1510 1511 return selectedIndex; 1512 } 1513 1514 1519 protected void writeTitleProperty(CmsResource res) { 1520 1521 String resPath = getCms().getSitePath(res); 1522 String currentPropertyValue = getParamPropertyValue(); 1523 try { 1524 CmsProperty currentProperty = getCms().readPropertyObject( 1525 resPath, 1526 CmsPropertyDefinition.PROPERTY_TITLE, 1527 false); 1528 if (currentProperty.isNullProperty()) { 1530 currentProperty = new CmsProperty(); 1532 currentProperty.setName(CmsPropertyDefinition.PROPERTY_TITLE); 1533 if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) { 1534 currentProperty.setStructureValue(currentPropertyValue); 1536 currentProperty.setResourceValue(null); 1537 } else { 1538 currentProperty.setStructureValue(null); 1540 currentProperty.setResourceValue(currentPropertyValue); 1541 } 1542 } else if (currentProperty.getStructureValue() != null) { 1543 currentProperty.setStructureValue(currentPropertyValue); 1545 currentProperty.setResourceValue(null); 1546 } else { 1547 currentProperty.setStructureValue(null); 1549 currentProperty.setResourceValue(currentPropertyValue); 1550 } 1551 CmsLock lock = getCms().getLock(res); 1552 if (lock.getType() == CmsLock.TYPE_UNLOCKED) { 1553 getCms().lockResource(resPath); 1555 } 1556 getCms().writePropertyObject(resPath, currentProperty); 1558 getCms().unlockResource(resPath); 1560 } catch (CmsException e) { 1561 LOG.error(e); 1563 } 1564 } 1565} | Popular Tags |