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.HtmlMessages, 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 HtmlMessages extends
052: javax.faces.component.html.HtmlMessages {
053: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlMessages";
054: public static final String RENDERER_TYPE = "com.icesoft.faces.Messages";
055: private static final boolean DEFAULT_VISIBLE = true;
056: private String renderedOnUserRole = null;
057: private Effect effect;
058: private Boolean visible = null;
059: private String errorClass = null;
060: private String fatalClass = null;
061: private String infoClass = null;
062: private String warnClass = null;
063: private String styleClass = null;
064: private CurrentStyle currentStyle;
065:
066: public HtmlMessages() {
067: super ();
068: setRendererType(RENDERER_TYPE);
069: }
070:
071: public void setValueBinding(String s, ValueBinding vb) {
072: if (s != null && s.indexOf("effect") != -1) {
073: // If this is an effect attribute make sure Ice Extras is included
074: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
075: getFacesContext());
076: }
077: super .setValueBinding(s, vb);
078: }
079:
080: /**
081: * <p>Set the value of the <code>effect</code> property.</p>
082: */
083: public void setEffect(Effect effect) {
084: this .effect = effect;
085: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
086: getFacesContext());
087: }
088:
089: /**
090: * <p>Return the value of the <code>effect</code> property.</p>
091: */
092: public Effect getEffect() {
093: if (effect != null) {
094: return effect;
095: }
096: ValueBinding vb = getValueBinding("effect");
097: return vb != null ? (Effect) vb.getValue(getFacesContext())
098: : null;
099: }
100:
101: /**
102: * <p>Set the value of the <code>visible</code> property.</p>
103: */
104: public void setVisible(boolean visible) {
105: this .visible = Boolean.valueOf(visible);
106: }
107:
108: /**
109: * <p>Return the value of the <code>visible</code> property.</p>
110: */
111: public boolean getVisible() {
112: if (visible != null) {
113: return visible.booleanValue();
114: }
115: ValueBinding vb = getValueBinding("visible");
116: Boolean boolVal = vb != null ? (Boolean) vb
117: .getValue(getFacesContext()) : null;
118: return boolVal != null ? boolVal.booleanValue()
119: : DEFAULT_VISIBLE;
120: }
121:
122: /**
123: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
124: */
125: public void setRenderedOnUserRole(String renderedOnUserRole) {
126: this .renderedOnUserRole = renderedOnUserRole;
127: }
128:
129: /**
130: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
131: */
132: public String getRenderedOnUserRole() {
133: if (renderedOnUserRole != null) {
134: return renderedOnUserRole;
135: }
136: ValueBinding vb = getValueBinding("renderedOnUserRole");
137: return vb != null ? (String) vb.getValue(getFacesContext())
138: : null;
139: }
140:
141: /**
142: * <p>Return the value of the <code>rendered</code> property.</p>
143: */
144: public boolean isRendered() {
145: if (!Util.isRenderedOnUserRole(this )) {
146: return false;
147: }
148: return super .isRendered();
149: }
150:
151: /**
152: * <p>Return the value of the <code>currentStyle</code> property.</p>
153: */
154: public CurrentStyle getCurrentStyle() {
155: return currentStyle;
156: }
157:
158: /**
159: * <p>Set the value of the <code>currentStyle</code> property.</p>
160: */
161: public void setCurrentStyle(CurrentStyle currentStyle) {
162: this .currentStyle = currentStyle;
163: }
164:
165: /**
166: * <p>Gets the state of the instance as a <code>Serializable</code>
167: * Object.</p>
168: */
169: public Object saveState(FacesContext context) {
170: Object values[] = new Object[5];
171: values[0] = super .saveState(context);
172: values[1] = renderedOnUserRole;
173: values[2] = effect;
174: values[3] = currentStyle;
175: values[4] = visible;
176: return ((Object) (values));
177: }
178:
179: /**
180: * <p>Perform any processing required to restore the state from the entries
181: * in the state Object.</p>
182: */
183: public void restoreState(FacesContext context, Object state) {
184: Object values[] = (Object[]) state;
185: super .restoreState(context, values[0]);
186: renderedOnUserRole = (String) values[1];
187: effect = (Effect) values[2];
188: currentStyle = (CurrentStyle) values[3];
189: visible = (Boolean) values[4];
190: }
191:
192: /**
193: * <p>Set the value of the <code>styleClass</code> property.</p>
194: */
195: public void setStyleClass(String styleClass) {
196: this .styleClass = styleClass;
197: }
198:
199: /**
200: * <p>Return the value of the <code>styleClass</code> property.</p>
201: */
202: public String getStyleClass() {
203: return Util.getQualifiedStyleClass(this , styleClass,
204: CSS_DEFAULT.MESSAGES_STYLE_CLASS, "styleClass");
205: }
206:
207: /**
208: * <p>Set the value of the <code>errorClass</code> property.</p>
209: */
210: public void setErrorClass(String errorClass) {
211: this .errorClass = errorClass;
212: }
213:
214: /**
215: * <p>Return the value of the <code>errorClass</code> property.</p>
216: */
217: public String getErrorClass() {
218: return Util.getQualifiedStyleClass(this , errorClass,
219: CSS_DEFAULT.ERROR_STYLE_CLASS, "errorClass");
220: }
221:
222: /**
223: * <p>Set the value of the <code>fataClass</code> property.</p>
224: */
225: public void setFatalClass(String fatalClass) {
226: this .fatalClass = fatalClass;
227: }
228:
229: /**
230: * <p>Return the value of the <code>fataClass</code> property.</p>
231: */
232: public String getFatalClass() {
233: return Util.getQualifiedStyleClass(this , fatalClass,
234: CSS_DEFAULT.FATAL_STYLE_CLASS, "fatalClass");
235: }
236:
237: /**
238: * <p>Set the value of the <code>infoClass</code> property.</p>
239: */
240: public void setInfoClass(String infoClass) {
241: this .infoClass = infoClass;
242: }
243:
244: /**
245: * <p>Return the value of the <code>infoClass</code> property.</p>
246: */
247: public String getInfoClass() {
248: return Util.getQualifiedStyleClass(this , infoClass,
249: CSS_DEFAULT.INFO_STYLE_CLASS, "infoClass");
250: }
251:
252: /**
253: * <p>Set the value of the <code>warnClass</code> property.</p>
254: */
255: public void setWarnClass(String warnClass) {
256: this .warnClass = warnClass;
257: }
258:
259: /**
260: * <p>Return the value of the <code>warnClass</code> property.</p>
261: */
262: public String getWarnClass() {
263: return Util.getQualifiedStyleClass(this , warnClass,
264: CSS_DEFAULT.WARN_STYLE_CLASS, "warnClass");
265: }
266: }
|