1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.sharepoint.methods;
16  
17  import com.liferay.portal.sharepoint.Property;
18  import com.liferay.portal.sharepoint.ResponseElement;
19  import com.liferay.portal.sharepoint.SharepointRequest;
20  import com.liferay.portal.sharepoint.SharepointStorage;
21  import com.liferay.portal.sharepoint.Tree;
22  import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * <a href="GetDocsMetaInfoMethodImpl.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Bruno Farache
31   */
32  public class GetDocsMetaInfoMethodImpl extends BaseMethodImpl {
33  
34      public String getMethodName() {
35          return _METHOD_NAME;
36      }
37  
38      public String getRootPath(SharepointRequest sharepointRequest) {
39          String urlList = sharepointRequest.getParameterValue("url_list");
40  
41          urlList = urlList.substring(1, urlList.length() - 1);
42  
43          int pos = urlList.lastIndexOf("sharepoint/");
44  
45          if (pos != -1) {
46              urlList = urlList.substring(pos + 11);
47          }
48  
49          return urlList;
50      }
51  
52      protected List<ResponseElement> getElements(
53              SharepointRequest sharepointRequest)
54          throws Exception {
55  
56          List<ResponseElement> elements = new ArrayList<ResponseElement>();
57  
58          SharepointStorage storage = sharepointRequest.getSharepointStorage();
59  
60          Tree documentListTree = new Tree();
61  
62          try {
63              documentListTree.addChild(
64                  storage.getDocumentTree(sharepointRequest));
65          }
66          catch (Exception e1) {
67              if (e1 instanceof NoSuchFileEntryException) {
68                  try {
69                      documentListTree.addChild(
70                          storage.getFolderTree(sharepointRequest));
71                  }
72                  catch (Exception e2) {
73                  }
74              }
75          }
76  
77          Property documentProperty = new Property(
78              "document_list", documentListTree);
79  
80          elements.add(documentProperty);
81  
82          elements.add(new Property("urldirs", new Tree()));
83  
84          return elements;
85      }
86  
87      private static final String _METHOD_NAME = "getDocsMetaInfo";
88  
89  }