KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > monitor > session > component > UIListSessionLog


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.portlets.monitor.session.component;
6
7 import java.text.SimpleDateFormat JavaDoc;
8 import org.exoplatform.faces.core.component.UIGrid;
9 import org.exoplatform.faces.core.component.UIPageListIterator;
10 import org.exoplatform.faces.core.component.model.*;
11 import org.exoplatform.faces.core.event.ExoActionEvent;
12 import org.exoplatform.faces.core.event.ExoActionListener;
13 import org.exoplatform.services.portal.log.PortalLogService;
14 import org.exoplatform.services.portal.log.Query;
15 import org.exoplatform.services.portal.log.SessionLogData;
16 import org.exoplatform.services.portal.log.SessionLogDataDescription;
17 /**
18  * Created y the eXo platform team
19  * User: Benjamin Mestrallet
20  * Date: 22 juin 2004
21  */

22 public class UIListSessionLog extends UIGrid {
23   private static SimpleDateFormat JavaDoc ft_ = new SimpleDateFormat JavaDoc("dd/MM/yy HH:mm:ss") ;
24   final static public String JavaDoc VIEW_ACTION = "view" ;
25   private static Parameter[] VIEW_PARAMS = {new Parameter(ACTION , VIEW_ACTION) } ;
26
27   private boolean adminRole_ ;
28   private UIPageListIterator uiPageIterator_ ;
29   private PortalLogService service_ ;
30
31   public UIListSessionLog(PortalLogService service) throws Exception JavaDoc {
32     setId("UIListSessionLog") ;
33     service_ = service ;
34     uiPageIterator_ = new UIPageListIterator(new SessionLogDataHandler()) ;
35     adminRole_ = hasRole("admin") ;
36     add(new Rows(uiPageIterator_.getPageListDataHandler(), "even", "odd").
37         add(new Column("#{UIListSessionLog.header.session-owner}", "sessionOwner")).
38         add(new Column("#{UIListSessionLog.header.remote-user}", "remoteUser")).
39         add(new Column("#{UIListSessionLog.header.ip-address}", "ipAddress")).
40         add(new Column("#{UIListSessionLog.header.client-type}", "clientType")).
41         add(new Column("#{UIListSessionLog.header.access-time}", "accessTime")).
42         add(new Column("#{UIListSessionLog.header.requests}", "requests")).
43         add(new Column("#{UIListSessionLog.header.duration}", "duration")).
44         add(new Column("#{UIListSessionLog.header.error-count}", "errorCount")).
45         add(new ActionColumn("#{UIListSessionLog.header.action}", OBJECTID).
46             add(adminRole_ ,new Button("#{UIListSessionLog.button.view}", VIEW_PARAMS)))) ;
47     add(new Row().
48         add(new ComponentCell(this, uiPageIterator_).
49             addColspan("9").addStyle("text-align: right")));
50     addActionListener(ViewActionListener.class, VIEW_ACTION) ;
51     update(new Query()) ;
52   }
53
54   public void update(Query query) throws Exception JavaDoc {
55     uiPageIterator_.setPageList(service_.getSessionLogDatas(query)) ;
56   }
57   
58   static public class SessionLogDataHandler extends PageListDataHandler {
59     private SessionLogDataDescription data_ ;
60     
61     public String JavaDoc getData(String JavaDoc fieldName) {
62       if(OBJECTID.equals(fieldName)) return data_.getId() ;
63       if("sessionOwner".equals(fieldName)) return data_.getSessionOwner() ;
64       if("remoteUser".equals(fieldName)) return data_.getRemoteUser() ;
65       if("ipAddress".equals(fieldName)) return data_.getIPAddress() ;
66       if("clientType".equals(fieldName)) return data_.getClientName() ;
67       if("accessTime".equals(fieldName)) return ft_.format(data_.getAccessTime()) ;
68       if("requests".equals(fieldName)) return Integer.toString(data_.getActionCount());
69       if("duration".equals(fieldName)) return Integer.toString(data_.getDuration());
70       if("errorCount".equals(fieldName)) return Integer.toString(data_.getErrorCount());
71         return "" ;
72     }
73     
74     public void setCurrentObject(Object JavaDoc o) { data_ = (SessionLogDataDescription) o; }
75   }
76   
77   static public class ViewActionListener extends ExoActionListener {
78     public void execute(ExoActionEvent event) throws Exception JavaDoc {
79       UIListSessionLog uiLog = (UIListSessionLog) event.getSource() ;
80       String JavaDoc objectId = event.getParameter(OBJECTID) ;
81       SessionLogData data = uiLog.service_.getSessionLogData(objectId) ;
82       UIActionHistory uiHistory = (UIActionHistory) uiLog.getSibling(UIActionHistory.class) ;
83       uiHistory.setActionHistory(UIListSessionLog.class, data.getActionHistory()) ;
84       uiLog.setRenderedSibling(UIActionHistory.class );
85     }
86   }
87 }
Popular Tags