001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.component.html;
030:
031: import java.util.*;
032:
033: import javax.el.*;
034:
035: import javax.faces.component.*;
036: import javax.faces.context.*;
037:
038: public class HtmlMessage extends UIMessage {
039: public static final String COMPONENT_TYPE = "javax.faces.HtmlMessage";
040:
041: private static final HashMap<String, PropEnum> _propMap = new HashMap<String, PropEnum>();
042:
043: private String _dir;
044: private ValueExpression _dirExpr;
045:
046: private String _errorClass;
047: private ValueExpression _errorClassExpr;
048:
049: private String _errorStyle;
050: private ValueExpression _errorStyleExpr;
051:
052: private String _fatalClass;
053: private ValueExpression _fatalClassExpr;
054:
055: private String _fatalStyle;
056: private ValueExpression _fatalStyleExpr;
057:
058: private String _infoClass;
059: private ValueExpression _infoClassExpr;
060:
061: private String _infoStyle;
062: private ValueExpression _infoStyleExpr;
063:
064: private String _lang;
065: private ValueExpression _langExpr;
066:
067: private String _style;
068: private ValueExpression _styleExpr;
069:
070: private String _styleClass;
071: private ValueExpression _styleClassExpr;
072:
073: private String _title;
074: private ValueExpression _titleExpr;
075:
076: private String _warnClass;
077: private ValueExpression _warnClassExpr;
078:
079: private String _warnStyle;
080: private ValueExpression _warnStyleExpr;
081:
082: private Boolean _tooltip;
083: private ValueExpression _tooltipExpr;
084:
085: public HtmlMessage() {
086: setRendererType("javax.faces.Message");
087: }
088:
089: //
090: // properties
091: //
092:
093: public String getDir() {
094: if (_dir != null)
095: return _dir;
096: else if (_dirExpr != null)
097: return Util.evalString(_dirExpr);
098: else
099: return null;
100: }
101:
102: public void setDir(String dir) {
103: _dir = dir;
104: }
105:
106: public String getErrorClass() {
107: if (_errorClass != null)
108: return _errorClass;
109: else if (_errorClassExpr != null)
110: return Util.evalString(_errorClassExpr);
111: else
112: return null;
113: }
114:
115: public void setErrorClass(String errorClass) {
116: _errorClass = errorClass;
117: }
118:
119: public String getErrorStyle() {
120: if (_errorStyle != null)
121: return _errorStyle;
122: else if (_errorStyleExpr != null)
123: return Util.evalString(_errorStyleExpr);
124: else
125: return null;
126: }
127:
128: public void setErrorStyle(String errorStyle) {
129: _errorStyle = errorStyle;
130: }
131:
132: public String getFatalClass() {
133: if (_fatalClass != null)
134: return _fatalClass;
135: else if (_fatalClassExpr != null)
136: return Util.evalString(_fatalClassExpr);
137: else
138: return null;
139: }
140:
141: public void setFatalClass(String fatalClass) {
142: _fatalClass = fatalClass;
143: }
144:
145: public String getFatalStyle() {
146: if (_fatalStyle != null)
147: return _fatalStyle;
148: else if (_fatalStyleExpr != null)
149: return Util.evalString(_fatalStyleExpr);
150: else
151: return null;
152: }
153:
154: public void setFatalStyle(String fatalStyle) {
155: _fatalStyle = fatalStyle;
156: }
157:
158: public String getInfoClass() {
159: if (_infoClass != null)
160: return _infoClass;
161: else if (_infoClassExpr != null)
162: return Util.evalString(_infoClassExpr);
163: else
164: return null;
165: }
166:
167: public void setInfoClass(String infoClass) {
168: _infoClass = infoClass;
169: }
170:
171: public String getInfoStyle() {
172: if (_infoStyle != null)
173: return _infoStyle;
174: else if (_infoStyleExpr != null)
175: return Util.evalString(_infoStyleExpr);
176: else
177: return null;
178: }
179:
180: public void setInfoStyle(String infoStyle) {
181: _infoStyle = infoStyle;
182: }
183:
184: public String getLang() {
185: if (_lang != null)
186: return _lang;
187: else if (_langExpr != null)
188: return Util.evalString(_langExpr);
189: else
190: return null;
191: }
192:
193: public void setLang(String lang) {
194: _lang = lang;
195: }
196:
197: public String getStyle() {
198: if (_style != null)
199: return _style;
200: else if (_styleExpr != null)
201: return Util.evalString(_styleExpr);
202: else
203: return null;
204: }
205:
206: public void setStyle(String style) {
207: _style = style;
208: }
209:
210: public String getStyleClass() {
211: if (_styleClass != null)
212: return _styleClass;
213: else if (_styleClassExpr != null)
214: return Util.evalString(_styleClassExpr);
215: else
216: return null;
217: }
218:
219: public void setStyleClass(String styleClass) {
220: _styleClass = styleClass;
221: }
222:
223: public String getTitle() {
224: if (_title != null)
225: return _title;
226: else if (_titleExpr != null)
227: return Util.evalString(_titleExpr);
228: else
229: return null;
230: }
231:
232: public void setTitle(String title) {
233: _title = title;
234: }
235:
236: public String getWarnClass() {
237: if (_warnClass != null)
238: return _warnClass;
239: else if (_warnClassExpr != null)
240: return Util.evalString(_warnClassExpr);
241: else
242: return null;
243: }
244:
245: public void setWarnClass(String warnClass) {
246: _warnClass = warnClass;
247: }
248:
249: public String getWarnStyle() {
250: if (_warnStyle != null)
251: return _warnStyle;
252: else if (_warnStyleExpr != null)
253: return Util.evalString(_warnStyleExpr);
254: else
255: return null;
256: }
257:
258: public void setWarnStyle(String warnStyle) {
259: _warnStyle = warnStyle;
260: }
261:
262: public boolean isTooltip() {
263: if (_tooltip != null)
264: return _tooltip;
265: else if (_tooltipExpr != null)
266: return Util.evalBoolean(_tooltipExpr);
267: else
268: return false;
269: }
270:
271: public void setTooltip(boolean tooltip) {
272: _tooltip = tooltip;
273: }
274:
275: //
276: // value expression override
277: //
278:
279: /**
280: * Returns the value expression with the given name.
281: */
282: @Override
283: public ValueExpression getValueExpression(String name) {
284: PropEnum prop = _propMap.get(name);
285:
286: if (prop != null) {
287: switch (prop) {
288: case DIR:
289: return _dirExpr;
290: case ERROR_CLASS:
291: return _errorClassExpr;
292: case ERROR_STYLE:
293: return _errorStyleExpr;
294: case FATAL_CLASS:
295: return _fatalClassExpr;
296: case FATAL_STYLE:
297: return _fatalStyleExpr;
298: case INFO_CLASS:
299: return _infoClassExpr;
300: case INFO_STYLE:
301: return _infoStyleExpr;
302: case LANG:
303: return _langExpr;
304: case STYLE:
305: return _styleExpr;
306: case STYLE_CLASS:
307: return _styleClassExpr;
308: case TITLE:
309: return _titleExpr;
310: case WARN_CLASS:
311: return _warnClassExpr;
312: case WARN_STYLE:
313: return _warnStyleExpr;
314: case TOOLTIP:
315: return _tooltipExpr;
316: }
317: }
318:
319: return super .getValueExpression(name);
320: }
321:
322: /**
323: * Sets the value expression with the given name.
324: */
325: @Override
326: public void setValueExpression(String name, ValueExpression expr) {
327: PropEnum prop = _propMap.get(name);
328:
329: if (prop != null) {
330: switch (prop) {
331: case DIR:
332: if (expr != null && expr.isLiteralText()) {
333: _dir = Util.evalString(expr);
334: return;
335: } else
336: _dirExpr = expr;
337: break;
338:
339: case ERROR_CLASS:
340: if (expr != null && expr.isLiteralText()) {
341: _errorClass = Util.evalString(expr);
342: return;
343: } else
344: _errorClassExpr = expr;
345: break;
346:
347: case ERROR_STYLE:
348: if (expr != null && expr.isLiteralText()) {
349: _errorStyle = Util.evalString(expr);
350: return;
351: } else
352: _errorStyleExpr = expr;
353: break;
354:
355: case FATAL_CLASS:
356: if (expr != null && expr.isLiteralText()) {
357: _fatalClass = Util.evalString(expr);
358: return;
359: } else
360: _fatalClassExpr = expr;
361: break;
362:
363: case FATAL_STYLE:
364: if (expr != null && expr.isLiteralText()) {
365: _fatalStyle = Util.evalString(expr);
366: return;
367: } else
368: _fatalStyleExpr = expr;
369: break;
370:
371: case INFO_CLASS:
372: if (expr != null && expr.isLiteralText()) {
373: _infoClass = Util.evalString(expr);
374: return;
375: } else
376: _infoClassExpr = expr;
377: break;
378:
379: case INFO_STYLE:
380: if (expr != null && expr.isLiteralText()) {
381: _infoStyle = Util.evalString(expr);
382: return;
383: } else
384: _infoStyleExpr = expr;
385: break;
386:
387: case LANG:
388: if (expr != null && expr.isLiteralText()) {
389: _lang = Util.evalString(expr);
390: return;
391: } else
392: _langExpr = expr;
393: break;
394:
395: case STYLE:
396: if (expr != null && expr.isLiteralText()) {
397: _style = Util.evalString(expr);
398: return;
399: } else
400: _styleExpr = expr;
401: break;
402:
403: case STYLE_CLASS:
404: if (expr != null && expr.isLiteralText()) {
405: _styleClass = Util.evalString(expr);
406: return;
407: } else
408: _styleClassExpr = expr;
409: break;
410:
411: case TITLE:
412: if (expr != null && expr.isLiteralText()) {
413: _title = Util.evalString(expr);
414: return;
415: } else
416: _titleExpr = expr;
417: break;
418:
419: case TOOLTIP:
420: if (expr != null && expr.isLiteralText()) {
421: _tooltip = Util.evalBoolean(expr);
422: return;
423: } else
424: _tooltipExpr = expr;
425: break;
426:
427: case WARN_CLASS:
428: if (expr != null && expr.isLiteralText()) {
429: _warnClass = Util.evalString(expr);
430: return;
431: } else
432: _warnClassExpr = expr;
433: break;
434:
435: case WARN_STYLE:
436: if (expr != null && expr.isLiteralText()) {
437: _warnStyle = Util.evalString(expr);
438: return;
439: } else
440: _warnStyleExpr = expr;
441: break;
442: }
443: }
444:
445: super .setValueExpression(name, expr);
446: }
447:
448: public Object saveState(FacesContext context) {
449: Object parent = super .saveState(context);
450:
451: return new Object[] { parent, _dir, _errorClass, _errorStyle,
452: _fatalClass, _fatalStyle, _infoClass, _infoStyle,
453: _lang, _style, _styleClass, _title, _tooltip,
454: _warnClass, _warnStyle, };
455: }
456:
457: public void restoreState(FacesContext context, Object value) {
458: Object[] state = (Object[]) value;
459:
460: if (state != null)
461: super .restoreState(context, state[0]);
462:
463: int i = 1;
464:
465: _dir = (String) state[i++];
466: _errorClass = (String) state[i++];
467: _errorStyle = (String) state[i++];
468: _fatalClass = (String) state[i++];
469: _fatalStyle = (String) state[i++];
470: _infoClass = (String) state[i++];
471: _infoStyle = (String) state[i++];
472: _lang = (String) state[i++];
473: _style = (String) state[i++];
474: _styleClass = (String) state[i++];
475: _title = (String) state[i++];
476: _tooltip = (Boolean) state[i++];
477: _warnClass = (String) state[i++];
478: _warnStyle = (String) state[i++];
479: }
480:
481: //
482: // private impl
483: //
484:
485: private enum PropEnum {
486: DIR, ERROR_CLASS, ERROR_STYLE, FATAL_CLASS, FATAL_STYLE, INFO_CLASS, INFO_STYLE, LANG, STYLE, STYLE_CLASS, TITLE, TOOLTIP, WARN_CLASS, WARN_STYLE,
487: }
488:
489: static {
490: _propMap.put("dir", PropEnum.DIR);
491: _propMap.put("errorClass", PropEnum.ERROR_CLASS);
492: _propMap.put("errorStyle", PropEnum.ERROR_STYLE);
493: _propMap.put("fatalClass", PropEnum.FATAL_CLASS);
494: _propMap.put("fatalStyle", PropEnum.FATAL_STYLE);
495: _propMap.put("infoClass", PropEnum.INFO_CLASS);
496: _propMap.put("infoStyle", PropEnum.INFO_STYLE);
497: _propMap.put("lang", PropEnum.LANG);
498: _propMap.put("style", PropEnum.STYLE);
499: _propMap.put("styleClass", PropEnum.STYLE_CLASS);
500: _propMap.put("title", PropEnum.TITLE);
501: _propMap.put("tooltip", PropEnum.TOOLTIP);
502: _propMap.put("warnClass", PropEnum.WARN_CLASS);
503: _propMap.put("warnStyle", PropEnum.WARN_STYLE);
504: }
505: }
|