You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@apache.org on 2001/07/22 21:26:54 UTC
cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib WebdavResource.java WebdavState.java
remm 01/07/22 12:26:54
Modified: src/webdav/client/src/org/apache/webdav/lib
WebdavResource.java WebdavState.java
Log:
- Submit lock tokens in the If header for methods which need it (I never
realized this wasn't implemented yet).
Revision Changes Path
1.20 +44 -8 jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java
Index: WebdavResource.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- WebdavResource.java 2001/07/22 16:55:45 1.19
+++ WebdavResource.java 2001/07/22 19:26:54 1.20
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v 1.19 2001/07/22 16:55:45 remm Exp $
- * $Revision: 1.19 $
- * $Date: 2001/07/22 16:55:45 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v 1.20 2001/07/22 19:26:54 remm Exp $
+ * $Revision: 1.20 $
+ * $Date: 2001/07/22 19:26:54 $
*
* ====================================================================
*
@@ -588,6 +588,33 @@
/**
+ * Generate and add the If header to the specified HTTP method.
+ */
+ private void generateIfHeader(HttpMethod method) {
+
+ if (client == null)
+ return;
+ if (method == null)
+ return;
+
+ WebdavState state = (WebdavState) client.getState();
+ String[] lockTokens = state.getAllLocks(method.getPath());
+
+ if (lockTokens.length == 0)
+ return;
+
+ StringBuffer ifHeaderValue = new StringBuffer();
+
+ for (int i = 0; i < lockTokens.length; i++) {
+ ifHeaderValue.append("(<").append(lockTokens[i]).append(">) ");
+ }
+
+ method.setHeader("If", ifHeaderValue.toString());
+
+ }
+
+
+ /**
* Parse the <code>java.util.Date</code> string for HTTP-date.
*
* @return The parsed date.
@@ -1881,6 +1908,7 @@
setClient();
AclMethod method = new AclMethod(path);
+ generateIfHeader(method);
for (int i=0; i<aces.length ; i++) {
Ace ace = aces[i];
method.addAce(ace);
@@ -2103,6 +2131,7 @@
setClient();
PutMethod method = new PutMethod(HttpURL.getPathQuery(path));
+ generateIfHeader(method);
method.sendData(data);
method.setDebug(debug);
client.executeMethod(method);
@@ -2143,6 +2172,7 @@
setClient();
PutMethod method = new PutMethod(HttpURL.getPathQuery(path));
+ generateIfHeader(method);
method.sendData(is);
method.setDebug(debug);
client.executeMethod(method);
@@ -2186,6 +2216,7 @@
setClient();
PutMethod method = new PutMethod(HttpURL.getPath(path));
+ generateIfHeader(method);
method.sendData(data);
method.setDebug(debug);
client.executeMethod(method);
@@ -2229,6 +2260,7 @@
setClient();
PutMethod method = new PutMethod(HttpURL.getPath(path));
+ generateIfHeader(method);
method.sendData(file);
method.setDebug(debug);
client.executeMethod(method);
@@ -2275,6 +2307,7 @@
setClient();
PutMethod method = new PutMethod(HttpURL.getPath(path));
+ generateIfHeader(method);
method.sendData(url);
method.setDebug(debug);
client.executeMethod(method);
@@ -2698,6 +2731,7 @@
setClient();
PropPatchMethod method = new PropPatchMethod(HttpURL.getPath(path));
+ generateIfHeader(method);
Enumeration names = property.keys();
boolean hasSomething = false;
if (names.hasMoreElements())
@@ -2793,6 +2827,7 @@
setClient();
DeleteMethod method = new DeleteMethod(HttpURL.getPath(path));
+ generateIfHeader(method);
method.setDebug(debug);
client.executeMethod(method);
@@ -2836,6 +2871,7 @@
setClient();
MoveMethod method = new MoveMethod(source, destination);
+ generateIfHeader(method);
method.setOverwrite(overwrite);
method.setDebug(debug);
client.executeMethod(method);
@@ -2883,6 +2919,7 @@
setClient();
CopyMethod method = new CopyMethod(source, destination);
+ generateIfHeader(method);
method.setOverwrite(overwrite);
method.setDebug(debug);
client.executeMethod(method);
@@ -2927,6 +2964,7 @@
setClient();
MkcolMethod method = new MkcolMethod(HttpURL.getPath(path));
+ generateIfHeader(method);
method.setDebug(debug);
client.executeMethod(method);
@@ -3026,6 +3064,7 @@
short lockType = LockMethod.SCOPE_EXCLUSIVE;
LockMethod method =
new LockMethod(HttpURL.getPath(path), owner, lockType, timeout);
+ generateIfHeader(method);
method.setDebug(debug);
client.executeMethod(method);
String lock = method.getLockToken();
@@ -3080,16 +3119,13 @@
WebdavState state = (WebdavState) client.getState();
// Check the given path is alright.
path = HttpURL.getPath(path);
- Enumeration locks = state.getLocks(path);
- String lock = null;
- while (locks.hasMoreElements()) {
- lock = (String) locks.nextElement();
- }
+ String lock = state.getLock(path);
if (lock == null)
return false;
// unlock for the given path.
UnlockMethod method = new UnlockMethod(path);
+ generateIfHeader(method);
method.setLockToken(lock);
method.setDebug(debug);
client.executeMethod(method);
1.2 +52 -21 jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavState.java
Index: WebdavState.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavState.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebdavState.java 2001/07/22 03:10:27 1.1
+++ WebdavState.java 2001/07/22 19:26:54 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavState.java,v 1.1 2001/07/22 03:10:27 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2001/07/22 03:10:27 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavState.java,v 1.2 2001/07/22 19:26:54 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/07/22 19:26:54 $
*
* ====================================================================
*
@@ -65,6 +65,7 @@
import java.io.IOException;
import java.util.HashMap;
+import java.util.ArrayList;
import java.util.Vector;
import java.util.Enumeration;
import org.apache.commons.httpclient.State;
@@ -77,15 +78,27 @@
public class WebdavState extends State {
+ // -------------------------------------------------------------- Constants
+
+
+ private static final String[] EMPTY_ARRAY = new String[0];
+
+
// ----------------------------------------------------- Instance Variables
/**
* Lock tokens.
*/
- protected HashMap lockTokens = new HashMap();
+ protected HashMap locks = new HashMap();
+ /**
+ * Lock list.
+ */
+ protected ArrayList lockTokens = new ArrayList();
+
+
// ------------------------------------------------------------- Properties
@@ -97,12 +110,12 @@
*/
public void addLock(String uri, String value) {
- Vector currentLocks = (Vector) lockTokens.get(uri);
- if (currentLocks == null)
- currentLocks = new Vector();
- currentLocks.addElement(value);
- lockTokens.put(uri, currentLocks);
+ if (lockTokens.contains(value))
+ return;
+ locks.put(uri, value);
+ lockTokens.add(value);
+
}
@@ -114,10 +127,10 @@
*/
public void removeLock(String uri, String value) {
- Vector currentLocks = (Vector) lockTokens.get(uri);
- if (currentLocks == null)
- return;
- currentLocks.removeElement(value);
+ locks.remove(uri);
+ int i = lockTokens.indexOf(value);
+ if (i != -1)
+ lockTokens.remove(i);
}
@@ -129,22 +142,41 @@
*/
public void removeLocks(String uri) {
- lockTokens.remove(uri);
+ String result = (String) locks.remove(uri);
+ if (result != null) {
+ int i = lockTokens.indexOf(result);
+ if (i != -1)
+ lockTokens.remove(i);
+ }
}
/**
+ * Get lock
+ *
+ * @param uri Uri
+ */
+ public String getLock(String uri) {
+
+ return (String) locks.get(uri);
+
+ }
+
+
+ /**
* Get locks
*
* @param uri Uri
* @return Enumeration of lock tokens
+ * @deprecated
*/
public Enumeration getLocks(String uri) {
- Vector result = (Vector) lockTokens.get(uri);
- if (result == null)
- result = new Vector();
+ Vector result = new Vector();
+ String lockToken = getLock(uri);
+ if (lockToken != null)
+ result.addElement(lockToken);
return result.elements();
}
@@ -154,12 +186,11 @@
* Get all locks scoped to that uri.
*
* @param uri Uri
- * @return Enumeration of lock tokens
+ * @return Iterator of lock tokens
*/
- public Enumeration getAllLocks(String uri) {
+ public String[] getAllLocks(String uri) {
- // FIXME: Won't support collection locks
- return getLocks(uri);
+ return (String[]) lockTokens.toArray(EMPTY_ARRAY);
}