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.sharepoint.methods;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  import com.liferay.portal.sharepoint.Property;
19  import com.liferay.portal.sharepoint.ResponseElement;
20  import com.liferay.portal.sharepoint.SharepointRequest;
21  import com.liferay.portal.sharepoint.SharepointStorage;
22  import com.liferay.portal.sharepoint.SharepointUtil;
23  import com.liferay.portal.sharepoint.Tree;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  /**
29   * <a href="MoveDocumentMethodImpl.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Bruno Farache
32   */
33  public class MoveDocumentMethodImpl extends BaseMethodImpl {
34  
35      public String getMethodName() {
36          return _METHOD_NAME;
37      }
38  
39      public String getRootPath(SharepointRequest sharepointRequest) {
40          return sharepointRequest.getParameterValue("oldUrl");
41      }
42  
43      protected List<ResponseElement> getElements(
44              SharepointRequest sharepointRequest)
45          throws Exception {
46  
47          List<ResponseElement> elements = new ArrayList<ResponseElement>();
48  
49          String oldUrl = sharepointRequest.getParameterValue("oldUrl");
50  
51          oldUrl = SharepointUtil.replaceBackSlashes(oldUrl);
52  
53          String newUrl = sharepointRequest.getParameterValue("newUrl");
54  
55          newUrl = SharepointUtil.replaceBackSlashes(oldUrl);
56  
57          SharepointStorage storage = sharepointRequest.getSharepointStorage();
58  
59          Tree[] results = storage.moveDocument(sharepointRequest);
60  
61          elements.add(new Property("message", StringPool.BLANK));
62          elements.add(new Property("oldUrl", oldUrl));
63          elements.add(new Property("newUrl", newUrl));
64  
65          Property documentListProperty = new Property(
66              "document_list", new Tree());
67  
68          elements.add(documentListProperty);
69  
70          elements.add(new Property("moved_docs", results[0]));
71          elements.add(new Property("moved_dirs", results[1]));
72  
73          return elements;
74      }
75  
76      private static final String _METHOD_NAME = "move document";
77  
78  }