KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > tags > LastVisitTag


1 /*
2  * $$Id$$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 11.06.2003
27  *
28  */

29 package org.jresearch.gossip.tags;
30
31 import java.util.Date JavaDoc;
32 import java.util.HashMap JavaDoc;
33
34 import javax.servlet.jsp.JspException JavaDoc;
35 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
36
37 import org.apache.log.Logger;
38 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
39 import org.jresearch.gossip.IConst;
40 import org.jresearch.gossip.beans.user.User;
41 import org.jresearch.gossip.exception.SystemException;
42 import org.jresearch.gossip.log.avalon.JGossipLog;
43
44 /**
45  * DOCUMENT ME!
46  *
47  * @author Bel
48  */

49 public class LastVisitTag extends TagSupport JavaDoc {
50
51     /**
52      * Logger instance.
53      */

54     private Logger log;
55
56     private String JavaDoc intime;
57
58     private Date JavaDoc inTime;
59
60     private String JavaDoc tid;
61
62     private String JavaDoc sender;
63
64     /**
65      * Default c'tor.
66      */

67     public LastVisitTag() {
68         super();
69         try {
70             log = JGossipLog.getInstance().getAppLogger();
71         } catch (SystemException e) { /* Ignore Exception! */
72         }
73     }
74
75     /**
76      * DOCUMENT ME!
77      *
78      * @throws JspException
79      * DOCUMENT ME!
80      */

81     private void eval() throws JspException JavaDoc {
82         inTime = (Date JavaDoc) ExpressionEvaluatorManager.evaluate("intime", intime,
83                 Date JavaDoc.class, this, pageContext);
84
85         sender = (String JavaDoc) ExpressionEvaluatorManager.evaluate("sender", sender,
86                 String JavaDoc.class, this, pageContext);
87
88         tid = ExpressionEvaluatorManager.evaluate("tid", tid, Integer JavaDoc.class,
89                 this, pageContext).toString();
90     }
91
92     /**
93      * DOCUMENT ME!
94      *
95      * @return DOCUMENT ME!
96      *
97      * @throws JspException
98      * DOCUMENT ME!
99      */

100     public int doStartTag() throws JspException JavaDoc {
101         eval();
102
103         try {
104             User user = (User) pageContext.getSession().getAttribute(
105                     IConst.SESSION.USER_KEY);
106
107             Date JavaDoc lastvisit = null;
108             HashMap JavaDoc visited = (HashMap JavaDoc) pageContext.getSession().getAttribute(
109                     IConst.SESSION.LAST_INTIME);
110
111             if ((!visited.isEmpty()) && visited.containsKey(tid)) {
112                 lastvisit = (Date JavaDoc) visited.get(tid);
113             } else {
114                 lastvisit = user.getIntime();
115             }
116
117             String JavaDoc username = (user.getName() != null) ? user.getName() : " ";
118
119             if (lastvisit.before(getIntime()) && (!username.equals(sender))) {
120                 pageContext.setAttribute(IConst.PAGE.HAVE_AN_UPDATED_TOPICS,
121                         IConst.VALUES.TRUE);
122
123                 return super.EVAL_BODY_INCLUDE;
124             }
125         } catch (Exception JavaDoc ex) {
126             if (log.isErrorEnabled()) {
127                 log.error("LastVisitTag::", ex);
128             }
129             throw new JspException JavaDoc("error in LastVisitTag tag:", ex);
130         }
131
132         return (SKIP_BODY);
133     }
134
135     /**
136      * DOCUMENT ME!
137      *
138      * @return
139      */

140     private Date JavaDoc getIntime() {
141         return inTime;
142     }
143
144     /**
145      * DOCUMENT ME!
146      *
147      * @return
148      */

149     public String JavaDoc getSender() {
150         return sender;
151     }
152
153     /**
154      * DOCUMENT ME!
155      *
156      * @return
157      */

158     public String JavaDoc getTid() {
159         return tid;
160     }
161
162     /**
163      * DOCUMENT ME!
164      *
165      * @param string
166      */

167     public void setIntime(String JavaDoc string) {
168         intime = string;
169     }
170
171     /**
172      * DOCUMENT ME!
173      *
174      * @param string
175      */

176     public void setSender(String JavaDoc string) {
177         sender = string;
178     }
179
180     /**
181      * DOCUMENT ME!
182      *
183      * @param string
184      */

185     public void setTid(String JavaDoc string) {
186         tid = string;
187     }
188 }
189
Popular Tags