1 23 24 package org.apache.slide.webdav.method; 25 26 import java.io.IOException ; 27 import java.util.List ; 28 29 import org.apache.slide.common.NamespaceAccessToken; 30 import org.apache.slide.common.ServiceAccessException; 31 import org.apache.slide.common.SlideException; 32 import org.apache.slide.event.EventDispatcher; 33 import org.apache.slide.lock.ObjectLockedException; 34 import org.apache.slide.structure.ObjectNode; 35 import org.apache.slide.webdav.WebdavException; 36 import org.apache.slide.webdav.WebdavServletConfig; 37 import org.apache.slide.webdav.event.WebdavEvent; 38 import org.apache.slide.webdav.util.BindConstants; 39 import org.apache.slide.webdav.util.PreconditionViolationException; 40 import org.apache.slide.webdav.util.ViolatedPrecondition; 41 import org.apache.slide.webdav.util.WebdavStatus; 42 import org.jdom.JDOMException; 43 44 45 49 public class UnbindMethod extends AbstractWebdavMethod implements BindConstants, WriteMethod { 50 51 private String collectionUri; 52 private String segment; 53 private ObjectNode collectionNode = null; 55 56 57 63 public UnbindMethod(NamespaceAccessToken token, WebdavServletConfig config) { 64 super(token, config); 65 } 66 67 72 protected void parseRequest() throws WebdavException { 73 collectionUri = requestUri; 74 if (collectionUri == null) { 75 collectionUri = "/"; 76 } 77 78 List content; 79 80 try{ 82 content = parseRequestContent(E_UNBIND).getChildren(); 83 segment = MethodUtil.getChildText(content, E_SEGMENT); 84 } 85 catch (IOException e) { int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR; 87 sendError( statusCode, e ); 88 throw new WebdavException( statusCode ); 89 } 90 catch (JDOMException e) { int statusCode = WebdavStatus.SC_BAD_REQUEST; 92 sendError( statusCode, e ); 93 throw new WebdavException( statusCode ); 94 } 95 96 collectionUri = requestUri; 97 if (collectionUri == null) { 98 collectionUri = "/"; 99 } 100 101 } 103 104 private void checkPreconditions() throws PreconditionViolationException, ServiceAccessException { 105 106 resp.setStatus( WebdavStatus.SC_OK ); 107 108 try { 109 collectionNode = structure.retrieve( slideToken, collectionUri ); 110 } 111 catch( ServiceAccessException e ) { 112 throw e; 113 } 114 catch (SlideException e) {} 116 if (collectionNode == null || !isCollection(collectionUri)) { 117 throw new PreconditionViolationException( 118 new ViolatedPrecondition(C_UNBIND_FROM_COLLECTION, WebdavStatus.SC_CONFLICT), collectionUri); 119 } 120 if (!collectionNode.hasBinding(segment)) { 121 throw new PreconditionViolationException( 122 new ViolatedPrecondition(C_UNBIND_SOURCE_EXISTS, WebdavStatus.SC_CONFLICT), collectionUri); 123 } 124 } 125 126 131 protected void executeRequest() throws WebdavException, IOException { 132 133 slideToken.setForceStoreEnlistment(true); 135 136 try { 138 if (isLockNull(collectionUri)) { 139 int statusCode = WebdavStatus.SC_NOT_FOUND; 140 sendError( statusCode, "lock-null resource", new Object []{collectionUri} ); 141 throw new WebdavException( statusCode ); 142 } 143 } 144 catch (ServiceAccessException e) { 145 int statusCode = getErrorCode((Exception )e); 146 sendError( statusCode, e ); 147 throw new WebdavException( statusCode ); 148 } 149 150 try { 151 if ( WebdavEvent.UNBIND.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.UNBIND, new WebdavEvent(this)); 152 153 checkPreconditions(); 154 structure.removeBinding( slideToken, collectionNode, segment ); 155 } 156 catch (ObjectLockedException e) { 157 ViolatedPrecondition violatedPrecondition; 158 if (collectionUri.equals(e.getObjectUri())) { 159 violatedPrecondition = 160 new ViolatedPrecondition(C_LOCKED_UPDATE_ALLOWED, WebdavStatus.SC_LOCKED); 161 } 162 else { 163 violatedPrecondition = 164 new ViolatedPrecondition(C_PROTECTED_URL_DELETION_ALLOWED, WebdavStatus.SC_CONFLICT); 165 } 166 sendPreconditionViolation( 167 new PreconditionViolationException(violatedPrecondition, collectionNode.getUri()) 168 ); 169 } 170 catch (PreconditionViolationException e) { 171 sendPreconditionViolation(e); 172 throw e; 173 } 174 catch (Exception e) { 175 int statusCode = getErrorCode( e ); 176 sendError( statusCode, e ); 177 throw new WebdavException( statusCode ); 178 } 179 } 180 181 } 182 183 | Popular Tags |