KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CheckinMethod.java,v 1.29 2004/08/05 14:43:29 dflorey Exp $
3  * $Revision: 1.29 $
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 import java.util.Iterator JavaDoc;
27
28 import org.apache.slide.common.NamespaceAccessToken;
29 import org.apache.slide.common.ServiceAccessException;
30 import org.apache.slide.event.EventDispatcher;
31 import org.apache.slide.webdav.WebdavException;
32 import org.apache.slide.webdav.WebdavServletConfig;
33 import org.apache.slide.webdav.event.WebdavEvent;
34 import org.apache.slide.webdav.util.DeltavConstants;
35 import org.apache.slide.webdav.util.PreconditionViolationException;
36 import org.apache.slide.webdav.util.VersioningHelper;
37 import org.apache.slide.webdav.util.WebdavStatus;
38 import org.apache.slide.webdav.util.WebdavUtils;
39 import org.jdom.Element;
40 import org.jdom.JDOMException;
41
42 /**
43  * CHECKIN method.
44  *
45  */

46 public class CheckinMethod extends AbstractWebdavMethod implements DeltavConstants, WriteMethod {
47
48     /** Resource to be written. */
49     private String JavaDoc resourcePath;
50
51     /** Marshalling variables */
52     private boolean forkOk = false;
53     private boolean keepCheckedOut = false;
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 CheckinMethod(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
77         resourcePath = requestUri;
78         if (resourcePath == null) {
79             resourcePath = "/";
80         }
81
82
83         if( req.getContentLength() > 0 ) {
84 // readRequestContent();
85
try{
86                 Iterator JavaDoc i = parseRequestContent(E_CHECKIN).getChildren().iterator();
87                 while( i.hasNext() ) {
88                     Element e = (Element)i.next();
89                     if( e.getName().equals(E_FORK_OK) )
90                         forkOk = true;
91                     if( e.getName().equals(E_KEEP_CHECKED_OUT) ) {
92                         keepCheckedOut = true;
93                     }
94                 }
95             }
96             catch (IOException JavaDoc e){
97                 int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
98                 sendError( statusCode, e );
99                 throw new WebdavException( statusCode );
100             }
101             catch (JDOMException e){
102                 int statusCode = WebdavStatus.SC_BAD_REQUEST;
103                 sendError( statusCode, e );
104                 throw new WebdavException( statusCode );
105             }
106         }
107     }
108
109     /**
110      * Execute the request.
111      *
112      * @throws WebdavException
113      * @throws IOException
114      */

115     protected void executeRequest() throws WebdavException, IOException JavaDoc {
116         String JavaDoc locationValue = null;
117
118         // Prevent dirty reads
119
slideToken.setForceStoreEnlistment(true);
120         
121         // check lock-null resources
122
try {
123             if (isLockNull(resourcePath)) {
124                 int statusCode = WebdavStatus.SC_NOT_FOUND;
125                 sendError( statusCode, "lock-null resource", new Object JavaDoc[]{resourcePath} );
126                 throw new WebdavException( statusCode );
127             }
128         }
129         catch (ServiceAccessException e) {
130             int statusCode = getErrorCode( e );
131             sendError( statusCode, e );
132             throw new WebdavException( statusCode );
133         }
134
135         try {
136             VersioningHelper vh = VersioningHelper.getVersioningHelper(
137                 slideToken, token, req, resp, getConfig() );
138
139             if ( WebdavEvent.CHECKIN.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.CHECKIN, new WebdavEvent(this));
140
141             locationValue = vh.checkin( resourcePath , forkOk, keepCheckedOut, false);
142         }
143         catch (PreconditionViolationException e) {
144             sendPreconditionViolation(e);
145             throw e;
146         }
147         catch (Exception JavaDoc e) {
148             int statusCode = getErrorCode( e );
149             sendError( statusCode, e );
150             throw new WebdavException( statusCode );
151         }
152         finally {
153             resp.setHeader(H_CACHE_CONTROL, NO_CACHE);
154             if( locationValue != null && locationValue.length() > 0 ) {
155                 locationValue = getFullPath( locationValue );
156                 // the location header is "utf-8" expected
157
resp.setHeader( H_LOCATION, WebdavUtils.encodeURL(locationValue, "utf-8") );
158             }
159         }
160     }
161 }
162
163
164
Popular Tags