%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.layout.impl.GetPagesAction |
|
|
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.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 | 0 | 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 | 0 | super(template, errorTemplate, pageManager, securityBehavior); |
58 | 0 | } |
59 | ||
60 | public boolean run(RequestContext requestContext, Map resultMap) |
|
61 | { |
|
62 | 0 | boolean success = true; |
63 | 0 | String status = "success"; |
64 | try |
|
65 | { |
|
66 | 0 | resultMap.put(ACTION, "getpages"); |
67 | 0 | if (false == checkAccess(requestContext, JetspeedActions.VIEW)) |
68 | { |
|
69 | // if (!createNewPageOnEdit(requestContext)) |
|
70 | // { |
|
71 | 0 | success = false; |
72 | 0 | resultMap.put(REASON, "Insufficient access to get portlets"); |
73 | 0 | return success; |
74 | // } |
|
75 | // status = "refresh"; |
|
76 | } |
|
77 | 0 | List pages = retrievePages(requestContext); |
78 | 0 | resultMap.put(STATUS, status); |
79 | 0 | resultMap.put(PAGES, pages); |
80 | } |
|
81 | 0 | catch (Exception e) |
82 | { |
|
83 | // Log the exception |
|
84 | 0 | log.error("exception while getting portlet info", e); |
85 | ||
86 | // Return a failure indicator |
|
87 | 0 | success = false; |
88 | 0 | } |
89 | ||
90 | 0 | return success; |
91 | } |
|
92 | ||
93 | protected List retrievePages(RequestContext requestContext) |
|
94 | { |
|
95 | 0 | List list = new ArrayList(); |
96 | ||
97 | 0 | String folderName = getActionParameter(requestContext, FOLDER); |
98 | 0 | if (folderName == null) |
99 | { |
|
100 | 0 | return list; |
101 | } |
|
102 | try |
|
103 | { |
|
104 | 0 | Folder folder = pageManager.getFolder(folderName); |
105 | 0 | Iterator it = folder.getPages().iterator(); |
106 | 0 | while (it.hasNext()) |
107 | { |
|
108 | 0 | Page page = (Page)it.next(); |
109 | 0 | list.add(page); |
110 | 0 | } |
111 | 0 | Collections.sort(list, this); |
112 | } |
|
113 | 0 | catch (Exception e) |
114 | { |
|
115 | 0 | } |
116 | 0 | return list; |
117 | } |
|
118 | ||
119 | ||
120 | public int compare(Object obj1, Object obj2) |
|
121 | { |
|
122 | 0 | Page page1 = (Page)obj1; |
123 | 0 | Page page2 = (Page)obj2; |
124 | 0 | String name1 = page1.getName(); |
125 | 0 | String name2 = page2.getName(); |
126 | 0 | name1 = (name1 == null) ? "unknown" : name1; |
127 | 0 | name2 = (name2 == null) ? "unknown" : name2; |
128 | 0 | return name1.compareTo(name2); |
129 | } |
|
130 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |