1 31 32 package org.opencms.workplace.tools; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsProperty; 36 import org.opencms.file.CmsPropertyDefinition; 37 import org.opencms.i18n.CmsMessages; 38 import org.opencms.jsp.CmsJspNavBuilder; 39 import org.opencms.jsp.CmsJspNavElement; 40 import org.opencms.main.CmsException; 41 import org.opencms.main.CmsLog; 42 import org.opencms.util.CmsStringUtil; 43 import org.opencms.workplace.CmsWorkplace; 44 45 import java.util.HashMap ; 46 import java.util.Iterator ; 47 import java.util.Map ; 48 49 import org.apache.commons.logging.Log; 50 51 60 public abstract class A_CmsToolHandler implements I_CmsToolHandler { 61 62 63 public static final String ARG_PARAM_NAME = "params"; 64 65 66 public static final String ARG_PATH_NAME = "path"; 67 68 69 public static final String ARGS_PROPERTY_DEFINITION = "admintoolhandler-args"; 70 71 72 public static final String ARGUMENT_SEPARATOR = "|"; 73 74 75 public static final String DEFAULT_DISABLED_HELPTEXT = "${key." + Messages.GUI_TOOLS_DISABLED_HELP_0 + "}"; 76 77 78 public static final String VALUE_SEPARATOR = ":"; 79 80 81 private static final String ARG_CONFIRMATION_NAME = "confirmation"; 82 83 84 private String m_confirmationMessage; 85 86 87 private String m_disabledHelpText; 88 89 90 private String m_group; 91 92 93 private String m_helpText; 94 95 96 private String m_iconPath; 97 98 99 private String m_link; 100 101 102 private String m_name; 103 104 105 private String m_parameters; 106 107 108 private String m_path; 109 110 111 private float m_position; 112 113 114 private String m_shortName; 115 116 117 private String m_smallIconPath; 118 119 120 private static final Log LOG = CmsLog.getLog(A_CmsToolHandler.class); 121 122 127 public String getConfirmationMessage() { 128 129 return m_confirmationMessage; 130 } 131 132 135 public String getDisabledHelpText() { 136 137 return m_disabledHelpText; 138 } 139 140 143 public String getGroup() { 144 145 return m_group; 146 } 147 148 151 public String getHelpText() { 152 153 return m_helpText; 154 } 155 156 159 public String getIconPath() { 160 161 return m_iconPath; 162 } 163 164 167 public String getLink() { 168 169 return m_link; 170 } 171 172 175 public String getName() { 176 177 return m_name; 178 } 179 180 183 public Map getParameters(CmsWorkplace wp) { 184 185 Map argMap = new HashMap (); 186 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_parameters)) { 187 String toolParams = wp.resolveMacros(m_parameters); 188 Iterator itArgs = CmsStringUtil.splitAsList(toolParams, "&").iterator(); 189 while (itArgs.hasNext()) { 190 String arg = (String )itArgs.next(); 191 int pos = arg.indexOf("="); 192 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(arg.substring(pos + 1))) { 193 argMap.put(arg.substring(0, pos), arg.substring(pos + 1)); 194 } 195 } 196 } 197 return argMap; 198 } 199 200 203 public String getPath() { 204 205 return m_path; 206 } 207 208 211 public float getPosition() { 212 213 return m_position; 214 } 215 216 219 public String getShortName() { 220 221 return m_shortName; 222 } 223 224 227 public String getSmallIconPath() { 228 229 return m_smallIconPath; 230 } 231 232 237 public void setConfirmationMessage(String confirmationMessage) { 238 239 m_confirmationMessage = confirmationMessage; 240 } 241 242 247 public void setDisabledHelpText(String disabledHelpText) { 248 249 m_disabledHelpText = disabledHelpText; 250 } 251 252 257 public void setGroup(String group) { 258 259 m_group = group; 260 } 261 262 267 public void setHelpText(String helpText) { 268 269 m_helpText = helpText; 270 } 271 272 277 public void setIconPath(String iconPath) { 278 279 m_iconPath = iconPath; 280 } 281 282 287 public void setLink(String link) { 288 289 m_link = link; 290 } 291 292 297 public void setName(String name) { 298 299 m_name = name; 300 } 301 302 307 public void setParameterString(String paramString) { 308 309 m_parameters = paramString; 310 } 311 312 317 public void setPath(String path) { 318 319 m_path = path; 320 } 321 322 327 public void setPosition(float position) { 328 329 m_position = position; 330 } 331 332 337 public void setShortName(String shortName) { 338 339 m_shortName = shortName; 340 } 341 342 347 public void setSmallIconPath(String smallIconPath) { 348 349 m_smallIconPath = smallIconPath; 350 } 351 352 381 public boolean setup(CmsObject cms, CmsToolRootHandler root, String resourcePath) { 382 383 CmsJspNavElement navElem = CmsJspNavBuilder.getNavigationForResource(cms, resourcePath); 384 385 String name = navElem.getNavText(); 386 if (CmsMessages.isUnknownKey(name)) { 387 name = navElem.getTitle(); 388 } 389 if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) { 390 name = "${key." + Messages.GUI_TOOLS_DEFAULT_NAME_0 + "}"; 391 } 392 String shortName = name; 393 if (name.indexOf(VALUE_SEPARATOR) >= 0) { 394 shortName = name.substring(name.indexOf(VALUE_SEPARATOR) + 1); 395 name = name.substring(0, name.indexOf(VALUE_SEPARATOR)); 396 } 397 setName(name); 398 setShortName(shortName); 399 400 String iconPath = navElem.getNavImage(); 401 if (CmsStringUtil.isEmptyOrWhitespaceOnly(iconPath)) { 402 iconPath = "admin/images/default_tool_big.png:admin/images/default_tool_small.png"; 403 } 404 String smallIconPath = iconPath; 405 if (iconPath.indexOf(VALUE_SEPARATOR) >= 0) { 406 smallIconPath = iconPath.substring(iconPath.indexOf(VALUE_SEPARATOR) + 1); 407 iconPath = iconPath.substring(0, iconPath.indexOf(VALUE_SEPARATOR)); 408 } 409 setIconPath(iconPath); 410 setSmallIconPath(smallIconPath); 411 412 String helpText = navElem.getDescription(); 413 if (CmsStringUtil.isEmptyOrWhitespaceOnly(helpText)) { 414 helpText = "${key." + Messages.GUI_TOOLS_DEFAULT_HELP_0 + "}"; 415 } 416 String disabledHelpText = DEFAULT_DISABLED_HELPTEXT; 417 if (helpText.indexOf(VALUE_SEPARATOR) >= 0) { 418 disabledHelpText = helpText.substring(helpText.indexOf(VALUE_SEPARATOR) + 1); 419 helpText = helpText.substring(0, helpText.indexOf(VALUE_SEPARATOR)); 420 } 421 setHelpText(helpText); 422 setDisabledHelpText(disabledHelpText); 423 424 String group = navElem.getInfo(); 425 if (CmsStringUtil.isEmptyOrWhitespaceOnly(group)) { 426 group = "${key." + Messages.GUI_TOOLS_DEFAULT_GROUP_0 + "}"; 427 } 428 429 String path = resourcePath; 430 setLink(cms, resourcePath); 431 try { 432 if (cms.readResource(resourcePath).isFolder()) { 433 path = CmsToolManager.TOOLPATH_SEPARATOR 434 + resourcePath.substring( 435 root.getUri().length(), 436 resourcePath.lastIndexOf(CmsToolManager.TOOLPATH_SEPARATOR)); 437 } else { 438 path = CmsToolManager.TOOLPATH_SEPARATOR 439 + resourcePath.substring(root.getUri().length(), resourcePath.lastIndexOf('.')); 440 } 441 } catch (CmsException e) { 442 } 444 setPath(path); 446 setGroup(group); 447 setPosition(navElem.getNavPosition()); 448 449 setParameters(cms, resourcePath); 451 452 return !path.equals(resourcePath); 453 } 454 455 458 public String toString() { 459 460 return m_path + " - " + m_group + " - " + m_position; 461 } 462 463 474 protected void setLink(CmsObject cms, String resourcePath) { 475 476 String link = resourcePath; 477 try { 478 cms.readFolder(resourcePath); 480 481 if (resourcePath.endsWith(CmsToolManager.TOOLPATH_SEPARATOR)) { 483 resourcePath = resourcePath.substring(0, resourcePath.lastIndexOf(CmsToolManager.TOOLPATH_SEPARATOR)); 484 } 485 486 link = CmsToolManager.VIEW_JSPPAGE_LOCATION; 488 489 CmsProperty prop = cms.readPropertyObject(resourcePath, CmsPropertyDefinition.PROPERTY_DEFAULT_FILE, false); 491 String defFile = "index.jsp"; 492 if (!prop.isNullProperty()) { 493 defFile = prop.getValue(); 494 } 495 if (!defFile.startsWith(CmsToolManager.TOOLPATH_SEPARATOR)) { 496 defFile = resourcePath + CmsToolManager.TOOLPATH_SEPARATOR + defFile; 498 } 499 if (defFile.indexOf("?") > 0) { 500 if (cms.existsResource(defFile.substring(0, defFile.indexOf("?")))) { 501 link = defFile; 502 } 503 } else if (cms.existsResource(defFile)) { 504 link = defFile; 505 } 506 } catch (CmsException e) { 507 } 509 510 setLink(link); 511 } 512 513 519 protected void setParameters(CmsObject cms, String resourcePath) { 520 521 try { 522 CmsProperty prop = cms.readPropertyObject(resourcePath, ARGS_PROPERTY_DEFINITION, false); 523 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(prop.getValue())) { 524 Map argsMap = new HashMap (); 525 Iterator itArgs = CmsStringUtil.splitAsList(prop.getValue(), ARGUMENT_SEPARATOR).iterator(); 526 while (itArgs.hasNext()) { 527 String arg = ""; 528 try { 529 arg = (String )itArgs.next(); 530 int pos = arg.indexOf(VALUE_SEPARATOR); 531 argsMap.put(arg.substring(0, pos), arg.substring(pos + 1)); 532 } catch (StringIndexOutOfBoundsException e) { 533 LOG.error("sep: " + VALUE_SEPARATOR + "arg: " + arg); 534 throw e; 535 } 536 } 537 if (argsMap.get(ARG_PATH_NAME) != null) { 538 setPath((String )argsMap.get(ARG_PATH_NAME)); 539 } 540 if (argsMap.get(ARG_CONFIRMATION_NAME) != null) { 541 setConfirmationMessage((String )argsMap.get(ARG_CONFIRMATION_NAME)); 542 } 543 if (argsMap.get(ARG_PARAM_NAME) != null) { 544 setParameterString((String )argsMap.get(ARG_PARAM_NAME)); 545 } 546 } 547 } catch (CmsException e) { 548 } 550 } 551 } | Popular Tags |