KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > menu > context > ItemPartSupport


1 package com.blandware.atleap.webapp.taglib.core.menu.context;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.JspTagException JavaDoc;
5 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
6 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
7 import java.io.IOException JavaDoc;
8 import java.io.StringWriter JavaDoc;
9
10 /**
11  * <p>This class implements all common functionality of ItemPart. It renders
12  * its body if and only if <b>enabled</b> matches <code>enabled</code> attribute
13  * of parent <em>item</em> tag.
14  * </p>
15  * <p>
16  * Note: tag body may be rendered twice: first time for including in context
17  * menu, second time for including in page (of needed).
18  * </p>
19  * <p><a HREF="ItemPartSupport.java.htm"><i>View Source</i></a></p>
20  *
21  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
22  * @version $Revision: 1.3 $ $Date: 2005/09/21 13:46:05 $
23  */

24 public class ItemPartSupport extends SimpleTagSupport JavaDoc implements ItemPart {
25
26     /**
27      * Internal flag to decide, where to render body content
28      */

29     protected int renderingFlag = FLAG_RENDER_TO_PAGE;
30
31     /**
32      * Internal flag initialized by tags which extend this one. Used to
33      * determine, whether or not to process body content
34      */

35     protected boolean enabled = false;
36
37     /**
38      * Creates new instance of ItemPartSupport
39      */

40     public ItemPartSupport() {
41     }
42
43     /**
44      * @see ItemPart#getRenderingFlag()
45      */

46     public int getRenderingFlag() {
47         return renderingFlag;
48     }
49
50     /**
51      * Performs tag logic
52      *
53      * @throws javax.servlet.jsp.JspException
54      * @throws java.io.IOException
55      */

56     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
57
58         // search for parent item tag
59
ItemTag parentItemTag = (ItemTag) findAncestorWithClass(this, ItemTag.class);
60         if ( parentItemTag == null ) {
61             throw new JspTagException JavaDoc("This tag is only valid when nested within 'item' tag");
62         }
63
64         if ( parentItemTag.getEnabled().booleanValue() == enabled ) {
65             JspFragment JavaDoc body = getJspBody();
66             if ( body != null ) {
67                 if ( parentItemTag.getIncludeInContextMenu().booleanValue() ) {
68                     renderingFlag = FLAG_RENDER_TO_MENU;
69                     StringWriter JavaDoc sw = new StringWriter JavaDoc();
70                     body.invoke(sw);
71                     parentItemTag.getItem().setContent(sw.toString().trim());
72                 }
73
74                 if ( parentItemTag.getIncludeInPage().booleanValue() ) {
75                     renderingFlag = FLAG_RENDER_TO_PAGE;
76                     body.invoke(null);
77                 }
78             }
79         }
80     }
81 }
82
Popular Tags