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.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.StringBundler;
20  import com.liferay.portal.webdav.Resource;
21  import com.liferay.portal.webdav.WebDAVException;
22  import com.liferay.portal.webdav.WebDAVRequest;
23  import com.liferay.portal.webdav.WebDAVStorage;
24  import com.liferay.portal.webdav.WebDAVUtil;
25  
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  /**
30   * <a href="CopyMethodImpl.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   * @author Alexander Chow
34   */
35  public class CopyMethodImpl implements Method {
36  
37      public int process(WebDAVRequest webDavRequest) throws WebDAVException {
38          WebDAVStorage storage = webDavRequest.getWebDAVStorage();
39          HttpServletRequest request = webDavRequest.getHttpServletRequest();
40  
41          String destination = WebDAVUtil.getDestination(
42              request, storage.getRootPath());
43  
44          StringBundler sb = new StringBundler();
45  
46          if (_log.isInfoEnabled()) {
47              sb.append("Destination is ");
48              sb.append(destination);
49          }
50  
51          int status = HttpServletResponse.SC_FORBIDDEN;
52  
53          if ((!destination.equals(webDavRequest.getPath())) &&
54              (WebDAVUtil.getGroupId(destination) ==
55                  webDavRequest.getGroupId())) {
56  
57              Resource resource = storage.getResource(webDavRequest);
58  
59              if (resource == null) {
60                  status = HttpServletResponse.SC_NOT_FOUND;
61              }
62              else if (resource.isCollection()) {
63                  boolean overwrite = WebDAVUtil.isOverwrite(request);
64                  long depth = WebDAVUtil.getDepth(request);
65  
66                  if (_log.isInfoEnabled()) {
67                      sb.append(", overwrite is ");
68                      sb.append(overwrite);
69                      sb.append(", depth is ");
70                      sb.append(depth);
71  
72                      _log.info(sb.toString());
73                  }
74  
75                  status = storage.copyCollectionResource(
76                      webDavRequest, resource, destination, overwrite, depth);
77              }
78              else {
79                  boolean overwrite = WebDAVUtil.isOverwrite(request);
80  
81                  if (_log.isInfoEnabled()) {
82                      sb.append(", overwrite is ");
83                      sb.append(overwrite);
84  
85                      _log.info(sb.toString());
86                  }
87  
88                  status = storage.copySimpleResource(
89                      webDavRequest, resource, destination, overwrite);
90              }
91          }
92  
93          return status;
94      }
95  
96      private static Log _log = LogFactoryUtil.getLog(CopyMethodImpl.class);
97  
98  }