001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.sharepoint.methods;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.sharepoint.Property;
019    import com.liferay.portal.sharepoint.ResponseElement;
020    import com.liferay.portal.sharepoint.SharepointRequest;
021    import com.liferay.portal.sharepoint.SharepointStorage;
022    import com.liferay.portal.sharepoint.SharepointUtil;
023    import com.liferay.portal.sharepoint.Tree;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    /**
029     * @author Bruno Farache
030     */
031    public class MoveDocumentMethodImpl extends BaseMethodImpl {
032    
033            public String getMethodName() {
034                    return _METHOD_NAME;
035            }
036    
037            public String getRootPath(SharepointRequest sharepointRequest) {
038                    return sharepointRequest.getParameterValue("oldUrl");
039            }
040    
041            protected List<ResponseElement> getElements(
042                            SharepointRequest sharepointRequest)
043                    throws Exception {
044    
045                    List<ResponseElement> elements = new ArrayList<ResponseElement>();
046    
047                    String oldUrl = sharepointRequest.getParameterValue("oldUrl");
048    
049                    oldUrl = SharepointUtil.replaceBackSlashes(oldUrl);
050    
051                    String newUrl = sharepointRequest.getParameterValue("newUrl");
052    
053                    newUrl = SharepointUtil.replaceBackSlashes(oldUrl);
054    
055                    SharepointStorage storage = sharepointRequest.getSharepointStorage();
056    
057                    Tree[] results = storage.moveDocument(sharepointRequest);
058    
059                    elements.add(new Property("message", StringPool.BLANK));
060                    elements.add(new Property("oldUrl", oldUrl));
061                    elements.add(new Property("newUrl", newUrl));
062    
063                    Property documentListProperty = new Property(
064                            "document_list", new Tree());
065    
066                    elements.add(documentListProperty);
067    
068                    elements.add(new Property("moved_docs", results[0]));
069                    elements.add(new Property("moved_dirs", results[1]));
070    
071                    return elements;
072            }
073    
074            private static final String _METHOD_NAME = "move document";
075    
076    }