1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.webdav.methods;
21  
22  import com.liferay.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.webdav.Resource;
25  import com.liferay.portal.webdav.WebDAVException;
26  import com.liferay.portal.webdav.WebDAVRequest;
27  import com.liferay.portal.webdav.WebDAVStorage;
28  import com.liferay.portal.webdav.WebDAVUtil;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  
33  /**
34   * <a href="MoveMethodImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   * @author Alexander Chow
38   *
39   */
40  public class MoveMethodImpl implements Method {
41  
42      public int process(WebDAVRequest webDavRequest) throws WebDAVException {
43          WebDAVStorage storage = webDavRequest.getWebDAVStorage();
44          HttpServletRequest request = webDavRequest.getHttpServletRequest();
45  
46          String destination = WebDAVUtil.getDestination(
47              request, storage.getRootPath());
48  
49          StringBuilder sb = new StringBuilder();
50  
51          if (_log.isInfoEnabled()) {
52              sb.append("Destination is " + destination);
53          }
54  
55          int status = HttpServletResponse.SC_FORBIDDEN;
56  
57          if ((!destination.equals(webDavRequest.getPath())) &&
58              (WebDAVUtil.getGroupId(destination) ==
59                  webDavRequest.getGroupId())) {
60  
61              Resource resource = storage.getResource(webDavRequest);
62  
63              if (resource == null) {
64                  status = HttpServletResponse.SC_NOT_FOUND;
65              }
66              else {
67                  boolean overwrite = WebDAVUtil.isOverwrite(request);
68  
69                  if (_log.isInfoEnabled()) {
70                      sb.append(", overwrite is " + overwrite);
71  
72                      _log.info(sb.toString());
73                  }
74  
75                  if (resource.isCollection()) {
76                      status = storage.moveCollectionResource(
77                          webDavRequest, resource, destination, overwrite);
78                  }
79                  else {
80                      status = storage.moveSimpleResource(
81                          webDavRequest, resource, destination, overwrite);
82                  }
83              }
84          }
85  
86          return status;
87      }
88  
89      private static Log _log = LogFactoryUtil.getLog(MoveMethodImpl.class);
90  
91  }