KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > servlet > jsp > taglib > IfTag


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.servlet.jsp.taglib;
10
11 import java.util.Iterator JavaDoc;
12 import java.util.LinkedList JavaDoc;
13
14 import javax.servlet.jsp.JspException JavaDoc;
15 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
16
17 import org.jboss.portal.common.context.Context;
18 import org.jboss.portal.common.context.NamedContext;
19 import org.jboss.portal.core.servlet.jsp.PortalJsp;
20
21 /**
22  * Include a piece of code or not according to a condition
23  * @author <a HREF="theute@jboss.org">Thomas Heute</a>
24  * $Revision: 1.2 $
25  */

26 public class IfTag
27       extends TagSupport JavaDoc
28 {
29    /**
30     * Context of the section
31     */

32    private String JavaDoc ctx;
33
34    private Iterator JavaDoc children;
35    
36    private LinkedList JavaDoc contextStack;
37    
38    private boolean include = false;
39    
40    /**
41     * @param ctx The ctx to set.
42     */

43    public void setCtx(String JavaDoc ctx)
44    {
45       this.ctx = ctx;
46    }
47
48    
49    public int doStartTag() throws JspException JavaDoc
50    {
51       contextStack = (LinkedList JavaDoc)PortalJsp.contextStack.get();
52       
53       // If no context has been set
54
if (contextStack.isEmpty()) {
55          include = false;
56          PortalJsp.log.debug("No context has been found");
57          return SKIP_BODY;
58       }
59       
60       Context currentContext = ((NamedContext)contextStack.getLast()).getContext();
61       children = currentContext.childIterator(ctx);
62       
63       if (children.hasNext())
64       {
65          include = true;
66          contextStack.addLast(new NamedContext(ctx, (Context)children.next()));
67          return EVAL_PAGE;
68       } else {
69          include = false;
70          return SKIP_BODY;
71       }
72    }
73    
74    public int doEndTag() {
75       if (include) {
76          contextStack.removeLast();
77       }
78       return SKIP_BODY;
79    }
80
81    
82    /*
83    private String isTrue;
84    private String isFalse;
85    
86    
87    public int doStartTag() throws JspException {
88       ServletRequest servletRequest = pageContext.getRequest();
89       try {
90         System.out.println("Hello:" + isTrue);
91         PortletRequest portletRequest = (PortletRequest)servletRequest.getAttribute("javax.portlet.request");
92         Enumeration enum2 = portletRequest.getPreferences().getNames();
93         System.out.println("<<<<<< PorletPreferences");
94         while (enum2.hasMoreElements()) {
95            System.out.println(enum2.nextElement());
96         }
97         System.out.println(">>>>>> PorletPreferences");
98         
99         
100       } catch (Exception ex) {
101         throw new JspTagException("SimpleTag: " +
102           ex.getMessage());
103       }
104       return SKIP_BODY;
105     }
106    
107     public int doEndTag() {
108       return EVAL_PAGE;
109     }
110     
111    public void setIsFalse(String isFalse)
112    {
113       this.isFalse = isFalse;
114    }
115
116       public void setIsTrue(String isTrue)
117    {
118       this.isTrue = isTrue;
119    }
120    */

121 }
122
Popular Tags