ozeigermann 2004/07/05 08:23:55
Modified: webdavclient/clientlib/src/java/org/apache/webdav/lib/methods
LockMethod.java UnlockMethod.java
webdavclient/commandline/src/java/org/apache/webdav/cmd
ClientLexer.java ClientParser.java Client.g
SlideTokenTypes.java Client.java
webdavclient/clientlib/src/java/org/apache/webdav/lib
WebdavState.java WebdavResource.java
Log:
Initial rudimentary client side implementation for external transactional
control matching MS Exchange Server and current Slide HEAD extensions.
Revision Changes Path
1.4 +44 -5
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/LockMethod.java
Index: LockMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/LockMethod.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LockMethod.java 24 May 2004 09:14:10 -0000 1.3
+++ LockMethod.java 5 Jul 2004 15:23:55 -0000 1.4
@@ -144,12 +144,39 @@
* Lock token.
*/
private String lockToken = null;
+
+ private boolean typeTransaction = false;
// ----------------------------------------------------------- Constructors
/**
+ * Creates a lock method that can <em>start a transaction</em> when server
supports
+ * them in a
+ * <a
href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_webdav_lock.asp">MS
like style</a>.
+ * The transacion handle of the started transaction will be returned as the
lock token.
+ * To let subsequent requests participate in the transaction add a
+ * <code>Transaction</code> header with the lock token as value. You will have
to enclose it in '<' and '>' just
+ * like ordinary lock tokens.
+ * <br><br>
+ * To either commit or abort the transaction
+ * use [EMAIL PROTECTED] UnlockMethod}.
+ *
+ * @param path any path inside Slide's scope
+ * @param owner of this transaction
+ * @param timeout timeout of this transaction
+ * @param isTransaction <code>true</code> when this method is used to starte a
transaction
+ *
+ */
+ public LockMethod(String path, String owner, int timeout, boolean
isTransaction) {
+ this(path);
+ setOwner(owner);
+ setTimeout(timeout);
+ setTypeTransaction(isTransaction);
+ }
+
+ /**
* Method constructor.
*/
public LockMethod() {
@@ -243,7 +270,13 @@
}
}
+ public boolean isTypeTransaction() {
+ return typeTransaction;
+ }
+ public void setTypeTransaction(boolean typeTransaction) {
+ this.typeTransaction = typeTransaction;
+ }
/**
* Depth setter.
@@ -364,6 +397,7 @@
this.depth = DEPTH_INFINITY;
this.scope = SCOPE_EXCLUSIVE;
this.timeout = TIMEOUT_INFINITY;
+ this.typeTransaction = false;
}
@@ -445,8 +479,13 @@
Element locktype = document.createElement("DAV:locktype");
lockinfo.appendChild(locktype);
- Element write = document.createElement("DAV:write");
- locktype.appendChild(write);
+ if (typeTransaction) {
+ Element transaction = document.createElement("DAV:transaction");
+ locktype.appendChild(transaction);
+ } else {
+ Element write = document.createElement("DAV:write");
+ locktype.appendChild(write);
+ }
Element owner = document.createElement("DAV:owner");
lockinfo.appendChild(owner);
1.4 +64 -11
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/UnlockMethod.java
Index: UnlockMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/UnlockMethod.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UnlockMethod.java 13 May 2004 13:06:39 -0000 1.3
+++ UnlockMethod.java 5 Jul 2004 15:23:55 -0000 1.4
@@ -40,16 +40,39 @@
public class UnlockMethod
extends XMLResponseMethodBase {
-
+ public final static int NO_TRANSACTION = -1;
+ public final static int ABORT_TRANSACTION = 0;
+ public final static int COMMIT_TRANSACTION = 1;
+
// ----------------------------------------------------- Instance Variables
private String lockToken = null;
+ private int transactionStatus = NO_TRANSACTION;
// ----------------------------------------------------------- Constructors
-
+ /**
+ * Creates an unlock method that <em>ends a transaction</em> when server
supports
+ * them in a
+ * <a
href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_webdav_lock.asp">MS
like style</a>.
+ * The transacion handle of transaction is stored as the lock token.
+ * <br><br>
+ * To start a transaction
+ * use [EMAIL PROTECTED] LockMethod}.
+
+ * @param path any path inside Slide's scope
+ * @param txHandle lock token specifying transaction handle
+ * @param transactionStatus status of transaction as described in [EMAIL
PROTECTED] #setTransactionStatus(int)}
+ *
+ */
+ public UnlockMethod(String path, String txHandle, int transactionStatus) {
+ this(path);
+ setLockToken(txHandle);
+ setTransactionStatus(transactionStatus);
+ }
+
/**
* Method constructor.
*/
@@ -82,6 +105,28 @@
this.lockToken = lockToken;
}
+ /**
+ * Gets the parameter described in [EMAIL PROTECTED] #setTransactionStatus}.
+ *
+ * @return either [EMAIL PROTECTED] UnlockMethod#COMMIT_TRANSACTION} or [EMAIL
PROTECTED] UnlockMethod#ABORT_TRANSACTION} as the real
+ * transaction status or [EMAIL PROTECTED] UnlockMethod#NO_TRANSACTION} to
indicate this method is not used for
+ * transaction control
+ */
+ public int getTransactionStatus() {
+ return transactionStatus;
+ }
+
+ /**
+ * Sets the transaction status of this method when it is used to end a
externally controlled
+ * transaction.
+ *
+ * @param transactionStatus [EMAIL PROTECTED] UnlockMethod#COMMIT_TRANSACTION}
to set the status to successful commit or
+ * [EMAIL PROTECTED] UnlockMethod#ABORT_TRANSACTION} to let the transaction
abort discarding all changes associated to it.
+ *
+ */
+ public void setTransactionStatus(int transactionStatus) {
+ this.transactionStatus = transactionStatus;
+ }
// --------------------------------------------------- WebdavMethod Methods
@@ -89,6 +134,10 @@
return "UNLOCK";
}
+ public void recycle() {
+ this.transactionStatus = NO_TRANSACTION;
+ }
+
/**
* Set header, handling the special case of the lock-token header so
* that it calls [EMAIL PROTECTED] #setLockToken} instead.
@@ -105,9 +154,6 @@
}
}
-
-
-
/**
* Generate additional headers needed by the request.
*
@@ -123,13 +169,20 @@
}
+ protected String generateRequestBody() {
+ if (getTransactionStatus() == NO_TRANSACTION) {
+ return "";
+ } else {
+ return "<D:transactioninfo xmlns:D='DAV:'>\n <D:transactionstatus>"
+ + (getTransactionStatus() == ABORT_TRANSACTION ? "<D:abort/>" :
"<D:commit/>")
+ + "</D:transactionstatus>\n</D:transactioninfo>";
+ }
+ }
+
protected void processResponseBody(HttpState state, HttpConnection conn) {
if ((getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) &&
(state instanceof WebdavState)) {
((WebdavState) state).removeLock(getPath(), lockToken);
}
}
-
-
-
}
1.7 +70 -67
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/ClientLexer.java
Index: ClientLexer.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/ClientLexer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ClientLexer.java 29 Apr 2004 10:18:11 -0000 1.6
+++ ClientLexer.java 5 Jul 2004 15:23:55 -0000 1.7
@@ -77,70 +77,73 @@
caseSensitiveLiterals = false;
setCaseSensitive(true);
literals = new Hashtable();
+ literals.put(new ANTLRHashString("spool", this), new Integer(8));
+ literals.put(new ANTLRHashString("copy", this), new Integer(33));
+ literals.put(new ANTLRHashString("mkdir", this), new Integer(31));
+ literals.put(new ANTLRHashString("uncheckout", this), new Integer(63));
+ literals.put(new ANTLRHashString("delete", this), new Integer(34));
+ literals.put(new ANTLRHashString("abort", this), new Integer(48));
+ literals.put(new ANTLRHashString("grant", this), new Integer(52));
+ literals.put(new ANTLRHashString("off", this), new Integer(10));
+ literals.put(new ANTLRHashString("acl", this), new Integer(57));
+ literals.put(new ANTLRHashString("help", this), new Integer(4));
+ literals.put(new ANTLRHashString("lcd", this), new Integer(22));
+ literals.put(new ANTLRHashString("ldir", this), new Integer(26));
+ literals.put(new ANTLRHashString("mv", this), new Integer(74));
+ literals.put(new ANTLRHashString("lock", this), new Integer(49));
+ literals.put(new ANTLRHashString("to", this), new Integer(53));
+ literals.put(new ANTLRHashString("versioncontrol", this), new Integer(59));
+ literals.put(new ANTLRHashString("mkws", this), new Integer(67));
+ literals.put(new ANTLRHashString("mkcol", this), new Integer(30));
+ literals.put(new ANTLRHashString("from", this), new Integer(56));
+ literals.put(new ANTLRHashString("dir", this), new Integer(29));
literals.put(new ANTLRHashString("propfind", this), new Integer(37));
- literals.put(new ANTLRHashString("mkws", this), new Integer(64));
- literals.put(new ANTLRHashString("unlock", this), new Integer(47));
- literals.put(new ANTLRHashString("to", this), new Integer(50));
- literals.put(new ANTLRHashString("principalcollectionset", this), new
Integer(55));
- literals.put(new ANTLRHashString("checkin", this), new Integer(58));
- literals.put(new ANTLRHashString("get", this), new Integer(44));
- literals.put(new ANTLRHashString("mv", this), new Integer(71));
- literals.put(new ANTLRHashString("exit", this), new Integer(65));
+ literals.put(new ANTLRHashString("checkin", this), new Integer(61));
+ literals.put(new ANTLRHashString("quit", this), new Integer(69));
literals.put(new ANTLRHashString("open", this), new Integer(17));
- literals.put(new ANTLRHashString("mkcol", this), new Integer(30));
+ literals.put(new ANTLRHashString("locks", this), new Integer(51));
+ literals.put(new ANTLRHashString("status", this), new Integer(7));
+ literals.put(new ANTLRHashString("exit", this), new Integer(68));
+ literals.put(new ANTLRHashString("unlock", this), new Integer(50));
+ literals.put(new ANTLRHashString("rm", this), new Integer(36));
+ literals.put(new ANTLRHashString("set", this), new Integer(71));
literals.put(new ANTLRHashString("lls", this), new Integer(25));
- literals.put(new ANTLRHashString("dir", this), new Integer(29));
- literals.put(new ANTLRHashString("lock", this), new Integer(46));
+ literals.put(new ANTLRHashString("proppatch", this), new Integer(42));
+ literals.put(new ANTLRHashString("propput", this), new Integer(75));
+ literals.put(new ANTLRHashString("commit", this), new Integer(47));
+ literals.put(new ANTLRHashString("propgetall", this), new Integer(41));
+ literals.put(new ANTLRHashString("close", this), new Integer(72));
+ literals.put(new ANTLRHashString("principalcollectionset", this), new
Integer(58));
+ literals.put(new ANTLRHashString("run", this), new Integer(11));
+ literals.put(new ANTLRHashString("deny", this), new Integer(54));
+ literals.put(new ANTLRHashString("report", this), new Integer(64));
+ literals.put(new ANTLRHashString("put", this), new Integer(45));
literals.put(new ANTLRHashString("connect", this), new Integer(16));
- literals.put(new ANTLRHashString("locks", this), new Integer(48));
- literals.put(new ANTLRHashString("copy", this), new Integer(33));
- literals.put(new ANTLRHashString("acl", this), new Integer(54));
- literals.put(new ANTLRHashString("del", this), new Integer(35));
- literals.put(new ANTLRHashString("checkout", this), new Integer(59));
- literals.put(new ANTLRHashString("propput", this), new Integer(72));
- literals.put(new ANTLRHashString("cd", this), new Integer(23));
- literals.put(new ANTLRHashString("on", this), new Integer(13));
- literals.put(new ANTLRHashString("pwd", this), new Integer(21));
- literals.put(new ANTLRHashString("mkdir", this), new Integer(31));
- literals.put(new ANTLRHashString("disconnect", this), new Integer(18));
- literals.put(new ANTLRHashString("move", this), new Integer(32));
- literals.put(new ANTLRHashString("cp", this), new Integer(70));
- literals.put(new ANTLRHashString("set", this), new Integer(68));
+ literals.put(new ANTLRHashString("propget", this), new Integer(38));
+ literals.put(new ANTLRHashString("revoke", this), new Integer(55));
literals.put(new ANTLRHashString("echo", this), new Integer(12));
- literals.put(new ANTLRHashString("rm", this), new Integer(36));
- literals.put(new ANTLRHashString("report", this), new Integer(61));
+ literals.put(new ANTLRHashString("disconnect", this), new Integer(18));
literals.put(new ANTLRHashString("debug", this), new Integer(14));
- literals.put(new ANTLRHashString("spool", this), new Integer(8));
+ literals.put(new ANTLRHashString("move", this), new Integer(32));
+ literals.put(new ANTLRHashString("bye", this), new Integer(70));
+ literals.put(new ANTLRHashString("cd", this), new Integer(23));
+ literals.put(new ANTLRHashString("cp", this), new Integer(73));
+ literals.put(new ANTLRHashString("propfindall", this), new Integer(40));
+ literals.put(new ANTLRHashString("del", this), new Integer(35));
+ literals.put(new ANTLRHashString("get", this), new Integer(44));
+ literals.put(new ANTLRHashString("lpwd", this), new Integer(19));
literals.put(new ANTLRHashString("cc", this), new Integer(24));
- literals.put(new ANTLRHashString("pwc", this), new Integer(20));
- literals.put(new ANTLRHashString("off", this), new Integer(10));
- literals.put(new ANTLRHashString("versioncontrol", this), new Integer(56));
- literals.put(new ANTLRHashString("grant", this), new Integer(49));
- literals.put(new ANTLRHashString("ldir", this), new Integer(26));
- literals.put(new ANTLRHashString("propget", this), new Integer(38));
- literals.put(new ANTLRHashString("help", this), new Integer(4));
+ literals.put(new ANTLRHashString("on", this), new Integer(13));
literals.put(new ANTLRHashString("options", this), new Integer(15));
+ literals.put(new ANTLRHashString("begin", this), new Integer(46));
+ literals.put(new ANTLRHashString("ereport", this), new Integer(65));
+ literals.put(new ANTLRHashString("pwd", this), new Integer(21));
+ literals.put(new ANTLRHashString("principalcol", this), new Integer(76));
+ literals.put(new ANTLRHashString("update", this), new Integer(60));
+ literals.put(new ANTLRHashString("checkout", this), new Integer(62));
+ literals.put(new ANTLRHashString("lreport", this), new Integer(66));
literals.put(new ANTLRHashString("ls", this), new Integer(28));
- literals.put(new ANTLRHashString("status", this), new Integer(7));
- literals.put(new ANTLRHashString("propfindall", this), new Integer(40));
- literals.put(new ANTLRHashString("ereport", this), new Integer(62));
- literals.put(new ANTLRHashString("close", this), new Integer(69));
- literals.put(new ANTLRHashString("from", this), new Integer(53));
- literals.put(new ANTLRHashString("principalcol", this), new Integer(73));
- literals.put(new ANTLRHashString("lpwd", this), new Integer(19));
- literals.put(new ANTLRHashString("bye", this), new Integer(67));
- literals.put(new ANTLRHashString("quit", this), new Integer(66));
- literals.put(new ANTLRHashString("delete", this), new Integer(34));
- literals.put(new ANTLRHashString("put", this), new Integer(45));
- literals.put(new ANTLRHashString("deny", this), new Integer(51));
- literals.put(new ANTLRHashString("propgetall", this), new Integer(41));
- literals.put(new ANTLRHashString("run", this), new Integer(11));
- literals.put(new ANTLRHashString("uncheckout", this), new Integer(60));
- literals.put(new ANTLRHashString("lcd", this), new Integer(22));
- literals.put(new ANTLRHashString("update", this), new Integer(57));
- literals.put(new ANTLRHashString("proppatch", this), new Integer(42));
- literals.put(new ANTLRHashString("lreport", this), new Integer(63));
- literals.put(new ANTLRHashString("revoke", this), new Integer(52));
+ literals.put(new ANTLRHashString("pwc", this), new Integer(20));
}
public Token nextToken() throws TokenStreamException {
@@ -299,17 +302,17 @@
match('-');
{
- int _cnt107=0;
- _loop107:
+ int _cnt112=0;
+ _loop112:
do {
if ((_tokenSet_0.member(LA(1)))) {
mCHARS(false);
}
else {
- if ( _cnt107>=1 ) { break _loop107; } else {throw new
NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
+ if ( _cnt112>=1 ) { break _loop112; } else {throw new
NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
}
- _cnt107++;
+ _cnt112++;
} while (true);
}
if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
@@ -460,7 +463,7 @@
{
mCHARS(false);
{
- _loop111:
+ _loop116:
do {
switch ( LA(1)) {
case '!': case '#': case '$': case '%':
@@ -493,7 +496,7 @@
}
default:
{
- break _loop111;
+ break _loop116;
}
}
} while (true);
@@ -506,13 +509,13 @@
match('"');
text.setLength(_saveIndex);
{
- _loop113:
+ _loop118:
do {
if ((_tokenSet_1.member(LA(1)))) {
matchNot('"');
}
else {
- break _loop113;
+ break _loop118;
}
} while (true);
1.7 +140 -17
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/ClientParser.java
Index: ClientParser.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/ClientParser.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ClientParser.java 29 Apr 2004 10:18:11 -0000 1.6
+++ ClientParser.java 5 Jul 2004 15:23:55 -0000 1.7
@@ -438,6 +438,21 @@
update();
break;
}
+ case BEGIN:
+ {
+ begin();
+ break;
+ }
+ case COMMIT:
+ {
+ commit();
+ break;
+ }
+ case ABORT:
+ {
+ abort();
+ break;
+ }
default:
{
throw new NoViableAltException(LT(1), getFilename());
@@ -519,13 +534,13 @@
cmd = LT(1);
match(STRING);
{
- _loop96:
+ _loop101:
do {
if ((LA(1)==STRING)) {
match(STRING);
}
else {
- break _loop96;
+ break _loop101;
}
} while (true);
@@ -2045,8 +2060,8 @@
Vector properties = new Vector();
{
- int _cnt88=0;
- _loop88:
+ int _cnt93=0;
+ _loop93:
do {
switch ( LA(1)) {
case STRING:
@@ -2069,10 +2084,10 @@
}
default:
{
- if ( _cnt88>=1 ) { break _loop88; } else
{throw new NoViableAltException(LT(1), getFilename());}
+ if ( _cnt93>=1 ) { break _loop93; } else
{throw new NoViableAltException(LT(1), getFilename());}
}
}
- _cnt88++;
+ _cnt93++;
} while (true);
}
match(ON);
@@ -2080,8 +2095,8 @@
Vector historyUris = new Vector();
{
- int _cnt90=0;
- _loop90:
+ int _cnt95=0;
+ _loop95:
do {
if ((LA(1)==STRING)) {
uri = LT(1);
@@ -2091,10 +2106,10 @@
}
else {
- if ( _cnt90>=1 ) { break _loop90; } else
{throw new NoViableAltException(LT(1), getFilename());}
+ if ( _cnt95>=1 ) { break _loop95; } else
{throw new NoViableAltException(LT(1), getFilename());}
}
- _cnt90++;
+ _cnt95++;
} while (true);
}
match(EOL);
@@ -2212,11 +2227,98 @@
}
}
+ public final void begin() throws RecognitionException, TokenStreamException {
+
+ Token timeout = null;
+ Token owner = null;
+
+ try { // for error handling
+ match(BEGIN);
+ {
+ switch ( LA(1)) {
+ case STRING:
+ {
+ timeout = LT(1);
+ match(STRING);
+ {
+ switch ( LA(1)) {
+ case STRING:
+ {
+ owner = LT(1);
+ match(STRING);
+ break;
+ }
+ case EOL:
+ {
+ break;
+ }
+ default:
+ {
+ throw new NoViableAltException(LT(1),
getFilename());
+ }
+ }
+ }
+ break;
+ }
+ case EOL:
+ {
+ break;
+ }
+ default:
+ {
+ throw new NoViableAltException(LT(1), getFilename());
+ }
+ }
+ }
+ match(EOL);
+
+ client.beginTransaction(text(timeout), text(owner));
+
+ }
+ catch (RecognitionException ex) {
+
+ printUsage("begin");
+
+ }
+ }
+
+ public final void commit() throws RecognitionException, TokenStreamException {
+
+
+ try { // for error handling
+ match(COMMIT);
+
+ client.commitTransaction();
+
+ }
+ catch (RecognitionException ex) {
+
+ printUsage("commit");
+
+ }
+ }
+
+ public final void abort() throws RecognitionException, TokenStreamException {
+
+
+ try { // for error handling
+ match(ABORT);
+
+ client.abortTransaction();
+
+ }
+ catch (RecognitionException ex) {
+
+ printUsage("abort");
+
+ }
+ }
+
public final void skip() throws RecognitionException, TokenStreamException {
{
- _loop100:
+ _loop105:
do {
switch ( LA(1)) {
case STRING:
@@ -2261,6 +2363,9 @@
case PROPPATCH:
case GET:
case PUT:
+ case BEGIN:
+ case COMMIT:
+ case ABORT:
case LOCK:
case UNLOCK:
case LOCKS:
@@ -2295,7 +2400,7 @@
}
default:
{
- break _loop100;
+ break _loop105;
}
}
} while (true);
@@ -2633,6 +2738,21 @@
match(UPDATE);
break;
}
+ case BEGIN:
+ {
+ match(BEGIN);
+ break;
+ }
+ case COMMIT:
+ {
+ match(COMMIT);
+ break;
+ }
+ case ABORT:
+ {
+ match(ABORT);
+ break;
+ }
default:
{
throw new NoViableAltException(LT(1), getFilename());
@@ -2688,6 +2808,9 @@
"PROPSET",
"\"get\"",
"\"put\"",
+ "\"begin\"",
+ "\"commit\"",
+ "\"abort\"",
"\"lock\"",
"\"unlock\"",
"\"locks\"",
@@ -2726,7 +2849,7 @@
};
private static final long[] mk_tokenSet_0() {
- long[] data = { -10133649051624464L, 15L, 0L, 0L};
+ long[] data = { -81065343182709776L, 127L, 0L, 0L};
return data;
}
public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
1.8 +50 -5
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.g
Index: Client.g
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.g,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Client.g 29 Apr 2004 10:18:11 -0000 1.7
+++ Client.g 5 Jul 2004 15:23:55 -0000 1.8
@@ -212,6 +212,9 @@
| checkout
| uncheckout
| update
+ | begin
+ | commit
+ | abort
)
;
@@ -615,6 +618,42 @@
printUsage("put");
}
+begin :
+ BEGIN (timeout:STRING (owner:STRING)? )? EOL
+ {
+ client.beginTransaction(text(timeout), text(owner));
+ }
+ ;
+ exception
+ catch [RecognitionException ex]
+ {
+ printUsage("begin");
+ }
+
+commit :
+ COMMIT
+ {
+ client.commitTransaction();
+ }
+ ;
+ exception
+ catch [RecognitionException ex]
+ {
+ printUsage("commit");
+ }
+
+abort :
+ ABORT
+ {
+ client.abortTransaction();
+ }
+ ;
+ exception
+ catch [RecognitionException ex]
+ {
+ printUsage("abort");
+ }
+
lock
: LOCK
(path:STRING)?
@@ -1062,6 +1101,9 @@
| CHECKOUT
| UNCHECKOUT
| UPDATE
+ | BEGIN
+ | COMMIT
+ | ABORT
;
// ----------------------------------------- lexical analyzer class definitions
@@ -1150,6 +1192,9 @@
CHECKOUT = "checkout";
UNCHECKOUT = "uncheckout";
UPDATE = "update";
+ BEGIN = "begin";
+ COMMIT = "commit";
+ ABORT = "abort";
}
// ---------------------------------------------------------------- lexer rules
1.6 +41 -38
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/SlideTokenTypes.java
Index: SlideTokenTypes.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/SlideTokenTypes.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SlideTokenTypes.java 29 Apr 2004 10:18:11 -0000 1.5
+++ SlideTokenTypes.java 5 Jul 2004 15:23:55 -0000 1.6
@@ -76,39 +76,42 @@
int PROPSET = 43;
int GET = 44;
int PUT = 45;
- int LOCK = 46;
- int UNLOCK = 47;
- int LOCKS = 48;
- int GRANT = 49;
- int TO = 50;
- int DENY = 51;
- int REVOKE = 52;
- int FROM = 53;
- int ACL = 54;
- int PRINCIPALCOLLECTIONSET = 55;
- int VERSIONCONTROL = 56;
- int UPDATE = 57;
- int CHECKIN = 58;
- int CHECKOUT = 59;
- int UNCHECKOUT = 60;
- int REPORT = 61;
- int EREPORT = 62;
- int LREPORT = 63;
- int MKWS = 64;
- int EXIT = 65;
- int QUIT = 66;
- int BYE = 67;
- int SET = 68;
- int CLOSE = 69;
- int CP = 70;
- int MV = 71;
- int PROPPUT = 72;
- int PRINCIPALCOL = 73;
- int WS = 74;
- int CHARS = 75;
- int ALPHANUM = 76;
- int ALPHA = 77;
- int LOWALPHA = 78;
- int UPALPHA = 79;
- int DIGIT = 80;
+ int BEGIN = 46;
+ int COMMIT = 47;
+ int ABORT = 48;
+ int LOCK = 49;
+ int UNLOCK = 50;
+ int LOCKS = 51;
+ int GRANT = 52;
+ int TO = 53;
+ int DENY = 54;
+ int REVOKE = 55;
+ int FROM = 56;
+ int ACL = 57;
+ int PRINCIPALCOLLECTIONSET = 58;
+ int VERSIONCONTROL = 59;
+ int UPDATE = 60;
+ int CHECKIN = 61;
+ int CHECKOUT = 62;
+ int UNCHECKOUT = 63;
+ int REPORT = 64;
+ int EREPORT = 65;
+ int LREPORT = 66;
+ int MKWS = 67;
+ int EXIT = 68;
+ int QUIT = 69;
+ int BYE = 70;
+ int SET = 71;
+ int CLOSE = 72;
+ int CP = 73;
+ int MV = 74;
+ int PROPPUT = 75;
+ int PRINCIPALCOL = 76;
+ int WS = 77;
+ int CHARS = 78;
+ int ALPHANUM = 79;
+ int ALPHA = 80;
+ int LOWALPHA = 81;
+ int UPALPHA = 82;
+ int DIGIT = 83;
}
1.16 +70 -3
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.java
Index: Client.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Client.java 29 Apr 2004 13:54:17 -0000 1.15
+++ Client.java 5 Jul 2004 15:23:55 -0000 1.16
@@ -1479,7 +1479,74 @@
}
}
+ void beginTransaction(String timeout, String owner)
+ {
+ try {
+ String path = checkUri(null);
+ // Test the parameter
+ //
+ // Timeout
+ int to=0;
+ if ((timeout != null) &&
(timeout.toLowerCase().substring(0,5).equals("-tinf")) ) { //infinite
+ to = LockMethod.TIMEOUT_INFINITY;
+ } else {
+ to = (timeout == null)? 120 :
Integer.parseInt(timeout.substring(2));
+ }
+
+ // owner
+ owner = (owner != null) ? (owner.substring(2)) : owner;
+
+ out.print("Starting transaction ");
+ if (webdavResource.startTransaction(path, owner, to)) {
+ out.println("succeeded.");
+ out.println("Handle: '"+webdavResource.getTransactionHandle()+"'");
+ } else {
+ out.println("failed.");
+ out.println(webdavResource.getStatusMessage());
+ }
+ }
+ catch (Exception ex) {
+ handleException(ex);
+ }
+ }
+
+ void commitTransaction()
+ {
+ try {
+ String path = checkUri(null);
+
+ out.print("Committing transaction: '" +
webdavResource.getTransactionHandle() + "' ");
+ if (webdavResource.commitTransaction(path)) {
+ out.println("succeeded.");
+ } else {
+ out.println("failed.");
+ out.println(webdavResource.getStatusMessage());
+ }
+ }
+ catch (Exception ex) {
+ handleException(ex);
+ }
+ }
+
+ void abortTransaction()
+ {
+ try {
+ String path = checkUri(null);
+
+ out.print("Rolling transaction: '"
+webdavResource.getTransactionHandle()+ "' ");
+ if (webdavResource.abortTransaction(path)) {
+ out.println("succeeded.");
+ } else {
+ out.println("failed.");
+ out.println(webdavResource.getStatusMessage());
+ }
+ }
+ catch (Exception ex) {
+ handleException(ex);
+ }
+ }
+
///////////////////////////////////////////////////////////////////
// Support methods
///////////////////////////////////////////////////////////////////
1.3 +13 -3
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavState.java
Index: WebdavState.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavState.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebdavState.java 11 Feb 2004 11:30:51 -0000 1.2
+++ WebdavState.java 5 Jul 2004 15:23:55 -0000 1.3
@@ -57,6 +57,10 @@
*/
protected ArrayList lockTokens = new ArrayList();
+ /**
+ * Transaction handle of current session of <code>null</code> if not inside of
transaction.
+ */
+ protected String transactionHandle = null;
// ------------------------------------------------------------- Properties
@@ -156,5 +160,11 @@
}
+ public String getTransactionHandle() {
+ return transactionHandle;
+ }
+ public void setTransactionHandle(String transactionHandle) {
+ this.transactionHandle = transactionHandle;
+ }
}
1.20 +131 -3
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java
Index: WebdavResource.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- WebdavResource.java 2 Jul 2004 11:32:21 -0000 1.19
+++ WebdavResource.java 5 Jul 2004 15:23:55 -0000 1.20
@@ -83,6 +83,8 @@
import org.apache.webdav.lib.properties.PrincipalCollectionSetProperty;
import org.apache.webdav.lib.properties.ResourceTypeProperty;
+import sun.text.Normalizer;
+
/**
* The class <code>WebdavResource</code> is an abstract representation
* for WebDAV resource.<p>
@@ -830,6 +832,20 @@
// --------------------------------------------------------- Basic settings
/**
+ * Generates and adds the "Transaction" header if this method is part of
+ * an externally controlled transaction.
+ */
+ protected void generateTransactionHeader(HttpMethod method) {
+ if (client == null || method == null) return;
+
+ WebdavState state = (WebdavState) client.getState();
+ String txHandle = state.getTransactionHandle();
+ if (txHandle != null) {
+ method.setRequestHeader("Transaction", "<" + txHandle + ">");
+ }
+ }
+
+ /**
* Generate and add the If header to the specified HTTP method.
*/
protected void generateIfHeader(HttpMethod method) {
@@ -2223,6 +2239,8 @@
Ace ace = aces[i];
method.addAce(ace);
}
+
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2255,6 +2273,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Enumeration responses = method.getResponses();
@@ -2307,6 +2326,7 @@
properties.elements());
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Enumeration responses = method.getResponses();
@@ -2360,6 +2380,7 @@
properties.elements());
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Enumeration responses = method.getResponses();
@@ -2418,6 +2439,7 @@
GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
+ generateTransactionHeader(method);
client.executeMethod(method);
int statusCode = method.getStatusLine().getStatusCode();
@@ -2457,6 +2479,7 @@
setClient();
GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2495,6 +2518,7 @@
setClient();
GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2564,6 +2588,7 @@
method.setRequestHeader("Content-Length", String.valueOf(data.length));
method.setRequestBody(new ByteArrayInputStream(data));
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2605,6 +2630,7 @@
method.setRequestHeader("Content-Type", getGetContentType());
method.setRequestContentLength(PutMethod.CONTENT_LENGTH_CHUNKED);
method.setRequestBody(is);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2648,6 +2674,7 @@
if (getGetContentType() != null && !getGetContentType().equals(""))
method.setRequestHeader("Content-Type", getGetContentType());
method.setRequestBody(data);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2695,6 +2722,7 @@
? (int) fileLength
: PutMethod.CONTENT_LENGTH_CHUNKED);
method.setRequestBody(new FileInputStream(file));
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2741,6 +2769,7 @@
if (getGetContentType() != null && !getGetContentType().equals(""))
method.setRequestHeader("Content-Type", getGetContentType());
method.setRequestBody(url.openStream());
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2783,6 +2812,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -2840,6 +2870,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Vector options = new Vector();
@@ -2898,6 +2929,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Vector options = new Vector();
@@ -2951,6 +2983,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Vector options = new Vector();
@@ -3036,6 +3069,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -3054,6 +3088,7 @@
depth);
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Vector results = new Vector();
@@ -3092,6 +3127,7 @@
properties.elements());
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
return method.getResponses();
@@ -3107,6 +3143,7 @@
properties.elements());
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
/*first draft, does work anyhow
@@ -3159,6 +3196,7 @@
histUri.elements());
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Vector results = new Vector();
@@ -3196,6 +3234,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
client.executeMethod(method);
Vector results = new Vector();
@@ -3274,6 +3313,7 @@
method.setDebug(debug);
// Default depth=infinity, type=allprop
+ generateTransactionHeader(method);
int status = client.executeMethod(method);
// Set status code for this resource.
@@ -3347,6 +3387,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
int status = client.executeMethod(method);
// Set status code for this resource.
@@ -3445,6 +3486,7 @@
properties.elements());
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
int status = client.executeMethod(method);
// Also accept OK sent by buggy servers.
@@ -3767,6 +3809,7 @@
}
}
if (hasSomething) {
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
// Possbile Status Codes => SC_OK
// WebdavStatus.SC_FORBIDDEN, SC_CONFLICT, SC_LOCKED, 507
@@ -3807,6 +3850,7 @@
setClient();
HeadMethod method = new HeadMethod(URIUtil.encodePathQuery(path));
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -3850,6 +3894,7 @@
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -3897,6 +3942,7 @@
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
method.setOverwrite(overwrite);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
// Possbile MOVE Status Codes => SC_CREATED, SC_NO_CONTENT
@@ -3945,6 +3991,7 @@
generateIfHeader(method);
method.setOverwrite(overwrite);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
// Possbile COPY Status Codes => SC_CREATED, SC_NO_CONTENT
@@ -3989,6 +4036,7 @@
MkcolMethod method = new MkcolMethod(URIUtil.encodePath(path));
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
// Possbile MKCOL Status Codes => SC_CREATED
@@ -4147,6 +4195,75 @@
}
+ public boolean startTransaction(String path, String owner, int timeout) throws
IOException {
+ setClient();
+
+ if (owner == null) {
+ owner = (httpURL.getUser() != null) ? httpURL.getUser() : defaultOwner;
+ }
+
+ // default lock type setting
+ LockMethod method = new LockMethod(path, owner, timeout, true);
+ method.setDebug(debug);
+ method.setFollowRedirects(this.followRedirects);
+
+ generateIfHeader(method);
+ int statusCode = client.executeMethod(method);
+ String txHandle = method.getLockToken();
+ WebdavState state = (WebdavState) client.getState();
+ if (state != null) {
+ state.setTransactionHandle(txHandle);
+ }
+ this.owner = method.getOwner();
+
+ // Possbile LOCK Status Codes => SC_OK
+ // WebdavStatus.SC_SC_PRECONDITION_FAILED, SC_LOCKED
+ setStatusCode(statusCode, txHandle);
+
+ return (statusCode >= 200 && statusCode < 300) ? true : false;
+ }
+
+ public String getTransactionHandle() throws IOException {
+ setClient();
+
+ // Get the lock for the given path.
+ WebdavState state = (WebdavState) client.getState();
+ if (state == null) return null;
+ String txHandle = state.getTransactionHandle();
+ return txHandle;
+ }
+
+ public boolean commitTransaction(String path) throws IOException {
+ return endTransaction(path, UnlockMethod.COMMIT_TRANSACTION);
+ }
+
+ public boolean abortTransaction(String path) throws IOException {
+ return endTransaction(path, UnlockMethod.ABORT_TRANSACTION);
+ }
+
+ public boolean endTransaction(String path, int transactionStatus) throws
IOException {
+ setClient();
+
+ // Get the lock for the given path.
+ WebdavState state = (WebdavState) client.getState();
+ if (state == null) return false;
+ String txHandle = state.getTransactionHandle();
+ if (txHandle == null) return false;
+ UnlockMethod method = new UnlockMethod(path, txHandle, transactionStatus);
+ method.setDebug(debug);
+ method.setFollowRedirects(this.followRedirects);
+
+ generateIfHeader(method);
+ int statusCode = client.executeMethod(method);
+
+ setStatusCode(statusCode);
+ if (statusCode >= 200 && statusCode < 300) {
+ state.setTransactionHandle(null);
+ return true;
+ }
+ return false;
+ }
+
/**
* Execute the Unlock method for this WebdavResource.
*
@@ -4313,6 +4430,7 @@
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -4331,6 +4449,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -4351,6 +4470,7 @@
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -4394,6 +4514,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
// Possbile MKCOL Status Codes => SC_CREATED
@@ -4523,6 +4644,7 @@
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -4562,6 +4684,7 @@
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -4604,6 +4727,7 @@
method.setFollowRedirects(this.followRedirects);
generateIfHeader(method);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
@@ -4710,6 +4834,7 @@
method.setDebug(debug);
method.setFollowRedirects(this.followRedirects);
+ generateTransactionHeader(method);
int status = client.executeMethod(method);
// Set status code for this resource.
@@ -4765,6 +4890,7 @@
URIUtil.encodePath(newBinding));
method.setDebug(debug);
method.setOverwrite(overwrite);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
// Possbile BIND Status Codes => SC_CREATED, SC_NO_CONTENT
@@ -4801,6 +4927,7 @@
UnbindMethod method =
new UnbindMethod(URIUtil.encodePath(binding));
method.setDebug(debug);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
// Possbile BIND Status Codes => SC_CREATED, SC_NOT_FOUND
@@ -4857,6 +4984,7 @@
URIUtil.encodePath(newBinding));
method.setDebug(debug);
method.setOverwrite(overwrite);
+ generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
// Possbile BIND Status Codes => SC_CREATED, SC_NO_CONTENT
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]