1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }