1 31 32 package org.opencms.workplace.commons; 33 34 import org.opencms.file.CmsResource; 35 import org.opencms.file.CmsResourceFilter; 36 import org.opencms.jsp.CmsJspActionElement; 37 import org.opencms.lock.CmsLock; 38 import org.opencms.main.CmsException; 39 import org.opencms.main.CmsLog; 40 import org.opencms.main.OpenCms; 41 import org.opencms.security.CmsPermissionSet; 42 import org.opencms.workplace.CmsDialogSelector; 43 import org.opencms.workplace.CmsMultiDialog; 44 import org.opencms.workplace.CmsWorkplaceSettings; 45 import org.opencms.workplace.I_CmsDialogHandler; 46 47 import java.util.ArrayList ; 48 import java.util.Iterator ; 49 import java.util.List ; 50 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 import javax.servlet.jsp.JspException ; 54 import javax.servlet.jsp.PageContext ; 55 56 import org.apache.commons.logging.Log; 57 58 73 public class CmsDelete extends CmsMultiDialog implements I_CmsDialogHandler { 74 75 76 public static final int ACTION_DELETE = 100; 77 78 79 public static final String DIALOG_TYPE = "delete"; 80 81 82 public static final String PARAM_DELETEVFSLINKS = "deletevfslinks"; 83 84 85 public static final String URI_DELETE_DIALOG = PATH_DIALOGS + "delete_standard.jsp"; 86 87 88 private static final Log LOG = CmsLog.getLog(CmsDelete.class); 89 90 private String m_deleteVfsLinks; 91 92 95 public CmsDelete() { 96 97 super(null); 98 } 99 100 105 public CmsDelete(CmsJspActionElement jsp) { 106 107 super(jsp); 108 } 109 110 117 public CmsDelete(PageContext context, HttpServletRequest req, HttpServletResponse res) { 118 119 this(new CmsJspActionElement(context, req, res)); 120 } 121 122 127 public void actionDelete() throws JspException { 128 129 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 131 try { 132 boolean isFolder = false; 133 if (!isMultiOperation()) { 134 CmsResource resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 135 resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 136 isFolder = resource.isFolder(); 137 } 138 if (performDialogOperation()) { 139 if (isMultiOperation() || isFolder) { 141 List folderList = new ArrayList (1); 143 folderList.add(CmsResource.getParentFolder((String )getResourceList().get(0))); 144 getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList); 145 } 146 actionCloseDialog(); 147 } else { 148 getJsp().include(FILE_DIALOG_SCREEN_WAIT); 150 } 151 } catch (Throwable e) { 152 includeErrorpage(this, e); 154 } 155 } 156 157 162 public String buildDeleteSiblings() { 163 164 StringBuffer result = new StringBuffer (512); 165 if (isMultiOperation() || (hasVfsLinks() && hasCorrectLockstate())) { 166 int defaultMode = getSettings().getUserSettings().getDialogDeleteFileMode(); 168 if (! isMultiOperation()) { 169 result.append(key(Messages.GUI_DELETE_WARNING_SIBLINGS_0)); 170 result.append("<p>"); 171 } 172 result.append("<input type=\"radio\" name=\""); 173 result.append(PARAM_DELETEVFSLINKS); 174 result.append("\" value=\"false\""); 175 if (defaultMode == CmsResource.DELETE_PRESERVE_SIBLINGS) { 176 result.append(" checked=\"checked\""); 177 } 178 result.append("> "); 179 result.append(key(Messages.GUI_DELETE_PRESERVE_SIBLINGS_0)); 180 result.append("<br>"); 181 result.append("<input type=\"radio\" name=\""); 182 result.append(PARAM_DELETEVFSLINKS); 183 result.append("\" value=\"true\""); 184 if (defaultMode == CmsResource.DELETE_REMOVE_SIBLINGS) { 185 result.append(" checked=\"checked\""); 186 } 187 result.append("> "); 188 result.append(key(Messages.GUI_DELETE_ALL_SIBLINGS_0)); 189 result.append("<p>"); 190 } 191 if (isMultiOperation()) { 192 result.append(key(Messages.GUI_DELETE_MULTI_CONFIRMATION_0)); 193 } else { 194 result.append(key(Messages.GUI_DELETE_CONFIRMATION_0)); 195 } 196 return result.toString(); 197 } 198 199 202 public String getDialogHandler() { 203 204 return CmsDialogSelector.DIALOG_DELETE; 205 } 206 207 210 public String getDialogUri(String resource, CmsJspActionElement jsp) { 211 212 return URI_DELETE_DIALOG; 213 } 214 215 220 public String getParamDeleteVfsLinks() { 221 222 return m_deleteVfsLinks; 223 } 224 225 233 public boolean hasCorrectLockstate() { 234 235 CmsLock lock = null; 236 try { 237 lock = getCms().getLock(getParamResource()); 239 } catch (CmsException e) { 240 LOG.error(e.getLocalizedMessage(), e); 242 return false; 243 } 244 int type = lock.getType(); 245 boolean autoLockFeature = lock.isNullLock() && OpenCms.getWorkplaceManager().autoLockResources(); 247 return (autoLockFeature || type == CmsLock.TYPE_EXCLUSIVE || type == CmsLock.TYPE_INHERITED); 248 } 249 250 255 public boolean hasVfsLinks() { 256 257 try { 258 return getCms().readSiblings(getParamResource(), CmsResourceFilter.ALL).size() > 1; 259 } catch (CmsException e) { 260 LOG.error(e.getLocalizedMessage(), e); 261 return false; 262 } 263 264 } 265 266 271 public void setParamDeleteVfsLinks(String value) { 272 273 m_deleteVfsLinks = value; 274 } 275 276 279 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 280 281 fillParamValues(request); 283 284 if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) { 286 setParamAction(DIALOG_CANCEL); 288 } 289 290 setParamDialogtype(DIALOG_TYPE); 292 if (DIALOG_TYPE.equals(getParamAction())) { 294 setAction(ACTION_DELETE); 295 } else if (DIALOG_WAIT.equals(getParamAction())) { 296 setAction(ACTION_WAIT); 297 } else if (DIALOG_CANCEL.equals(getParamAction())) { 298 setAction(ACTION_CANCEL); 299 } else { 300 setAction(ACTION_DEFAULT); 301 setDialogTitle(Messages.GUI_DELETE_RESOURCE_1, Messages.GUI_DELETE_MULTI_2); 303 } 304 } 305 306 312 protected boolean performDialogOperation() throws CmsException { 313 314 int deleteOption = -1; 315 316 boolean isFolder = isOperationOnFolder(); 318 if ((isMultiOperation() || isFolder) && !DIALOG_WAIT.equals(getParamAction())) { 320 return false; 322 } 323 324 deleteOption = Boolean.valueOf(getParamDeleteVfsLinks()).booleanValue() ? CmsResource.DELETE_REMOVE_SIBLINGS 326 : CmsResource.DELETE_PRESERVE_SIBLINGS; 327 328 Iterator i = getResourceList().iterator(); 329 while (i.hasNext()) { 331 String resName = (String )i.next(); 332 try { 333 performSingleDeleteOperation(resName, deleteOption); 334 } catch (CmsException e) { 335 if (isMultiOperation()) { 336 addMultiOperationException(e); 338 } else { 339 throw e; 341 } 342 } 343 } 344 checkMultiOperationException(Messages.get(), Messages.ERR_DELETE_MULTI_0); 346 347 return true; 348 } 349 350 357 protected void performSingleDeleteOperation(String resource, int deleteOption) throws CmsException { 358 359 checkLock(resource); 361 getCms().deleteResource(resource, deleteOption); 363 } 364 365 } | Popular Tags |