KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > webdav > methods > DELETE


1 /* ========================================================================== *
2  * Copyright (C) 2004-2005 Pier Fumagalli <http://www.betaversion.org/~pier/> *
3  * All rights reserved. *
4  * ========================================================================== *
5  * *
6  * Licensed under the Apache License, Version 2.0 (the "License"). You may *
7  * not use this file except in compliance with the License. You may obtain a *
8  * copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>. *
9  * *
10  * Unless required by applicable law or agreed to in writing, software *
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT *
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the *
13  * License for the specific language governing permissions and limitations *
14  * under the License. *
15  * *
16  * ========================================================================== */

17 package com.sslexplorer.vfs.webdav.methods;
18
19 import java.io.IOException JavaDoc;
20
21 import org.apache.commons.vfs.FileSystemException;
22
23 import com.sslexplorer.vfs.VFSLockManager;
24 import com.sslexplorer.vfs.VFSResource;
25 import com.sslexplorer.vfs.webdav.DAVMethod;
26 import com.sslexplorer.vfs.webdav.DAVMultiStatus;
27 import com.sslexplorer.vfs.webdav.DAVTransaction;
28 import com.sslexplorer.vfs.webdav.LockedException;
29
30 /**
31  * <a HREF="http://www.rfc-editor.org/rfc/rfc2518.txt">WebDAV</a>
32  * <code>DELETE</code> method implementation.
33  *
34  * @author <a HREF="http://www.betaversion.org/~pier/">Pier Fumagalli</a>
35  */

36 public class DELETE implements DAVMethod {
37
38     /**
39      * <p>
40      * Create a new {@link DELETE} instance.
41      * </p>
42      */

43     public DELETE() {
44         super();
45     }
46
47     /**
48      * <p>
49      * Process the <code>DELETE</code> method.
50      * </p>
51      */

52     public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException JavaDoc {
53         
54         String JavaDoc handle = VFSLockManager.getNewHandle();
55         VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), true, true, handle);
56         
57         try {
58             try {
59                 resource.delete();
60                 transaction.setStatus(204);
61                 resource.getMount().resourceDelete(resource, transaction, null);
62             } catch (FileSystemException ex) {
63                 transaction.setStatus(423);
64                 DAVMultiStatus s = new DAVMultiStatus();
65                 throw s;
66             }
67         } catch (DAVMultiStatus multistatus) {
68             multistatus.write(transaction);
69             resource.getMount().resourceDelete(resource, transaction, multistatus);
70         } finally {
71             VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle);
72         }
73     }
74 }
75
Popular Tags