KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > method > UnbindMethod


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UnbindMethod.java,v 1.15 2004/08/02 16:36:01 unico Exp $
3  * $Revision: 1.15 $
4  * $Date: 2004/08/02 16:36:01 $
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.slide.webdav.method;
25
26 import java.io.IOException JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.apache.slide.common.NamespaceAccessToken;
30 import org.apache.slide.common.ServiceAccessException;
31 import org.apache.slide.common.SlideException;
32 import org.apache.slide.event.EventDispatcher;
33 import org.apache.slide.lock.ObjectLockedException;
34 import org.apache.slide.structure.ObjectNode;
35 import org.apache.slide.webdav.WebdavException;
36 import org.apache.slide.webdav.WebdavServletConfig;
37 import org.apache.slide.webdav.event.WebdavEvent;
38 import org.apache.slide.webdav.util.BindConstants;
39 import org.apache.slide.webdav.util.PreconditionViolationException;
40 import org.apache.slide.webdav.util.ViolatedPrecondition;
41 import org.apache.slide.webdav.util.WebdavStatus;
42 import org.jdom.JDOMException;
43
44
45 /**
46  * UNBIND method.
47  *
48  */

49 public class UnbindMethod extends AbstractWebdavMethod implements BindConstants, WriteMethod {
50     
51     private String JavaDoc collectionUri;
52     private String JavaDoc segment;
53     //private boolean overwrite;
54
private ObjectNode collectionNode = null;
55     
56     
57     /**
58      * Constructor.
59      *
60      * @param token the token for accessing the namespace
61      * @param config configuration of the WebDAV servlet
62      */

63     public UnbindMethod(NamespaceAccessToken token, WebdavServletConfig config) {
64         super(token, config);
65     }
66     
67     /**
68      * Parse WebDAV XML query.
69      *
70      * @exception WebdavException
71      */

72     protected void parseRequest() throws WebdavException {
73         collectionUri = requestUri;
74         if (collectionUri == null) {
75             collectionUri = "/";
76         }
77         
78         List JavaDoc content;
79         
80 // readRequestContent();
81
try{
82             content = parseRequestContent(E_UNBIND).getChildren();
83             segment = MethodUtil.getChildText(content, E_SEGMENT);
84         }
85         catch (IOException JavaDoc e) { // TODO: merge exception handling into jdom access methods
86
int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
87             sendError( statusCode, e );
88             throw new WebdavException( statusCode );
89         }
90         catch (JDOMException e) { // TODO: merge exception handling into jdom access methods
91
int statusCode = WebdavStatus.SC_BAD_REQUEST;
92             sendError( statusCode, e );
93             throw new WebdavException( statusCode );
94         }
95         
96         collectionUri = requestUri;
97         if (collectionUri == null) {
98             collectionUri = "/";
99         }
100         
101         //overwrite = requestHeaders.getOverwrite(true);
102
}
103     
104     private void checkPreconditions() throws PreconditionViolationException, ServiceAccessException {
105         
106         resp.setStatus( WebdavStatus.SC_OK );
107         
108         try {
109             collectionNode = structure.retrieve( slideToken, collectionUri );
110         }
111         catch( ServiceAccessException e ) {
112             throw e;
113         }
114         catch (SlideException e) {} // ignore silently
115

116         if (collectionNode == null || !isCollection(collectionUri)) {
117             throw new PreconditionViolationException(
118                 new ViolatedPrecondition(C_UNBIND_FROM_COLLECTION, WebdavStatus.SC_CONFLICT), collectionUri);
119         }
120         if (!collectionNode.hasBinding(segment)) {
121             throw new PreconditionViolationException(
122                 new ViolatedPrecondition(C_UNBIND_SOURCE_EXISTS, WebdavStatus.SC_CONFLICT), collectionUri);
123         }
124     }
125     
126     /**
127      * Execute the request.
128      *
129      * @exception WebdavException
130      */

131     protected void executeRequest() throws WebdavException, IOException JavaDoc {
132         
133         // Prevent dirty reads
134
slideToken.setForceStoreEnlistment(true);
135         
136         // check lock-null resources
137
try {
138             if (isLockNull(collectionUri)) {
139                 int statusCode = WebdavStatus.SC_NOT_FOUND;
140                 sendError( statusCode, "lock-null resource", new Object JavaDoc[]{collectionUri} );
141                 throw new WebdavException( statusCode );
142             }
143         }
144         catch (ServiceAccessException e) {
145             int statusCode = getErrorCode((Exception JavaDoc)e);
146             sendError( statusCode, e );
147             throw new WebdavException( statusCode );
148         }
149
150         try {
151             if ( WebdavEvent.UNBIND.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.UNBIND, new WebdavEvent(this));
152
153             checkPreconditions();
154             structure.removeBinding( slideToken, collectionNode, segment );
155         }
156         catch (ObjectLockedException e) {
157             ViolatedPrecondition violatedPrecondition;
158             if (collectionUri.equals(e.getObjectUri())) {
159                 violatedPrecondition =
160                     new ViolatedPrecondition(C_LOCKED_UPDATE_ALLOWED, WebdavStatus.SC_LOCKED);
161             }
162             else {
163                 violatedPrecondition =
164                     new ViolatedPrecondition(C_PROTECTED_URL_DELETION_ALLOWED, WebdavStatus.SC_CONFLICT);
165             }
166             sendPreconditionViolation(
167                 new PreconditionViolationException(violatedPrecondition, collectionNode.getUri())
168             );
169         }
170         catch (PreconditionViolationException e) {
171             sendPreconditionViolation(e);
172             throw e;
173         }
174         catch (Exception JavaDoc e) {
175             int statusCode = getErrorCode( e );
176             sendError( statusCode, e );
177             throw new WebdavException( statusCode );
178         }
179     }
180     
181 }
182
183
Popular Tags