KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.net.URI JavaDoc;
21
22 import com.sslexplorer.vfs.VFSLockManager;
23 import com.sslexplorer.vfs.VFSResource;
24 import com.sslexplorer.vfs.webdav.DAVException;
25 import com.sslexplorer.vfs.webdav.DAVMethod;
26 import com.sslexplorer.vfs.webdav.DAVMultiStatus;
27 import com.sslexplorer.vfs.webdav.DAVProcessor;
28 import com.sslexplorer.vfs.webdav.DAVServlet;
29 import com.sslexplorer.vfs.webdav.DAVTransaction;
30 import com.sslexplorer.vfs.webdav.LockedException;
31
32 /**
33  * <p>
34  * <a HREF="http://www.rfc-editor.org/rfc/rfc2518.txt">WebDAV</a>
35  * <code>MOVE</code> metohd implementation.
36  * </p>
37  *
38  * @author <a HREF="http://www.betaversion.org/~pier/">Pier Fumagalli</a>
39  */

40 public class MOVE implements DAVMethod {
41
42     /**
43      * <p>
44      * Create a new {@link MOVE} instance.
45      * </p>
46      */

47     public MOVE() {
48         super();
49     }
50
51     /**
52      * <p>
53      * Process the <code>MOVE</code> method.
54      * </p>
55      *
56      * @throws IOException
57      */

58     public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException JavaDoc {
59         String JavaDoc handle = VFSLockManager.getNewHandle();
60         VFSResource dest = null;
61         VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), true, true, handle);
62         
63         try {
64             try {
65                 //super.process(transaction, resource);
66
DAVProcessor processor = DAVServlet.getDAVProcessor(transaction.getRequest());
67                 URI JavaDoc target = transaction.getDestination();
68                 if (target == null)
69                     throw new DAVException(412, "No destination");
70                 dest = processor.getRepository().getResource(resource.getLaunchSession(), target.getPath(), transaction.getCredentials());
71                 
72                 VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), true, false, handle);
73                 
74                 resource.move(dest, true);
75                 resource.getMount().resourceMoved(resource, dest, transaction, null);
76                 transaction.setStatus(204);
77             } catch (DAVMultiStatus multistatus) {
78                 multistatus.write(transaction);
79             }
80         } catch (Exception JavaDoc e) {
81             resource.getMount().resourceMoved(resource, dest, transaction, e);
82             if(e instanceof LockedException)
83                 throw (LockedException) e;
84             IOException JavaDoc ioe = new IOException JavaDoc(e.getMessage());
85             ioe.initCause(e);
86             throw ioe;
87         } finally {
88             VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle);
89         }
90     }
91 }
92
Popular Tags