KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > user > component > UILogout


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

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 /**
23  * Created y the eXo platform team
24  * User: Benjamin Mestrallet
25  * Date: 1 mai 2004
26  */

27 public class UILogout extends UIGrid {
28   public static final String JavaDoc LOGOUT_ACTION = "logout";
29   public static final Parameter[] LOGOUT_PARAMS = {new Parameter(ACTION, LOGOUT_ACTION)} ;
30
31   private String JavaDoc fullName_;
32   private String JavaDoc logoutPath_;
33
34   public UILogout() throws Exception JavaDoc {
35     setId("UILogout");
36     setClazz("UILogout");
37     RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class) ;
38     String JavaDoc accessibility = rinfo.getAccessibility() ;
39     if (RequestInfo.ADMIN_ACCESS.equals(accessibility)) {
40       PortalResources presources =
41         (PortalResources)SessionContainer.getComponent(PortalResources.class) ;
42       String JavaDoc 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 JavaDoc getFullName() { return fullName_; }
62   
63   static public class LogoutActionListener extends ExoActionListener {
64         public void execute(ExoActionEvent event) throws Exception JavaDoc {
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