001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }