KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > component > HtmlComponent


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

16
17 package org.apache.struts.faces.component;
18
19
20 import javax.faces.component.UIOutput;
21 import javax.faces.context.FacesContext;
22 import javax.faces.el.ValueBinding;
23
24
25 /**
26  * <p>Custom component that replaces the Struts
27  * <code>&lt;html:html&gt;</code> tag.</p>
28  */

29
30 public class HtmlComponent extends UIOutput {
31
32
33     // ------------------------------------------------------------ Constructors
34

35
36     /**
37      * <p>Create a new {@link HtmlComponent} with default properties.</p>
38      */

39     public HtmlComponent() {
40
41         super();
42         setRendererType("org.apache.struts.faces.Html");
43
44     }
45
46
47     // ------------------------------------------------------ Instance Variables
48

49
50     /**
51      * <p>Flag indicating we should create a locale.</p>
52      */

53     private boolean locale = true;
54     private boolean localeSet = false;
55
56
57     /**
58      * <p>Flag indicating we should render XHTML output.</p>
59      */

60     private boolean xhtml = false;
61     private boolean xhtmlSet = false;
62
63
64     // ---------------------------------------------------- Component Properties
65

66
67     /**
68      * <p>Return the component family to which this component belongs.</p>
69      */

70     public String JavaDoc getFamily() {
71
72         return "org.apache.struts.faces.Html";
73
74     }
75
76
77     /**
78      * <p>Return a flag indicating whether a locale should be created.</p>
79      */

80     public boolean isLocale() {
81
82         if (localeSet) {
83             return locale;
84         }
85         ValueBinding vb = getValueBinding("locale");
86         if (vb != null) {
87             Boolean JavaDoc value = (Boolean JavaDoc) vb.getValue(getFacesContext());
88             if (null == value) {
89                 return locale;
90             }
91             return value.booleanValue();
92         } else {
93             return locale;
94         }
95
96     }
97
98
99     /**
100      * <p>Set the flag indicating whether a locale should be created.</p>
101      *
102      * @param locale The new flag
103      */

104     public void setLocale(boolean locale) {
105
106         this.locale = locale;
107         this.localeSet = true;
108
109     }
110
111
112     /**
113      * <p>Return a flag indicating whether xhtml should be created.</p>
114      */

115     public boolean isXhtml() {
116
117         if (xhtmlSet) {
118             return xhtml;
119         }
120         ValueBinding vb = getValueBinding("xhtml");
121         if (vb != null) {
122             Boolean JavaDoc value = (Boolean JavaDoc) vb.getValue(getFacesContext());
123             if (null == value) {
124                 return xhtml;
125             }
126             return value.booleanValue();
127         } else {
128             return xhtml;
129         }
130
131     }
132
133
134     /**
135      * <p>Set the flag indicating whether xhtml should be created.</p>
136      *
137      * @param xhtml The new flag
138      */

139     public void setXhtml(boolean xhtml) {
140
141         this.xhtml = xhtml;
142         this.xhtmlSet = true;
143
144     }
145
146
147     // ---------------------------------------------------- StateManager Methods
148

149
150     /**
151      * <p>Restore the state of this component.</p>
152      *
153      * @param context <code>FacesContext</code> for the current request
154      * @param state State object from which to restore our state
155      */

156     public void restoreState(FacesContext context, Object JavaDoc state) {
157
158         Object JavaDoc values[] = (Object JavaDoc[]) state;
159         super.restoreState(context, values[0]);
160         locale = ((Boolean JavaDoc) values[1]).booleanValue();
161         localeSet = ((Boolean JavaDoc) values[2]).booleanValue();
162         xhtml = ((Boolean JavaDoc) values[3]).booleanValue();
163         xhtmlSet = ((Boolean JavaDoc) values[4]).booleanValue();
164
165     }
166
167
168     /**
169      * <p>Save the state of this component.</p>
170      *
171      * @param context <code>FacesContext</code> for the current request
172      */

173     public Object JavaDoc saveState(FacesContext context) {
174
175         Object JavaDoc values[] = new Object JavaDoc[5];
176         values[0] = super.saveState(context);
177         values[1] = locale ? Boolean.TRUE : Boolean.FALSE;
178         values[2] = localeSet ? Boolean.TRUE : Boolean.FALSE;
179         values[3] = xhtml ? Boolean.TRUE : Boolean.FALSE;
180         values[4] = xhtmlSet ? Boolean.TRUE : Boolean.FALSE;
181         return values;
182
183     }
184
185
186 }
187
Popular Tags