1 5 package org.exoplatform.portlets.portal.component; 6 7 import javax.faces.context.ExternalContext; 8 import javax.faces.context.FacesContext; 9 import javax.portlet.ActionResponse; 10 import org.exoplatform.faces.core.component.UIGrid; 11 import org.exoplatform.faces.core.component.UIPageListIterator; 12 import org.exoplatform.faces.core.component.model.*; 13 import org.exoplatform.faces.core.event.CheckRoleInterceptor; 14 import org.exoplatform.faces.core.event.ExoActionEvent; 15 import org.exoplatform.faces.core.event.ExoActionListener; 16 import org.exoplatform.container.SessionContainer ; 17 import org.exoplatform.portal.filter.AdminRequestFilter; 18 import org.exoplatform.portal.session.RequestInfo; 19 import org.exoplatform.services.portal.PortalConfigDescription; 20 import org.exoplatform.services.portal.PortalConfigService; 21 import org.exoplatform.services.portal.Query; 22 28 public class UIAvailablePortal extends UIGrid { 29 static Parameter[] VIEW = { new Parameter(ACTION , "view") } ; 30 static Parameter[] EDIT = { new Parameter(ACTION , "edit") } ; 31 static Parameter[] ADMIN = { new Parameter(ACTION , "admin") } ; 32 33 private UIPageListIterator uiPageIterator_ ; 34 private boolean adminRole_ ; 35 private PortalConfigService service_ ; 36 public UIAvailablePortal(UISearchForm uiSearchForm, 37 PortalConfigService service) throws Exception { 38 setId("UIAvailablePortal") ; 39 service_ = service ; 40 uiPageIterator_ = new UIPageListIterator(new PortalDataHandler()) ; 41 adminRole_ = hasRole("admin") ; 42 adminRole_ = true ; 43 add(new Rows(uiPageIterator_.getPageListDataHandler(), "even", "odd"). 44 add(new Column("#{UIAvailablePortal.header.owner}", "owner")). 45 add(new Column("#{UIAvailablePortal.header.edit-permission}", "editPermission")). 46 add(new Column("#{UIAvailablePortal.header.view-permission}", "viewPermission")). 47 add(new ActionColumn("#{UIAvailablePortal.header.action}", "owner"). 48 add(adminRole_,new Button("#{UIAvailablePortal.button.admin}", ADMIN)))) ; 51 add(new Row(). 52 add(new ComponentCell(this, uiPageIterator_). 53 addColspan("4").addClazz("footer"))); 54 add(new Row(). 55 add(new ComponentCell(this, uiSearchForm). 56 addColspan("4"))); 57 58 addActionListener(ViewActionListener.class, "view") ; 59 addActionListener(AdminActionListener.class, "admin") ; 60 refresh(new Query(null, null, null)) ; 61 } 62 63 public void refresh(Query q) throws Exception { 64 uiPageIterator_.setPageList(service_.findAllPortalConfigDescriptions(q)) ; 65 } 66 67 static public class PortalDataHandler extends PageListDataHandler { 68 private PortalConfigDescription desc_ ; 69 70 public String getData(String fieldName) { 71 if("owner".equals(fieldName)) return desc_.getOwner() ; 72 if("viewPermission".equals(fieldName)) return desc_.getViewPermission() ; 73 if("editPermission".equals(fieldName)) return desc_.getEditPermission() ; 74 return null ; 75 } 76 77 public void setCurrentObject(Object o) { desc_ = (PortalConfigDescription) o; } 78 } 79 80 static public class AdminActionListener extends ExoActionListener { 81 public AdminActionListener() { 82 addInterceptor(new CheckRoleInterceptor("admin")) ; 83 } 84 85 public void execute(ExoActionEvent event) throws Exception { 86 String owner = event.getParameter(OBJECTID) ; 87 RequestInfo rinfo = (RequestInfo) SessionContainer.getComponent(RequestInfo.class); 88 String path = rinfo.getContextPath() + "/faces/admin/" + owner + 89 "?" + AdminRequestFilter.ACTION + "=" + AdminRequestFilter.ADMIN ; 90 ExternalContext eContext = FacesContext.getCurrentInstance().getExternalContext(); 91 ActionResponse response = (ActionResponse) eContext.getResponse(); 92 response.sendRedirect(path); 93 } 94 } 95 96 static public class ViewActionListener extends ExoActionListener { 97 public ViewActionListener() { 98 addInterceptor(new CheckRoleInterceptor("admin")) ; 99 } 100 101 public void execute(ExoActionEvent event) throws Exception { 102 } 103 } 104 } | Popular Tags |