1 17 package org.alfresco.repo.webdav; 18 19 import javax.servlet.http.HttpServletResponse ; 20 21 import org.alfresco.service.cmr.lock.LockService; 22 import org.alfresco.service.cmr.lock.LockStatus; 23 import org.alfresco.service.cmr.model.FileInfo; 24 import org.alfresco.service.cmr.model.FileNotFoundException; 25 26 31 public class UnlockMethod extends WebDAVMethod 32 { 33 private String m_strLockToken = null; 34 35 38 public UnlockMethod() 39 { 40 } 41 42 47 protected final String getLockToken() 48 { 49 return m_strLockToken; 50 } 51 52 57 protected void parseRequestHeaders() throws WebDAVServerException 58 { 59 String strLockTokenHeader = m_request.getHeader(WebDAV.HEADER_LOCK_TOKEN); 61 62 if (logger.isDebugEnabled()) 64 logger.debug("Parsing Lock-Token header: " + strLockTokenHeader); 65 66 if (strLockTokenHeader != null && strLockTokenHeader.startsWith("<") && strLockTokenHeader.endsWith(">")) 68 { 69 try 70 { 71 m_strLockToken = strLockTokenHeader.substring( 72 WebDAV.OPAQUE_LOCK_TOKEN.length() + 1, 73 strLockTokenHeader.length() - 1); 74 } 75 catch (IndexOutOfBoundsException e) 76 { 77 logger.warn("Failed to parse If header: " + strLockTokenHeader); 78 } 79 } 80 81 if (m_strLockToken == null) 83 { 84 throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST); 85 } 86 } 87 88 93 protected void parseRequestBody() throws WebDAVServerException 94 { 95 } 97 98 103 protected void executeImpl() throws WebDAVServerException 104 { 105 if (logger.isDebugEnabled()) 106 { 107 logger.debug("Lock node; path=" + getPath() + ", token=" + getLockToken()); 108 } 109 110 FileInfo lockNodeInfo = null; 111 try 112 { 113 lockNodeInfo = getDAVHelper().getNodeForPath(getRootNodeRef(), getPath(), getServletPath()); 114 } 115 catch (FileNotFoundException e) 116 { 117 throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); 118 } 119 120 String [] lockInfo = WebDAV.parseLockToken(getLockToken()); 122 if (lockInfo == null) 123 { 124 throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); 126 } 127 128 LockService lockService = getDAVHelper().getLockService(); 130 133 LockStatus lockSts = lockService.getLockStatus(lockNodeInfo.getNodeRef()); 134 if (lockSts == LockStatus.LOCK_OWNER) 135 { 136 lockService.unlock(lockNodeInfo.getNodeRef()); 138 139 m_response.setStatus(HttpServletResponse.SC_NO_CONTENT); 141 142 if (logger.isDebugEnabled()) 144 { 145 logger.debug("Unlock token=" + getLockToken() + " Successful"); 146 } 147 } 148 else if (lockSts == LockStatus.NO_LOCK) 149 { 150 if (logger.isDebugEnabled()) 152 logger.debug("Unlock token=" + getLockToken() + " Not locked"); 153 154 throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); 156 } 157 else if (lockSts == LockStatus.LOCKED) 158 { 159 if (logger.isDebugEnabled()) 161 logger.debug("Unlock token=" + getLockToken() + " Not lock owner"); 162 163 throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED); 165 } 166 else if (lockSts == LockStatus.LOCK_EXPIRED) 167 { 168 if (logger.isDebugEnabled()) 170 logger.debug("Unlock token=" + getLockToken() + " Lock expired"); 171 172 m_response.setStatus(HttpServletResponse.SC_NO_CONTENT); 174 } 175 } 176 } 177 | Popular Tags |