1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.webdav.methods;
16  
17  import com.liferay.portal.kernel.servlet.HttpHeaders;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portal.util.PortalUtil;
21  import com.liferay.portal.webdav.Status;
22  import com.liferay.portal.webdav.WebDAVException;
23  import com.liferay.portal.webdav.WebDAVRequest;
24  import com.liferay.portal.webdav.WebDAVStorage;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  /**
30   * <a href="MkcolMethodImpl.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   * @author Alexander Chow
34   */
35  public class MkcolMethodImpl implements Method {
36  
37      public int process(WebDAVRequest webDavRequest) throws WebDAVException {
38          WebDAVStorage storage = webDavRequest.getWebDAVStorage();
39          HttpServletRequest request = webDavRequest.getHttpServletRequest();
40          HttpServletResponse response = webDavRequest.getHttpServletResponse();
41          long groupId = webDavRequest.getGroupId();
42  
43          int statusCode = HttpServletResponse.SC_FORBIDDEN;
44  
45          if (groupId != 0) {
46              Status status = storage.makeCollection(webDavRequest);
47  
48              if (Validator.isNotNull(status.getObject())) {
49                  response.setHeader(
50                      HttpHeaders.LOCATION,
51                      PortalUtil.getPortalURL(request) +
52                          webDavRequest.getRootPath() + StringPool.SLASH +
53                              status.getObject());
54              }
55  
56              statusCode = status.getCode();
57          }
58  
59          return statusCode;
60      }
61  
62  }