KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/VersionControlMethod.java,v 1.5 2004/08/02 15:45:48 unico Exp $
3  * $Revision: 1.5 $
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
37  */

38 public class VersionControlMethod
39     extends XMLResponseMethodBase implements DepthSupport {
40
41
42     // -------------------------------------------------------------- Constants
43

44
45
46     // ----------------------------------------------------- Instance Variables
47
private String JavaDoc sComment, sCreatorDisplayName;
48
49         private String JavaDoc sTarget = null;
50
51
52     // ----------------------------------------------------------- Constructors
53

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

58     public VersionControlMethod() {
59         sComment ="none";
60         sCreatorDisplayName ="unknown";
61     }
62
63
64     /**
65      * Method constructor.
66      */

67     public VersionControlMethod(String JavaDoc path) {
68         super(path);
69     }
70
71     public VersionControlMethod(String JavaDoc path, String JavaDoc sTarget) {
72         super(path);
73         this.sTarget = sTarget;
74
75     }
76
77
78
79
80
81     // ------------------------------------------------------------- Properties
82

83
84     public int getDepth(){
85         return 0;
86     }
87
88     public void setDepth(int depth){
89     /*azblm: don't know if needed and / or allowed */
90     }
91
92
93     public void setRequestHeader(String JavaDoc headerName, String JavaDoc headerValue) {
94         super.setRequestHeader(headerName, headerValue);
95         if (sTarget != null) {
96             // set the default utf-8 encoding, if not already present
97
if (getRequestHeader("Content-Type") == null ) super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
98         }
99     }
100
101
102
103     // --------------------------------------------------- WebdavMethod Methods
104

105
106     public String JavaDoc getName() {
107         return "VERSION-CONTROL";
108     }
109
110     /**
111      * DAV requests that contain a body must override this function to
112      * generate that body.
113      *
114      * <p>The default behavior simply returns an empty body.</p>
115      */

116     protected String JavaDoc generateRequestBody() {
117
118         if (sTarget != null){
119             XMLPrinter printer = new XMLPrinter();
120
121
122             printer.writeXMLHeader();
123
124             printer.writeElement("D", "DAV:", "version-control", XMLPrinter.OPENING);
125             printer.writeElement("D", "version", XMLPrinter.OPENING);
126
127             printer.writeElement("D", "href", XMLPrinter.OPENING);
128             printer.writeText(sTarget);
129             printer.writeElement("D", "href", XMLPrinter.CLOSING);
130             printer.writeElement("D", "version", XMLPrinter.CLOSING);
131             printer.writeElement("D", "version-control", XMLPrinter.CLOSING);
132
133             return printer.toString();
134         }
135         else
136             return "";
137
138     }
139
140     /**
141      * Parse response.
142      *
143      * @param input Input stream
144      */

145     public void parseResponse(InputStream JavaDoc input, HttpState state, HttpConnection conn)
146         throws IOException JavaDoc, HttpException {
147         try
148         {
149             int code = getStatusLine().getStatusCode();
150             if (code == WebdavStatus.SC_CONFLICT ||
151                 code == WebdavStatus.SC_FORBIDDEN ) {
152                 parseXMLResponse(input);
153             }
154         }
155         catch (IOException JavaDoc e) {
156                 // FIX ME: provide a way to deliver non xml data
157
}
158     }
159
160
161 }
162
Popular Tags