001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.ext;
035:
036: import com.icesoft.faces.component.CSS_DEFAULT;
037: import com.icesoft.faces.component.ext.taglib.Util;
038: import com.icesoft.faces.context.effects.CurrentStyle;
039: import com.icesoft.faces.context.effects.Effect;
040: import com.icesoft.faces.context.effects.JavascriptContext;
041:
042: import javax.faces.context.FacesContext;
043: import javax.faces.el.ValueBinding;
044:
045: /**
046: * This is an extension of javax.faces.component.html.HtmlMessage, which
047: * provides some additional behavior to this component such as: <ul> <li>changes
048: * the component's rendered state based on the authentication</li> <li>adds
049: * effects to the component</li> <ul>
050: */
051: public class HtmlMessage extends javax.faces.component.html.HtmlMessage {
052: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlMessage";
053: public static final String RENDERER_TYPE = "com.icesoft.faces.Message";
054: private static final boolean DEFAULT_VISIBLE = true;
055: private String renderedOnUserRole = null;
056: private Effect effect;
057: private Boolean visible = null;
058: private String errorClass = null;
059: private String fatalClass = null;
060: private String infoClass = null;
061: private String warnClass = null;
062: private String styleClass = null;
063: private CurrentStyle currentStyle;
064:
065: public HtmlMessage() {
066: super ();
067: setRendererType(RENDERER_TYPE);
068: }
069:
070: public void setValueBinding(String s, ValueBinding vb) {
071: if (s != null && s.indexOf("effect") != -1) {
072: // If this is an effect attribute make sure Ice Extras is included
073: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
074: getFacesContext());
075: }
076: super .setValueBinding(s, vb);
077: }
078:
079: /**
080: * <p>Set the value of the <code>effect</code> property.</p>
081: */
082: public void setEffect(Effect effect) {
083: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
084: getFacesContext());
085: this .effect = effect;
086: }
087:
088: /**
089: * <p>Return the value of the <code>effect</code> property.</p>
090: */
091: public Effect getEffect() {
092: if (effect != null) {
093: return effect;
094: }
095: ValueBinding vb = getValueBinding("effect");
096: return vb != null ? (Effect) vb.getValue(getFacesContext())
097: : null;
098: }
099:
100: /**
101: * <p>Set the value of the <code>visible</code> property.</p>
102: */
103: public void setVisible(boolean visible) {
104: this .visible = Boolean.valueOf(visible);
105: }
106:
107: /**
108: * <p>Return the value of the <code>visible</code> property.</p>
109: */
110: public boolean getVisible() {
111: if (visible != null) {
112: return visible.booleanValue();
113: }
114: ValueBinding vb = getValueBinding("visible");
115: Boolean boolVal = vb != null ? (Boolean) vb
116: .getValue(getFacesContext()) : null;
117: return boolVal != null ? boolVal.booleanValue()
118: : DEFAULT_VISIBLE;
119: }
120:
121: /**
122: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
123: */
124: public void setRenderedOnUserRole(String renderedOnUserRole) {
125: this .renderedOnUserRole = renderedOnUserRole;
126: }
127:
128: /**
129: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
130: */
131: public String getRenderedOnUserRole() {
132: if (renderedOnUserRole != null) {
133: return renderedOnUserRole;
134: }
135: ValueBinding vb = getValueBinding("renderedOnUserRole");
136: return vb != null ? (String) vb.getValue(getFacesContext())
137: : null;
138: }
139:
140: /**
141: * <p>Return the value of the <code>rendered</code> property.</p>
142: */
143: public boolean isRendered() {
144: if (!Util.isRenderedOnUserRole(this )) {
145: return false;
146: }
147: return super .isRendered();
148: }
149:
150: /**
151: * <p>Return the value of the <code>currentStyle</code> property.</p>
152: */
153: public CurrentStyle getCurrentStyle() {
154: return currentStyle;
155: }
156:
157: /**
158: * <p>Set the value of the <code>currentStyle</code> property.</p>
159: */
160: public void setCurrentStyle(CurrentStyle currentStyle) {
161: this .currentStyle = currentStyle;
162: }
163:
164: /**
165: * <p>Gets the state of the instance as a <code>Serializable</code>
166: * Object.</p>
167: */
168: public Object saveState(FacesContext context) {
169: Object values[] = new Object[5];
170: values[0] = super .saveState(context);
171: values[1] = renderedOnUserRole;
172: values[2] = effect;
173: values[3] = currentStyle;
174: values[4] = visible;
175: return ((Object) (values));
176: }
177:
178: /**
179: * <p>Perform any processing required to restore the state from the entries
180: * in the state Object.</p>
181: */
182: public void restoreState(FacesContext context, Object state) {
183: Object values[] = (Object[]) state;
184: super .restoreState(context, values[0]);
185: renderedOnUserRole = (String) values[1];
186: effect = (Effect) values[2];
187: currentStyle = (CurrentStyle) values[3];
188: visible = (Boolean) values[4];
189: }
190:
191: /**
192: * <p>Set the value of the <code>styleClass</code> property.</p>
193: */
194: public void setStyleClass(String styleClass) {
195: this .styleClass = styleClass;
196: }
197:
198: /**
199: * <p>Return the value of the <code>styleClass</code> property.</p>
200: */
201: public String getStyleClass() {
202: return Util.getQualifiedStyleClass(this , styleClass,
203: CSS_DEFAULT.MESSAGE_STYLE_CLASS, "styleClass");
204: }
205:
206: /**
207: * <p>Set the value of the <code>errorClass</code> property.</p>
208: */
209: public void setErrorClass(String errorClass) {
210: this .errorClass = errorClass;
211: }
212:
213: /**
214: * <p>Return the value of the <code>errorClass</code> property.</p>
215: */
216: public String getErrorClass() {
217: return Util.getQualifiedStyleClass(this , errorClass,
218: CSS_DEFAULT.ERROR_STYLE_CLASS, "errorClass");
219: }
220:
221: /**
222: * <p>Set the value of the <code>fataClass</code> property.</p>
223: */
224: public void setFatalClass(String fatalClass) {
225: this .fatalClass = fatalClass;
226: }
227:
228: /**
229: * <p>Return the value of the <code>fataClass</code> property.</p>
230: */
231: public String getFatalClass() {
232: return Util.getQualifiedStyleClass(this , fatalClass,
233: CSS_DEFAULT.FATAL_STYLE_CLASS, "fatalClass");
234: }
235:
236: /**
237: * <p>Set the value of the <code>infoClass</code> property.</p>
238: */
239: public void setInfoClass(String infoClass) {
240: this .infoClass = infoClass;
241: }
242:
243: /**
244: * <p>Return the value of the <code>infoClass</code> property.</p>
245: */
246: public String getInfoClass() {
247: return Util.getQualifiedStyleClass(this , infoClass,
248: CSS_DEFAULT.INFO_STYLE_CLASS, "infoClass");
249: }
250:
251: /**
252: * <p>Set the value of the <code>warnClass</code> property.</p>
253: */
254: public void setWarnClass(String warnClass) {
255: this .warnClass = warnClass;
256: }
257:
258: /**
259: * <p>Return the value of the <code>warnClass</code> property.</p>
260: */
261: public String getWarnClass() {
262: return Util.getQualifiedStyleClass(this , warnClass,
263: CSS_DEFAULT.WARN_STYLE_CLASS, "warnClass");
264: }
265: }
|