1 23 24 package org.apache.webdav.lib.methods; 25 26 import java.io.IOException ; 27 import org.apache.commons.httpclient.HttpConnection; 28 import org.apache.commons.httpclient.HttpException; 29 30 import org.apache.commons.httpclient.HttpState; 31 import org.apache.commons.httpclient.HttpStatus; 32 import org.apache.webdav.lib.WebdavState; 33 34 38 public class UnlockMethod 39 extends XMLResponseMethodBase { 40 41 public final static int NO_TRANSACTION = -1; 42 public final static int ABORT_TRANSACTION = 0; 43 public final static int COMMIT_TRANSACTION = 1; 44 45 47 48 private String lockToken = null; 49 50 private int transactionStatus = NO_TRANSACTION; 51 52 54 68 public UnlockMethod(String path, String txHandle, int transactionStatus) { 69 this(path); 70 setLockToken(txHandle); 71 setTransactionStatus(transactionStatus); 72 } 73 74 77 public UnlockMethod() { 78 } 79 80 81 84 public UnlockMethod(String path) { 85 super(path); 86 } 87 88 89 92 public UnlockMethod(String path, String lockToken) { 93 this(path); 94 setLockToken(lockToken); 95 } 96 97 98 100 101 public void setLockToken(String lockToken) { 102 checkNotUsed(); 103 this.lockToken = lockToken; 104 } 105 106 113 public int getTransactionStatus() { 114 return transactionStatus; 115 } 116 117 125 public void setTransactionStatus(int transactionStatus) { 126 this.transactionStatus = transactionStatus; 127 } 128 129 131 public String getName() { 132 return "UNLOCK"; 133 } 134 135 public void recycle() { 136 this.transactionStatus = NO_TRANSACTION; 137 } 138 139 146 public void setRequestHeader(String headerName, String headerValue) { 147 if (headerName.equalsIgnoreCase("Lock-Token")){ 148 setLockToken(headerValue); 149 } 150 else{ 151 super.setRequestHeader(headerName, headerValue); 152 } 153 } 154 155 161 public void addRequestHeaders(HttpState state, HttpConnection conn) 162 throws IOException , HttpException { 163 164 super.addRequestHeaders(state, conn); 165 166 super.setRequestHeader("Lock-Token", "<" + lockToken + ">"); 167 168 } 169 170 protected String generateRequestBody() { 171 if (getTransactionStatus() == NO_TRANSACTION) { 172 return ""; 173 } else { 174 return "<D:transactioninfo xmlns:D='DAV:'>\n <D:transactionstatus>" 175 + (getTransactionStatus() == ABORT_TRANSACTION ? "<D:abort/>" : "<D:commit/>") 176 + "</D:transactionstatus>\n</D:transactioninfo>"; 177 } 178 } 179 180 protected void processResponseBody(HttpState state, HttpConnection conn) { 181 if ((getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) && 182 (state instanceof WebdavState)) { 183 ((WebdavState) state).removeLock(getPath(), lockToken); 184 } 185 } 186 } 187 | Popular Tags |