View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.layout.impl;
18  
19  import java.util.Map;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.jetspeed.JetspeedActions;
24  import org.apache.jetspeed.ajax.AjaxAction;
25  import org.apache.jetspeed.ajax.AjaxBuilder;
26  import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
27  import org.apache.jetspeed.om.folder.Folder;
28  import org.apache.jetspeed.page.PageManager;
29  import org.apache.jetspeed.request.RequestContext;
30  
31  /***
32   * Get the immediate contents of a folder in Ajax Format 
33   *
34   * @author <a>Vivek Kumar</a>
35   * @author <a href="mailto:firevelocity@gmail.com">Vivek Kumar</a>
36   * AJAX Parameters: 
37   *    folder: full path to the folder 
38   *    
39   * @version $Id: $
40   */
41  public class GetFoldersListAction 
42      extends BaseGetResourceAction 
43      implements AjaxAction, AjaxBuilder, Constants
44  {
45      protected Log log = LogFactory.getLog(GetThemesAction.class);
46      
47      public GetFoldersListAction(String template, 
48              String errorTemplate,
49              PageManager pageManager,
50              PortletActionSecurityBehavior securityBehavior)
51      {
52          super(template, errorTemplate, pageManager, securityBehavior);        
53      }
54  
55      public boolean run(RequestContext requestContext, Map resultMap)
56      {
57          boolean success = true;
58          String status = "success";
59          try
60          {
61              resultMap.put(ACTION, "getfolderlist");
62              if (false == checkAccess(requestContext, JetspeedActions.VIEW))
63              {
64                      success = false;
65                      resultMap.put(REASON, "Insufficient access to get folderlist");
66                      return success;
67              }                     
68              String folderName = getActionParameter(requestContext, "data");            
69              if (folderName == null)
70              {
71                  success = false;
72                  resultMap.put(REASON, "Folder name not found.");
73                  return success;                
74              }
75              Folder folder = pageManager.getFolder(folderName);
76              resultMap.put("folders", folder.getFolders().iterator());
77              resultMap.put("pages", folder.getPages().iterator());
78              resultMap.put("links", folder.getLinks().iterator());
79              resultMap.put(STATUS, status);            
80          } 
81          catch (Exception e)
82          {
83              // Log the exception
84              log.error("exception while getting theme info", e);
85              // Return a failure indicator
86              success = false;
87          }
88  
89          return success;
90      }
91      
92      
93  }