001: /*
002: * $Id: HtmlComponent.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.faces.component;
023:
024: import javax.faces.component.UIOutput;
025: import javax.faces.context.FacesContext;
026: import javax.faces.el.ValueBinding;
027:
028: /**
029: * <p>Custom component that replaces the Struts
030: * <code><html:html></code> tag.</p>
031: */
032:
033: public class HtmlComponent extends UIOutput {
034:
035: // ------------------------------------------------------------ Constructors
036:
037: /**
038: * <p>Create a new {@link HtmlComponent} with default properties.</p>
039: */
040: public HtmlComponent() {
041:
042: super ();
043: setRendererType("org.apache.struts.faces.Html");
044:
045: }
046:
047: // ------------------------------------------------------ Instance Variables
048:
049: /**
050: * <p>Flag indicating we should create a locale.</p>
051: */
052: private boolean locale = true;
053: private boolean localeSet = false;
054:
055: /**
056: * <p>Flag indicating we should render XHTML output.</p>
057: */
058: private boolean xhtml = false;
059: private boolean xhtmlSet = false;
060:
061: // ---------------------------------------------------- Component Properties
062:
063: /**
064: * <p>Return the component family to which this component belongs.</p>
065: */
066: public String getFamily() {
067:
068: return "org.apache.struts.faces.Html";
069:
070: }
071:
072: /**
073: * <p>Return a flag indicating whether a locale should be created.</p>
074: */
075: public boolean isLocale() {
076:
077: if (localeSet) {
078: return locale;
079: }
080: ValueBinding vb = getValueBinding("locale");
081: if (vb != null) {
082: Boolean value = (Boolean) vb.getValue(getFacesContext());
083: if (null == value) {
084: return locale;
085: }
086: return value.booleanValue();
087: } else {
088: return locale;
089: }
090:
091: }
092:
093: /**
094: * <p>Set the flag indicating whether a locale should be created.</p>
095: *
096: * @param locale The new flag
097: */
098: public void setLocale(boolean locale) {
099:
100: this .locale = locale;
101: this .localeSet = true;
102:
103: }
104:
105: /**
106: * <p>Return a flag indicating whether xhtml should be created.</p>
107: */
108: public boolean isXhtml() {
109:
110: if (xhtmlSet) {
111: return xhtml;
112: }
113: ValueBinding vb = getValueBinding("xhtml");
114: if (vb != null) {
115: Boolean value = (Boolean) vb.getValue(getFacesContext());
116: if (null == value) {
117: return xhtml;
118: }
119: return value.booleanValue();
120: } else {
121: return xhtml;
122: }
123:
124: }
125:
126: /**
127: * <p>Set the flag indicating whether xhtml should be created.</p>
128: *
129: * @param xhtml The new flag
130: */
131: public void setXhtml(boolean xhtml) {
132:
133: this .xhtml = xhtml;
134: this .xhtmlSet = true;
135:
136: }
137:
138: // ---------------------------------------------------- StateManager Methods
139:
140: /**
141: * <p>Restore the state of this component.</p>
142: *
143: * @param context <code>FacesContext</code> for the current request
144: * @param state State object from which to restore our state
145: */
146: public void restoreState(FacesContext context, Object state) {
147:
148: Object values[] = (Object[]) state;
149: super .restoreState(context, values[0]);
150: locale = ((Boolean) values[1]).booleanValue();
151: localeSet = ((Boolean) values[2]).booleanValue();
152: xhtml = ((Boolean) values[3]).booleanValue();
153: xhtmlSet = ((Boolean) values[4]).booleanValue();
154:
155: }
156:
157: /**
158: * <p>Save the state of this component.</p>
159: *
160: * @param context <code>FacesContext</code> for the current request
161: */
162: public Object saveState(FacesContext context) {
163:
164: Object values[] = new Object[5];
165: values[0] = super .saveState(context);
166: values[1] = locale ? Boolean.TRUE : Boolean.FALSE;
167: values[2] = localeSet ? Boolean.TRUE : Boolean.FALSE;
168: values[3] = xhtml ? Boolean.TRUE : Boolean.FALSE;
169: values[4] = xhtmlSet ? Boolean.TRUE : Boolean.FALSE;
170: return values;
171:
172: }
173:
174: }
|