View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/IsWebEventTag.java,v 1.4 2006/02/17 16:04:18 hkollmann Exp $
3    * $Revision: 1.4 $
4    * $Date: 2006/02/17 16:04:18 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.taglib;
25  
26  import java.util.StringTokenizer;
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  
31  import org.dbforms.event.AbstractWebEvent;
32  
33  import org.dbforms.util.Util;
34  
35  import javax.servlet.jsp.JspException;
36  
37  
38  
39  /***
40   * DOCUMENT ME!
41   *
42   * @author $author$
43   * @version $Revision: 1.4 $
44   */
45  public class IsWebEventTag extends AbstractDbBaseHandlerTag
46     implements javax.servlet.jsp.tagext.TryCatchFinally {
47     // logging category for this class
48     private static Log logCat = LogFactory.getLog(IsWebEventTag.class.getName());
49     private String     event;
50     private String     value;
51  
52     /***
53      * Creates a new IsWebEvent object.
54      */
55     public IsWebEventTag() {
56        value = "true";
57        event = null;
58     }
59  
60     /***
61      * DOCUMENT ME!
62      *
63      * @param str DOCUMENT ME!
64      */
65     public final void setEvent(String str) {
66        event = str;
67     }
68  
69  
70     /***
71      * DOCUMENT ME!
72      *
73      * @param string
74      */
75     public void setValue(String string) {
76        value = string;
77     }
78  
79  
80     /***
81      * DOCUMENT ME!
82      *
83      * @return
84      */
85     public String getValue() {
86        return value;
87     }
88  
89     /***
90      * DOCUMENT ME!
91      */
92     public void doFinally() {
93        value = "true";
94        event = null;
95        super.doFinally();
96     }
97  
98  
99     /***
100     * DOCUMENT ME!
101     *
102     * @return DOCUMENT ME!
103     *
104     * @throws JspException DOCUMENT ME!
105     */
106    public int doStartTag() throws JspException {
107       AbstractWebEvent we = getParentForm()
108                        .getWebEvent();
109 
110       if ((we == null) || (event == null) || (value == null)) {
111          logCat.debug("Can't do IsWebEvent with  webEvent: " + we + "  event: "
112                       + event + "   value: " + value);
113 
114          return SKIP_BODY;
115       }
116 
117       String  className = we.getType();
118       
119       /*
120        * Philip Grunikiewicz
121        * 2006-01-27
122        * 
123        * Events can be concatenated together to form a logical OR
124        */
125       boolean eventNameMatch = false;
126       StringTokenizer st = new StringTokenizer(event, ",");
127       while (st.hasMoreTokens()) {
128     	  
129     	  String anEvent = st.nextToken().trim();
130     	  eventNameMatch = className.toUpperCase().indexOf(anEvent.toUpperCase()) != -1;
131     	  if (eventNameMatch == true) break;
132       }
133 
134       if (logCat.isDebugEnabled()) {
135          logCat.debug(" IsLocalWebEvent webEvent className: " + className
136                       + "    event: " + event + "  value: " + value);
137       }
138 
139       return (Util.getTrue(value) == eventNameMatch) ? EVAL_BODY_INCLUDE
140                                                      : SKIP_BODY;
141    }
142 }