KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > BodyLayoutTagSupport


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.PageContext JavaDoc;
5 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
6
7 import fr.improve.struts.taglib.layout.util.ParentFinder;
8
9 /**
10  * Ancestor class for all body layout tag.
11  * This class automatically register the tag in a tag stack to avoid the problem of findinf parent tag with dynamic include.
12  * It also provides method to initialize dynamically computed values.
13  *
14  * @author JN Ribette
15  */

16 public class BodyLayoutTagSupport extends BodyTagSupport JavaDoc implements LayoutTag {
17     
18     /**
19      * Return the tag pageContext.
20      */

21     public final PageContext JavaDoc getPageContext() {
22         return pageContext;
23     }
24   
25     /**
26      * Start the tag :
27      * <ul>
28      * <li>register the tag (call registerTag)</li>
29      * <li>initialize dynamic values (call initDynamicValues). This is the place to compute EL values.</li>
30      * <li>handle tag start (call doStartLayoutTag)</li>
31      * </ul>
32      */

33     public final int doStartTag() throws JspException JavaDoc {
34         registerTag();
35         initDynamicValues();
36         return doStartLayoutTag();
37     }
38   
39     /**
40      * end the tag:
41      * <ul>
42      * <li>handle tag end (call doEndLayoutTag)</li>
43      * <li>reset initial values (call reset). Due to tag pooling, values fixed by the jsp that have been changed by the code
44      * must be restored to their initial values.</li>
45      * <li>deregister the tag (call desreigsterTag)</li>
46      * </ul>
47      */

48   public final int doEndTag() throws JspException JavaDoc {
49     try {
50       return doEndLayoutTag();
51     } finally {
52       reset();
53       deregisterTag();
54     }
55   }
56   
57   public int doStartLayoutTag() throws JspException JavaDoc {
58     return super.doStartTag();
59   }
60   public int doEndLayoutTag() throws JspException JavaDoc {
61     return super.doEndTag();
62   }
63   
64   protected void initDynamicValues() throws JspException JavaDoc {
65     // Do nothing.
66
}
67   
68   protected void reset() {
69     // do nothing, to be override.
70
}
71   
72   /**
73    * Register this tag in the layout tag stack.
74    * Even if this is a bad idea, overriding this method allow to insert a tag betwwen this tag and its parent.
75    */

76   protected void registerTag() throws JspException JavaDoc {
77     ParentFinder.registerTag(pageContext, this);
78   }
79   
80   /**
81    * Deregister this tag in the layout tag stack.
82    * Even if this is a bad idea, overriding this method allow to insert a tag betwwen this tag and its parent.
83    */

84   protected void deregisterTag() throws JspException JavaDoc {
85     ParentFinder.deregisterTag(pageContext);
86   }
87
88 }
89
Popular Tags