1 31 32 package org.opencms.workplace; 33 34 import org.opencms.file.CmsGroup; 35 import org.opencms.file.CmsProject; 36 import org.opencms.file.CmsResourceFilter; 37 import org.opencms.i18n.CmsEncoder; 38 import org.opencms.jsp.CmsJspActionElement; 39 import org.opencms.main.CmsException; 40 import org.opencms.main.CmsLog; 41 import org.opencms.main.OpenCms; 42 import org.opencms.site.CmsSite; 43 import org.opencms.site.CmsSiteManager; 44 import org.opencms.synchronize.CmsSynchronizeSettings; 45 import org.opencms.util.CmsRequestUtil; 46 import org.opencms.util.CmsStringUtil; 47 48 import java.util.ArrayList ; 49 import java.util.Arrays ; 50 import java.util.Collections ; 51 import java.util.Iterator ; 52 import java.util.List ; 53 import java.util.Vector ; 54 55 import javax.servlet.http.HttpServletRequest ; 56 57 import org.apache.commons.logging.Log; 58 59 76 public class CmsFrameset extends CmsWorkplace { 77 78 79 public static final String [] FRAMES = {"top", "head", "body", "foot"}; 80 81 82 public static final List FRAMES_LIST = Arrays.asList(FRAMES); 83 84 85 public static final String JSP_WORKPLACE_URI = CmsWorkplace.VFS_PATH_WORKPLACE + "views/workplace.jsp"; 86 87 88 public static final String PARAM_WP_START = "wpStart"; 89 90 91 public static final String PARAM_WP_VIEW = "wpView"; 92 93 94 public static final String PUBLISHBUTTON_SHOW_ALWAYS = "always"; 95 96 97 public static final String PUBLISHBUTTON_SHOW_AUTO = "auto"; 98 99 100 public static final String PUBLISHBUTTON_SHOW_NEVER = "never"; 101 102 103 private static final Log LOG = CmsLog.getLog(CmsFrameset.class); 104 105 106 private boolean m_reloadRequired; 107 108 109 public static final String PARAM_WP_FRAME = "wpFrame"; 110 111 116 public CmsFrameset(CmsJspActionElement jsp) { 117 118 super(jsp); 119 } 120 121 126 public String getBroadcastMessage() { 127 128 StringBuffer result = new StringBuffer (512); 129 String message = getBroadcastMessageString(); 130 131 if (CmsStringUtil.isNotEmpty(message)) { 132 result.append("\n<script type=\"text/javascript\">\n<!--\n"); 134 result.append("function showMessage() {\n"); 136 result.append("\talert(decodeURIComponent(\""); 137 result.append(CmsEncoder.escapeWBlanks(message, CmsEncoder.ENCODING_UTF_8)); 139 result.append("\"));\n}\n"); 140 result.append("setTimeout('showMessage();', 2000);"); 141 result.append("\n//-->\n</script>"); 142 } 143 return result.toString(); 144 } 145 146 152 public String getGroupSelect(String htmlAttributes) { 153 154 List allGroups = new Vector (); 156 try { 157 allGroups = getCms().getGroupsOfUser(getSettings().getUser().getName()); 158 } catch (CmsException e) { 159 if (LOG.isInfoEnabled()) { 161 LOG.info(e.getLocalizedMessage()); 162 } 163 } 164 165 List options = new ArrayList (); 166 List values = new ArrayList (); 167 168 int numGroups = allGroups.size(); 170 for (int i = 0; i < numGroups; i++) { 171 CmsGroup loopGroup = (CmsGroup)allGroups.get(i); 172 String loopGroupName = loopGroup.getName(); 173 values.add(loopGroupName); 174 options.add(loopGroupName); 175 } 176 177 return buildSelect(htmlAttributes, options, values, 0); 178 } 179 180 185 public String getLoginAddress() { 186 187 return getCms().getRequestContext().getRemoteAddress(); 188 } 189 190 195 public String getLoginTime() { 196 197 return getMessages().getDateTime(getSettings().getUser().getLastlogin()); 198 } 199 200 207 public String getProjectSelect(String htmlAttributes, String htmlWidth) { 208 209 List allProjects; 211 try { 212 allProjects = getCms().getAllAccessibleProjects(); 213 } catch (CmsException e) { 214 if (LOG.isInfoEnabled()) { 216 LOG.info(e.getLocalizedMessage()); 217 } 218 allProjects = Collections.EMPTY_LIST; 219 } 220 221 List options = new ArrayList (); 222 List values = new ArrayList (); 223 int selectedIndex = 0; 224 225 for (int i = 0, n = allProjects.size(); i < n; i++) { 227 CmsProject loopProject = (CmsProject)allProjects.get(i); 228 String loopProjectName = loopProject.getName(); 229 String loopProjectId = Integer.toString(loopProject.getId()); 230 231 values.add(loopProjectId); 232 options.add(loopProjectName); 233 234 if (loopProject.getId() == getSettings().getProject()) { 235 selectedIndex = i; 237 } 238 } 240 if (CmsStringUtil.isNotEmpty(htmlWidth)) { 241 StringBuffer buf = new StringBuffer (htmlAttributes.length() + htmlWidth.length() + 2); 242 buf.append(htmlAttributes); 243 buf.append(" "); 244 buf.append(htmlWidth); 245 htmlAttributes = buf.toString(); 246 } 247 248 return buildSelect(htmlAttributes, options, values, selectedIndex); 249 } 250 251 257 public String getPublishButton() { 258 259 String publishButton = OpenCms.getWorkplaceManager().getDefaultUserSettings().getPublishButtonAppearance(); 260 if (PUBLISHBUTTON_SHOW_NEVER.equals(publishButton)) { 261 return ""; 262 } 263 264 int buttonStyle = getSettings().getUserSettings().getWorkplaceButtonStyle(); 265 266 if (PUBLISHBUTTON_SHOW_AUTO.equals(publishButton)) { 267 if (getCms().isManagerOfProject()) { 268 return button("../commons/publishproject.jsp", "body", "publish.png", Messages.GUI_BUTTON_PUBLISH_0 , buttonStyle); 269 } else { 270 return ""; 271 } 272 } 273 274 if (getCms().isManagerOfProject()) { 275 return (button("../commons/publishproject.jsp", "body", "publish.png", Messages.GUI_BUTTON_PUBLISH_0, buttonStyle)); 276 } else { 277 return (button(null, null, "publish_in.png", Messages.GUI_BUTTON_PUBLISH_0, buttonStyle)); 278 } 279 } 280 281 287 public String getSiteSelect(String htmlAttributes) { 288 289 List options = new ArrayList (); 290 List values = new ArrayList (); 291 int selectedIndex = 0; 292 293 List sites = CmsSiteManager.getAvailableSites(getCms(), true); 294 295 Iterator i = sites.iterator(); 296 int pos = 0; 297 while (i.hasNext()) { 298 CmsSite site = (CmsSite)i.next(); 299 values.add(site.getSiteRoot()); 300 options.add(site.getTitle()); 301 if (site.getSiteRoot().equals(getSettings().getSite())) { 302 selectedIndex = pos; 304 } 305 pos++; 306 } 307 308 return buildSelect(htmlAttributes, options, values, selectedIndex); 309 } 310 311 317 public String getStartupUri() { 318 319 String result = getSettings().getViewStartup(); 320 if (result == null) { 321 result = getSettings().getViewUri(); 323 } else { 324 getSettings().setViewStartup(null); 326 } 327 return CmsRequestUtil.appendParameter(result, CmsFrameset.PARAM_WP_FRAME, FRAMES[2]); 328 } 329 330 336 public String getViewSelect(String htmlAttributes) { 337 338 List options = new ArrayList (); 339 List values = new ArrayList (); 340 int selectedIndex = 0; 341 342 Iterator i = OpenCms.getWorkplaceManager().getViews().iterator(); 344 int count = -1; 345 String currentView = getSettings().getViewUri(); 346 if (CmsStringUtil.isNotEmpty(currentView)) { 347 int pos = currentView.indexOf('?'); 349 if (pos >= 0) { 350 currentView = currentView.substring(0, pos); 351 } 352 } 353 while (i.hasNext()) { 354 CmsWorkplaceView view = (CmsWorkplaceView)i.next(); 355 if (getCms().existsResource(view.getUri(), CmsResourceFilter.ONLY_VISIBLE_NO_DELETED)) { 356 count++; 357 String loopLink = getJsp().link(view.getUri()); 359 String localizedKey = resolveMacros(view.getKey()); 360 options.add(localizedKey); 361 values.add(loopLink); 362 363 if (loopLink.equals(currentView)) { 364 selectedIndex = count; 365 } 366 } 367 } 368 369 return buildSelect(htmlAttributes, options, values, selectedIndex); 370 } 371 372 377 public String getWorkplaceReloadUri() { 378 379 return getJsp().link(CmsFrameset.JSP_WORKPLACE_URI); 380 } 381 382 394 public boolean isReloadRequired() { 395 396 return m_reloadRequired; 397 } 398 399 404 public boolean isSyncEnabled() { 405 406 CmsSynchronizeSettings syncSettings = getSettings().getUserSettings().getSynchronizeSettings(); 407 return (syncSettings != null) && syncSettings.isSyncEnabled(); 408 } 409 410 415 public boolean showSiteSelector() { 416 417 if (getSettings().getUserSettings().getRestrictExplorerView()) { 418 return false; 420 } 421 int siteCount = CmsSiteManager.getAvailableSites(getCms(), true).size(); 423 return (siteCount > 1); 424 } 425 426 427 430 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 431 432 String frame = CmsRequestUtil.getNotEmptyDecodedParameter(request, CmsFrameset.PARAM_WP_FRAME); 434 if ((frame == null) || (FRAMES_LIST.indexOf(frame) < 0)) { 435 frame = FRAMES[0]; 437 } 438 439 if (FRAMES[0].equals(frame)) { 440 topFrameReload(settings); 442 } 443 444 String startup = CmsRequestUtil.getNotEmptyDecodedParameter(request, CmsFrameset.PARAM_WP_START); 446 if (startup != null) { 447 m_reloadRequired = true; 448 settings.setViewStartup(startup); 449 } 450 451 String view = request.getParameter(CmsFrameset.PARAM_WP_VIEW); 453 if (view != null) { 454 m_reloadRequired = true; 455 settings.setViewUri(view); 456 settings.getFrameUris().put("body", view); 458 settings.getFrameUris().put("admin_content", "/system/workplace/action/administration_content_top.html"); 459 } 460 461 m_reloadRequired = initSettings(settings, request) || m_reloadRequired; 462 } 463 464 469 protected void topFrameReload(CmsWorkplaceSettings settings) { 470 471 initUserSettings(getCms(), settings, true); 473 474 settings.setListObject(null); 476 } 477 } 478
| Popular Tags
|