KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > jsp > tags > BodyTag


1 package org.apache.turbine.services.jsp.tags;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.PageContext JavaDoc;
21 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
22
23 /**
24  * Supporting class for the body tag.
25  * Tags that surround the screen content that will replace the
26  * <x:screen section="body" /> tag in a layout template.
27  * An optional attributes parameter can be used to set the value
28  * of the <x:bodyAttributes />, which can also be in the
29  * layout.
30  * Example usage:
31  * <x:body attributes='onLoad="jsfunc()"'>
32  * some html content
33  * </x:body>
34  *
35  * @author <a HREF="mailto:john.mcnally@clearink.com">John D. McNally</a>
36  * @version $Id: BodyTag.java,v 1.1.2.2 2004/05/20 03:03:07 seade Exp $
37  */

38 public class BodyTag extends TagSupport JavaDoc
39 {
40     static final String JavaDoc ATTRIBUTES = "_body_tag_attributes_";
41     
42     /**
43      * attributes parameter can be used to add screen specific attribute values
44      * to the &lt;body&gt; tag.
45      */

46     private String JavaDoc attributes;
47
48     /**
49      * The setter for body tag attributes relevant to the screen containing
50      * this tag.
51      */

52     public void setAttributes(String JavaDoc attributes)
53     {
54         pageContext.setAttribute(ATTRIBUTES, attributes,
55             PageContext.REQUEST_SCOPE);
56         this.attributes = attributes;
57     }
58     
59     /**
60      * Method called when the tag is encountered. If the layout is in
61      * the body section, the contents between the body tags are executed.
62      * Otherwise they are skipped.
63      *
64      * @return EVAL_BODY_INCLUDE, if the section has been set to body
65      * or SKIP_BODY, if this section is not active.
66      */

67     public int doStartTag() throws JspException JavaDoc
68     {
69         boolean isActive = ScreenTag.BODY.equals(
70             pageContext.getAttribute(ScreenTag.SECTION_KEY,
71                 PageContext.REQUEST_SCOPE) );
72         if (isActive)
73         {
74              return EVAL_BODY_INCLUDE;
75         }
76         return SKIP_BODY;
77     }
78     
79     /**
80      * Method called when the end tag is encountered; it does nothing.
81      *
82      * @return EVAL_PAGE
83      */

84     public int doEndTag() throws JspException JavaDoc
85     {
86         return EVAL_PAGE;
87     }
88 }
89
Popular Tags