1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.layout.impl;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Comparator;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.jetspeed.JetspeedActions;
29 import org.apache.jetspeed.ajax.AjaxAction;
30 import org.apache.jetspeed.ajax.AjaxBuilder;
31 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
32 import org.apache.jetspeed.om.folder.Folder;
33 import org.apache.jetspeed.om.page.Page;
34 import org.apache.jetspeed.page.PageManager;
35 import org.apache.jetspeed.request.RequestContext;
36
37 /***
38 * Get Pages retrieves all pages for the given folder
39 *
40 * AJAX Parameters:
41 * folder = the path of folder containing the pages
42 *
43 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
44 * @version $Id: $
45 */
46 public class GetPagesAction
47 extends BasePortletAction
48 implements AjaxAction, AjaxBuilder, Constants, Comparator
49 {
50 protected static final Log log = LogFactory.getLog(GetPortletsAction.class);
51
52 public GetPagesAction(String template,
53 String errorTemplate,
54 PageManager pageManager,
55 PortletActionSecurityBehavior securityBehavior)
56 {
57 super(template, errorTemplate, pageManager, securityBehavior);
58 }
59
60 public boolean run(RequestContext requestContext, Map resultMap)
61 {
62 boolean success = true;
63 String status = "success";
64 try
65 {
66 resultMap.put(ACTION, "getpages");
67 if (false == checkAccess(requestContext, JetspeedActions.VIEW))
68 {
69
70
71 success = false;
72 resultMap.put(REASON, "Insufficient access to get portlets");
73 return success;
74
75
76 }
77 List pages = retrievePages(requestContext);
78 resultMap.put(STATUS, status);
79 resultMap.put(PAGES, pages);
80 }
81 catch (Exception e)
82 {
83
84 log.error("exception while getting portlet info", e);
85
86
87 success = false;
88 }
89
90 return success;
91 }
92
93 protected List retrievePages(RequestContext requestContext)
94 {
95 List list = new ArrayList();
96
97 String folderName = getActionParameter(requestContext, FOLDER);
98 if (folderName == null)
99 {
100 return list;
101 }
102 try
103 {
104 Folder folder = pageManager.getFolder(folderName);
105 Iterator it = folder.getPages().iterator();
106 while (it.hasNext())
107 {
108 Page page = (Page)it.next();
109 list.add(page);
110 }
111 Collections.sort(list, this);
112 }
113 catch (Exception e)
114 {
115 }
116 return list;
117 }
118
119
120 public int compare(Object obj1, Object obj2)
121 {
122 Page page1 = (Page)obj1;
123 Page page2 = (Page)obj2;
124 String name1 = page1.getName();
125 String name2 = page2.getName();
126 name1 = (name1 == null) ? "unknown" : name1;
127 name2 = (name2 == null) ? "unknown" : name2;
128 return name1.compareTo(name2);
129 }
130 }