KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

43     public MKCOL() {
44         super();
45     }
46
47     /**
48      * <p>
49      * Process the <code>MKCOL</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             transaction.setHeader("content-type", "application/octet-stream");
59             /*
60              * Unsupported media type, we don't want content
61              */

62             if (transaction.getInputStream() != null)
63                 throw new DAVException(415, "No request body allowed in request");
64
65             /* Create the collection */
66             resource.makeCollection();
67             transaction.setStatus(201);
68             resource.getMount().resourceCollectionCreated(resource, transaction, null);
69         } catch (Exception JavaDoc e) {
70             resource.getMount().resourceCollectionCreated(resource, transaction, e);
71             IOException JavaDoc ioe = new IOException JavaDoc(e.getMessage());
72             ioe.initCause(e);
73             throw ioe;
74         } finally {
75             VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle);
76         }
77     }
78 }
Popular Tags