KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > lib > methods > UpdateMethod


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/UpdateMethod.java,v 1.6 2004/08/02 15:45:48 unico Exp $
3  * $Revision: 1.6 $
4  * $Date: 2004/08/02 15:45:48 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.webdav.lib.methods;
25
26 import java.io.IOException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import org.apache.commons.httpclient.HttpConnection;
29 import org.apache.commons.httpclient.HttpException;
30 import org.apache.commons.httpclient.HttpState;
31 import org.apache.webdav.lib.util.WebdavStatus;
32 import org.apache.webdav.lib.util.XMLPrinter;
33
34
35 /**
36  * The Update method updates a version-controlled resource to a new version.
37  * Two parameters are required, the path of the resource, and a URI identifying
38  * the version from the history to which to update.
39  *
40  */

41 public class UpdateMethod extends XMLResponseMethodBase {
42
43
44     // -------------------------------------------------------------- Constants
45

46
47
48     // ----------------------------------------------------- Instance Variables
49

50     private String JavaDoc target = null;
51
52
53     // ----------------------------------------------------------- Constructors
54

55
56     /**
57      * Method constructor.
58      */

59     public UpdateMethod() {
60     }
61
62
63    /**
64      * Method constructor.
65      */

66     public UpdateMethod(String JavaDoc path) {
67         super(path);
68     }
69
70
71
72     /**
73      * Method constructor.
74      *
75      * @param path
76      * @param target
77      */

78     public UpdateMethod(String JavaDoc path, String JavaDoc target) {
79         super(path);
80         this.target = target;
81     }
82
83
84     public String JavaDoc getName() {
85         return "UPDATE";
86     }
87
88     /**
89      * DAV requests that contain a body must override this function to
90      * generate that body.
91      *
92      * <p>The default behavior simply returns an empty body.</p>
93      */

94     protected String JavaDoc generateRequestBody() {
95         if (target != null) {
96             XMLPrinter printer = new XMLPrinter();
97
98
99             printer.writeXMLHeader();
100             printer.writeElement("D", "DAV:", "update", XMLPrinter.OPENING);
101             printer.writeElement("D", "version", XMLPrinter.OPENING);
102             printer.writeElement("D", "href", XMLPrinter.OPENING);
103             printer.writeText(target);
104             printer.writeElement("D", "href", XMLPrinter.CLOSING);
105             printer.writeElement("D", "version", XMLPrinter.CLOSING);
106             printer.writeElement("D", "update", XMLPrinter.CLOSING);
107
108             return printer.toString();
109         }
110         else
111             return "";
112     }
113
114     /**
115      * Parse response.
116      *
117      * @param input Input stream
118      */

119     public void parseResponse(InputStream JavaDoc input, HttpState state, HttpConnection conn)
120         throws IOException JavaDoc, HttpException {
121         try
122         {
123             int code = getStatusLine().getStatusCode();
124             if (code == WebdavStatus.SC_CONFLICT ||
125                 code == WebdavStatus.SC_MULTI_STATUS ||
126                 code == WebdavStatus.SC_FORBIDDEN ) {
127                 parseXMLResponse(input);
128             }
129         }
130         catch (IOException JavaDoc e) {
131                 // FIX ME: provide a way to deliver non xml data
132
}
133     }
134
135
136 }
137
Popular Tags