001: /*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022:
023: package org.skunk.dav.client.method;
024:
025: import org.skunk.dav.client.AbstractWriteDAVMethod;
026: import org.skunk.dav.client.DAVConstants;
027: import org.skunk.dav.client.DAVMethodName;
028: import org.skunk.dav.client.IfHeader;
029:
030: public class PutMethod extends AbstractWriteDAVMethod {
031: private byte[] putData;
032: private String lockToken;
033:
034: public PutMethod(String url, byte[] putData) {
035: super (url);
036: this .putData = putData;
037: }
038:
039: // public void processRequestHeaders()
040: // {
041: // if (lockToken!=null)
042: // {
043: // StringBuffer ifHeader=new StringBuffer("<");
044: // ifHeader.append(getRequestURL());
045: // ifHeader.append("> (<");
046: // ifHeader.append(lockToken);
047: // ifHeader.append(">)");
048: // getRequestHeaders().put(DAVConstants.IF_HEADER, ifHeader.toString());
049: // }
050: // }
051:
052: public final DAVMethodName getRequestMethodName() {
053: return DAVMethodName.PUT;
054: }
055:
056: public void processRequestBody() {
057: setRequestBody(putData);
058: }
059:
060: // public void setLockToken(String lockToken)
061: // {
062: // this.lockToken=lockToken;
063: // }
064:
065: // public String getLockToken()
066: // {
067: // return lockToken;
068: // }
069:
070: /**
071: * convenience method for the case when there is only one
072: * lock token; for more flexibility, create an IfHeader.
073: * Note that using this will create a new IfHeader at request header
074: * processing time, destroying any IfHeader that has been manually
075: * created!! This method exists solely for backwards compatibility;
076: * it will probably be deprecated in the future.
077: */
078: public void setLockToken(String lockToken) {
079: this .lockToken = lockToken;
080: }
081:
082: /**
083: * accesses the locktoken property set with the setLockToken() method.
084: */
085: public String getLockToken() {
086: return lockToken;
087: }
088:
089: public void processRequestHeaders() {
090: if (this .lockToken != null) {
091: // blow away any if headers that are lying around
092: IfHeader iffy = new IfHeader(true);
093: iffy.addStateToken(getRequestURL(), lockToken);
094: this .setIfHeader(iffy);
095: }
096: super .processRequestHeaders();
097: }
098: }
099:
100: /* $Log: PutMethod.java,v $
101: /* Revision 1.7 2001/07/17 04:41:32 smulloni
102: /* integrated IfHeader more closely into method package; added lock test.
103: /*
104: /* Revision 1.6 2001/07/15 18:16:37 smulloni
105: /* fixed some copyright notices.
106: /*
107: /* Revision 1.5 2000/12/03 23:53:27 smulloni
108: /* added license and copyright preamble to java files.
109: /*
110: /* Revision 1.4 2000/11/09 23:35:09 smullyan
111: /* log added to every Java file, with the help of python. Lock stealing
112: /* implemented, and treatment of locks made more robust.
113: /* */
|