KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jag > taglib > ExistTag


1 /* Copyright (C) 2003 Finalist IT Group
2  *
3  * This file is part of JAG - the Java J2EE Application Generator
4  *
5  * JAG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * JAG is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with JAG; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */

17
18 package com.finalist.jag.taglib;
19
20 import com.finalist.jag.*;
21 import com.finalist.jag.taglib.util.RequestUtil;
22
23
24 /**
25  * Class ExistTag
26  *
27  *
28  * @author Wendel D. de Witte
29  * @version %I%, %G%
30  */

31 public class ExistTag extends TagBodySupport {
32
33    /** Field name */
34    private String JavaDoc name = null;
35
36    /** Field property */
37    private String JavaDoc property = null;
38
39    /** Field equal */
40    protected boolean exist = false;
41
42    /** Field sensitive */
43    protected int counter = 0;
44
45    /////////////////////////////////////
46

47    /**
48     * Method getName
49     *
50     *
51     * @return
52     *
53     */

54    public String JavaDoc getName() {
55       return (this.name);
56    }
57
58    /**
59     * Method setName
60     *
61     *
62     * @param name
63     *
64     */

65    public void setName(String JavaDoc name) {
66       this.name = name;
67    }
68
69    /**
70     * Method getValue
71     *
72     *
73     * @return
74     *
75     */

76    public String JavaDoc getProperty() {
77       return (this.property);
78    }
79
80    /**
81     * Method setValue
82     *
83     *
84     * @param property
85     *
86     */

87    public void setProperty(String JavaDoc property) {
88       this.property = property;
89    }
90
91    /**
92     * Method doStartTag
93     *
94     *
95     * @return
96     *
97     * @throws JagException
98     *
99     */

100    public int doStartTag() throws JagException {
101       exist = !(RequestUtil.lookupString(getPageContext(), name, property) == null &&
102             getPageContext().getAttribute(name) == null); //also check for 'variables' as context attributes
103

104       return (EVAL_PAGE);
105    }
106
107    /**
108     * Method exist
109     *
110     *
111     * @return
112     *
113     */

114    protected boolean exist() {
115       return (exist && (counter++ < 1));
116    }
117
118    /**
119     * Method doAfterBodyTag
120     *
121     *
122     * @return
123     *
124     * @throws JagException
125     *
126     */

127    public int doAfterBodyTag() throws JagException {
128
129       return exist()
130             ? (EVAL_BODY_TAG)
131             : (SKIP_BODY);
132    }
133 }
134
135
Popular Tags