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 HtmlMessages extends UIMessages {
039: public static final String COMPONENT_TYPE = "javax.faces.HtmlMessages";
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 _layout;
068: private ValueExpression _layoutExpr;
069:
070: private String _style;
071: private ValueExpression _styleExpr;
072:
073: private String _styleClass;
074: private ValueExpression _styleClassExpr;
075:
076: private String _title;
077: private ValueExpression _titleExpr;
078:
079: private String _warnClass;
080: private ValueExpression _warnClassExpr;
081:
082: private String _warnStyle;
083: private ValueExpression _warnStyleExpr;
084:
085: private Boolean _tooltip;
086: private ValueExpression _tooltipExpr;
087:
088: public HtmlMessages() {
089: setRendererType("javax.faces.Messages");
090: }
091:
092: //
093: // properties
094: //
095:
096: public String getDir() {
097: if (_dir != null)
098: return _dir;
099: else if (_dirExpr != null)
100: return Util.evalString(_dirExpr);
101: else
102: return null;
103: }
104:
105: public void setDir(String dir) {
106: _dir = dir;
107: }
108:
109: public String getErrorClass() {
110: if (_errorClass != null)
111: return _errorClass;
112: else if (_errorClassExpr != null)
113: return Util.evalString(_errorClassExpr);
114: else
115: return null;
116: }
117:
118: public void setErrorClass(String errorClass) {
119: _errorClass = errorClass;
120: }
121:
122: public String getErrorStyle() {
123: if (_errorStyle != null)
124: return _errorStyle;
125: else if (_errorStyleExpr != null)
126: return Util.evalString(_errorStyleExpr);
127: else
128: return null;
129: }
130:
131: public void setErrorStyle(String errorStyle) {
132: _errorStyle = errorStyle;
133: }
134:
135: public String getFatalClass() {
136: if (_fatalClass != null)
137: return _fatalClass;
138: else if (_fatalClassExpr != null)
139: return Util.evalString(_fatalClassExpr);
140: else
141: return null;
142: }
143:
144: public void setFatalClass(String fatalClass) {
145: _fatalClass = fatalClass;
146: }
147:
148: public String getFatalStyle() {
149: if (_fatalStyle != null)
150: return _fatalStyle;
151: else if (_fatalStyleExpr != null)
152: return Util.evalString(_fatalStyleExpr);
153: else
154: return null;
155: }
156:
157: public void setFatalStyle(String fatalStyle) {
158: _fatalStyle = fatalStyle;
159: }
160:
161: public String getInfoClass() {
162: if (_infoClass != null)
163: return _infoClass;
164: else if (_infoClassExpr != null)
165: return Util.evalString(_infoClassExpr);
166: else
167: return null;
168: }
169:
170: public void setInfoClass(String infoClass) {
171: _infoClass = infoClass;
172: }
173:
174: public String getInfoStyle() {
175: if (_infoStyle != null)
176: return _infoStyle;
177: else if (_infoStyleExpr != null)
178: return Util.evalString(_infoStyleExpr);
179: else
180: return null;
181: }
182:
183: public void setInfoStyle(String infoStyle) {
184: _infoStyle = infoStyle;
185: }
186:
187: public String getLang() {
188: if (_lang != null)
189: return _lang;
190: else if (_langExpr != null)
191: return Util.evalString(_langExpr);
192: else
193: return null;
194: }
195:
196: public void setLang(String lang) {
197: _lang = lang;
198: }
199:
200: public String getLayout() {
201: if (_layout != null)
202: return _layout;
203: else if (_layoutExpr != null)
204: return Util.evalString(_layoutExpr);
205: else
206: return null;
207: }
208:
209: public void setLayout(String layout) {
210: _layout = layout;
211: }
212:
213: public String getStyle() {
214: if (_style != null)
215: return _style;
216: else if (_styleExpr != null)
217: return Util.evalString(_styleExpr);
218: else
219: return null;
220: }
221:
222: public void setStyle(String style) {
223: _style = style;
224: }
225:
226: public String getStyleClass() {
227: if (_styleClass != null)
228: return _styleClass;
229: else if (_styleClassExpr != null)
230: return Util.evalString(_styleClassExpr);
231: else
232: return null;
233: }
234:
235: public void setStyleClass(String styleClass) {
236: _styleClass = styleClass;
237: }
238:
239: public String getTitle() {
240: if (_title != null)
241: return _title;
242: else if (_titleExpr != null)
243: return Util.evalString(_titleExpr);
244: else
245: return null;
246: }
247:
248: public void setTitle(String title) {
249: _title = title;
250: }
251:
252: public String getWarnClass() {
253: if (_warnClass != null)
254: return _warnClass;
255: else if (_warnClassExpr != null)
256: return Util.evalString(_warnClassExpr);
257: else
258: return null;
259: }
260:
261: public void setWarnClass(String warnClass) {
262: _warnClass = warnClass;
263: }
264:
265: public String getWarnStyle() {
266: if (_warnStyle != null)
267: return _warnStyle;
268: else if (_warnStyleExpr != null)
269: return Util.evalString(_warnStyleExpr);
270: else
271: return null;
272: }
273:
274: public void setWarnStyle(String warnStyle) {
275: _warnStyle = warnStyle;
276: }
277:
278: public boolean isTooltip() {
279: if (_tooltip != null)
280: return _tooltip;
281: else if (_tooltipExpr != null)
282: return Util.evalBoolean(_tooltipExpr);
283: else
284: return false;
285: }
286:
287: public void setTooltip(boolean tooltip) {
288: _tooltip = tooltip;
289: }
290:
291: //
292: // value expression override
293: //
294:
295: /**
296: * Returns the value expression with the given name.
297: */
298: @Override
299: public ValueExpression getValueExpression(String name) {
300: PropEnum prop = _propMap.get(name);
301:
302: if (prop != null) {
303: switch (prop) {
304: case DIR:
305: return _dirExpr;
306: case ERROR_CLASS:
307: return _errorClassExpr;
308: case ERROR_STYLE:
309: return _errorStyleExpr;
310: case FATAL_CLASS:
311: return _fatalClassExpr;
312: case FATAL_STYLE:
313: return _fatalStyleExpr;
314: case INFO_CLASS:
315: return _infoClassExpr;
316: case INFO_STYLE:
317: return _infoStyleExpr;
318: case LANG:
319: return _langExpr;
320: case LAYOUT:
321: return _layoutExpr;
322: case STYLE:
323: return _styleExpr;
324: case STYLE_CLASS:
325: return _styleClassExpr;
326: case TITLE:
327: return _titleExpr;
328: case WARN_CLASS:
329: return _warnClassExpr;
330: case WARN_STYLE:
331: return _warnStyleExpr;
332: case TOOLTIP:
333: return _tooltipExpr;
334: }
335: }
336:
337: return super .getValueExpression(name);
338: }
339:
340: /**
341: * Sets the value expression with the given name.
342: */
343: @Override
344: public void setValueExpression(String name, ValueExpression expr) {
345: PropEnum prop = _propMap.get(name);
346:
347: if (prop != null) {
348: switch (prop) {
349: case DIR:
350: if (expr != null && expr.isLiteralText()) {
351: _dir = Util.evalString(expr);
352: return;
353: } else
354: _dirExpr = expr;
355: break;
356:
357: case ERROR_CLASS:
358: if (expr != null && expr.isLiteralText()) {
359: _errorClass = Util.evalString(expr);
360: return;
361: } else
362: _errorClassExpr = expr;
363: break;
364:
365: case ERROR_STYLE:
366: if (expr != null && expr.isLiteralText()) {
367: _errorStyle = Util.evalString(expr);
368: return;
369: } else
370: _errorStyleExpr = expr;
371: break;
372:
373: case FATAL_CLASS:
374: if (expr != null && expr.isLiteralText()) {
375: _fatalClass = Util.evalString(expr);
376: return;
377: } else
378: _fatalClassExpr = expr;
379: break;
380:
381: case FATAL_STYLE:
382: if (expr != null && expr.isLiteralText()) {
383: _fatalStyle = Util.evalString(expr);
384: return;
385: } else
386: _fatalStyleExpr = expr;
387: break;
388:
389: case INFO_CLASS:
390: if (expr != null && expr.isLiteralText()) {
391: _infoClass = Util.evalString(expr);
392: return;
393: } else
394: _infoClassExpr = expr;
395: break;
396:
397: case INFO_STYLE:
398: if (expr != null && expr.isLiteralText()) {
399: _infoStyle = Util.evalString(expr);
400: return;
401: } else
402: _infoStyleExpr = expr;
403: break;
404:
405: case LANG:
406: if (expr != null && expr.isLiteralText()) {
407: _lang = Util.evalString(expr);
408: return;
409: } else
410: _langExpr = expr;
411: break;
412:
413: case LAYOUT:
414: if (expr != null && expr.isLiteralText()) {
415: _layout = Util.evalString(expr);
416: return;
417: } else
418: _layoutExpr = expr;
419: break;
420:
421: case STYLE:
422: if (expr != null && expr.isLiteralText()) {
423: _style = Util.evalString(expr);
424: return;
425: } else
426: _styleExpr = expr;
427: break;
428:
429: case STYLE_CLASS:
430: if (expr != null && expr.isLiteralText()) {
431: _styleClass = Util.evalString(expr);
432: return;
433: } else
434: _styleClassExpr = expr;
435: break;
436:
437: case TITLE:
438: if (expr != null && expr.isLiteralText()) {
439: _title = Util.evalString(expr);
440: return;
441: } else
442: _titleExpr = expr;
443: break;
444:
445: case TOOLTIP:
446: if (expr != null && expr.isLiteralText()) {
447: _tooltip = Util.evalBoolean(expr);
448: return;
449: } else
450: _tooltipExpr = expr;
451: break;
452:
453: case WARN_CLASS:
454: if (expr != null && expr.isLiteralText()) {
455: _warnClass = Util.evalString(expr);
456: return;
457: } else
458: _warnClassExpr = expr;
459: break;
460:
461: case WARN_STYLE:
462: if (expr != null && expr.isLiteralText()) {
463: _warnStyle = Util.evalString(expr);
464: return;
465: } else
466: _warnStyleExpr = expr;
467: break;
468: }
469: }
470:
471: super .setValueExpression(name, expr);
472: }
473:
474: //
475: // state
476:
477: public Object saveState(FacesContext context) {
478: Object parent = super .saveState(context);
479:
480: return new Object[] { parent, _dir, _errorClass, _errorStyle,
481: _fatalClass, _fatalStyle, _infoClass, _infoStyle,
482: _lang, _style, _styleClass, _title, _tooltip,
483: _warnClass, _warnStyle, };
484: }
485:
486: public void restoreState(FacesContext context, Object value) {
487: Object[] state = (Object[]) value;
488:
489: if (state != null)
490: super .restoreState(context, state[0]);
491:
492: int i = 1;
493:
494: _dir = (String) state[i++];
495: _errorClass = (String) state[i++];
496: _errorStyle = (String) state[i++];
497: _fatalClass = (String) state[i++];
498: _fatalStyle = (String) state[i++];
499: _infoClass = (String) state[i++];
500: _infoStyle = (String) state[i++];
501: _lang = (String) state[i++];
502: _style = (String) state[i++];
503: _styleClass = (String) state[i++];
504: _title = (String) state[i++];
505: _tooltip = (Boolean) state[i++];
506: _warnClass = (String) state[i++];
507: _warnStyle = (String) state[i++];
508: }
509:
510: //
511: // private impl
512: //
513:
514: private enum PropEnum {
515: DIR, ERROR_CLASS, ERROR_STYLE, FATAL_CLASS, FATAL_STYLE, INFO_CLASS, INFO_STYLE, LANG, LAYOUT, STYLE, STYLE_CLASS, TITLE, TOOLTIP, WARN_CLASS, WARN_STYLE,
516: }
517:
518: static {
519: _propMap.put("dir", PropEnum.DIR);
520: _propMap.put("errorClass", PropEnum.ERROR_CLASS);
521: _propMap.put("errorStyle", PropEnum.ERROR_STYLE);
522: _propMap.put("fatalClass", PropEnum.FATAL_CLASS);
523: _propMap.put("fatalStyle", PropEnum.FATAL_STYLE);
524: _propMap.put("infoClass", PropEnum.INFO_CLASS);
525: _propMap.put("infoStyle", PropEnum.INFO_STYLE);
526: _propMap.put("lang", PropEnum.LANG);
527: _propMap.put("layout", PropEnum.LAYOUT);
528: _propMap.put("style", PropEnum.STYLE);
529: _propMap.put("styleClass", PropEnum.STYLE_CLASS);
530: _propMap.put("title", PropEnum.TITLE);
531: _propMap.put("tooltip", PropEnum.TOOLTIP);
532: _propMap.put("warnClass", PropEnum.WARN_CLASS);
533: _propMap.put("warnStyle", PropEnum.WARN_STYLE);
534: }
535: }
|