KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/UnbindMethod.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 org.apache.webdav.lib.util.XMLPrinter;
27
28 /**
29  * The UNBIND method modifies the collection identified by the Request-URI,
30  * by removing the binding identified by the segment specified in the UNBIND
31  * body.
32  *
33  * UNBIND Method Example:
34  * >> Request:
35  * UNBIND /CollX HTTP/1.1
36  * Host: www.example.com
37  * Content-Type: text/xml; charset="utf-8"
38  * Content-Length: xxx
39  * <?xml version="1.0" encoding="utf-8" ?>
40  * <D:unbind xmlns:D="DAV:">
41  * <D:segment>foo.html</D:segment>
42  * </D:unbind>
43  *
44  * >> Response:
45  * HTTP/1.1 200 OK
46  * The server removed the binding named "foo.html" from the collection,
47  * "http://www.example.com/CollX". A request to the resource named
48  * "http://www.example.com/CollX/foo.html" will return a 404 (Not Found)
49  * response.
50  *
51  */

52 public class UnbindMethod
53     extends XMLResponseMethodBase {
54
55
56     public static final String JavaDoc NAME = "UNBIND";
57
58     private String JavaDoc segment = null;
59
60     // ----------------------------------------------------------- Constructors
61

62
63     /**
64      * Method constructor.
65      */

66     public UnbindMethod() {
67     }
68
69     public UnbindMethod(String JavaDoc binding) {
70         super(binding.substring(0, binding.lastIndexOf('/')));
71         this.segment = binding.substring(binding.lastIndexOf('/') + 1);
72     }
73
74     public String JavaDoc getName() {
75         return NAME;
76     }
77
78     /**
79      * DAV requests that contain a body must override this function to
80      * generate that body.
81      *
82      * <p>The default behavior simply returns an empty body.</p>
83      */

84     protected String JavaDoc generateRequestBody() {
85
86         if (segment == null)
87             throw new IllegalStateException JavaDoc
88                 ("Segment must be set before calling this function.");
89
90         XMLPrinter printer = new XMLPrinter();
91
92         printer.writeXMLHeader();
93         printer.writeElement("D", "DAV:", "unbind", XMLPrinter.OPENING);
94         printer.writeElement("D", "segment", XMLPrinter.OPENING);
95         printer.writeText(segment);
96         printer.writeElement("D", "segment", XMLPrinter.CLOSING);
97         printer.writeElement("D", "unbind", XMLPrinter.CLOSING);
98
99         return printer.toString();
100     }
101
102     /**
103      * @return resource name to be unbound
104      */

105     public String JavaDoc getSegment() {
106         return segment;
107     }
108
109     /**
110      * @param segment resource name to be unbound
111      */

112     public void setSegment(String JavaDoc segment) {
113         this.segment = segment;
114     }
115
116 }
117
118
Popular Tags