KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portlet > admin > services > PageRegistryService


1 /*
2  * Copyright 2003,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.pluto.portlet.admin.services;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
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 JavaDoc CLASS_NAME = "PageRegistryService";
47
48 // private List _rows = new ArrayList();
49
// private int _rowIndex = 1;
50
// private List _cols = new ArrayList();
51
// private int _colIndex = 1;
52

53     /**
54      *
55      */

56     public PageRegistryService() {
57         super(CLASS_NAME);
58     }
59
60 /*
61     public Iterator getPageRegistry(String prPath) {
62         final String METHOD_NAME = "getPageRegistry(prPath)";
63         List pages = new ArrayList();
64         PageRegistryXao xao = new PageRegistryXao();
65         List prpages = xao.getFragments(prPath);
66         Iterator iter = prpages.iterator();
67         while (iter.hasNext()) {
68             FragmentType frag = (FragmentType) iter.next();
69             //get rid of navigation fragment
70             if(!frag.getName().equals("navigation")) {
71                 pages.add(frag);
72             }
73         }
74         logDebug(METHOD_NAME, "Page count: " + pages.size());
75         return pages.iterator();
76     }
77 */

78
79     public Iterator JavaDoc getPageRegistry() {
80     final String JavaDoc METHOD_NAME = "getPageRegistry()";
81         List JavaDoc pages = new ArrayList JavaDoc();
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 JavaDoc e) {
87             PlutoAdminException pae = new PlutoAdminException(e);
88             logError(CLASS_NAME, METHOD_NAME, e);
89             throw pae;
90         }
91         Collection JavaDoc prpages = portal.getFragments();
92         Iterator JavaDoc iter = prpages.iterator();
93         while (iter.hasNext()) {
94           FragmentImpl frag = (FragmentImpl) iter.next();
95           //exclude navigation fragment
96
if(!frag.getName().equals("navigation")) {
97             //fill a PageTO
98
PageTO page = new PageTO();
99             page.setName(frag.getName());
100             //figure out number of rows and columns
101
//rows first
102
Collection JavaDoc 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 JavaDoc 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      * Get list for View page.
123      *
124      * @param prPath
125      * @return
126     public List getPageVOList(String prPath) {
127         final String METHOD_NAME = "getPageVOList(prPath)";
128         logMethodStart(METHOD_NAME);
129         List pagevos = new ArrayList();
130         Iterator iter = getPageRegistry(prPath);
131         while (iter.hasNext()) {
132             FragmentType frag = (FragmentType) iter.next();
133             pagevos.add(new PageTO(frag));
134         }
135         logMethodEnd(METHOD_NAME, "PageTO count: " + pagevos.size());
136         return pagevos;
137     }
138      */

139
140 /*
141     public FragmentType getPage(String prPath, String name) {
142         FragmentType page = null;
143         Iterator iter = getPageRegistry(prPath);
144         while (iter.hasNext()) {
145             FragmentType frag = (FragmentType) iter.next();
146             //get rid of navigation fragments
147             if(frag.getName().equals(name)) {
148                 page = frag;
149                 break;
150             }
151         }
152         return page;
153     }
154 */

155
156 /*
157     public PageTO getPageVO(String prPath, String name){
158         final String METHOD_NAME = "getPage(prPath,name)";
159         logMethodStart(METHOD_NAME);
160         PageTO page = null;
161         List pages = getPageVOList(prPath);
162         Iterator iter = pages.iterator();
163         while (iter.hasNext()) {
164             PageTO element = (PageTO) iter.next();
165             if (element.getName().equals(name)) {
166                 page = element;
167                 break;
168             }
169         }
170         logMethodEnd(METHOD_NAME, page);
171         return page;
172     }
173 */

174
175     public PageTO getPageVO(String JavaDoc name){
176         final String JavaDoc METHOD_NAME = "getPageVO(name)";
177         logMethodStart(METHOD_NAME);
178         PageTO page = null;
179         Iterator JavaDoc 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     private List getPortletList(int index, PageTO page) {
194         final String METHOD_NAME = "getPortletList(index,page)";
195         logMethodStart(METHOD_NAME);
196         logParam(METHOD_NAME, "index", index);
197         logParam(METHOD_NAME, "page", page);
198         List cplets = new ArrayList();
199         List plets = page.getPortlets();
200         logDebug(METHOD_NAME, "Portlet list: " + plets);
201         Iterator iter = plets.iterator();
202         while (iter.hasNext()) {
203             PortletTO plet = (PortletTO) iter.next();
204             if (plet.getCol() == index) {
205                 PropertyType prop = new PropertyTypeImpl();
206                 prop.setName(plet.getName());
207                 prop.setValue(plet.getValue());
208                 cplets.add(prop);
209             }
210         }
211         logMethodEnd(METHOD_NAME, cplets);
212         return cplets;
213     }
214 */

215
216 /*
217     private void addRow() {
218         final String METHOD_NAME = "addRow()";
219         logMethodStart(METHOD_NAME);
220         FragmentType frag = new FragmentTypeImpl();
221         frag.setTypeattr("row");
222         frag.setName("r" + _rowIndex);
223         List list = frag.getFragmentOrNavigationOrProperty();
224         list.addAll(_cols);
225         _rows.add(frag);
226         _rowIndex++;
227         logMethodEnd(METHOD_NAME);
228     }
229 */

230
231 /*
232     private void addCol(PageTO page) {
233         final String METHOD_NAME = "addCol(page)";
234         logMethodStart(METHOD_NAME);
235         logParam(METHOD_NAME, "page", page);
236         FragmentType frag = new FragmentTypeImpl();
237         frag.setTypeattr("col");
238         frag.setName("c" + _colIndex);
239         List list = frag.getFragmentOrNavigationOrProperty();
240         List portlets = getPortletList(_colIndex, page);
241         list.addAll(portlets);
242         _cols.add(frag);
243         _colIndex++;
244         logMethodEnd(METHOD_NAME);
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 JavaDoc iter = getPageRegistry();
255         req.setAttribute(PlutoAdminConstants.PAGE_LIST_ATTR, iter);
256 // req.getPortletSession().removeAttribute(PlutoAdminConstants.PAGE_ATTR);
257
}
258
259     public void getPage(ActionRequest req) {
260         String JavaDoc 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 JavaDoc 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 JavaDoc title = req.getParameter("title");
271         page.setTitle(title);
272         String JavaDoc description = req.getParameter("description");
273         page.setDescription(description);
274         String JavaDoc rows = req.getParameter("numrows");
275         page.setRows(Integer.parseInt(rows));
276         String JavaDoc 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 JavaDoc getPortletMapForSelect(String JavaDoc app) {
284         Map JavaDoc map = new HashMap JavaDoc();
285         List JavaDoc portlets = null;
286         Iterator JavaDoc 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         //go through portlets
295
Iterator JavaDoc 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 }
303
Popular Tags