KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > loginterface > LogEntryView


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.web.admin.loginterface;
15
16 import java.util.Date JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.text.DateFormat JavaDoc;
19 import java.rmi.RemoteException JavaDoc;
20
21 import org.ejbca.core.model.log.Admin;
22 import org.ejbca.core.model.log.LogEntry;
23 import org.ejbca.ui.web.admin.rainterface.SortBy;
24 import org.ejbca.util.dn.DNFieldExtractor;
25
26 /**
27  * A class used as a help class for displaying LogEntries.
28  *
29  * @author TomSelleck
30  * @version $Id: LogEntryView.java,v 1.3 2006/12/02 11:17:58 anatom Exp $
31  */

32 public class LogEntryView implements java.io.Serializable JavaDoc, Cloneable JavaDoc, Comparable JavaDoc {
33     // Public constants.
34
public static final int TIME = 0;
35     public static final int ADMINTYPE = 1;
36     public static final int ADMINDATA = 2;
37     public static final int ADMINCERTSERNO = 3;
38     public static final int CA = 4;
39     public static final int MODULE = 5;
40     public static final int USERNAME = 6;
41     public static final int CERTIFICATE = 7;
42     public static final int CERTIFICATESERNO = 8;
43     public static final int EVENT = 9;
44     public static final int COMMENT = 10;
45     public static final int VERIFY = 11;
46    
47     public static final String JavaDoc TRUE = "T";
48     public static final String JavaDoc FALSE = "F";
49     
50     public static final int NUMBEROF_FIELDS=12;
51
52     
53     /** Creates a new instance of UserView */
54     public LogEntryView(SubjectDNProxy dnproxy) {
55       logentrydata = new String JavaDoc[NUMBEROF_FIELDS];
56       for(int i=0; i< NUMBEROF_FIELDS ; i++){
57         logentrydata[i] = "";
58       }
59       this.dnproxy = dnproxy;
60     }
61     
62     public LogEntryView(LogEntry logentry, SubjectDNProxy dnproxy, String JavaDoc[] localinfoeventnames, String JavaDoc[] localerroreventnames, String JavaDoc[] localmodulenames, HashMap JavaDoc caidtonamemap) throws RemoteException JavaDoc{
63       logentrydata = new String JavaDoc[NUMBEROF_FIELDS];
64       for(int i=0; i< NUMBEROF_FIELDS ; i++){
65         logentrydata[i] = "";
66       }
67       this.dnproxy = dnproxy;
68       setValues(logentry,localinfoeventnames,localerroreventnames, localmodulenames, caidtonamemap);
69     }
70     
71    
72     // Public methods.
73
/** Method that returns the specific logentry pointed by the parameter. */
74     public String JavaDoc getValue(int parameter){
75       return logentrydata[parameter];
76     }
77
78     /** Method that returns the specific logentry pointed by the parameter. */
79     public void setValue(int parameter, String JavaDoc value){
80       logentrydata[parameter]=value;
81     }
82     
83     /** Method that returns the logentrydata as a String array */
84     public String JavaDoc[] getValues(){
85       return logentrydata;
86     }
87        
88     /* Sets the values according to the values in the LogEntry object.*/
89     public void setValues(LogEntry logentry, String JavaDoc[] localinfoeventnames, String JavaDoc[] localerroreventnames,String JavaDoc[] localmodulenames, HashMap JavaDoc caidtonamemap) throws RemoteException JavaDoc{
90         
91        logentrydata[TIME] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(logentry.getTime());
92        this.time = logentry.getTime();
93       
94        logentrydata[ADMINTYPE] = Integer.toString(logentry.getAdminType());
95        if(logentry.getAdminType() == Admin.TYPE_CLIENTCERT_USER){
96           String JavaDoc dnstring = dnproxy.getSubjectDN(logentry.getAdminData());
97           if(dnstring !=null){
98             DNFieldExtractor dn = new DNFieldExtractor(dnstring, DNFieldExtractor.TYPE_SUBJECTDN);
99             logentrydata[ADMINCERTSERNO] = logentry.getAdminData();
100             logentrydata[ADMINDATA] = dn.getField(DNFieldExtractor.CN,0) + ", " + dn.getField(DNFieldExtractor.O,0);
101           }
102        }else{
103           if(logentry.getAdminType() == Admin.TYPE_PUBLIC_WEB_USER){
104             if(logentry.getAdminData() != null)
105               logentrydata[ADMINDATA] = "IP : " + logentry.getAdminData();
106             if(logentrydata[ADMINDATA] == null)
107              logentrydata[ADMINDATA] = "";
108           }else{
109             if(logentry.getAdminData() != null)
110               logentrydata[ADMINDATA] = logentry.getAdminData();
111             if(logentrydata[ADMINDATA] == null)
112              logentrydata[ADMINDATA] = "";
113           }
114        }
115        
116               
117        logentrydata[CA] = (String JavaDoc) caidtonamemap.get(new Integer JavaDoc(logentry.getCAId()));
118        
119        logentrydata[MODULE] = localmodulenames[logentry.getModule()];
120          
121        logentrydata[USERNAME] = logentry.getUsername();
122        if(logentrydata[USERNAME] != null && logentrydata[USERNAME].trim().equals(""))
123          logentrydata[USERNAME] = null;
124
125        logentrydata[CERTIFICATESERNO] = logentry.getCertificateSNR();
126        if(logentry.getCertificateSNR() != null)
127          if(logentry.getCertificateSNR().trim().equals(""))
128             logentrydata[CERTIFICATESERNO] = null;
129          else
130             logentrydata[CERTIFICATESERNO] = logentry.getCertificateSNR();
131          
132        if(logentrydata[CERTIFICATESERNO] != null){
133           String JavaDoc dnstring = dnproxy.getSubjectDN(logentry.getCertificateSNR());
134           if(dnstring != null){
135             DNFieldExtractor dn = new DNFieldExtractor(dnstring, DNFieldExtractor.TYPE_SUBJECTDN);
136             logentrydata[CERTIFICATE] = dn.getField(DNFieldExtractor.CN,0) + ", " + dn.getField(DNFieldExtractor.O,0);
137           }
138        }
139        
140        if(logentry.getEvent() < LogEntry.EVENT_ERROR_BOUNDRARY)
141          logentrydata[EVENT] = localinfoeventnames[logentry.getEvent()];
142        else
143          logentrydata[EVENT] = localerroreventnames[logentry.getEvent() - LogEntry.EVENT_ERROR_BOUNDRARY];
144        
145        logentrydata[COMMENT] = logentry.getComment();
146        logentrydata[VERIFY] = logentry.getVerifyResult();
147     }
148           
149     public int compareTo(Object JavaDoc obj) {
150       int returnvalue = -1;
151       int sortby = this.sortby.getSortBy();
152       switch(sortby){
153           case SortBy.USERNAME :
154             returnvalue = logentrydata[USERNAME].compareTo(((LogEntryView) obj).getValue(USERNAME));
155             break;
156           case SortBy.ADMINTYPE :
157             returnvalue = logentrydata[ADMINTYPE].compareTo(((LogEntryView) obj).getValue(ADMINTYPE));
158             break;
159           case SortBy.ADMINDATA :
160             returnvalue = logentrydata[ADMINDATA].compareTo(((LogEntryView) obj).getValue(ADMINDATA));
161             break;
162           case SortBy.CA :
163             returnvalue = logentrydata[CA].compareTo(((LogEntryView) obj).getValue(CA));
164             break;
165           case SortBy.MODULE :
166             returnvalue = logentrydata[MODULE].compareTo(((LogEntryView) obj).getValue(MODULE));
167             break;
168           case SortBy.CERTIFICATE :
169             returnvalue = logentrydata[CERTIFICATE].compareTo(((LogEntryView) obj).getValue(CERTIFICATE));
170             break;
171           case SortBy.EVENT :
172             returnvalue = logentrydata[EVENT].compareTo(((LogEntryView) obj).getValue(EVENT));
173             break;
174           case SortBy.COMMENT :
175             returnvalue = logentrydata[COMMENT].compareTo(((LogEntryView) obj).getValue(COMMENT));
176             break;
177           case SortBy.TIME :
178             returnvalue = time.compareTo(((LogEntryView) obj).getTime());
179             break;
180           default:
181             returnvalue = time.compareTo(((LogEntryView) obj).getTime());
182       }
183       if(this.sortby.getSortOrder() == SortBy.DECENDING)
184         returnvalue = 0-returnvalue;
185           
186       return returnvalue;
187     }
188     
189     public void setSortBy(SortBy sortby){
190       this.sortby=sortby;
191     }
192     
193     public Date JavaDoc getTime(){return time;}
194     
195     // Private constants.
196

197     // Private methods.
198
private String JavaDoc[] logentrydata;
199     private SortBy sortby;
200     private Date JavaDoc time;
201     private SubjectDNProxy dnproxy;
202 }
203
Popular Tags