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.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="MoveMethodImpl.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   * @author Alexander Chow
34   */
35  public class MoveMethodImpl 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 {
63                  boolean overwrite = WebDAVUtil.isOverwrite(request);
64  
65                  if (_log.isInfoEnabled()) {
66                      sb.append(", overwrite is ");
67                      sb.append(overwrite);
68  
69                      _log.info(sb.toString());
70                  }
71  
72                  if (resource.isCollection()) {
73                      status = storage.moveCollectionResource(
74                          webDavRequest, resource, destination, overwrite);
75                  }
76                  else {
77                      status = storage.moveSimpleResource(
78                          webDavRequest, resource, destination, overwrite);
79                  }
80              }
81          }
82  
83          return status;
84      }
85  
86      private static Log _log = LogFactoryUtil.getLog(MoveMethodImpl.class);
87  
88  }