KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > tool > TemplatePageAttributes


1 package org.apache.turbine.tool;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" and
29  * "Apache Turbine" must not be used to endorse or promote products
30  * derived from this software without prior written permission. For
31  * written permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * "Apache Turbine", nor may "Apache" appear in their name, without
35  * prior written permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 import org.apache.turbine.RunData;
58 import org.apache.turbine.services.pull.ApplicationTool;
59
60 /**
61  * Template context tool that will set various attributes of the HTML
62  * page. It is automatically placed in the Template context as
63  * '$page'. Here's an example of some uses:
64  *
65  * <p>
66  * $page.setBgColor("#ffffff");
67  * $page.setBgColor("white");
68  * $page.setBackground("/images/standardbg.jpeg");
69  * $page.setTitle("This is the title!");
70  * $page.setKeywords("turbine, cool, servlet framework");
71  * $page.setStyleSheet("/style.css");
72  *
73  * This should become a general attribute storage class
74  * for a page. We should have something general like:
75  *
76  * $page.setAttr("bgcolor", "#ffffff")
77  *
78  * Instead of set methods for HTML because we might want
79  * to set attributes for WML output or anything else.
80  *
81  * @author <a HREF="mailto:sean@somacity.com">Sean Legassick</a>
82  * @version $Id: TemplatePageAttributes.java,v 1.1 2002/06/01 22:05:28 jvanzyl Exp $
83  */

84 public class TemplatePageAttributes
85     implements ApplicationTool
86 {
87     /** The RunData object. */
88     private RunData data = null;
89
90     /** The title. */
91     private String JavaDoc title = null;
92     private String JavaDoc bgColor = null;
93
94     /**
95      * Default constructor. The init method must be called before use
96      */

97     public TemplatePageAttributes()
98     {
99     }
100
101     /**
102      * Construct a new instance with the given RunData object.
103      *
104      * @param data a RunData instance
105      */

106     public TemplatePageAttributes(RunData data)
107     {
108         this.data = data;
109     }
110
111     /**
112      * Initialise this instance with the given RunData object.
113      * (ApplicationTool method)
114      *
115      * @param data Assumed to be a RunData instance
116      */

117     public void init(Object JavaDoc data)
118     {
119         // we blithely cast to RunData as the runtime error thrown
120
// if data is null or not RunData is appropriate.
121
data = (RunData)data;
122
123         // clear cached title
124
title = null;
125         bgColor = null;
126     }
127
128     /**
129      * Refresh method - does nothing
130      */

131     public void refresh()
132     {
133         // empty
134
}
135
136     /**
137      * Set the title in the page. This returns an empty String so
138      * that the template doesn't complain about getting a null return
139      * value.
140      *
141      * @param title A String with the title.
142      */

143     public TemplatePageAttributes setTitle(String JavaDoc title)
144     {
145         this.title = title;
146         return this;
147     }
148
149     /**
150      * Get the title in the page. This returns an empty String if
151      * empty so that the template doesn't complain about getting a null
152      * return value.
153      *
154      * @return A String with the title.
155      */

156     public String JavaDoc getTitle()
157     {
158         return title;
159     }
160
161     /**
162      * Set the background color for the BODY tag. You can use either
163      * color names or color values (e.g. "white" or "#ffffff" or
164      * "ffffff").
165      *
166      * @param bgColor the background color.
167      * @return A TemplatePageAttributes (self).
168      */

169     public TemplatePageAttributes setBgColor(String JavaDoc bgColor)
170     {
171         this.bgColor = bgColor;
172         return this;
173     }
174
175     public String JavaDoc getBgColor()
176     {
177         return bgColor;
178     }
179
180     /**
181      * A dummy toString method that returns an empty string.
182      *
183      * @return An empty String ("").
184      */

185     public String JavaDoc toString()
186     {
187         return "";
188     }
189 }
190
Popular Tags