001    /**
002     * Copyright (c) 2000-2013 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.sharepoint.Property;
018    import com.liferay.portal.sharepoint.ResponseElement;
019    import com.liferay.portal.sharepoint.SharepointRequest;
020    import com.liferay.portal.sharepoint.SharepointStorage;
021    import com.liferay.portal.sharepoint.Tree;
022    import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
023    
024    import java.util.ArrayList;
025    import java.util.List;
026    
027    /**
028     * @author Bruno Farache
029     */
030    public class GetDocsMetaInfoMethodImpl extends BaseMethodImpl {
031    
032            @Override
033            public String getMethodName() {
034                    return _METHOD_NAME;
035            }
036    
037            @Override
038            public String getRootPath(SharepointRequest sharepointRequest) {
039                    String urlList = sharepointRequest.getParameterValue("url_list");
040    
041                    return urlList.substring(1, urlList.length() - 1);
042            }
043    
044            @Override
045            protected List<ResponseElement> getElements(
046                            SharepointRequest sharepointRequest)
047                    throws Exception {
048    
049                    List<ResponseElement> elements = new ArrayList<ResponseElement>();
050    
051                    SharepointStorage storage = sharepointRequest.getSharepointStorage();
052    
053                    Tree documentListTree = new Tree();
054    
055                    try {
056                            documentListTree.addChild(
057                                    storage.getDocumentTree(sharepointRequest));
058                    }
059                    catch (Exception e1) {
060                            if (e1 instanceof NoSuchFileEntryException) {
061                                    try {
062                                            documentListTree.addChild(
063                                                    storage.getFolderTree(sharepointRequest));
064                                    }
065                                    catch (Exception e2) {
066                                    }
067                            }
068                    }
069    
070                    Property documentProperty = new Property(
071                            "document_list", documentListTree);
072    
073                    elements.add(documentProperty);
074    
075                    elements.add(new Property("urldirs", new Tree()));
076    
077                    return elements;
078            }
079    
080            private static final String _METHOD_NAME = "getDocsMetaInfo";
081    
082    }