1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.faces.component;
23
24
25 import javax.faces.component.UIOutput;
26 import javax.faces.context.FacesContext;
27 import javax.faces.el.ValueBinding;
28
29
30 /**
31 * <p>Custom component that replaces the Struts
32 * <code><html:html></code> tag.</p>
33 */
34
35 public class HtmlComponent extends UIOutput {
36
37
38
39
40
41 /**
42 * <p>Create a new {@link HtmlComponent} with default properties.</p>
43 */
44 public HtmlComponent() {
45
46 super();
47 setRendererType("org.apache.struts.faces.Html");
48
49 }
50
51
52
53
54
55 /**
56 * <p>Flag indicating we should create a locale.</p>
57 */
58 private boolean locale = true;
59 private boolean localeSet = false;
60
61
62 /**
63 * <p>Flag indicating we should render XHTML output.</p>
64 */
65 private boolean xhtml = false;
66 private boolean xhtmlSet = false;
67
68
69
70
71
72 /**
73 * <p>Return the component family to which this component belongs.</p>
74 */
75 public String getFamily() {
76
77 return "org.apache.struts.faces.Html";
78
79 }
80
81
82 /**
83 * <p>Return a flag indicating whether a locale should be created.</p>
84 */
85 public boolean isLocale() {
86
87 if (localeSet) {
88 return locale;
89 }
90 ValueBinding vb = getValueBinding("locale");
91 if (vb != null) {
92 Boolean value = (Boolean) vb.getValue(getFacesContext());
93 if (null == value) {
94 return locale;
95 }
96 return value.booleanValue();
97 } else {
98 return locale;
99 }
100
101 }
102
103
104 /**
105 * <p>Set the flag indicating whether a locale should be created.</p>
106 *
107 * @param locale The new flag
108 */
109 public void setLocale(boolean locale) {
110
111 this.locale = locale;
112 this.localeSet = true;
113
114 }
115
116
117 /**
118 * <p>Return a flag indicating whether xhtml should be created.</p>
119 */
120 public boolean isXhtml() {
121
122 if (xhtmlSet) {
123 return xhtml;
124 }
125 ValueBinding vb = getValueBinding("xhtml");
126 if (vb != null) {
127 Boolean value = (Boolean) vb.getValue(getFacesContext());
128 if (null == value) {
129 return xhtml;
130 }
131 return value.booleanValue();
132 } else {
133 return xhtml;
134 }
135
136 }
137
138
139 /**
140 * <p>Set the flag indicating whether xhtml should be created.</p>
141 *
142 * @param xhtml The new flag
143 */
144 public void setXhtml(boolean xhtml) {
145
146 this.xhtml = xhtml;
147 this.xhtmlSet = true;
148
149 }
150
151
152
153
154
155 /**
156 * <p>Restore the state of this component.</p>
157 *
158 * @param context <code>FacesContext</code> for the current request
159 * @param state State object from which to restore our state
160 */
161 public void restoreState(FacesContext context, Object state) {
162
163 Object values[] = (Object[]) state;
164 super.restoreState(context, values[0]);
165 locale = ((Boolean) values[1]).booleanValue();
166 localeSet = ((Boolean) values[2]).booleanValue();
167 xhtml = ((Boolean) values[3]).booleanValue();
168 xhtmlSet = ((Boolean) values[4]).booleanValue();
169
170 }
171
172
173 /**
174 * <p>Save the state of this component.</p>
175 *
176 * @param context <code>FacesContext</code> for the current request
177 */
178 public Object saveState(FacesContext context) {
179
180 Object values[] = new Object[5];
181 values[0] = super.saveState(context);
182 values[1] = locale ? Boolean.TRUE : Boolean.FALSE;
183 values[2] = localeSet ? Boolean.TRUE : Boolean.FALSE;
184 values[3] = xhtml ? Boolean.TRUE : Boolean.FALSE;
185 values[4] = xhtmlSet ? Boolean.TRUE : Boolean.FALSE;
186 return values;
187
188 }
189
190
191 }