KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.PageContext JavaDoc;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 /**
25  * Supporting class for the bodyAttributes tag.
26  * Sends the contents of the a screen's body tag's attributes
27  * parameter to the output stream. If the screen did not set
28  * the attributes parameter, a default may be used if specified
29  * in this tag. Example usage:
30  * <body <x:bodyAttributes default='onLoad="jsfunc()"' />>
31  *
32  * @author <a HREF="mailto:john.mcnally@clearink.com">John D. McNally</a>
33  * @version $Id: BodyAttributesTag.java,v 1.1.2.2 2004/05/20 03:03:07 seade Exp $
34  */

35 public class BodyAttributesTag extends TagSupport JavaDoc
36 {
37     /**
38      * The default body tag attributes, if none is specified in the screen.
39      */

40     private String JavaDoc def;
41     
42     /**
43      * The setter for the default body tag attributes.
44      */

45     public void setDefault(String JavaDoc def)
46     {
47         this.def = def;
48     }
49     
50     /**
51      * Method called when the tag is encountered to send attributes to the
52      * output stream
53      *
54      * @return SKIP_BODY, as it is intended to be a single tag.
55      */

56     public int doStartTag() throws JspException JavaDoc
57     {
58         String JavaDoc bodyAttributes = (String JavaDoc)pageContext
59             .getAttribute(BodyTag.ATTRIBUTES, PageContext.REQUEST_SCOPE);
60         try
61         {
62             if (bodyAttributes != null)
63             {
64                 pageContext.getOut().print(bodyAttributes);
65             }
66             else
67             {
68                 pageContext.getOut().print(def);
69             }
70         }
71         catch(java.io.IOException JavaDoc ex)
72         {
73             throw new JspException JavaDoc(ex.getMessage());
74         }
75         return SKIP_BODY;
76     }
77 }
78
Popular Tags