KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > webdav > DeleteMethod


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.webdav;
18
19 import java.util.List JavaDoc;
20
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 import org.alfresco.service.cmr.model.FileFolderService;
24 import org.alfresco.service.cmr.model.FileInfo;
25 import org.alfresco.service.cmr.model.FileNotFoundException;
26 import org.alfresco.service.cmr.repository.NodeRef;
27
28 /**
29  * Implements the WebDAV DELETE method
30  *
31  * @author gavinc
32  */

33 public class DeleteMethod extends WebDAVMethod
34 {
35     /**
36      * Default constructor
37      */

38     public DeleteMethod()
39     {
40     }
41
42     /**
43      * Parse the request headers
44      *
45      * @exception WebDAVServerException
46      */

47     protected void parseRequestHeaders() throws WebDAVServerException
48     {
49         // Nothing to do in this method
50
}
51
52     /**
53      * Parse the request body
54      *
55      * @exception WebDAVServerException
56      */

57     protected void parseRequestBody() throws WebDAVServerException
58     {
59         // Nothing to do in this method
60
}
61
62     /**
63      * Execute the request
64      *
65      * @exception WebDAVServerException
66      */

67     protected void executeImpl() throws WebDAVServerException, Exception JavaDoc
68     {
69         if (logger.isDebugEnabled())
70         {
71             logger.debug("WebDAV DELETE: " + getPath());
72         }
73         
74         FileFolderService fileFolderService = getFileFolderService();
75
76         NodeRef rootNodeRef = getRootNodeRef();
77
78         String JavaDoc path = getPath();
79         List JavaDoc<String JavaDoc> pathElements = getDAVHelper().splitAllPaths(path);
80         FileInfo fileInfo = null;
81         try
82         {
83             // get the node to delete
84
fileInfo = fileFolderService.resolveNamePath(rootNodeRef, pathElements);
85         }
86         catch (FileNotFoundException e)
87         {
88             if (logger.isDebugEnabled())
89             {
90                 logger.debug("Node not found: " + getPath());
91             }
92             throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
93         }
94         // delete it
95
fileFolderService.delete(fileInfo.getNodeRef());
96     }
97 }
98
Popular Tags