1 31 32 package org.opencms.workplace; 33 34 import org.opencms.file.CmsResource; 35 import org.opencms.file.CmsResourceFilter; 36 import org.opencms.i18n.CmsMessageContainer; 37 import org.opencms.jsp.CmsJspActionElement; 38 import org.opencms.main.CmsException; 39 import org.opencms.main.CmsLog; 40 import org.opencms.main.OpenCms; 41 import org.opencms.security.CmsPermissionSet; 42 import org.opencms.util.CmsRequestUtil; 43 import org.opencms.util.CmsStringUtil; 44 import org.opencms.workplace.tools.CmsToolDialog; 45 import org.opencms.workplace.tools.CmsToolManager; 46 47 import java.io.IOException ; 48 import java.util.HashMap ; 49 import java.util.Map ; 50 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 import javax.servlet.jsp.JspException ; 54 import javax.servlet.jsp.JspWriter ; 55 import javax.servlet.jsp.PageContext ; 56 57 import org.apache.commons.logging.Log; 58 59 68 public class CmsDialog extends CmsToolDialog { 69 70 71 public static final int ACTION_CANCEL = 4; 72 73 74 public static final int ACTION_CLOSEPOPUP = 6; 75 76 77 public static final int ACTION_CLOSEPOPUP_SAVE = 7; 78 79 80 public static final int ACTION_CONFIRMED = 1; 81 82 83 public static final int ACTION_DEFAULT = 0; 84 85 86 public static final int ACTION_OK = 3; 87 88 90 public static final int ACTION_REPORT_BEGIN = 90; 91 92 93 public static final int ACTION_REPORT_END = 92; 94 95 96 public static final int ACTION_REPORT_UPDATE = 91; 97 98 99 public static final int ACTION_SET = 5; 100 101 102 public static final int ACTION_WAIT = 2; 103 104 105 public static final int BUTTON_ADVANCED = 3; 106 107 108 public static final int BUTTON_BACK = 9; 109 110 111 public static final int BUTTON_CANCEL = 1; 112 113 114 public static final int BUTTON_CLOSE = 2; 115 116 117 public static final int BUTTON_CONTINUE = 10; 118 119 120 public static final int BUTTON_DETAILS = 5; 121 122 123 public static final int BUTTON_DISCARD = 8; 124 125 126 public static final int BUTTON_EDIT = 7; 127 128 129 public static final int BUTTON_OK = 0; 130 131 132 public static final int BUTTON_OK_NO_SUBMIT = 6; 133 134 135 public static final int BUTTON_SET = 4; 136 137 138 public static final String DIALOG_BACK = "back"; 139 140 141 public static final String DIALOG_CANCEL = "cancel"; 142 143 144 public static final String DIALOG_CONFIRMED = "confirmed"; 145 146 147 public static final String DIALOG_CONTINUE = "continue"; 148 149 150 public static final String DIALOG_INITIAL = "initial"; 151 152 153 public static final String DIALOG_OK = "ok"; 154 155 156 public static final String DIALOG_SET = "set"; 157 158 159 public static final String DIALOG_WAIT = "wait"; 160 161 162 public static final String PARAM_ACTION = "action"; 163 164 165 public static final String PARAM_CLOSELINK = "closelink"; 166 167 168 public static final String PARAM_DIALOGTYPE = "dialogtype"; 169 170 171 public static final String PARAM_ERRORSTACK = "errorstack"; 172 173 174 public static final String PARAM_FILE = "file"; 175 176 177 public static final String PARAM_FRAMENAME = "framename"; 178 179 180 public static final String PARAM_ISPOPUP = "ispopup"; 181 182 183 public static final String PARAM_LOCK = "lock"; 184 185 186 public static final String PARAM_MESSAGE = "message"; 187 188 189 public static final String PARAM_REDIRECT = "redirect"; 190 191 192 public static final String PARAM_RESOURCE = "resource"; 193 194 195 public static final String PARAM_TARGET = "target"; 196 197 198 public static final String PARAM_THREAD = "thread"; 199 200 201 public static final String PARAM_THREAD_HASNEXT = "threadhasnext"; 202 203 204 public static final String PARAM_TITLE = "title"; 205 206 207 public static final String REPORT_BEGIN = "reportbegin"; 208 209 210 public static final String REPORT_END = "reportend"; 211 212 213 public static final String REPORT_UPDATE = "reportupdate"; 214 215 216 protected static final String ATTRIBUTE_THROWABLE = "throwable"; 217 218 219 private static final Log LOG = CmsLog.getLog(CmsDialog.class); 220 221 private int m_action; 222 223 231 private String m_onlineHelpUriCustom; 232 private String m_paramAction; 233 private String m_paramCloseLink; 234 private String m_paramDialogtype; 235 private String m_paramFrameName; 236 private String m_paramIsPopup; 237 private String m_paramMessage; 238 private String m_paramRedirect; 239 private String m_paramResource; 240 private String m_paramTitle; 241 242 247 public CmsDialog(CmsJspActionElement jsp) { 248 249 super(jsp); 250 } 251 252 259 public CmsDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 260 261 this(new CmsJspActionElement(context, req, res)); 262 } 263 264 281 public static CmsDialog initCmsDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 282 283 CmsDialog wp = (CmsDialog)req.getAttribute(CmsWorkplace.SESSION_WORKPLACE_CLASS); 284 if (wp == null) { 285 wp = new CmsDialog(new CmsJspActionElement(context, req, res)); 287 wp.fillParamValues(req); 288 } 289 return wp; 290 } 291 292 301 public void actionCloseDialog() throws JspException { 302 303 Map params = new HashMap (); 305 params.put(PARAM_RESOURCE, ""); 306 if (isPopup()) { 307 try { 308 JspWriter out = getJsp().getJspContext().getOut(); 310 out.write("<html><head></head>\n"); 311 out.write("<body onload=\"top.close();\">\n"); 312 out.write("</body>\n"); 313 out.write("</html>\n"); 314 } catch (IOException e) { 315 getJsp().include(FILE_EXPLORER_FILELIST, null, params); 317 } 318 } else if (getParamCloseLink() != null) { 319 try { 321 if (Boolean.valueOf(getParamRedirect()).booleanValue()) { 322 getJsp().getResponse().sendRedirect(getParamCloseLink()); 324 } else { 325 if (!isForwarded()) { 327 setForwarded(true); 328 CmsRequestUtil.forwardRequest( 329 getParamCloseLink(), 330 getJsp().getRequest(), 331 getJsp().getResponse()); 332 } 333 } 334 } catch (Exception e) { 335 throw new JspException (e.getMessage(), e); 337 } 338 } else if (getParamFramename() != null) { 339 342 String frameUri = (String )getSettings().getFrameUris().get(getParamFramename()); 344 if (frameUri != null) { 345 if (frameUri.startsWith(OpenCms.getSystemInfo().getOpenCmsContext())) { 347 frameUri = frameUri.substring(OpenCms.getSystemInfo().getOpenCmsContext().length()); 349 } 350 if (frameUri.endsWith("administration_content_top.html")) { 351 String wpClass = this.getClass().getName(); 352 String wpPackage = this.getClass().getPackage().getName(); 353 if ((wpPackage.endsWith("commons") || wpPackage.endsWith("gallery")) 354 && (!wpClass.endsWith("Report"))) { 355 getJsp().include(FILE_EXPLORER_FILELIST, null, params); 357 } else { 358 try { 359 getJsp().getResponse().sendRedirect( 361 getJsp().link(frameUri) + "?sender=/system/workplace/administration/"); 362 } catch (IOException e) { 363 params.put("sender", "/system/workplace/administration/"); 364 getJsp().include(frameUri, null, params); 365 } 366 } 367 } else { 368 getJsp().include(frameUri, null, params); 370 } 371 } else { 372 getJsp().include(FILE_EXPLORER_FILELIST, null, params); 374 } 375 } else { 376 getJsp().include(FILE_EXPLORER_FILELIST, null, params); 378 } 379 } 380 381 388 public String dialog(int segment, String attributes) { 389 390 if (segment == HTML_START) { 391 StringBuffer html = new StringBuffer (512); 392 if (useNewStyle()) { 393 html.append(dialogTitle()); 394 } 395 html.append("<table class=\"dialog\" cellpadding=\"0\" cellspacing=\"0\""); 396 if (attributes != null) { 397 html.append(" "); 398 html.append(attributes); 399 } 400 html.append("><tr><td>\n<table class=\"dialogbox\" cellpadding=\"0\" cellspacing=\"0\">\n"); 401 html.append("<tr><td>\n"); 402 if (useNewStyle() && getToolManager().hasToolPathForUrl(getJsp().getRequestContext().getUri())) { 403 html.append(getAdminTool().groupHtml(this)); 404 } 405 return html.toString(); 406 } else { 407 return "</td></tr></table>\n</td></tr></table>\n<p> </p>\n"; 408 } 409 } 410 411 419 public String dialogBlock(int segment, String headline, boolean error) { 420 421 if (segment == HTML_START) { 422 StringBuffer result = new StringBuffer (512); 423 String errorStyle = ""; 424 if (error) { 425 errorStyle = " dialogerror"; 426 } 427 result.append("<!-- 3D block start -->\n"); 428 result.append("<fieldset class=\"dialogblock\">\n"); 429 if (CmsStringUtil.isNotEmpty(headline)) { 430 result.append("<legend>"); 431 result.append("<span class=\"textbold"); 432 result.append(errorStyle); 433 result.append("\" unselectable=\"on\">"); 434 result.append(headline); 435 result.append("</span></legend>\n"); 436 } 437 return result.toString(); 438 } else { 439 return "</fieldset>\n<!-- 3D block end -->\n"; 440 } 441 } 442 443 448 public String dialogBlockEnd() { 449 450 return dialogBlock(HTML_END, null, false); 451 } 452 453 459 public String dialogBlockStart(String headline) { 460 461 return dialogBlock(HTML_START, headline, false); 462 } 463 464 470 public String dialogButtonRow(int segment) { 471 472 if (segment == HTML_START) { 473 return "<!-- button row start -->\n<div class=\"dialogbuttons\" unselectable=\"on\">\n"; 474 } else { 475 return "</div>\n<!-- button row end -->\n"; 476 } 477 } 478 479 484 public String dialogButtonRowEnd() { 485 486 return dialogButtonRow(HTML_END); 487 } 488 489 494 public String dialogButtonRowStart() { 495 496 return dialogButtonRow(HTML_START); 497 } 498 499 506 public String dialogButtons(int[] buttons, String [] attributes) { 507 508 StringBuffer result = new StringBuffer (256); 509 result.append(dialogButtonRow(HTML_START)); 510 for (int i = 0; i < buttons.length; i++) { 511 dialogButtonsHtml(result, buttons[i], attributes[i]); 512 } 513 result.append(dialogButtonRow(HTML_END)); 514 return result.toString(); 515 } 516 517 522 public String dialogButtonsClose() { 523 524 return dialogButtons(new int[] {BUTTON_CLOSE}, new String [1]); 525 } 526 527 533 public String dialogButtonsClose(String closeAttribute) { 534 535 return dialogButtons(new int[] {BUTTON_CLOSE}, new String [] {closeAttribute}); 536 } 537 538 545 public String dialogButtonsCloseDetails(String closeAttribute, String detailsAttribute) { 546 547 return dialogButtons(new int[] {BUTTON_CLOSE, BUTTON_DETAILS}, new String [] {closeAttribute, detailsAttribute}); 548 } 549 550 555 public String dialogButtonsOk() { 556 557 return dialogButtons(new int[] {BUTTON_OK}, new String [1]); 558 } 559 560 566 public String dialogButtonsOk(String okAttribute) { 567 568 return dialogButtons(new int[] {BUTTON_OK}, new String [] {okAttribute}); 569 } 570 571 576 public String dialogButtonsOkCancel() { 577 578 return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL}, new String [2]); 579 } 580 581 588 public String dialogButtonsOkCancel(String okAttributes, String cancelAttributes) { 589 590 return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL}, new String [] {okAttributes, cancelAttributes}); 591 } 592 593 601 public String dialogButtonsOkCancelAdvanced(String okAttributes, String cancelAttributes, String advancedAttributes) { 602 603 return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_ADVANCED}, new String [] { 604 okAttributes, 605 cancelAttributes, 606 advancedAttributes}); 607 } 608 609 617 public String dialogButtonsSetOkCancel(String setAttributes, String okAttributes, String cancelAttributes) { 618 619 return dialogButtons(new int[] {BUTTON_SET, BUTTON_OK, BUTTON_CANCEL}, new String [] { 620 setAttributes, 621 okAttributes, 622 cancelAttributes}); 623 } 624 625 632 public String dialogContent(int segment, String title) { 633 634 if (segment == HTML_START) { 635 StringBuffer result = new StringBuffer (512); 636 result.append(dialogHead(title)); 638 result.append("<div class=\"dialogcontent\" unselectable=\"on\">\n"); 639 result.append("<!-- dialogcontent start -->\n"); 640 return result.toString(); 641 } else { 642 return "<!-- dialogcontent end -->\n</div>\n"; 643 } 644 } 645 646 651 public String dialogContentEnd() { 652 653 return dialogContent(HTML_END, null); 654 } 655 656 662 public String dialogContentStart(String title) { 663 664 return dialogContent(HTML_START, title); 665 } 666 667 672 public String dialogEnd() { 673 674 return dialog(HTML_END, null); 675 } 676 677 683 public String dialogHead(String title) { 684 685 return "<div class=\"dialoghead\" unselectable=\"on\">" + (title == null ? "" : title) + "</div>"; 686 } 687 688 693 public String dialogHorizontalSpacer(int width) { 694 695 return "<td><span style=\"display:block; height: 1px; width: " + width + "px;\"></span></td>"; 696 } 697 698 704 public String dialogRow(int segment) { 705 706 if (segment == HTML_START) { 707 return "<div class=\"dialogrow\">"; 708 } else { 709 return "</div>\n"; 710 } 711 } 712 713 718 public String dialogRowEnd() { 719 720 return dialogRow(HTML_END); 721 } 722 723 728 public String dialogRowStart() { 729 730 return dialogRow(HTML_START); 731 } 732 733 738 public String dialogScriptSubmit() { 739 740 if (useNewStyle()) { 741 return super.dialogScriptSubmit(); 742 } 743 StringBuffer result = new StringBuffer (512); 744 result.append("function submitAction(actionValue, theForm, formName) {\n"); 745 result.append("\tif (theForm == null) {\n"); 746 result.append("\t\ttheForm = document.forms[formName];\n"); 747 result.append("\t}\n"); 748 result.append("\ttheForm." + PARAM_FRAMENAME + ".value = window.name;\n"); 749 result.append("\tif (actionValue == \"" + DIALOG_OK + "\") {\n"); 750 result.append("\t\treturn true;\n"); 751 result.append("\t}\n"); 752 result.append("\ttheForm." + PARAM_ACTION + ".value = actionValue;\n"); 753 result.append("\ttheForm.submit();\n"); 754 result.append("\treturn false;\n"); 755 result.append("}\n"); 756 757 return result.toString(); 758 } 759 760 765 public String dialogSeparator() { 766 767 return "<div class=\"dialogseparator\" unselectable=\"on\"></div>"; 768 } 769 770 775 public String dialogSpacer() { 776 777 return "<div class=\"dialogspacer\" unselectable=\"on\"> </div>"; 778 } 779 780 785 public String dialogStart() { 786 787 return dialog(HTML_START, null); 788 } 789 790 796 public String dialogStart(String attributes) { 797 798 return dialog(HTML_START, attributes); 799 } 800 801 807 public String dialogSubheadline(String headline) { 808 809 StringBuffer retValue = new StringBuffer (128); 810 retValue.append("<div class=\"dialogsubheader\" unselectable=\"on\">"); 811 retValue.append(headline); 812 retValue.append("</div>\n"); 813 return retValue.toString(); 814 } 815 816 825 public String dialogToggleStart(String headline, String id, boolean show) { 826 827 StringBuffer result = new StringBuffer (512); 828 String image = "plus.png"; 830 String styleClass = "hide"; 831 if (show) { 832 image = "minus.png"; 834 styleClass = "show"; 835 } 836 837 result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"); 838 result.append("<tr>\n"); 839 result.append("\t<td style=\"vertical-align: bottom; padding-bottom: 2px;\"><a HREF=\"javascript:toggleDetail('"); 840 result.append(id); 841 result.append("');\"><img SRC=\""); 842 result.append(getSkinUri()); 843 result.append("commons/"); 844 result.append(image); 845 result.append("\" class=\"noborder\" id=\"ic-"); 846 result.append(id); 847 result.append("\"></a></td>\n"); 848 result.append("\t<td>"); 849 result.append(dialogSubheadline(headline)); 850 result.append("</td>\n"); 851 result.append("</tr>\n"); 852 result.append("</table>\n"); 853 854 result.append("<div class=\""); 855 result.append(styleClass); 856 result.append("\" id=\""); 857 result.append(id); 858 result.append("\">\n"); 859 return result.toString(); 860 } 861 862 868 public String dialogWhiteBox(int segment) { 869 870 if (segment == HTML_START) { 871 return "<!-- white box start -->\n" 872 + "<div class=\"dialoginnerboxborder\">\n" 873 + "<div class=\"dialoginnerbox\" unselectable=\"off\">\n"; 874 } else { 875 return "</div>\n</div>\n<!-- white box end -->\n"; 876 } 877 } 878 879 884 public String dialogWhiteBoxEnd() { 885 886 return dialogWhiteBox(HTML_END); 887 } 888 889 894 public String dialogWhiteBoxStart() { 895 896 return dialogWhiteBox(HTML_START); 897 } 898 899 907 public int getAction() { 908 909 return m_action; 910 } 911 912 917 public String getCancelAction() { 918 919 return DIALOG_CANCEL; 920 } 921 922 930 public String getDialogRealUri() { 931 932 return getJsp().link(getJsp().getRequestContext().getUri()); 933 } 934 935 943 public String getDialogUri() { 944 945 if (!useNewStyle()) { 946 return getDialogRealUri(); 947 } else { 948 return CmsToolManager.linkForToolPath(getJsp(), getCurrentToolPath()); 949 } 950 } 951 952 957 public String getOnlineHelpUriCustom() { 958 959 if (m_onlineHelpUriCustom == null) { 960 return null; 961 } 962 StringBuffer result = new StringBuffer (m_onlineHelpUriCustom.length() + 4); 963 result.append("\""); 964 result.append(m_onlineHelpUriCustom); 965 result.append("\""); 966 return result.toString(); 967 } 968 969 980 public String getParamAction() { 981 982 return m_paramAction; 983 } 984 985 991 public String getParamCloseLink() { 992 993 if ((m_paramCloseLink == null) || "null".equals(m_paramCloseLink)) { 994 return null; 995 } 996 return m_paramCloseLink; 997 } 998 999 1012 public String getParamDialogtype() { 1013 1014 return m_paramDialogtype; 1015 } 1016 1017 1022 public String getParamFramename() { 1023 1024 if (m_paramFrameName != null && !"null".equals(m_paramFrameName)) { 1025 return m_paramFrameName; 1026 } else { 1027 return null; 1028 } 1029 } 1030 1031 1038 public String getParamIsPopup() { 1039 1040 return m_paramIsPopup; 1041 } 1042 1043 1052 public String getParamMessage() { 1053 1054 return m_paramMessage; 1055 } 1056 1057 1062 public String getParamRedirect() { 1063 1064 return m_paramRedirect; 1065 } 1066 1067 1076 public String getParamResource() { 1077 1078 if (m_paramResource != null && !"null".equals(m_paramResource)) { 1079 return m_paramResource; 1080 } else { 1081 return null; 1082 } 1083 } 1084 1085 1095 public String getParamTitle() { 1096 1097 return m_paramTitle; 1098 } 1099 1100 1106 public String getState() throws CmsException { 1107 1108 if (CmsStringUtil.isNotEmpty(getParamResource())) { 1109 CmsResource file = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 1110 if (getCms().isInsideCurrentProject(getParamResource())) { 1111 return key(Messages.getStateKey(file.getState())); 1112 } else { 1113 return key(Messages.GUI_EXPLORER_STATENIP_0); 1114 } 1115 } 1116 return "+++ resource parameter not found +++"; 1117 } 1118 1119 1125 public String htmlStart() { 1126 1127 return pageHtml(HTML_START, null); 1128 } 1129 1130 1139 public String htmlStart(String helpUrl) { 1140 1141 return pageHtml(HTML_START, helpUrl); 1142 } 1143 1144 1152 public String htmlStart(String helpUrl, String title) { 1153 1154 return pageHtml(HTML_START, helpUrl, title); 1155 } 1156 1157 1165 public String htmlStartStyle(String title, String stylesheet) { 1166 1167 return pageHtmlStyle(HTML_START, title, stylesheet); 1168 } 1169 1170 1177 public void includeErrorpage(CmsWorkplace wp, Throwable t) throws JspException { 1178 1179 CmsLog.getLog(wp).error(Messages.get().getBundle().key(Messages.ERR_WORKPLACE_DIALOG_0), t); 1180 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, wp); 1181 getJsp().getRequest().setAttribute(ATTRIBUTE_THROWABLE, t); 1182 getJsp().include(FILE_DIALOG_SCREEN_ERRORPAGE); 1183 } 1184 1185 1190 public boolean isPopup() { 1191 1192 return Boolean.valueOf(getParamIsPopup()).booleanValue(); 1193 } 1194 1195 1205 public String pageHtml(int segment, String helpUrl) { 1206 1207 return pageHtml(segment, helpUrl, null); 1208 } 1209 1210 1221 public String pageHtml(int segment, String helpUrl, String title) { 1222 1223 if (segment == HTML_START) { 1224 String stylesheet = null; 1225 if (isPopup() && !useNewStyle()) { 1226 stylesheet = "popup.css"; 1227 } 1228 StringBuffer result = new StringBuffer (pageHtmlStyle(segment, title, stylesheet)); 1229 if (getSettings().isViewExplorer()) { 1230 result.append("<script type=\"text/javascript\" SRC=\""); 1231 result.append(getSkinUri()); 1232 result.append("commons/explorer.js\"></script>\n"); 1233 } 1234 result.append("<script type=\"text/javascript\">\n"); 1235 result.append(dialogScriptSubmit()); 1236 if (helpUrl != null) { 1237 result.append("if (top.head && top.head.helpUrl) {\n"); 1238 result.append("\ttop.head.helpUrl=\""); 1239 result.append(helpUrl + "\";\n"); 1240 result.append("}\n\n"); 1241 } 1242 result.append("var onlineHelpUriCustom = "); 1247 result.append(getOnlineHelpUriCustom()); 1248 result.append(";\n"); 1249 1250 result.append("</script>\n"); 1251 return result.toString(); 1252 } else { 1253 return super.pageHtml(segment, null); 1254 } 1255 } 1256 1257 1270 public void setOnlineHelpUriCustom(String uri) { 1271 1272 m_onlineHelpUriCustom = uri; 1273 } 1274 1275 1280 public void setParamAction(String value) { 1281 1282 m_paramAction = value; 1283 } 1284 1285 1290 public void setParamCloseLink(String value) { 1291 1292 1294 m_paramCloseLink = value; 1295 } 1296 1297 1302 public void setParamDialogtype(String value) { 1303 1304 m_paramDialogtype = value; 1305 } 1306 1307 1312 public void setParamFramename(String value) { 1313 1314 m_paramFrameName = value; 1315 } 1316 1317 1322 public void setParamIsPopup(String value) { 1323 1324 m_paramIsPopup = value; 1325 } 1326 1327 1332 public void setParamMessage(String value) { 1333 1334 m_paramMessage = value; 1335 } 1336 1337 1342 public void setParamRedirect(String redirect) { 1343 1344 m_paramRedirect = redirect; 1345 } 1346 1347 1352 public void setParamResource(String value) { 1353 1354 m_paramResource = value; 1355 } 1356 1357 1362 public void setParamTitle(String value) { 1363 1364 m_paramTitle = value; 1365 } 1366 1367 1373 protected String appendDelimiter(String attribute) { 1374 1375 if (CmsStringUtil.isNotEmpty(attribute)) { 1376 if (!attribute.startsWith(" ")) { 1377 return " " + attribute; 1379 } else { 1380 return attribute; 1381 } 1382 } 1383 1384 return ""; 1385 } 1386 1387 1396 protected boolean checkResourcePermissions(CmsPermissionSet required, boolean neededForFolder) { 1397 1398 return checkResourcePermissions(required, neededForFolder, Messages.get().container( 1399 Messages.GUI_ERR_RESOURCE_PERMISSIONS_2, 1400 getParamResource(), 1401 required.getPermissionString())); 1402 } 1403 1404 1414 protected boolean checkResourcePermissions( 1415 CmsPermissionSet required, 1416 boolean neededForFolder, 1417 CmsMessageContainer errorMessage) { 1418 1419 boolean hasPermissions = false; 1420 try { 1421 CmsResource res; 1422 if (neededForFolder) { 1423 res = getCms().readResource(CmsResource.getParentFolder(getParamResource()), CmsResourceFilter.ALL); 1425 } else { 1426 res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 1427 } 1428 hasPermissions = getCms().hasPermissions(res, required, false, CmsResourceFilter.ALL); 1429 } catch (CmsException e) { 1430 if (LOG.isInfoEnabled()) { 1432 LOG.info(e); 1433 } 1434 } 1435 1436 if (!hasPermissions) { 1437 getSettings().setErrorMessage(errorMessage); 1439 } 1440 1441 return hasPermissions; 1442 } 1443 1444 1451 protected void dialogButtonsHtml(StringBuffer result, int button, String attribute) { 1452 1453 attribute = appendDelimiter(attribute); 1454 1455 switch (button) { 1456 case BUTTON_OK: 1457 result.append("<input name=\"ok\" value=\""); 1458 result.append(key(Messages.GUI_DIALOG_BUTTON_OK_0) + "\""); 1459 if (attribute.toLowerCase().indexOf("onclick") == -1) { 1460 result.append(" type=\"submit\""); 1461 } else { 1462 result.append(" type=\"button\""); 1463 } 1464 result.append(" class=\"dialogbutton\""); 1465 result.append(attribute); 1466 result.append(">\n"); 1467 break; 1468 case BUTTON_CANCEL: 1469 result.append("<input name=\"cancel\" type=\"button\" value=\""); 1470 result.append(key(Messages.GUI_DIALOG_BUTTON_CANCEL_0) + "\""); 1471 if (attribute.toLowerCase().indexOf("onclick") == -1) { 1472 result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\""); 1473 } 1474 result.append(" class=\"dialogbutton\""); 1475 result.append(attribute); 1476 result.append(">\n"); 1477 break; 1478 case BUTTON_EDIT: 1479 result.append("<input name=\"ok\" value=\""); 1480 result.append(key(Messages.GUI_DIALOG_BUTTON_EDIT_0) + "\""); 1481 if (attribute.toLowerCase().indexOf("onclick") == -1) { 1482 result.append(" type=\"submit\""); 1483 } else { 1484 result.append(" type=\"button\""); 1485 } 1486 result.append(" class=\"dialogbutton\""); 1487 result.append(attribute); 1488 result.append(">\n"); 1489 break; 1490 case BUTTON_DISCARD: 1491 result.append("<input name=\"cancel\" type=\"button\" value=\""); 1492 result.append(key(Messages.GUI_DIALOG_BUTTON_DISCARD_0) + "\""); 1493 if (attribute.toLowerCase().indexOf("onclick") == -1) { 1494 result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\""); 1495 } 1496 result.append(" class=\"dialogbutton\""); 1497 result.append(attribute); 1498 result.append(">\n"); 1499 break; 1500 case BUTTON_CLOSE: 1501 result.append("<input name=\"close\" type=\"button\" value=\""); 1502 result.append(key(Messages.GUI_DIALOG_BUTTON_CLOSE_0) + "\""); 1503 if (attribute.toLowerCase().indexOf("onclick") == -1) { 1504 result.append(" onclick=\"submitAction('" + DIALOG_CANCEL + "', form);\""); 1505 } 1506 result.append(" class=\"dialogbutton\""); 1507 result.append(attribute); 1508 result.append(">\n"); 1509 break; 1510 case BUTTON_ADVANCED: 1511 result.append("<input name=\"advanced\" type=\"button\" value=\""); 1512 result.append(key(Messages.GUI_DIALOG_BUTTON_ADVANCED_0) + "\""); 1513 result.append(" class=\"dialogbutton\""); 1514 result.append(attribute); 1515 result.append(">\n"); 1516 break; 1517 case BUTTON_SET: 1518 result.append("<input name=\"set\" type=\"button\" value=\""); 1519 result.append(key(Messages.GUI_DIALOG_BUTTON_SET_0) + "\""); 1520 if (attribute.toLowerCase().indexOf("onclick") == -1) { 1521 result.append(" onclick=\"submitAction('" + DIALOG_SET + "', form);\""); 1522 } 1523 result.append(" class=\"dialogbutton\""); 1524 result.append(attribute); 1525 result.append(">\n"); 1526 break; 1527 case BUTTON_BACK: 1528 result.append("<input name=\"set\" type=\"button\" value=\""); 1529 result.append(key(Messages.GUI_DIALOG_BUTTON_BACK_0) + "\""); 1530 if (attribute.toLowerCase().indexOf("onclick") == -1) { 1531 result.append(" onclick=\"submitAction('" + DIALOG_BACK + "', form);\""); 1532 } 1533 result.append(" class=\"dialogbutton\""); 1534 result.append(attribute); 1535 result.append(">\n"); 1536 break; 1537 case BUTTON_CONTINUE: 1538 result.append("<input name=\"set\" type=\"button\" value=\""); 1539 result.append(key(Messages.GUI_DIALOG_BUTTON_CONTINUE_0) + "\""); 1540 if (attribute.toLowerCase().indexOf("onclick") == -1) { 1541 result.append(" onclick=\"submitAction('" + DIALOG_CONTINUE + "', form);\""); 1542 } 1543 result.append(" class=\"dialogbutton\""); 1544 result.append(attribute); 1545 result.append(">\n"); 1546 break; 1547 case BUTTON_DETAILS: 1548 result.append("<input name=\"details\" type=\"button\" value=\""); 1549 result.append(key(Messages.GUI_DIALOG_BUTTON_DETAIL_0) + "\""); 1550 result.append(" class=\"dialogbutton\""); 1551 result.append(attribute); 1552 result.append(">\n"); 1553 break; 1554 default: 1555 result.append("<!-- invalid button code: "); 1557 result.append(button); 1558 result.append(" -->\n"); 1559 } 1560 } 1561 1562 1567 protected String getAdministrationBackLink() { 1568 1569 return CmsWorkplace.VFS_PATH_WORKPLACE 1570 + "action/administration_content_top.html" 1571 + "?sender=" 1572 + CmsResource.getParentFolder(getJsp().getRequestContext().getFolderUri()); 1573 } 1574 1575 1578 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 1579 1580 fillParamValues(request); 1581 if (DIALOG_CANCEL.equals(getParamAction())) { 1582 setAction(ACTION_CANCEL); 1583 } 1584 } 1585 1586 1591 protected void setAction(int value) { 1592 1593 m_action = value; 1594 } 1595} | Popular Tags |