1 23 24 package org.apache.slide.webdav.method; 25 26 import java.io.IOException ; 27 28 import org.apache.slide.common.NamespaceAccessToken; 29 import org.apache.slide.common.ServiceAccessException; 30 import org.apache.slide.common.SlideException; 31 import org.apache.slide.content.NodeRevisionDescriptor; 32 import org.apache.slide.content.NodeRevisionDescriptors; 33 import org.apache.slide.content.RevisionDescriptorNotFoundException; 34 import org.apache.slide.event.EventDispatcher; 35 import org.apache.slide.macro.DeleteListener; 36 import org.apache.slide.macro.DeleteMacroException; 37 import org.apache.slide.structure.ObjectNotFoundException; 38 import org.apache.slide.util.Configuration; 39 import org.apache.slide.webdav.WebdavException; 40 import org.apache.slide.webdav.WebdavServletConfig; 41 import org.apache.slide.webdav.event.WebdavEvent; 42 import org.apache.slide.webdav.util.DeltavConstants; 43 import org.apache.slide.webdav.util.PreconditionViolationException; 44 import org.apache.slide.webdav.util.PropertyHelper; 45 import org.apache.slide.webdav.util.UriHandler; 46 import org.apache.slide.webdav.util.VersioningHelper; 47 import org.apache.slide.webdav.util.ViolatedPrecondition; 48 import org.apache.slide.webdav.util.WebdavStatus; 49 import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind; 50 import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlled; 51 import org.apache.slide.webdav.util.resourcekind.ResourceKind; 52 import org.apache.slide.webdav.util.resourcekind.Working; 53 import org.jdom.JDOMException; 54 55 59 public class DeleteMethod extends AbstractMultistatusResponseMethod implements DeltavConstants, DeleteListener, WriteMethod { 60 61 62 64 65 68 private String toDelete; 69 70 73 protected NodeRevisionDescriptors historyNrds = null; 74 75 78 protected boolean isCollection = false; 79 80 84 protected UriHandler uriHandler = null; 85 86 89 protected VersioningHelper versioningHelper = null; 90 91 92 94 95 101 public DeleteMethod(NamespaceAccessToken token, 102 WebdavServletConfig config) { 103 super(token, config); 104 } 105 106 107 109 110 115 protected void parseRequest() 116 throws WebdavException { 117 versioningHelper = 118 VersioningHelper.getVersioningHelper(slideToken, token, req, resp, 119 config); 120 toDelete = requestUri; 121 if (toDelete == null) { 122 toDelete = "/"; 123 } 124 } 125 126 127 132 protected void executeRequest() 133 throws WebdavException { 134 135 slideToken.setForceStoreEnlistment(true); 137 138 try { 140 if (isLockNull(toDelete)) { 141 int statusCode = WebdavStatus.SC_NOT_FOUND; 142 sendError( statusCode, "lock-null resource", new Object []{toDelete} ); 143 throw new WebdavException( statusCode ); 144 } 145 } 146 catch (ServiceAccessException e) { 147 int statusCode = getErrorCode( e ); 148 sendError( statusCode, e ); 149 throw new WebdavException( statusCode ); 150 } 151 152 isCollection = isCollection(toDelete); 153 try { 154 if ( WebdavEvent.DELETE.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.DELETE, new WebdavEvent(this)); 155 156 macro.delete(slideToken, toDelete, null, this); 157 resp.setStatus(WebdavStatus.SC_NO_CONTENT); 158 } catch (DeleteMacroException dme) { 159 if (generateMultiStatusResponse(isCollection, dme, requestUri)) { 163 String errorMessage = generateErrorMessage(dme); 164 resp.setStatus(WebdavStatus.SC_MULTI_STATUS); 166 try { 167 resp.setContentType(TEXT_XML_UTF_8); 168 resp.getWriter().write(errorMessage); 169 } catch(IOException ex) { 170 int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR; 172 sendError( statusCode, ex ); 173 throw new WebdavException( statusCode ); 174 } 175 } else { 176 SlideException exception = (SlideException)dme.enumerateExceptions().nextElement(); 180 if (exception instanceof PreconditionViolationException) { 181 try { 182 sendPreconditionViolation((PreconditionViolationException)exception); 183 } catch(IOException ex) { 184 int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR; 186 sendError( statusCode, ex ); 187 throw new WebdavException( statusCode ); 188 } 189 } 190 else { 191 int statusCode = getErrorCode( exception ); 192 sendError( statusCode, exception ); 193 throw new WebdavException( statusCode ); 194 } 195 } 196 throw new WebdavException(WebdavStatus.SC_ACCEPTED, false); 201 } catch( SlideException x ) { 202 int statusCode = getErrorCode((SlideException)x); 203 sendError( statusCode, x ); 204 throw new WebdavException( statusCode ); 205 } 206 } 207 208 210 221 public void beforeDelete(String targetUri) throws SlideException { 222 223 if(Configuration.useVersionControl()) { 224 225 uriHandler = UriHandler.getUriHandler(targetUri); 226 if (uriHandler.isVersionUri() && !isCollection) { 227 throw new PreconditionViolationException(new ViolatedPrecondition(C_NO_VERSION_DELETE, 229 WebdavStatus.SC_FORBIDDEN), 230 targetUri); 231 } 232 233 NodeRevisionDescriptors nrds = content.retrieve(slideToken, targetUri); 236 NodeRevisionDescriptor nrd = content.retrieve(slideToken, nrds); 237 ResourceKind rk = AbstractResourceKind.determineResourceKind(token, nrds, nrd); 238 if(rk instanceof CheckedOutVersionControlled || rk instanceof Working) { 239 String vrUri = 240 VersioningHelper.getUriOfAssociatedVR(token, slideToken, content, targetUri); 241 try { 242 NodeRevisionDescriptors vrNrds = content.retrieve(slideToken, vrUri); 243 NodeRevisionDescriptor vrNrd = content.retrieve(slideToken, vrNrds); 244 PropertyHelper.removeHrefFromProperty(vrNrd, P_CHECKOUT_SET, targetUri); 245 content.store(slideToken, vrNrds.getUri(), vrNrd, null); 246 } 247 catch( ObjectNotFoundException e ) { 248 } 250 catch( RevisionDescriptorNotFoundException e ) { 251 } 253 catch( JDOMException e ) { 254 throw new SlideException( 255 "Unable to update DAV:checkout-set of "+vrUri+": "+e.getMessage() ); 256 } 257 } 258 } 259 } 260 261 262 272 public void afterDelete(String targetUri) throws SlideException { 273 } 274 275 276 277 } 278 279 | Popular Tags |