1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.pluto.portlet.admin.services;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.portlet.ActionRequest;
26 import javax.portlet.RenderRequest;
27
28 import org.apache.pluto.portalImpl.om.page.impl.FragmentImpl;
29 import org.apache.pluto.portalImpl.om.page.impl.PortalImpl;
30 import org.apache.pluto.portlet.admin.BaseAdminObject;
31 import org.apache.pluto.portlet.admin.PlutoAdminConstants;
32 import org.apache.pluto.portlet.admin.PlutoAdminException;
33 import org.apache.pluto.portlet.admin.bean.PageTO;
34 import org.apache.pluto.portlet.admin.bean.PortletTO;
35
36 /***
37 * Service concerned with pageregistry.xml persistence
38 *
39 *
40 * @author Craig Doremus
41 * @see org.apache.pluto.portlet.admin.controller.PageRegistryPortlet
42 *
43 */
44 public class PageRegistryService extends BaseAdminObject {
45
46 private static final String CLASS_NAME = "PageRegistryService";
47
48
49
50
51
52
53 /***
54 *
55 */
56 public PageRegistryService() {
57 super(CLASS_NAME);
58 }
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 public Iterator getPageRegistry() {
80 final String METHOD_NAME = "getPageRegistry()";
81 List pages = new ArrayList();
82 PortalImpl portal;
83 try {
84 org.apache.pluto.portlet.admin.model.PageRegistryXao xao = new org.apache.pluto.portlet.admin.model.PageRegistryXao();
85 portal = xao.load();
86 } catch (Exception e) {
87 PlutoAdminException pae = new PlutoAdminException(e);
88 logError(CLASS_NAME, METHOD_NAME, e);
89 throw pae;
90 }
91 Collection prpages = portal.getFragments();
92 Iterator iter = prpages.iterator();
93 while (iter.hasNext()) {
94 FragmentImpl frag = (FragmentImpl) iter.next();
95
96 if(!frag.getName().equals("navigation")) {
97
98 PageTO page = new PageTO();
99 page.setName(frag.getName());
100
101
102 Collection rfrags = frag.getFragments();
103 page.setTitle(frag.getNavigation().getTitle());
104 page.setDescription(frag.getNavigation().getDescription());
105 int rows = rfrags.size();
106 page.setRows(rows);
107 if (rows > 0) {
108 FragmentImpl row = (FragmentImpl)rfrags.iterator().next();
109 Collection cfrags = row.getFragments();
110 FragmentImpl col = (FragmentImpl)cfrags.iterator().next();
111 int cols = col.getFragments().size();
112 page.setCols(cols);
113 }
114 pages.add(page);
115 }
116 }
117 logDebug(METHOD_NAME, "Page count: " + pages.size());
118 return pages.iterator();
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175 public PageTO getPageVO(String name){
176 final String METHOD_NAME = "getPageVO(name)";
177 logMethodStart(METHOD_NAME);
178 PageTO page = null;
179 Iterator iter = getPageRegistry();
180 while (iter.hasNext()) {
181 PageTO element = (PageTO) iter.next();
182 if (element.getName().equals(name)) {
183 page = element;
184 break;
185 }
186 }
187 logMethodEnd(METHOD_NAME, page);
188 return page;
189 }
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 /***
249 * Gets the pages from pageregistry.xml for the View.
250 * @param prPath
251 * @param req
252 */
253 public void getAllPages(RenderRequest req) {
254 Iterator iter = getPageRegistry();
255 req.setAttribute(PlutoAdminConstants.PAGE_LIST_ATTR, iter);
256
257 }
258
259 public void getPage(ActionRequest req) {
260 String pageName = req.getParameter("pageName");
261 PageTO page = getPageVO(pageName);
262 req.getPortletSession().setAttribute(PlutoAdminConstants.PAGE_ATTR, page);
263 }
264
265 public void modifyPageAttributes(ActionRequest req) {
266 final String METHOD_NAME = "modifyRowsAndCols(request)";
267 logMethodStart(METHOD_NAME);
268 PageTO page = (PageTO)req.getPortletSession().getAttribute(PlutoAdminConstants.PAGE_ATTR);
269 logDebug(METHOD_NAME, "Current page: " + page);
270 String title = req.getParameter("title");
271 page.setTitle(title);
272 String description = req.getParameter("description");
273 page.setDescription(description);
274 String rows = req.getParameter("numrows");
275 page.setRows(Integer.parseInt(rows));
276 String cols = req.getParameter("numcols");
277 page.setCols(Integer.parseInt(cols));
278 logDebug(METHOD_NAME, "Updated current page: " + page);
279 req.getPortletSession().setAttribute(PlutoAdminConstants.PAGE_ATTR, page);
280 logMethodEnd(METHOD_NAME);
281 }
282
283 public Map getPortletMapForSelect(String app) {
284 Map map = new HashMap();
285 List portlets = null;
286 Iterator iter = getPageRegistry();
287 while (iter.hasNext()) {
288 PageTO page = (PageTO)iter.next();
289 if (page.getName().equalsIgnoreCase(app)) {
290 portlets = page.getPortlets();
291 break;
292 }
293 }
294
295 Iterator piter = portlets.iterator();
296 while(piter.hasNext()){
297 PortletTO plet = (PortletTO)piter.next();
298 map.put(plet.getName(), plet.getValue());
299 }
300 return map;
301 }
302 }