1 31 32 package org.opencms.workplace; 33 34 import org.opencms.db.CmsDbEntryNotFoundException; 35 import org.opencms.db.CmsUserSettings; 36 import org.opencms.file.CmsObject; 37 import org.opencms.file.CmsProject; 38 import org.opencms.file.CmsRequestContext; 39 import org.opencms.file.CmsResource; 40 import org.opencms.file.CmsResourceFilter; 41 import org.opencms.file.CmsUser; 42 import org.opencms.file.types.I_CmsResourceType; 43 import org.opencms.i18n.CmsEncoder; 44 import org.opencms.i18n.CmsMessages; 45 import org.opencms.i18n.CmsMultiMessages; 46 import org.opencms.jsp.CmsJspActionElement; 47 import org.opencms.lock.CmsLock; 48 import org.opencms.main.CmsBroadcast; 49 import org.opencms.main.CmsException; 50 import org.opencms.main.CmsLog; 51 import org.opencms.main.OpenCms; 52 import org.opencms.security.CmsPermissionSet; 53 import org.opencms.site.CmsSite; 54 import org.opencms.site.CmsSiteManager; 55 import org.opencms.util.CmsMacroResolver; 56 import org.opencms.util.CmsRequestUtil; 57 import org.opencms.util.CmsStringUtil; 58 import org.opencms.workplace.explorer.CmsExplorerTypeSettings; 59 import org.opencms.workplace.help.CmsHelpTemplateBean; 60 61 import java.io.IOException ; 62 import java.lang.reflect.InvocationTargetException ; 63 import java.lang.reflect.Method ; 64 import java.util.ArrayList ; 65 import java.util.Collection ; 66 import java.util.HashMap ; 67 import java.util.Iterator ; 68 import java.util.List ; 69 import java.util.Locale ; 70 import java.util.Map ; 71 72 import javax.servlet.ServletException ; 73 import javax.servlet.http.HttpServletRequest ; 74 import javax.servlet.http.HttpServletResponse ; 75 import javax.servlet.http.HttpSession ; 76 import javax.servlet.jsp.PageContext ; 77 78 import org.apache.commons.collections.Buffer; 79 import org.apache.commons.logging.Log; 80 81 91 public abstract class CmsWorkplace { 92 93 94 public static final boolean DEBUG = false; 95 96 97 public static final Locale DEFAULT_LOCALE = Locale.ENGLISH; 98 99 100 public static final String DEFAULT_LANGUAGE = DEFAULT_LOCALE.getLanguage(); 101 102 103 public static final String FILE_EXPLORER_FILELIST = CmsWorkplace.VFS_PATH_WORKPLACE 104 + "views/explorer/explorer_files.jsp"; 105 106 107 public static final int HTML_END = 1; 108 109 110 public static final int HTML_START = 0; 111 112 113 public static final String PARAM_WP_EXPLORER_RESOURCE = "wpExplorerResource"; 114 115 116 public static final String PARAM_WP_PROJECT = "wpProject"; 117 118 119 public static final String PARAM_WP_SITE = "wpSite"; 120 121 122 public static final String VFS_PATH_SYSTEM = "/system/"; 123 124 125 public static final String VFS_PATH_WORKPLACE = VFS_PATH_SYSTEM + "workplace/"; 126 127 128 public static final String PATH_DIALOGS = VFS_PATH_WORKPLACE + "commons/"; 129 130 131 public static final String PATH_WORKPLACE = VFS_PATH_WORKPLACE; 132 133 134 public static final String RFS_PATH_RESOURCES = "/resources/"; 135 136 137 public static final String TEMP_FILE_PREFIX = "~"; 138 139 140 public static final String VFS_DIR_DEFAULTBODIES = "default_bodies/"; 141 142 143 public static final String VFS_DIR_TEMPLATES = "templates/"; 144 145 146 public static final String VFS_PATH_COMMONS = VFS_PATH_WORKPLACE + "commons/"; 147 148 149 public static final String VFS_PATH_EDITORS = VFS_PATH_WORKPLACE + "editors/"; 150 151 152 public static final String VFS_PATH_GALLERIES = VFS_PATH_SYSTEM + "galleries/"; 153 154 155 public static final String VFS_PATH_LOCALES = VFS_PATH_WORKPLACE + "locales/"; 156 157 158 public static final String VFS_PATH_MODULES = VFS_PATH_SYSTEM + "modules/"; 159 160 161 public static final String VFS_PATH_RESOURCES = VFS_PATH_WORKPLACE + "resources/"; 162 163 164 public static final String VFS_PATH_VIEWS = VFS_PATH_WORKPLACE + "views/"; 165 166 167 public static final String DIALOG_PATH_COMMON = PATH_DIALOGS + "includes/"; 168 169 170 public static final String FILE_DIALOG_CLOSE = DIALOG_PATH_COMMON + "closedialog.jsp"; 171 172 173 public static final String FILE_DIALOG_SCREEN_CONFIRM = DIALOG_PATH_COMMON + "confirmation.jsp"; 174 175 176 public static final String FILE_DIALOG_SCREEN_ERROR = DIALOG_PATH_COMMON + "error.jsp"; 177 178 179 public static final String FILE_DIALOG_SCREEN_ERRORPAGE = DIALOG_PATH_COMMON + "errorpage.jsp"; 180 181 182 public static final String FILE_DIALOG_SCREEN_WAIT = DIALOG_PATH_COMMON + "wait.jsp"; 183 184 185 public static final String FILE_REPORT_OUTPUT = DIALOG_PATH_COMMON + "report.jsp"; 186 187 188 protected static final String REQUEST_ATTRIBUTE_MULTIPART = "__CmsWorkplace.MULTIPART"; 189 190 191 protected static final String REQUEST_ATTRIBUTE_RELOADTREE = "__CmsWorkplace.RELOADTREE"; 192 193 194 protected static final String SESSION_WORKPLACE_CLASS = "__CmsWorkplace.WORKPLACE_CLASS"; 195 196 197 private static final Log LOG = CmsLog.getLog(CmsWorkplace.class); 198 199 200 private static String m_file_explorer_filelist; 201 202 203 private static String m_skinUri; 204 205 206 private static String m_styleUri; 207 208 209 private CmsObject m_cms; 210 211 212 private int m_currentProjectId = -1; 213 214 215 private boolean m_forwarded; 216 217 218 private CmsJspActionElement m_jsp; 219 220 221 private CmsMacroResolver m_macroResolver; 222 223 224 private CmsMultiMessages m_messages; 225 226 227 private List m_multiPartFileItems; 228 229 230 private Map m_parameterMap; 231 232 233 private String m_resourceUri; 234 235 236 private HttpSession m_session; 237 238 239 private CmsWorkplaceSettings m_settings; 240 241 246 public CmsWorkplace(CmsJspActionElement jsp) { 247 248 initWorkplaceMembers(jsp); 249 } 250 251 258 public CmsWorkplace(PageContext context, HttpServletRequest req, HttpServletResponse res) { 259 260 this(new CmsJspActionElement(context, req, res)); 261 } 262 263 274 public static String buildSelect(String parameters, List options, List values, int selected, boolean useLineFeed) { 275 276 StringBuffer result = new StringBuffer (1024); 277 result.append("<select "); 278 if (parameters != null) { 279 result.append(parameters); 280 } 281 result.append(">"); 282 if (useLineFeed) { 283 result.append("\n"); 284 } 285 int length = options.size(); 286 String value = null; 287 for (int i = 0; i < length; i++) { 288 if (values != null) { 289 try { 290 value = (String )values.get(i); 291 } catch (Exception e) { 292 if (LOG.isInfoEnabled()) { 294 LOG.info(e.getLocalizedMessage()); 295 } 296 value = null; 298 } 299 } 300 if (value == null) { 301 result.append("<option"); 302 if (i == selected) { 303 result.append(" selected=\"selected\""); 304 } 305 result.append(">"); 306 result.append(options.get(i)); 307 result.append("</option>"); 308 if (useLineFeed) { 309 result.append("\n"); 310 } 311 } else { 312 result.append("<option value=\""); 313 result.append(value); 314 result.append("\""); 315 if (i == selected) { 316 result.append(" selected=\"selected\""); 317 } 318 result.append(">"); 319 result.append(options.get(i)); 320 result.append("</option>"); 321 if (useLineFeed) { 322 result.append("\n"); 323 } 324 } 325 } 326 result.append("</select>"); 327 if (useLineFeed) { 328 result.append("\n"); 329 } 330 return result.toString(); 331 } 332 333 340 public static String getResourceUri(String resourceName) { 341 342 StringBuffer result = new StringBuffer (256); 343 result.append(getSkinUri()); 344 result.append(resourceName); 345 return result.toString(); 346 } 347 348 353 public static String getSkinUri() { 354 355 if (m_skinUri == null) { 356 m_skinUri = OpenCms.getSystemInfo().getContextPath() + RFS_PATH_RESOURCES; 357 } 358 return m_skinUri; 359 } 360 361 367 public static String getStyleUri(CmsJspActionElement jsp) { 368 369 if (m_styleUri == null) { 370 371 CmsProject project = jsp.getCmsObject().getRequestContext().currentProject(); 372 try { 373 jsp.getCmsObject().getRequestContext().setCurrentProject( 374 jsp.getCmsObject().readProject(CmsProject.ONLINE_PROJECT_ID)); 375 m_styleUri = jsp.link("/system/workplace/commons/style/"); 376 } catch (CmsException e) { 377 LOG.error(e.getLocalizedMessage()); 378 } finally { 379 jsp.getCmsObject().getRequestContext().setCurrentProject(project); 380 } 381 } 382 return m_styleUri; 383 } 384 385 392 public static String getStyleUri(CmsJspActionElement jsp, String filename) { 393 394 if (m_styleUri == null) { 395 396 CmsProject project = jsp.getCmsObject().getRequestContext().currentProject(); 397 try { 398 jsp.getCmsObject().getRequestContext().setCurrentProject( 399 jsp.getCmsObject().readProject(CmsProject.ONLINE_PROJECT_ID)); 400 m_styleUri = jsp.link("/system/workplace/commons/style/"); 401 } catch (CmsException e) { 402 } finally { 404 jsp.getCmsObject().getRequestContext().setCurrentProject(project); 405 } 406 } 407 return m_styleUri + filename; 408 } 409 410 422 public static CmsWorkplaceSettings initUserSettings(CmsObject cms, CmsWorkplaceSettings settings, boolean update) { 423 424 if (settings == null) { 425 settings = new CmsWorkplaceSettings(); 426 } 427 428 CmsUser user; 430 if (update) { 431 try { 432 user = cms.readUser(cms.getRequestContext().currentUser().getId()); 434 } catch (CmsException e) { 435 if (LOG.isInfoEnabled()) { 437 LOG.info(e.getLocalizedMessage()); 438 } 439 user = cms.getRequestContext().currentUser(); 440 } 441 } else { 442 user = cms.getRequestContext().currentUser(); 443 } 444 settings.setUser(user); 446 settings.setUserSettings(new CmsUserSettings(cms, user)); 447 448 return settings; 450 } 451 452 467 public static synchronized CmsWorkplaceSettings initWorkplaceSettings( 468 CmsObject cms, 469 CmsWorkplaceSettings settings, 470 boolean update) { 471 472 settings = initUserSettings(cms, settings, update); 474 475 settings.setProject(cms.getRequestContext().currentProject().getId()); 477 478 String siteRoot = settings.getUserSettings().getStartSite(); 480 if (siteRoot.endsWith("/")) { 481 siteRoot = siteRoot.substring(0, siteRoot.length() - 1); 483 } 484 if (CmsStringUtil.isNotEmpty(siteRoot) && (CmsSiteManager.getSite(siteRoot) == null)) { 485 siteRoot = OpenCms.getWorkplaceManager().getDefaultUserSettings().getStartSite(); 487 if (siteRoot.endsWith("/")) { 488 siteRoot = siteRoot.substring(0, siteRoot.length() - 1); 490 } 491 } 492 boolean access = false; 493 CmsResource res = null; 494 try { 495 res = cms.readResource("/"); 497 access = cms.hasPermissions(res, CmsPermissionSet.ACCESS_VIEW); 498 } catch (CmsException e) { 499 if (LOG.isInfoEnabled()) { 501 LOG.info(e.getLocalizedMessage(), e); 502 } 503 504 } 505 if ((res == null) || !access) { 506 List sites = CmsSiteManager.getAvailableSites(cms, true); 507 if (sites.size() > 0) { 508 siteRoot = ((CmsSite)sites.get(0)).getSiteRoot(); 509 cms.getRequestContext().setSiteRoot(siteRoot); 510 } 511 } 512 settings.setSite(siteRoot); 514 515 settings.setExplorerResource(settings.getUserSettings().getStartFolder()); 517 518 settings.setViewUri(OpenCms.getLinkManager().substituteLink(cms, settings.getUserSettings().getStartView())); 520 521 settings.setResourceTypes(initWorkplaceResourceTypes(cms)); 523 524 return settings; 525 } 526 527 533 static void storeSettings(HttpSession session, CmsWorkplaceSettings settings) { 534 535 session.setAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS, settings); 537 } 538 539 545 private static Map initWorkplaceResourceTypes(CmsObject cms) { 546 547 Map resourceTypes = new HashMap (); 548 List allResTypes = OpenCms.getResourceManager().getResourceTypes(); 549 for (int i = 0; i < allResTypes.size(); i++) { 550 I_CmsResourceType type = (I_CmsResourceType)allResTypes.get(i); 552 CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(type.getTypeName()); 554 if (settings != null) { 555 CmsPermissionSet permissions = settings.getAccess().getPermissions(cms); 557 if (permissions.requiresWritePermission()) { 558 resourceTypes.put(new Integer (type.getTypeId()), type); 560 } 561 } 562 } 563 return resourceTypes; 564 } 565 566 573 public String allParamsAsHidden() { 574 575 StringBuffer result = new StringBuffer (512); 576 Map params = allParamValues(); 577 Iterator i = params.keySet().iterator(); 578 while (i.hasNext()) { 579 String param = (String )i.next(); 580 Object value = params.get(param); 581 result.append("<input type=\"hidden\" name=\""); 582 result.append(param); 583 result.append("\" value=\""); 584 String encoded = CmsEncoder.encode(value.toString(), getCms().getRequestContext().getEncoding()); 585 result.append(encoded); 586 result.append("\">\n"); 587 } 588 return result.toString(); 589 } 590 591 598 public String allParamsAsRequest() { 599 600 StringBuffer retValue = new StringBuffer (512); 601 HttpServletRequest request = getJsp().getRequest(); 602 Iterator paramNames = request.getParameterMap().keySet().iterator(); 603 while (paramNames.hasNext()) { 604 String paramName = (String )paramNames.next(); 605 String paramValue = request.getParameter(paramName); 606 retValue.append(paramName + "=" + CmsEncoder.encode(paramValue, getCms().getRequestContext().getEncoding())); 607 if (paramNames.hasNext()) { 608 retValue.append("&"); 609 } 610 } 611 return retValue.toString(); 612 } 613 614 619 public String bodyEnd() { 620 621 return pageBody(HTML_END, null, null); 622 } 623 624 630 public String bodyStart(String className) { 631 632 return pageBody(HTML_START, className, null); 633 } 634 635 642 public String bodyStart(String className, String parameters) { 643 644 return pageBody(HTML_START, className, parameters); 645 } 646 647 657 public String buildSelect(String parameters, List options, List values, int selected) { 658 659 return buildSelect(parameters, options, values, selected, true); 660 } 661 662 673 public String button(String href, String target, String image, String label, int type) { 674 675 return button(href, target, image, label, type, getSkinUri() + "buttons/"); 676 } 677 678 690 public String button(String href, String target, String image, String label, int type, String imagePath) { 691 692 StringBuffer result = new StringBuffer (256); 693 694 String anchorStart = "<a HREF=\""; 695 if (href != null && href.toLowerCase().startsWith("javascript:")) { 696 anchorStart = "<a HREF=\"#\" onclick=\""; 697 } 698 699 result.append("<td style=\"vertical-align: top;\">"); 700 switch (type) { 701 case 1: 702 if (href != null) { 704 result.append(anchorStart); 705 result.append(href); 706 result.append("\" class=\"button\""); 707 if (target != null) { 708 result.append(" target=\""); 709 result.append(target); 710 result.append("\""); 711 } 712 result.append(">"); 713 } 714 result.append("<span unselectable=\"on\" "); 715 if (href != null) { 716 result.append("class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\""); 717 } else { 718 result.append("class=\"disabled\""); 719 } 720 result.append("><span unselectable=\"on\" class=\"combobutton\" "); 721 result.append("style=\"background-image: url('"); 722 result.append(imagePath); 723 result.append(image); 724 if (image != null && image.indexOf('.') == -1) { 725 result.append(".png"); 727 } 728 result.append("');\">"); 729 result.append(shortKey(label)); 730 result.append("</span></span>"); 731 if (href != null) { 732 result.append("</a>"); 733 } 734 break; 735 736 case 2: 737 if (href != null) { 739 result.append(anchorStart); 740 result.append(href); 741 result.append("\" class=\"button\""); 742 if (target != null) { 743 result.append(" target=\""); 744 result.append(target); 745 result.append("\""); 746 } 747 result.append(">"); 748 } 749 result.append("<span unselectable=\"on\" "); 750 if (href != null) { 751 result.append("class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\""); 752 } else { 753 result.append("class=\"disabled\""); 754 } 755 result.append("><span unselectable=\"on\" class=\"txtbutton\">"); 756 result.append(shortKey(label)); 757 result.append("</span></span>"); 758 if (href != null) { 759 result.append("</a>"); 760 } 761 break; 762 763 default: 764 if (href != null) { 766 result.append(anchorStart); 767 result.append(href); 768 result.append("\" class=\"button\""); 769 if (target != null) { 770 result.append(" target=\""); 771 result.append(target); 772 result.append("\""); 773 } 774 result.append(" title=\""); 775 result.append(key(label)); 776 result.append("\">"); 777 } 778 result.append("<span unselectable=\"on\" "); 779 if (href != null) { 780 result.append("class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\""); 781 } else { 782 result.append("class=\"disabled\""); 783 } 784 result.append("><img class=\"button\" SRC=\""); 785 result.append(imagePath); 786 result.append(image); 787 if (image != null && image.indexOf('.') == -1) { 788 result.append(".png"); 790 } 791 result.append("\" alt=\""); 792 result.append(key(label)); 793 result.append("\">"); 794 result.append("</span>"); 795 if (href != null) { 796 result.append("</a>"); 797 } 798 break; 799 } 800 result.append("</td>\n"); 801 return result.toString(); 802 } 803 804 811 public String buttonBar(int segment) { 812 813 return buttonBar(segment, null); 814 } 815 816 824 public String buttonBar(int segment, String attributes) { 825 826 if (segment == HTML_START) { 827 String result = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\""; 828 if (attributes != null) { 829 result += " " + attributes; 830 } 831 return result + "><tr>\n"; 832 } else { 833 return "</tr></table>"; 834 } 835 } 836 837 842 public String buttonBarHorizontalLine() { 843 844 StringBuffer result = new StringBuffer (256); 845 result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\">\n"); 846 result.append("<tr>\n"); 847 result.append("\t<td class=\"horseparator\" ><img SRC=\""); 848 result.append(getSkinUri()); 849 result.append("tree/empty.gif\" border=\"0\" width=\"1\" height=\"1\" alt=\"\"></td>\n"); 850 result.append("</tr>\n"); 851 result.append("</table>\n"); 852 return result.toString(); 853 } 854 855 862 public String buttonBarLabel(String label) { 863 864 return buttonBarLabel(label, "norm"); 865 } 866 867 875 public String buttonBarLabel(String label, String className) { 876 877 StringBuffer result = new StringBuffer (128); 878 result.append("<td><span class=\""); 879 result.append(className); 880 result.append("\"><span unselectable=\"on\" class=\"txtbutton\">"); 881 result.append(key(label)); 882 result.append("</span></span></td>\n"); 883 return result.toString(); 884 } 885 886 895 public String buttonBarLine(int leftPixel, int rightPixel, String className) { 896 897 StringBuffer result = new StringBuffer (512); 898 if (leftPixel > 0) { 899 result.append(buttonBarLineSpacer(leftPixel)); 900 } 901 result.append("<td><span class=\""); 902 result.append(className); 903 result.append("\"></span></td>\n"); 904 if (rightPixel > 0) { 905 result.append(buttonBarLineSpacer(rightPixel)); 906 } 907 return result.toString(); 908 } 909 910 917 public String buttonBarLineSpacer(int pixel) { 918 919 StringBuffer result = new StringBuffer (128); 920 result.append("<td><span class=\"norm\"><span unselectable=\"on\" class=\"txtbutton\" style=\"padding-right: 0px; padding-left: "); 921 result.append(pixel); 922 result.append("px;\"></span></span></td>\n"); 923 return result.toString(); 924 } 925 926 934 public String buttonBarSeparator(int leftPixel, int rightPixel) { 935 936 return buttonBarLine(leftPixel, rightPixel, "separator"); 937 } 938 939 945 public String buttonBarSpacer(int width) { 946 947 StringBuffer result = new StringBuffer (128); 948 result.append("<td><span class=\"norm\"><span unselectable=\"on\" class=\"txtbutton\" style=\"width: "); 949 result.append(width); 950 result.append("px;\"></span></span></td>\n"); 951 return result.toString(); 952 } 953 954 962 public String buttonBarStartTab(int leftPixel, int rightPixel) { 963 964 StringBuffer result = new StringBuffer (512); 965 result.append(buttonBarLineSpacer(leftPixel)); 966 result.append("<td><span class=\"starttab\"><span style=\"width:1px; height:1px\"></span></span></td>\n"); 967 result.append(buttonBarLineSpacer(rightPixel)); 968 return result.toString(); 969 } 970 971 977 public void checkLock(String resource) throws CmsException { 978 979 checkLock(resource, org.opencms.lock.CmsLock.COMMON); 980 } 981 982 989 public void checkLock(String resource, int mode) throws CmsException { 990 991 CmsResource res = getCms().readResource(resource, CmsResourceFilter.ALL); 992 CmsLock lock = getCms().getLock(res); 993 if (OpenCms.getWorkplaceManager().autoLockResources()) { 994 if (lock.isNullLock()) { 996 getCms().lockResource(resource, mode); 998 } else if (!lock.getUserId().equals(getCms().getRequestContext().currentUser().getId())) { 999 throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource)); 1000 } 1001 } else { 1002 if (lock.isNullLock() 1003 || (!lock.isNullLock() && !lock.getUserId().equals(getCms().getRequestContext().currentUser().getId()))) { 1004 throw new CmsException(Messages.get().container(Messages.ERR_WORKPLACE_LOCK_RESOURCE_1, resource)); 1005 } 1006 } 1007 } 1008 1009 1016 public void fillParamValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 1017 1018 initSettings(settings, request); 1019 fillParamValues(request); 1020 } 1021 1022 1033 public void fillParamValues(HttpServletRequest request) { 1034 1035 m_parameterMap = null; 1036 if (null == request.getAttribute(REQUEST_ATTRIBUTE_MULTIPART)) { 1038 m_multiPartFileItems = CmsRequestUtil.readMultipartFileItems(request); 1040 if (m_multiPartFileItems != null) { 1041 m_parameterMap = CmsRequestUtil.readParameterMapFromMultiPart( 1043 getCms().getRequestContext().getEncoding(), 1044 m_multiPartFileItems); 1045 request.setAttribute(REQUEST_ATTRIBUTE_MULTIPART, Boolean.TRUE); 1046 } 1047 } 1048 if (m_parameterMap == null) { 1049 m_parameterMap = request.getParameterMap(); 1051 } 1052 1053 List methods = paramSetMethods(); 1054 Iterator i = methods.iterator(); 1055 while (i.hasNext()) { 1056 Method m = (Method )i.next(); 1057 String name = m.getName().substring(8).toLowerCase(); 1058 String [] values = (String [])m_parameterMap.get(name); 1059 String value = null; 1060 if (values != null) { 1061 value = values[0]; 1063 } 1064 if (CmsStringUtil.isEmpty(value)) { 1065 value = null; 1066 } 1067 value = decodeParamValue(name, value); 1068 try { 1069 if (LOG.isDebugEnabled() && (value != null)) { 1070 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_PARAM_2, m.getName(), value)); 1071 } 1072 m.invoke(this, new Object [] {value}); 1073 } catch (InvocationTargetException ite) { 1074 if (LOG.isInfoEnabled()) { 1076 LOG.info(ite.getLocalizedMessage()); 1077 } 1078 } catch (IllegalAccessException eae) { 1079 if (LOG.isInfoEnabled()) { 1081 LOG.info(eae.getLocalizedMessage()); 1082 } 1083 } 1084 } 1085 } 1086 1087 1094 public String getBroadcastMessageString() { 1095 1096 String sessionId = getSession().getId(); 1097 Buffer messageQueue = OpenCms.getSessionManager().getBroadcastQueue(sessionId); 1098 if (!messageQueue.isEmpty()) { 1099 StringBuffer result = new StringBuffer (512); 1101 while (!messageQueue.isEmpty()) { 1103 CmsBroadcast message = (CmsBroadcast)messageQueue.remove(); 1104 result.append('['); 1105 result.append(getMessages().getDateTime(message.getSendTime())); 1106 result.append("] "); 1107 result.append(key(Messages.GUI_LABEL_BROADCASTMESSAGEFROM_0)); 1108 result.append(' '); 1109 result.append(message.getUser().getName()); 1110 result.append(":\n"); 1111 result.append(message.getMessage()); 1112 result.append("\n\n"); 1113 } 1114 return result.toString(); 1115 } 1116 return null; 1118 } 1119 1120 1125 public CmsObject getCms() { 1126 1127 return m_cms; 1128 } 1129 1130 1135 public String getEncoding() { 1136 1137 return OpenCms.getWorkplaceManager().getEncoding(); 1138 } 1139 1140 1145 public String getExplorerFileListFullUri() { 1146 1147 if (m_file_explorer_filelist != null) { 1148 return m_file_explorer_filelist; 1149 } 1150 synchronized (this) { 1151 m_file_explorer_filelist = OpenCms.getLinkManager().substituteLink(getCms(), FILE_EXPLORER_FILELIST); 1152 } 1153 return m_file_explorer_filelist; 1154 } 1155 1156 1163 public String getFrameSource(String frameName, String uri) { 1164 1165 String frameString = "name=\"" + frameName + "\" SRC=\"" + uri + "\""; 1166 int paramIndex = uri.indexOf("?"); 1167 if (paramIndex != -1) { 1168 uri = uri.substring(0, uri.indexOf("?")); 1170 } 1171 getSettings().getFrameUris().put(frameName, uri); 1172 return frameString; 1173 } 1174 1175 1180 public CmsJspActionElement getJsp() { 1181 1182 return m_jsp; 1183 } 1184 1185 1190 public Locale getLocale() { 1191 1192 return m_settings.getUserSettings().getLocale(); 1193 } 1194 1195 1200 public CmsMacroResolver getMacroResolver() { 1201 1202 if (m_macroResolver == null) { 1203 m_macroResolver = CmsMacroResolver.newInstance() 1205 .setCmsObject(m_cms).setMessages(getMessages()).setJspPageContext( 1207 (m_jsp == null) ? null : m_jsp.getJspContext()); 1208 } 1209 return m_macroResolver; 1210 } 1211 1212 1217 public CmsMessages getMessages() { 1218 1219 return m_messages; 1220 } 1221 1222 1229 public List getMultiPartFileItems() { 1230 1231 return m_multiPartFileItems; 1232 } 1233 1234 1244 public String getResourceUri() { 1245 1246 if (m_resourceUri == null) { 1247 m_resourceUri = OpenCms.getSystemInfo().getContextPath() + CmsWorkplace.RFS_PATH_RESOURCES; 1248 } 1249 return m_resourceUri; 1250 } 1251 1252 1257 public HttpSession getSession() { 1258 1259 return m_session; 1260 } 1261 1262 1267 public CmsWorkplaceSettings getSettings() { 1268 1269 return m_settings; 1270 } 1271 1272 1278 public String getStyleUri(String filename) { 1279 1280 return getStyleUri(getJsp(), filename); 1281 } 1282 1283 1288 public String htmlEnd() { 1289 1290 return pageHtml(HTML_END, null); 1291 } 1292 1293 1300 public String htmlStart(String title) { 1301 1302 return pageHtml(HTML_START, title); 1303 } 1304 1305 1314 public boolean initSettings(CmsWorkplaceSettings settings, HttpServletRequest request) { 1315 1316 String project = request.getParameter(PARAM_WP_PROJECT); 1318 boolean reloadRequired = false; 1319 if (project != null) { 1320 reloadRequired = true; 1321 try { 1322 getCms().readProject(Integer.parseInt(project)); 1323 } catch (Exception e) { 1324 project = String.valueOf(CmsProject.ONLINE_PROJECT_ID); 1326 } 1327 try { 1328 m_cms.getRequestContext().setCurrentProject(getCms().readProject(Integer.parseInt(project))); 1329 } catch (Exception e) { 1330 if (LOG.isInfoEnabled()) { 1331 LOG.info(e); 1332 } 1333 } 1334 settings.setProject(Integer.parseInt(project)); 1335 } 1336 1337 String site = request.getParameter(PARAM_WP_SITE); 1339 if (site != null) { 1340 reloadRequired = true; 1341 m_cms.getRequestContext().setSiteRoot(site); 1342 settings.setSite(site); 1343 } 1344 1345 String explorerResource = request.getParameter(PARAM_WP_EXPLORER_RESOURCE); 1347 if (explorerResource != null) { 1348 reloadRequired = true; 1349 settings.setExplorerResource(explorerResource); 1350 } 1351 1352 return reloadRequired; 1353 } 1354 1355 1360 public boolean isForwarded() { 1361 1362 return m_forwarded; 1363 } 1364 1365 1370 public boolean isHelpEnabled() { 1371 1372 return getCms().existsResource( 1373 resolveMacros(CmsHelpTemplateBean.PATH_HELP), 1374 CmsResourceFilter.IGNORE_EXPIRATION); 1375 } 1376 1377 1382 public boolean isSubElement() { 1383 1384 return !getJsp().getRequestContext().getUri().equals(getJsp().info("opencms.request.element.uri")); 1385 } 1386 1387 1402 public String key(String keyName) { 1403 1404 return getMessages().key(keyName); 1405 } 1406 1407 1424 public String key(String keyName, Object [] params) { 1425 1426 return getMessages().key(keyName, params); 1427 } 1428 1429 1442 public String keyDefault(String keyName, String defaultValue) { 1443 1444 return getMessages().keyDefault(keyName, defaultValue); 1445 } 1446 1447 1458 public String nullToEmpty(String value) { 1459 1460 if (value != null) { 1461 return value; 1462 } 1463 return ""; 1464 } 1465 1466 1474 public String pageBody(int segment, String className, String parameters) { 1475 1476 if (segment == HTML_START) { 1477 StringBuffer result = new StringBuffer (128); 1478 result.append("</head>\n<body unselectable=\"on\""); 1479 if (getSettings().isViewAdministration()) { 1480 if (className == null || "dialog".equals(className)) { 1481 className = "dialogadmin"; 1482 } 1483 if (parameters == null) { 1484 result.append(" onLoad=\"window.top.body.admin_head.location.href='"); 1485 result.append(getJsp().link(CmsWorkplace.VFS_PATH_WORKPLACE + "action/administration_head.html")); 1486 result.append("';\""); 1487 } 1488 } 1489 if (className != null) { 1490 result.append(" class=\""); 1491 result.append(className); 1492 result.append("\""); 1493 } 1494 if (CmsStringUtil.isNotEmpty(parameters)) { 1495 result.append(" "); 1496 result.append(parameters); 1497 } 1498 result.append(">\n"); 1499 return result.toString(); 1500 } else { 1501 return "</body>"; 1502 } 1503 } 1504 1505 1513 public String pageHtml(int segment, String title) { 1514 1515 return pageHtmlStyle(segment, title, null); 1516 } 1517 1518 1527 public String pageHtmlStyle(int segment, String title, String stylesheet) { 1528 1529 if (segment == HTML_START) { 1530 StringBuffer result = new StringBuffer (512); 1531 result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n"); 1532 result.append("<html>\n<head>\n"); 1533 if (title != null) { 1534 result.append("<title>"); 1535 result.append(title); 1536 result.append("</title>\n"); 1537 } 1538 result.append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset="); 1539 result.append(getEncoding()); 1540 result.append("\">\n"); 1541 result.append("<link rel=\"stylesheet\" type=\"text/css\" HREF=\""); 1542 1543 result.append(getStyleUri(getJsp(), stylesheet == null ? "workplace.css" : stylesheet)); 1544 result.append("\">\n"); 1545 return result.toString(); 1546 } else { 1547 return "</html>"; 1548 } 1549 } 1550 1551 1558 public String paramsAsHidden() { 1559 1560 return paramsAsHidden(null); 1561 } 1562 1563 1572 public String paramsAsHidden(Collection excludes) { 1573 1574 StringBuffer result = new StringBuffer (512); 1575 Map params = paramValues(); 1576 Iterator i = params.keySet().iterator(); 1577 while (i.hasNext()) { 1578 String param = (String )i.next(); 1579 if ((excludes == null) || (!excludes.contains(param))) { 1580 Object value = params.get(param); 1581 result.append("<input type=\"hidden\" name=\""); 1582 result.append(param); 1583 result.append("\" value=\""); 1584 String encoded = CmsEncoder.encode(value.toString(), getCms().getRequestContext().getEncoding()); 1585 result.append(encoded); 1586 result.append("\">\n"); 1587 } 1588 } 1589 return result.toString(); 1590 } 1591 1592 1599 public Map paramsAsParameterMap() { 1600 1601 return CmsRequestUtil.createParameterMap(paramValues()); 1602 } 1603 1604 1611 public String paramsAsRequest() { 1612 1613 StringBuffer result = new StringBuffer (512); 1614 Map params = paramValues(); 1615 Iterator i = params.keySet().iterator(); 1616 while (i.hasNext()) { 1617 String param = (String )i.next(); 1618 Object value = params.get(param); 1619 result.append(param); 1620 result.append("="); 1621 result.append(CmsEncoder.encode(value.toString(), getCms().getRequestContext().getEncoding())); 1622 if (i.hasNext()) { 1623 result.append("&"); 1624 } 1625 } 1626 return result.toString(); 1627 } 1628 1629 1643 public String resolveMacros(String input) { 1644 1645 return getMacroResolver().resolveMacros(input); 1647 } 1648 1649 1655 public void sendCmsRedirect(String location) throws IOException { 1656 1657 int todo = 0; 1659 getJsp().getResponse().sendRedirect(OpenCms.getSystemInfo().getOpenCmsContext() + location); 1660 } 1661 1662 1671 public void sendForward(String location, Map params) throws IOException , ServletException { 1672 1673 setForwarded(true); 1674 params = CmsRequestUtil.createParameterMap(params); 1676 CmsRequestUtil.forwardRequest(getJsp().link(location), params, getJsp().getRequest(), getJsp().getResponse()); 1677 } 1678 1679 1684 public void setForwarded(boolean forwarded) { 1685 1686 m_forwarded = forwarded; 1687 } 1688 1689 1695 public String shortKey(String keyName) { 1696 1697 String value = keyDefault(keyName + CmsMessages.KEY_SHORT_SUFFIX, (String )null); 1698 if (value == null) { 1699 return key(keyName); 1701 } 1702 return value; 1703 } 1704 1705 1710 protected void addMessages(CmsMessages messages) { 1711 1712 if (messages != null) { 1713 m_messages.addMessages(messages); 1714 } 1715 } 1716 1717 1722 protected void addMessages(String bundleName) { 1723 1724 addMessages(new CmsMessages(bundleName, getLocale())); 1725 } 1726 1727 1732 protected Map allParamValues() { 1733 1734 List methods = paramGetMethods(); 1735 Map map = new HashMap (methods.size()); 1736 Iterator i = methods.iterator(); 1737 while (i.hasNext()) { 1738 Method m = (Method )i.next(); 1739 Object o = null; 1740 try { 1741 o = m.invoke(this, new Object [0]); 1742 } catch (InvocationTargetException ite) { 1743 if (LOG.isInfoEnabled()) { 1745 LOG.info(ite); 1746 } 1747 } catch (IllegalAccessException eae) { 1748 if (LOG.isInfoEnabled()) { 1750 LOG.info(eae); 1751 } 1752 } 1753 if (o == null) { 1754 o = ""; 1755 } 1756 map.put(m.getName().substring(8).toLowerCase(), o); 1757 } 1758 return map; 1759 } 1760 1761 1774 protected String decodeParamValue(String paramName, String paramValue) { 1775 1776 if ((paramName != null) && (paramValue != null)) { 1777 return CmsEncoder.decode(paramValue, getCms().getRequestContext().getEncoding()); 1778 } else { 1779 return null; 1780 } 1781 } 1782 1783 1791 protected Map getParameterMap() { 1792 1793 return m_parameterMap; 1794 } 1795 1796 1804 protected void initMessages() { 1805 1806 } 1808 1809 1817 protected void initWorkplaceMembers(CmsJspActionElement jsp) { 1818 1819 if (jsp != null) { 1820 m_jsp = jsp; 1821 m_cms = m_jsp.getCmsObject(); 1822 m_session = m_jsp.getRequest().getSession(); 1823 1824 m_settings = (CmsWorkplaceSettings)m_session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS); 1826 1827 if (m_settings == null) { 1828 m_settings = new CmsWorkplaceSettings(); 1830 m_settings = initWorkplaceSettings(m_cms, m_settings, false); 1831 storeSettings(m_session, m_settings); 1832 } 1833 1834 CmsMessages messages = OpenCms.getWorkplaceManager().getMessages(getLocale()); 1836 m_messages = new CmsMultiMessages(getLocale()); 1838 m_messages.addMessages(messages); 1839 initMessages(); 1840 1841 initWorkplaceRequestValues(m_settings, m_jsp.getRequest()); 1843 1844 initWorkplaceCmsContext(m_settings, m_cms); 1846 } 1847 } 1848 1849 1856 protected abstract void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request); 1857 1858 1863 protected Map paramValues() { 1864 1865 List methods = paramGetMethods(); 1866 Map map = new HashMap (methods.size()); 1867 Iterator i = methods.iterator(); 1868 while (i.hasNext()) { 1869 Method m = (Method )i.next(); 1870 Object o = null; 1871 try { 1872 o = m.invoke(this, new Object [0]); 1873 } catch (InvocationTargetException ite) { 1874 if (LOG.isInfoEnabled()) { 1876 LOG.info(ite.getLocalizedMessage()); 1877 } 1878 } catch (IllegalAccessException eae) { 1879 if (LOG.isInfoEnabled()) { 1881 LOG.info(eae.getLocalizedMessage()); 1882 } 1883 } 1884 if (o != null) { 1885 map.put(m.getName().substring(8).toLowerCase(), o); 1886 } 1887 } 1888 return map; 1889 } 1890 1891 1896 protected void switchToCurrentProject() throws CmsException { 1897 1898 if (m_currentProjectId != -1) { 1899 getCms().getRequestContext().setCurrentProject(getCms().readProject(m_currentProjectId)); 1901 } 1902 } 1903 1904 1912 protected int switchToTempProject() throws CmsException { 1913 1914 m_currentProjectId = getSettings().getProject(); 1916 int tempProjectId = OpenCms.getWorkplaceManager().getTempFileProjectId(); 1917 getCms().getRequestContext().setCurrentProject(getCms().readProject(tempProjectId)); 1918 return tempProjectId; 1919 } 1920 1921 1928 private void initWorkplaceCmsContext(CmsWorkplaceSettings settings, CmsObject cms) { 1929 1930 CmsRequestContext reqCont = cms.getRequestContext(); 1931 1932 if (settings.getProject() != reqCont.currentProject().getId()) { 1934 try { 1935 reqCont.setCurrentProject(cms.readProject(settings.getProject())); 1936 } catch (CmsDbEntryNotFoundException e) { 1937 try { 1938 reqCont.setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID)); 1940 settings.setProject(CmsProject.ONLINE_PROJECT_ID); 1941 } catch (CmsException ex) { 1942 if (LOG.isInfoEnabled()) { 1944 LOG.info(ex.getLocalizedMessage()); 1945 } 1946 } 1947 } catch (CmsException e1) { 1948 if (LOG.isInfoEnabled()) { 1949 LOG.info(e1.getLocalizedMessage()); 1950 } 1951 } 1952 } 1953 1954 if (!(settings.getSite().equals(reqCont.getSiteRoot()))) { 1956 reqCont.setSiteRoot(settings.getSite()); 1958 } 1960 } 1961 1962 1969 private List paramGetMethods() { 1970 1971 List list = new ArrayList (); 1972 Method [] methods = this.getClass().getMethods(); 1973 int length = methods.length; 1974 for (int i = 0; i < length; i++) { 1975 Method method = methods[i]; 1976 if (method.getName().startsWith("getParam") && (method.getParameterTypes().length == 0)) { 1977 if (DEBUG) { 1978 System.err.println("getMethod: " + method.getName()); 1979 } 1980 list.add(method); 1981 } 1982 } 1983 return list; 1984 } 1985 1986 1993 private List paramSetMethods() { 1994 1995 List list = new ArrayList (); 1996 Method [] methods = this.getClass().getMethods(); 1997 int length = methods.length; 1998 for (int i = 0; i < length; i++) { 1999 Method method = methods[i]; 2000 if (method.getName().startsWith("setParam") 2001 && (method.getParameterTypes().length == 1) 2002 && (method.getParameterTypes()[0].equals(java.lang.String .class))) { 2003 if (DEBUG) { 2004 System.err.println("setMethod: " + method.getName()); 2005 } 2006 list.add(method); 2007 } 2008 } 2009 return list; 2010 } 2011} | Popular Tags |