001: /*
002: * $Id: WriteComponent.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:write></code> tag.</p>
031: */
032:
033: public class WriteComponent extends UIOutput {
034:
035: // ------------------------------------------------------------ Constructors
036:
037: /**
038: * <p>Create a new {@link WriteComponent} with default properties.</p>
039: */
040: public WriteComponent() {
041:
042: super ();
043: setRendererType("org.apache.struts.faces.Write");
044:
045: }
046:
047: // ------------------------------------------------------ Instance Variables
048:
049: /**
050: * <p>Flag indicating whether output should be filtered.</p>
051: */
052: private boolean filter = true;
053: private boolean filterSet = false;
054:
055: /**
056: * <p>CSS style(s) to be rendered for this component.</p>
057: */
058: private String style = null;
059:
060: /**
061: * <p>CSS style class(es) to be rendered for this component.</p>
062: */
063: private String styleClass = null;
064:
065: // ---------------------------------------------------- Component Properties
066:
067: /**
068: * <p>Return the component family to which this component belongs.</p>
069: */
070: public String getFamily() {
071:
072: return "org.apache.struts.faces.Write";
073:
074: }
075:
076: /**
077: * <p>Return a flag indicating whether filtering should take place.</p>
078: */
079: public boolean isFilter() {
080:
081: if (filterSet) {
082: return filter;
083: }
084: ValueBinding vb = getValueBinding("filter");
085: if (vb != null) {
086: Boolean value = (Boolean) vb.getValue(getFacesContext());
087: if (null == value) {
088: return filter;
089: }
090: return value.booleanValue();
091: } else {
092: return filter;
093: }
094:
095: }
096:
097: /**
098: * <p>Set the flag indicating that the output value should be filtered.</p>
099: *
100: * @param filter The new filter flag
101: */
102: public void setFilter(boolean filter) {
103:
104: this .filter = filter;
105: this .filterSet = true;
106:
107: }
108:
109: /**
110: * <p>Return the CSS style(s) to be rendered for this component.</p>
111: */
112: public String getStyle() {
113:
114: ValueBinding vb = getValueBinding("style");
115: if (vb != null) {
116: return (String) vb.getValue(getFacesContext());
117: } else {
118: return style;
119: }
120:
121: }
122:
123: /**
124: * <p>Set the CSS style(s) to be rendered for this component.</p>
125: *
126: * @param style The new CSS style(s)
127: */
128: public void setStyle(String style) {
129:
130: this .style = style;
131:
132: }
133:
134: /**
135: * <p>Return the CSS style class(es) to be rendered for this component.</p>
136: */
137: public String getStyleClass() {
138:
139: ValueBinding vb = getValueBinding("styleClass");
140: if (vb != null) {
141: return (String) vb.getValue(getFacesContext());
142: } else {
143: return styleClass;
144: }
145:
146: }
147:
148: /**
149: * <p>Set the CSS style class(es) to be rendered for this component.</p>
150: *
151: * @param styleClass The new CSS style class(es)
152: */
153: public void setStyleClass(String styleClass) {
154:
155: this .styleClass = styleClass;
156:
157: }
158:
159: // ---------------------------------------------------- StateManager Methods
160:
161: /**
162: * <p>Restore the state of this component.</p>
163: *
164: * @param context <code>FacesContext</code> for the current request
165: * @param state State object from which to restore our state
166: */
167: public void restoreState(FacesContext context, Object state) {
168:
169: Object values[] = (Object[]) state;
170: super .restoreState(context, values[0]);
171: filter = ((Boolean) values[1]).booleanValue();
172: filterSet = ((Boolean) values[2]).booleanValue();
173: style = (String) values[3];
174: styleClass = (String) values[4];
175:
176: }
177:
178: /**
179: * <p>Save the state of this component.</p>
180: *
181: * @param context <code>FacesContext</code> for the current request
182: */
183: public Object saveState(FacesContext context) {
184:
185: Object values[] = new Object[5];
186: values[0] = super .saveState(context);
187: values[1] = filter ? Boolean.TRUE : Boolean.FALSE;
188: values[2] = filterSet ? Boolean.TRUE : Boolean.FALSE;
189: values[3] = style;
190: values[4] = styleClass;
191: return values;
192:
193: }
194:
195: }
|