1 31 32 package org.opencms.workplace.tools; 33 34 import org.opencms.jsp.CmsJspActionElement; 35 import org.opencms.main.OpenCms; 36 import org.opencms.security.CmsRoleViolationException; 37 import org.opencms.util.CmsStringUtil; 38 import org.opencms.workplace.CmsDialog; 39 import org.opencms.workplace.CmsWorkplace; 40 import org.opencms.workplace.CmsWorkplaceSettings; 41 42 import java.util.HashMap ; 43 import java.util.Map ; 44 45 import javax.servlet.http.HttpServletRequest ; 46 47 57 public class CmsToolDialog extends CmsWorkplace { 58 59 60 public static final String PARAM_BASE = "base"; 61 62 63 public static final String PARAM_PATH = "path"; 64 65 66 public static final String PARAM_ROOT = "root"; 67 68 69 public static final String PARAM_STYLE = "style"; 70 71 72 public static final String STYLE_NEW = "new"; 73 74 75 private String m_paramBase; 76 77 78 private String m_paramPath; 79 80 81 private String m_paramRoot; 82 83 84 private String m_paramStyle; 85 86 91 public CmsToolDialog(CmsJspActionElement jsp) { 92 93 super(jsp); 94 } 95 96 103 public String dialogScriptSubmit() { 104 105 StringBuffer html = new StringBuffer (512); 106 html.append("function submitAction(actionValue, theForm, formName) {\n"); 107 html.append("\tif (theForm == null) {\n"); 108 html.append("\t\ttheForm = document.forms[formName];\n"); 109 html.append("\t}\n"); 110 html.append("\ttry {\n"); 111 html.append("\t\ttheForm.").append(CmsDialog.PARAM_FRAMENAME).append(".value = window.name;\n"); 112 html.append("\t} catch (e) {}\n"); 113 html.append("\tif (actionValue == '" + CmsDialog.DIALOG_OK + "') {\n"); 114 html.append("\t\tloadingOn();\n"); 115 html.append("\t\treturn true;\n"); 116 html.append("\t}\n"); 117 html.append("\ttheForm." + CmsDialog.PARAM_ACTION + ".value = actionValue;\n"); 118 html.append("\tsubmitForm(theForm);\n"); 119 html.append("\treturn true;\n"); 120 html.append("}\n"); 121 return html.toString(); 122 } 123 124 131 public String dialogTitle() { 132 133 StringBuffer html = new StringBuffer (512); 134 String toolPath = getCurrentToolPath(); 135 String parentPath = getParentPath(); 136 String rootKey = getToolManager().getCurrentRoot(this).getKey(); 137 CmsTool parentTool = getToolManager().resolveAdminTool(rootKey, parentPath); 138 String upLevelLink = CmsToolManager.linkForToolPath( 139 getJsp(), 140 parentPath, 141 parentTool.getHandler().getParameters(this)); 142 String parentName = getToolManager().resolveAdminTool(rootKey, parentPath).getHandler().getName(); 143 144 html.append(getToolManager().generateNavBar(toolPath, this)); 145 html.append("<div class='screenTitle'>\n"); 147 html.append("\t<table width='100%' cellspacing='0'>\n"); 148 html.append("\t\t<tr>\n"); 149 html.append("\t\t\t<td>\n"); 150 html.append(getAdminTool().getHandler().getName()); 151 html.append("\n\t\t\t</td>"); 152 if (getParentPath() != toolPath) { 154 html.append("\t\t\t<td class='uplevel'>\n\t\t\t\t"); 155 html.append(A_CmsHtmlIconButton.defaultButtonHtml( 156 getJsp(), 157 CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT, 158 "id-up-level", 159 Messages.get().getBundle(getLocale()).key(Messages.GUI_ADMIN_VIEW_UPLEVEL_0), 160 parentName, 161 true, 162 "admin/images/up.png", 163 null, 164 "openPage('" + upLevelLink + "');")); 165 html.append("\n\t\t\t</td>\n"); 166 } 167 html.append("\t\t</tr>\n"); 168 html.append("\t</table>\n"); 169 html.append("</div>\n"); 170 return CmsToolMacroResolver.resolveMacros(html.toString(), this); 171 } 172 173 178 public CmsTool getAdminTool() { 179 180 return getToolManager().getCurrentTool(this); 181 } 182 183 188 public String getCurrentToolPath() { 189 190 return getToolManager().getCurrentToolPath(this); 191 } 192 193 198 public String getParamBase() { 199 200 return m_paramBase; 201 } 202 203 208 public String getParamPath() { 209 210 return m_paramPath; 211 } 212 213 218 public String getParamRoot() { 219 220 return m_paramRoot; 221 } 222 223 228 public String getParamStyle() { 229 230 return m_paramStyle; 231 } 232 233 238 public String getParentPath() { 239 240 return getToolManager().getParent(this, getCurrentToolPath()); 241 } 242 243 248 public CmsToolManager getToolManager() { 249 250 return OpenCms.getWorkplaceManager().getToolManager(); 251 } 252 253 263 public String iconsBlockArea(int segment, String headline) { 264 265 StringBuffer result = new StringBuffer (512); 266 if (segment == HTML_START) { 267 result.append("<!-- icons block area start -->\n"); 268 result.append("<div class=\"dialogcontent\" unselectable=\"on\">"); 269 result.append("<fieldset class=\"dialogblock\">\n"); 270 result.append("<legend>"); 271 result.append("<span class=\"textbold"); 272 result.append("\" unselectable=\"on\">"); 273 result.append(headline); 274 result.append("</span></legend>\n"); 275 result.append("\t\t<table class='toolsArea' width='100%' cellspacing='0' cellpadding='0' border='0'>\n"); 276 result.append("\t\t\t<tr><td>\n"); 277 } else { 278 result.append("\t\t\t</td></tr>\n"); 279 result.append("\t\t</table>\n"); 280 result.append("</fieldset></div>\n"); 281 result.append("<p> </p>\n"); 282 result.append("<!-- icons block area end -->\n"); 283 } 284 return result.toString(); 285 } 286 287 294 public String iconsBlockAreaEnd() { 295 296 return iconsBlockArea(HTML_END, null); 297 } 298 299 308 public String iconsBlockAreaStart(String headline) { 309 310 return iconsBlockArea(HTML_START, headline); 311 } 312 313 319 public Map initAdminTool() throws CmsRoleViolationException { 320 321 Map params = new HashMap (getParameterMap()); 322 getToolManager().initParams(this); 324 325 if (!useNewStyle()) { 327 params.put(PARAM_STYLE, new String [] {CmsToolDialog.STYLE_NEW}); 328 setParamStyle(CmsToolDialog.STYLE_NEW); 329 } 330 331 try { 332 CmsDialog wp = (CmsDialog)this; 334 if (CmsStringUtil.isEmptyOrWhitespaceOnly(wp.getParamCloseLink())) { 336 if (!getToolManager().getBaseToolPath(this).equals(getToolManager().getCurrentToolPath(this))) { 337 Map args = getToolManager().resolveAdminTool(getParamRoot(), getParentPath()).getHandler().getParameters( 338 wp); 339 wp.setParamCloseLink(CmsToolManager.linkForToolPath(getJsp(), getParentPath(), args)); 340 params.put(CmsDialog.PARAM_CLOSELINK, new String [] {wp.getParamCloseLink()}); 341 } 342 } 343 } catch (Exception e) { 344 } 346 347 if (!getToolManager().getCurrentTool(this).getHandler().isEnabled(getCms())) { 348 throw new CmsRoleViolationException(Messages.get().container(Messages.ERR_ADMIN_INSUFFICIENT_RIGHTS_0)); 349 } 350 351 return params; 352 } 353 354 357 public String pageBody(int segment, String className, String parameters) { 358 359 if (!useNewStyle()) { 360 return super.pageBody(segment, className, parameters); 361 } else { 362 Map data = CmsStringUtil.extendAttribute(parameters, "onLoad", "bodyLoad();"); 363 String onLoad = (String )data.get("value"); 364 String myPars = (String )data.get("text"); 365 data = CmsStringUtil.extendAttribute(myPars, "onUnload", "bodyUnload();"); 366 String onUnload = (String )data.get("value"); 367 myPars = (String )data.get("text"); 368 if (segment == HTML_START) { 369 StringBuffer html = new StringBuffer (512); 370 html.append("</head>\n"); 371 html.append("<body onLoad="); 372 html.append(onLoad); 373 html.append(" onUnload="); 374 html.append(onUnload); 375 html.append(CmsStringUtil.isNotEmpty(className) ? " class='" + className + "'" : ""); 376 html.append(CmsStringUtil.isNotEmpty(myPars) ? " " + myPars : ""); 377 html.append(">\n"); 378 html.append("\t<table border='0' cellspacing='0' cellpadding='0' id='loaderContainer' onClick='return false;'>\n"); 379 html.append("\t\t<tr><td id='loaderContainerH'><div id='loader'>\n"); 380 html.append("\t\t\t<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td>\n"); 381 html.append("\t\t\t\t<p><img SRC='"); 382 html.append(getSkinUri()); 383 html.append("commons/wait.gif"); 384 html.append("' height='32' width='32' alt=''/>\n"); 385 html.append("\t\t\t\t<strong>"); 386 html.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_ADMIN_VIEW_LOADING_0)); 387 html.append("</strong></p>\n"); 388 html.append("\t\t\t</td></tr></table>\n"); 389 html.append("\t\t</div></td></tr>\n"); 390 html.append("\t</table>\n"); 391 html.append("\t<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td id='screenH'>\n"); 392 return html.toString(); 393 } else { 394 StringBuffer html = new StringBuffer (128); 395 html.append("\t</td></tr></table>\n"); 396 html.append("</body>"); 397 return html.toString(); 398 } 399 } 400 } 401 402 405 public String pageHtmlStyle(int segment, String title, String stylesheet) { 406 407 if (!useNewStyle() || segment != HTML_START) { 408 return super.pageHtmlStyle(segment, title, stylesheet); 409 } 410 411 StringBuffer html = new StringBuffer (512); 412 html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"); 413 html.append("<html>\n"); 414 html.append("<head>\n"); 415 html.append("<meta http-equiv='Content-Type' content='text/html; charset="); 416 html.append(getEncoding()); 417 html.append("' >\n"); 418 if (title != null) { 419 html.append("<title>"); 420 html.append(title); 421 html.append("</title>\n"); 422 } else { 423 html.append("<title></title>\n"); 425 } 426 html.append("<link rel='stylesheet' type='text/css' HREF='"); 427 html.append(getStyleUri(getJsp())); 428 html.append("new_admin.css'>\n"); 429 html.append("<script type='text/javascript' SRC='"); 430 html.append(getSkinUri()); 431 html.append("admin/javascript/general.js'></script>\n"); 432 html.append("<script type='text/javascript' SRC='"); 433 html.append(getResourceUri()); 434 html.append("editors/xmlcontent/help.js'></script>\n\n"); 435 html.append("<script type='text/javascript'>\n"); 436 html.append("\tfunction bodyLoad() {\n"); 437 html.append("\t\tsetContext(\""); 438 html.append(CmsStringUtil.escapeJavaScript(resolveMacros(getAdminTool().getHandler().getHelpText()))); 439 html.append("\");\n"); 440 html.append("\t\tsetActiveItemByName(\""); 441 html.append(getCurrentToolPath()); 442 html.append("\");\n"); 443 html.append("\t\tloadingOff();\n"); 444 html.append("\t\ttry {\n"); 445 html.append("\t\t\tdocument.getElementById('loaderContainerH').height = wHeight();\n"); 446 html.append("\t\t} catch (e) {}\n"); 447 html.append("\t}\n"); 448 html.append("\tfunction bodyUnload() {\n"); 449 html.append("\t\tloadingOn();\n"); 450 html.append("\t}\n"); 451 html.append("</script>\n"); 452 return html.toString(); 453 } 454 455 460 public void setParamBase(String paramBase) { 461 462 m_paramBase = paramBase; 463 } 464 465 470 public void setParamPath(String paramPath) { 471 472 m_paramPath = paramPath; 473 } 474 475 480 public void setParamRoot(String paramRoot) { 481 482 m_paramRoot = paramRoot; 483 } 484 485 490 public void setParamStyle(String paramStyle) { 491 492 m_paramStyle = paramStyle; 493 } 494 495 502 public boolean useNewStyle() { 503 504 return getParamStyle() != null && getParamStyle().equals(CmsToolDialog.STYLE_NEW); 505 } 506 507 510 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 511 512 fillParamValues(request); 513 } 514 } | Popular Tags |