1 31 32 package org.opencms.workplace.commons; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsResource; 36 import org.opencms.file.CmsResourceFilter; 37 import org.opencms.jsp.CmsJspActionElement; 38 import org.opencms.main.CmsException; 39 import org.opencms.security.CmsPermissionSet; 40 import org.opencms.workplace.CmsDialogSelector; 41 import org.opencms.workplace.CmsMultiDialog; 42 import org.opencms.workplace.CmsWorkplaceSettings; 43 import org.opencms.workplace.I_CmsDialogHandler; 44 45 import java.util.Iterator ; 46 47 import javax.servlet.http.HttpServletRequest ; 48 import javax.servlet.http.HttpServletResponse ; 49 import javax.servlet.jsp.JspException ; 50 import javax.servlet.jsp.PageContext ; 51 52 69 public class CmsLock extends CmsMultiDialog implements I_CmsDialogHandler { 70 71 72 public static final int ACTION_SUBMIT_NOCONFIRMATION = 200; 73 74 75 public static final String DIALOG_SUBMIT_NOCONFIRMATION = "submitnoconfirmation"; 76 77 78 public static final String DIALOG_TYPE_LOCK = "lock"; 79 80 public static final String DIALOG_TYPE_LOCKCHANGE = "lockchange"; 81 82 public static final String DIALOG_TYPE_UNLOCK = "unlock"; 83 84 85 public static final int TYPE_LOCK = 1; 86 87 public static final int TYPE_LOCKCHANGE = 2; 88 89 public static final int TYPE_UNLOCK = 3; 90 91 92 public static final String URI_LOCK_DIALOG = PATH_DIALOGS + "lock_standard.jsp"; 93 94 public static final String URI_LOCKCHANGE_DIALOG = PATH_DIALOGS + "lockchange_standard.jsp"; 95 96 public static final String URI_UNLOCK_DIALOG = PATH_DIALOGS + "unlock_standard.jsp"; 97 98 99 private boolean m_hasLockedSubResources; 100 101 104 public CmsLock() { 105 106 super(null); 107 } 108 109 114 public CmsLock(CmsJspActionElement jsp) { 115 116 super(jsp); 117 } 118 119 126 public CmsLock(PageContext context, HttpServletRequest req, HttpServletResponse res) { 127 128 this(new CmsJspActionElement(context, req, res)); 129 } 130 131 137 public static int getDialogAction(CmsObject cms) { 138 139 String fileName = CmsResource.getName(cms.getRequestContext().getUri()); 140 if (fileName == null) { 141 return TYPE_UNLOCK; 143 } else if (fileName.equalsIgnoreCase("lock.jsp")) { 144 return TYPE_LOCK; 146 } else if (fileName.indexOf("change") != -1) { 147 return TYPE_LOCKCHANGE; 149 } else { 150 return TYPE_UNLOCK; 152 } 153 } 154 155 160 public void actionToggleLock() throws JspException { 161 162 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 164 165 try { 166 167 if (performDialogOperation()) { 168 actionCloseDialog(); 170 } else { 171 getJsp().include(FILE_DIALOG_SCREEN_WAIT); 173 } 174 } catch (Throwable e) { 175 includeErrorpage(this, e); 177 } 178 } 179 180 185 public String buildDialogText() { 186 187 switch (getDialogAction(getCms())) { 188 case TYPE_LOCK: 189 if (hasLockedSubResources()) { 190 if (isMultiOperation()) { 191 return key(Messages.GUI_LOCK_MULTI_INFO_LOCKEDSUBRESOURCES_0); 192 } else { 193 return key(Messages.GUI_LOCK_INFO_LOCKEDSUBRESOURCES_0); 194 } 195 } else { 196 if (isMultiOperation()) { 197 return key(Messages.GUI_LOCK_MULTI_LOCK_CONFIRMATION_0); 198 } else { 199 return key(Messages.GUI_LOCK_CONFIRMATION_0); 200 } 201 } 202 case TYPE_LOCKCHANGE: 203 return key(Messages.GUI_LOCK_CHANGE_CONFIRMATION_0); 204 case TYPE_UNLOCK: 205 default: 206 if (isMultiOperation()) { 207 return key(Messages.GUI_LOCK_MULTI_UNLOCK_CONFIRMATION_0); 208 } else { 209 return key(Messages.GUI_LOCK_UNLOCK_CONFIRMATION_0); 210 } 211 } 212 } 213 214 217 public String getDialogHandler() { 218 219 return CmsDialogSelector.DIALOG_LOCK; 220 } 221 222 225 public String getDialogUri(String resource, CmsJspActionElement jsp) { 226 227 switch (getDialogAction(jsp.getCmsObject())) { 228 case TYPE_LOCK: 229 return URI_LOCK_DIALOG; 230 case TYPE_LOCKCHANGE: 231 return URI_LOCKCHANGE_DIALOG; 232 case TYPE_UNLOCK: 233 default: 234 return URI_UNLOCK_DIALOG; 235 } 236 } 237 238 243 public boolean hasLockedSubResources() { 244 245 return m_hasLockedSubResources; 246 } 247 248 253 public void setHasLockedSubResources(boolean hasLockedSubResources) { 254 255 m_hasLockedSubResources = hasLockedSubResources; 256 } 257 258 265 public boolean showConfirmation() { 266 267 boolean showConfirmation = getSettings().getUserSettings().getDialogShowLock(); 268 if (DIALOG_TYPE_LOCK.equals(getParamDialogtype())) { 269 Iterator i = getResourceList().iterator(); 271 while (i.hasNext()) { 272 String resName = (String )i.next(); 273 try { 274 CmsResource res = getCms().readResource(resName); 275 if (res.isFolder() && getCms().countLockedResources(resName) > 0) { 276 setHasLockedSubResources(true); 278 return true; 279 } 280 } catch (CmsException e) { 281 } 283 } 284 } 285 return showConfirmation; 286 } 287 288 291 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 292 293 fillParamValues(request); 295 296 if (DIALOG_CONFIRMED.equals(getParamAction())) { 298 setAction(ACTION_CONFIRMED); 299 } else if (DIALOG_CANCEL.equals(getParamAction())) { 300 setAction(ACTION_CANCEL); 301 } else if (DIALOG_WAIT.equals(getParamAction())) { 302 setAction(ACTION_WAIT); 303 } else { 304 switch (getDialogAction(getCms())) { 305 case TYPE_LOCK: 306 setDialogTitle(Messages.GUI_LOCK_RESOURCE_1, Messages.GUI_LOCK_MULTI_LOCK_2); 307 setParamDialogtype(DIALOG_TYPE_LOCK); 308 if (!isMultiOperation() && !checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) { 310 setAction(ACTION_CANCEL); 312 return; 313 } 314 break; 315 case TYPE_LOCKCHANGE: 316 setDialogTitle(Messages.GUI_LOCK_STEAL_1, Messages.GUI_LOCK_MULTI_STEAL_2); 317 setParamDialogtype(DIALOG_TYPE_UNLOCK); 318 break; 319 case TYPE_UNLOCK: 320 default: 321 setDialogTitle(Messages.GUI_LOCK_UNLOCK_1, Messages.GUI_LOCK_MULTI_UNLOCK_2); 322 setParamDialogtype(DIALOG_TYPE_UNLOCK); 323 } 324 if (showConfirmation()) { 326 setAction(ACTION_DEFAULT); 328 } else { 329 setAction(ACTION_SUBMIT_NOCONFIRMATION); 331 } 332 } 333 } 334 335 341 protected boolean performDialogOperation() throws CmsException { 342 343 if (isMultiOperation() && !DIALOG_WAIT.equals(getParamAction())) { 345 return false; 346 } 347 int dialogAction = getDialogAction(getCms()); 349 350 Iterator i = getResourceList().iterator(); 352 while (i.hasNext()) { 353 String resName = (String )i.next(); 354 try { 355 performSingleResourceOperation(resName, dialogAction); 356 } catch (CmsException e) { 357 addMultiOperationException(e); 359 } 360 } 361 String message; 363 if (dialogAction == TYPE_LOCK) { 364 message = Messages.ERR_LOCK_MULTI_0; 365 } else { 366 message = Messages.ERR_UNLOCK_MULTI_0; 367 } 368 checkMultiOperationException(Messages.get(), message); 369 370 return true; 371 } 372 373 380 protected void performSingleResourceOperation(String resourceName, int dialogAction) throws CmsException { 381 382 String originalResourceName = resourceName; 384 CmsResource res = getCms().readResource(resourceName, CmsResourceFilter.ALL); 385 if (res.isFolder() && !resourceName.endsWith("/")) { 386 resourceName += "/"; 387 } 388 switch (dialogAction) { 390 case TYPE_LOCK: 391 getCms().lockResource(originalResourceName); 392 break; 393 case TYPE_LOCKCHANGE: 394 getCms().changeLock(resourceName); 395 break; 396 case TYPE_UNLOCK: 397 default: 398 getCms().unlockResource(resourceName); 399 } 400 } 401 402 } | Popular Tags |