KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > libtags > HasNoEntriesTag


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.libtags;
7
8 import java.util.HashMap JavaDoc;
9
10 import javax.servlet.http.*;
11 import javax.servlet.jsp.JspException JavaDoc;
12 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
13
14 import com.raptus.owxv3.modules.base.BaseEntryCounter;
15
16 /**
17  * <hr>
18  * <table width="100%" border="0">
19  * <tr>
20  * <td width="24%"><b>Filename</b></td><td width="76%">HasEntriesTag.java</td>
21  * </tr>
22  * <tr>
23  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
24  * </tr>
25  * <tr>
26  * <td width="24%"><b>Date</b></td><td width="76%">14th of January 2003</td>
27  * </tr>
28  * </table>
29  * <hr>
30  * <table width="100%" border="0">
31  * <tr>
32  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
33  * </tr>
34  * </table>
35  * <hr>
36  */

37 public class HasNoEntriesTag extends TagSupport JavaDoc
38 {
39     protected String JavaDoc vmodule;
40     private final String JavaDoc CACHE_SESS_ID="com.raptus.owxv3.HAS_NOENTRIES_CACHE";
41     public void setVmodule(String JavaDoc v)
42     {
43         vmodule=v;
44     }
45     public String JavaDoc getVmodule()
46     {
47         return vmodule;
48     }
49     
50     public int doStartTag() throws JspException JavaDoc
51     {
52         //checking for cached result in session
53
HttpServletRequest req=(HttpServletRequest) pageContext.getRequest();
54         HttpSession session=req.getSession();
55         HashMap JavaDoc cache=(HashMap JavaDoc)session.getAttribute(CACHE_SESS_ID);
56         Boolean JavaDoc b=null;
57         if(cache!=null)
58         {
59             b=(Boolean JavaDoc)cache.get(vmodule);
60         }
61         if(b==null)
62         {
63             //try to obtain count using the DB
64
int count=BaseEntryCounter.countActiveEntriesIn(vmodule);
65             if(count>0)
66             {
67                 b=new Boolean JavaDoc(false);
68             }
69             else
70             {
71                 b=new Boolean JavaDoc(true);
72             }
73         }//end if
74

75         if(cache==null)
76         {
77             cache=new HashMap JavaDoc();
78         }
79         cache.put(vmodule,b);
80         session.setAttribute(CACHE_SESS_ID,cache);
81         
82         if(b.booleanValue()==true)
83         {
84             return (EVAL_BODY_INCLUDE);
85         }
86         else
87         {
88             return (SKIP_BODY);
89         }
90
91     }//end doStartTag
92

93
94     /**
95      * Evaluate the remainder of the current page normally.
96      *
97      * @exception JspException if a JSP exception occurs
98      */

99     public int doEndTag() throws JspException JavaDoc
100     {
101         return (EVAL_PAGE);
102     }
103
104     
105 }//end class
106
Popular Tags