KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > jwi > jgallery > tags > ElseTag


1 package de.jwi.jgallery.tags;
2
3 /*
4  * jGallery - Java web application to display image galleries
5  *
6  * Copyright (C) 2004 Juergen Weber
7  *
8  * This file is part of jGallery.
9  *
10  * jGallery is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * jGallery is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with jGallery; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston
23  */

24
25
26 import java.util.EmptyStackException JavaDoc;
27 import java.util.Stack JavaDoc;
28
29 import javax.servlet.ServletRequest JavaDoc;
30 import javax.servlet.jsp.JspException JavaDoc;
31 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
32
33 /**
34  * @author Juergen Weber
35  * Source file created on 18.02.2004
36  *
37  */

38 public class ElseTag extends BodyTagSupport JavaDoc
39 {
40
41     private boolean popResult()
42     throws JspException JavaDoc
43     {
44         Boolean JavaDoc b;
45
46         ServletRequest JavaDoc request = pageContext.getRequest();
47         Stack JavaDoc stack = (Stack JavaDoc) request.getAttribute("ifThenStack");
48         if (null != stack)
49         {
50             try
51             {
52                 b = (Boolean JavaDoc) stack.pop();
53             }
54             catch (EmptyStackException JavaDoc e)
55             {
56                 throw new JspException JavaDoc("EmptyStackException: Else Tag without If");
57             }
58         }
59         else
60         {
61             throw new JspException JavaDoc("Else Tag without If");
62         }
63         return b.booleanValue();
64     }
65
66     public int doStartTag() throws JspException JavaDoc
67     {
68         boolean lastResult = popResult();
69         if (lastResult)
70         {
71             return SKIP_BODY;
72         }
73         else
74         {
75             return EVAL_BODY_INCLUDE;
76         }
77     }
78 }
79
Popular Tags