KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UncheckoutMethod.java,v 1.20 2004/08/05 14:43:29 dflorey Exp $
3  * $Revision: 1.20 $
4  * $Date: 2004/08/05 14:43:29 $
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 package org.apache.slide.webdav.method;
24
25 import java.io.IOException JavaDoc;
26
27 import org.apache.slide.common.NamespaceAccessToken;
28 import org.apache.slide.common.ServiceAccessException;
29 import org.apache.slide.event.EventDispatcher;
30 import org.apache.slide.webdav.WebdavException;
31 import org.apache.slide.webdav.WebdavServletConfig;
32 import org.apache.slide.webdav.event.WebdavEvent;
33 import org.apache.slide.webdav.util.DeltavConstants;
34 import org.apache.slide.webdav.util.PreconditionViolationException;
35 import org.apache.slide.webdav.util.VersioningHelper;
36 import org.apache.slide.webdav.util.WebdavStatus;
37 import org.jdom.JDOMException;
38
39 /**
40  * UNCHECKOUT method.
41  *
42  */

43 public class UncheckoutMethod extends AbstractWebdavMethod implements DeltavConstants, WriteMethod {
44     
45     /**
46      * String constant for <code>no-cache</code>.
47      */

48     protected static final String JavaDoc NO_CACHE = "no-cache";
49     
50     /**
51      * Resource to be written.
52      */

53     private String JavaDoc resourcePath;
54     
55     
56     // ----------------------------------------------------------- Constructors
57

58     
59     /**
60      * Constructor.
61      *
62      * @param token the token for accessing the namespace
63      * @param config configuration of the WebDAV servlet
64      */

65     public UncheckoutMethod(NamespaceAccessToken token,
66                             WebdavServletConfig config) {
67         super(token, config);
68     }
69     
70     /**
71      * Parse WebDAV XML query.
72      *
73      * @throws WebdavException
74      */

75     protected void parseRequest() throws WebdavException {
76 // readRequestContent();
77
resourcePath = requestUri;
78         if (resourcePath == null) {
79             resourcePath = "/";
80         }
81         if (req.getContentLength() > 0) {
82             try{
83                 parseRequestContent();
84             }
85             catch (JDOMException e){
86                 int statusCode = WebdavStatus.SC_BAD_REQUEST;
87                 sendError( statusCode, e );
88                 throw new WebdavException( statusCode );
89             }
90             catch (IOException JavaDoc e){
91                 int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
92                 sendError( statusCode, e );
93                 throw new WebdavException( statusCode );
94             }
95         }
96     }
97     
98     /**
99      * Execute the request.
100      *
101      * @throws WebdavException
102      * @throws IOException
103      */

104     protected void executeRequest() throws WebdavException, IOException JavaDoc {
105         
106         // Prevent dirty reads
107
slideToken.setForceStoreEnlistment(true);
108         
109         // check lock-null resources
110
try {
111             if (isLockNull(resourcePath)) {
112                 int statusCode = WebdavStatus.SC_NOT_FOUND;
113                 sendError( statusCode, "lock-null resource", new Object JavaDoc[]{resourcePath} );
114                 throw new WebdavException( statusCode );
115             }
116         }
117         catch (ServiceAccessException e) {
118             int statusCode = getErrorCode((Exception JavaDoc)e);
119             sendError( statusCode, e );
120             throw new WebdavException( statusCode );
121         }
122
123         try {
124             if ( WebdavEvent.UNCHECKOUT.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.UNCHECKOUT, new WebdavEvent(this));
125
126             VersioningHelper vh = VersioningHelper.getVersioningHelper(
127                 slideToken, token, req, resp, getConfig() );
128             vh.uncheckout(resourcePath);
129         }
130         catch (PreconditionViolationException e) {
131             sendPreconditionViolation(e);
132             throw e;
133         }
134         catch (Exception JavaDoc e) {
135             int statusCode = getErrorCode(e);
136             sendError( statusCode, e );
137             throw new WebdavException( statusCode );
138         }
139         finally {
140             resp.setHeader(H_CACHE_CONTROL, NO_CACHE);
141         }
142         
143     }
144     
145     
146 }
147
148
149
150
Popular Tags