1 5 package org.exoplatform.faces.user.component; 6 7 import javax.faces.context.ExternalContext; 8 import javax.portlet.ActionResponse; 9 import org.exoplatform.container.SessionContainer; 10 import org.exoplatform.faces.core.component.UIGrid; 11 import org.exoplatform.faces.core.component.model.Button; 12 import org.exoplatform.faces.core.component.model.ListComponentCell; 13 import org.exoplatform.faces.core.component.model.Cell; 14 import org.exoplatform.faces.core.component.model.Parameter; 15 import org.exoplatform.faces.core.component.model.Row; 16 import org.exoplatform.faces.core.event.ExoActionEvent; 17 import org.exoplatform.faces.core.event.ExoActionListener; 18 import org.exoplatform.portal.filter.AdminRequestFilter; 19 import org.exoplatform.portal.session.RequestInfo; 20 import org.exoplatform.portal.session.PortalResources ; 21 import org.exoplatform.services.portletcontainer.pci.Output; 22 27 public class UILogout extends UIGrid { 28 public static final String LOGOUT_ACTION = "logout"; 29 public static final Parameter[] LOGOUT_PARAMS = {new Parameter(ACTION, LOGOUT_ACTION)} ; 30 31 private String fullName_; 32 private String logoutPath_; 33 34 public UILogout() throws Exception { 35 setId("UILogout"); 36 setClazz("UILogout"); 37 RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class) ; 38 String accessibility = rinfo.getAccessibility() ; 39 if (RequestInfo.ADMIN_ACCESS.equals(accessibility)) { 40 PortalResources presources = 41 (PortalResources)SessionContainer.getComponent(PortalResources.class) ; 42 String s = "<a HREF='" + rinfo.getOwnerURI() + '?' + 43 AdminRequestFilter.ACTION + '=' + AdminRequestFilter.RETURN + "'>" + 44 presources.getPortalResourceBundle().getString("UILogout.button.back") + 45 "</a>" ; 46 add(new Row(). 47 add(new Cell(s).addAlign("center"))); 48 } else { 49 logoutPath_ = rinfo.getContextPath() ; 50 fullName_ = rinfo.getPortalOwner(); 51 add(new Row(). 52 add(new ListComponentCell(). 53 add(new Button("#{UILogout.button.logout}", LOGOUT_PARAMS)). 54 addAlign("center"))); 55 addActionListener(LogoutActionListener.class , LOGOUT_ACTION) ; 56 } 57 58 } 59 60 61 public String getFullName() { return fullName_; } 62 63 static public class LogoutActionListener extends ExoActionListener { 64 public void execute(ExoActionEvent event) throws Exception { 65 UILogout comp = (UILogout) event.getComponent() ; 66 ExternalContext eContext = comp.getFacesContext().getExternalContext(); 67 ActionResponse response = (ActionResponse) eContext.getResponse(); 68 response.addProperty(Output.LOGOUT, "true"); 69 response.sendRedirect(comp.logoutPath_); 70 } 71 } 72 } | Popular Tags |