1 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 44 public class PageRegistryService extends BaseAdminObject { 45 46 private static final String CLASS_NAME = "PageRegistryService"; 47 48 53 56 public PageRegistryService() { 57 super(CLASS_NAME); 58 } 59 60 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 if(!frag.getName().equals("navigation")) { 97 PageTO page = new PageTO(); 99 page.setName(frag.getName()); 100 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 139 140 155 156 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 215 216 230 231 247 248 253 public void getAllPages(RenderRequest req) { 254 Iterator iter = getPageRegistry(); 255 req.setAttribute(PlutoAdminConstants.PAGE_LIST_ATTR, iter); 256 } 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 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 } 303 | Popular Tags |