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 req
251 */
252 public void getAllPages(RenderRequest req) {
253 Iterator iter = getPageRegistry();
254 req.setAttribute(PlutoAdminConstants.PAGE_LIST_ATTR, iter);
255
256 }
257
258 public void getPage(ActionRequest req) {
259 String pageName = req.getParameter("pageName");
260 PageTO page = getPageVO(pageName);
261 req.getPortletSession().setAttribute(PlutoAdminConstants.PAGE_ATTR, page);
262 }
263
264 public void modifyPageAttributes(ActionRequest req) {
265 final String METHOD_NAME = "modifyRowsAndCols(request)";
266 logMethodStart(METHOD_NAME);
267 PageTO page = (PageTO)req.getPortletSession().getAttribute(PlutoAdminConstants.PAGE_ATTR);
268 logDebug(METHOD_NAME, "Current page: " + page);
269 String title = req.getParameter("title");
270 page.setTitle(title);
271 String description = req.getParameter("description");
272 page.setDescription(description);
273 String rows = req.getParameter("numrows");
274 page.setRows(Integer.parseInt(rows));
275 String cols = req.getParameter("numcols");
276 page.setCols(Integer.parseInt(cols));
277 logDebug(METHOD_NAME, "Updated current page: " + page);
278 req.getPortletSession().setAttribute(PlutoAdminConstants.PAGE_ATTR, page);
279 logMethodEnd(METHOD_NAME);
280 }
281
282 public Map getPortletMapForSelect(String app) {
283 Map map = new HashMap();
284 List portlets = null;
285 Iterator iter = getPageRegistry();
286 while (iter.hasNext()) {
287 PageTO page = (PageTO)iter.next();
288 if (page.getName().equalsIgnoreCase(app)) {
289 portlets = page.getPortlets();
290 break;
291 }
292 }
293
294 Iterator piter = portlets.iterator();
295 while(piter.hasNext()){
296 PortletTO plet = (PortletTO)piter.next();
297 map.put(plet.getName(), plet.getValue());
298 }
299 return map;
300 }
301 }