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 HtmlGraphicImage extends UIGraphic {
039: public static final String COMPONENT_TYPE = "javax.faces.HtmlGraphicImage";
040:
041: private static final HashMap<String, PropEnum> _propMap = new HashMap<String, PropEnum>();
042:
043: private String _alt;
044: private ValueExpression _altExpr;
045:
046: private String _dir;
047: private ValueExpression _dirExpr;
048:
049: private String _height;
050: private ValueExpression _heightExpr;
051:
052: private Boolean _ismap;
053: private ValueExpression _ismapExpr;
054:
055: private String _lang;
056: private ValueExpression _langExpr;
057:
058: private String _longdesc;
059: private ValueExpression _longdescExpr;
060:
061: private String _onclick;
062: private ValueExpression _onclickExpr;
063:
064: private String _ondblclick;
065: private ValueExpression _ondblclickExpr;
066:
067: private String _onkeydown;
068: private ValueExpression _onkeydownExpr;
069:
070: private String _onkeypress;
071: private ValueExpression _onkeypressExpr;
072:
073: private String _onkeyup;
074: private ValueExpression _onkeyupExpr;
075:
076: private String _onmousedown;
077: private ValueExpression _onmousedownExpr;
078:
079: private String _onmousemove;
080: private ValueExpression _onmousemoveExpr;
081:
082: private String _onmouseout;
083: private ValueExpression _onmouseoutExpr;
084:
085: private String _onmouseover;
086: private ValueExpression _onmouseoverExpr;
087:
088: private String _onmouseup;
089: private ValueExpression _onmouseupExpr;
090:
091: private String _style;
092: private ValueExpression _styleExpr;
093:
094: private String _styleClass;
095: private ValueExpression _styleClassExpr;
096:
097: private String _title;
098: private ValueExpression _titleExpr;
099:
100: private String _usemap;
101: private ValueExpression _usemapExpr;
102:
103: private String _width;
104: private ValueExpression _widthExpr;
105:
106: public HtmlGraphicImage() {
107: setRendererType("javax.faces.Image");
108: }
109:
110: //
111: // properties
112: //
113:
114: public String getAlt() {
115: if (_alt != null)
116: return _alt;
117: else if (_altExpr != null)
118: return Util.evalString(_altExpr);
119: else
120: return null;
121: }
122:
123: public void setAlt(String value) {
124: _alt = value;
125: }
126:
127: public String getDir() {
128: if (_dir != null)
129: return _dir;
130: else if (_dirExpr != null)
131: return Util.evalString(_dirExpr);
132: else
133: return null;
134: }
135:
136: public void setDir(String value) {
137: _dir = value;
138: }
139:
140: public String getHeight() {
141: if (_height != null)
142: return _height;
143: else if (_heightExpr != null)
144: return Util.evalString(_heightExpr);
145: else
146: return null;
147: }
148:
149: public void setHeight(String value) {
150: _height = value;
151: }
152:
153: public boolean isIsmap() {
154: if (_ismap != null)
155: return _ismap;
156: else if (_ismapExpr != null)
157: return Util.evalBoolean(_ismapExpr);
158: else
159: return false;
160: }
161:
162: public void setIsmap(boolean value) {
163: _ismap = value;
164: }
165:
166: public String getLang() {
167: if (_lang != null)
168: return _lang;
169: else if (_langExpr != null)
170: return Util.evalString(_langExpr);
171: else
172: return null;
173: }
174:
175: public void setLang(String value) {
176: _lang = value;
177: }
178:
179: public String getLongdesc() {
180: if (_longdesc != null)
181: return _longdesc;
182: else if (_longdescExpr != null)
183: return Util.evalString(_longdescExpr);
184: else
185: return null;
186: }
187:
188: public void setLongdesc(String value) {
189: _longdesc = value;
190: }
191:
192: public String getOnclick() {
193: if (_onclick != null)
194: return _onclick;
195: else if (_onclickExpr != null)
196: return Util.evalString(_onclickExpr);
197: else
198: return null;
199: }
200:
201: public void setOnclick(String value) {
202: _onclick = value;
203: }
204:
205: public String getOndblclick() {
206: if (_ondblclick != null)
207: return _ondblclick;
208: else if (_ondblclickExpr != null)
209: return Util.evalString(_ondblclickExpr);
210: else
211: return null;
212: }
213:
214: public void setOndblclick(String value) {
215: _ondblclick = value;
216: }
217:
218: public String getOnkeydown() {
219: if (_onkeydown != null)
220: return _onkeydown;
221: else if (_onkeydownExpr != null)
222: return Util.evalString(_onkeydownExpr);
223: else
224: return null;
225: }
226:
227: public void setOnkeydown(String value) {
228: _onkeydown = value;
229: }
230:
231: public String getOnkeypress() {
232: if (_onkeypress != null)
233: return _onkeypress;
234: else if (_onkeypressExpr != null)
235: return Util.evalString(_onkeypressExpr);
236: else
237: return null;
238: }
239:
240: public void setOnkeypress(String value) {
241: _onkeypress = value;
242: }
243:
244: public String getOnkeyup() {
245: if (_onkeyup != null)
246: return _onkeyup;
247: else if (_onkeyupExpr != null)
248: return Util.evalString(_onkeyupExpr);
249: else
250: return null;
251: }
252:
253: public void setOnkeyup(String value) {
254: _onkeyup = value;
255: }
256:
257: public String getOnmousedown() {
258: if (_onmousedown != null)
259: return _onmousedown;
260: else if (_onmousedownExpr != null)
261: return Util.evalString(_onmousedownExpr);
262: else
263: return null;
264: }
265:
266: public void setOnmousedown(String value) {
267: _onmousedown = value;
268: }
269:
270: public String getOnmousemove() {
271: if (_onmousemove != null)
272: return _onmousemove;
273: else if (_onmousemoveExpr != null)
274: return Util.evalString(_onmousemoveExpr);
275: else
276: return null;
277: }
278:
279: public void setOnmousemove(String value) {
280: _onmousemove = value;
281: }
282:
283: public String getOnmouseout() {
284: if (_onmouseout != null)
285: return _onmouseout;
286: else if (_onmouseoutExpr != null)
287: return Util.evalString(_onmouseoutExpr);
288: else
289: return null;
290: }
291:
292: public void setOnmouseout(String value) {
293: _onmouseout = value;
294: }
295:
296: public String getOnmouseover() {
297: if (_onmouseover != null)
298: return _onmouseover;
299: else if (_onmouseoverExpr != null)
300: return Util.evalString(_onmouseoverExpr);
301: else
302: return null;
303: }
304:
305: public void setOnmouseover(String value) {
306: _onmouseover = value;
307: }
308:
309: public String getOnmouseup() {
310: if (_onmouseup != null)
311: return _onmouseup;
312: else if (_onmouseupExpr != null)
313: return Util.evalString(_onmouseupExpr);
314: else
315: return null;
316: }
317:
318: public void setOnmouseup(String value) {
319: _onmouseup = value;
320: }
321:
322: public String getStyle() {
323: if (_style != null)
324: return _style;
325: else if (_styleExpr != null)
326: return Util.evalString(_styleExpr);
327: else
328: return null;
329: }
330:
331: public void setStyle(String value) {
332: _style = value;
333: }
334:
335: public String getStyleClass() {
336: if (_styleClass != null)
337: return _styleClass;
338: else if (_styleClassExpr != null)
339: return Util.evalString(_styleClassExpr);
340: else
341: return null;
342: }
343:
344: public void setStyleClass(String value) {
345: _styleClass = value;
346: }
347:
348: public String getTitle() {
349: if (_title != null)
350: return _title;
351: else if (_titleExpr != null)
352: return Util.evalString(_titleExpr);
353: else
354: return null;
355: }
356:
357: public void setTitle(String value) {
358: _title = value;
359: }
360:
361: public String getUsemap() {
362: if (_usemap != null)
363: return _usemap;
364: else if (_usemapExpr != null)
365: return Util.evalString(_usemapExpr);
366: else
367: return null;
368: }
369:
370: public void setUsemap(String value) {
371: _usemap = value;
372: }
373:
374: public String getWidth() {
375: if (_width != null)
376: return _width;
377: else if (_widthExpr != null)
378: return Util.evalString(_widthExpr);
379: else
380: return null;
381: }
382:
383: public void setWidth(String value) {
384: _width = value;
385: }
386:
387: //
388: // value expression override
389: //
390:
391: /**
392: * Returns the value expression with the given name.
393: */
394: @Override
395: public ValueExpression getValueExpression(String name) {
396: PropEnum prop = _propMap.get(name);
397:
398: if (prop != null) {
399: switch (prop) {
400: case ALT:
401: return _altExpr;
402: case DIR:
403: return _dirExpr;
404: case HEIGHT:
405: return _heightExpr;
406: case ISMAP:
407: return _ismapExpr;
408: case LANG:
409: return _langExpr;
410: case LONGDESC:
411: return _longdescExpr;
412: case ONCLICK:
413: return _onclickExpr;
414: case ONDBLCLICK:
415: return _ondblclickExpr;
416: case ONKEYDOWN:
417: return _onkeydownExpr;
418: case ONKEYPRESS:
419: return _onkeypressExpr;
420: case ONKEYUP:
421: return _onkeyupExpr;
422: case ONMOUSEDOWN:
423: return _onmousedownExpr;
424: case ONMOUSEMOVE:
425: return _onmousemoveExpr;
426: case ONMOUSEOUT:
427: return _onmouseoutExpr;
428: case ONMOUSEOVER:
429: return _onmouseoverExpr;
430: case ONMOUSEUP:
431: return _onmouseupExpr;
432: case STYLE:
433: return _styleExpr;
434: case STYLE_CLASS:
435: return _styleClassExpr;
436: case TITLE:
437: return _titleExpr;
438: case USEMAP:
439: return _usemapExpr;
440: case WIDTH:
441: return _widthExpr;
442: }
443: }
444:
445: return super .getValueExpression(name);
446: }
447:
448: /**
449: * Sets the value expression with the given name.
450: */
451: @Override
452: public void setValueExpression(String name, ValueExpression expr) {
453: PropEnum prop = _propMap.get(name);
454:
455: if (prop != null) {
456: switch (prop) {
457: case ALT:
458: if (expr != null && expr.isLiteralText()) {
459: _alt = Util.evalString(expr);
460: return;
461: } else
462: _altExpr = expr;
463: break;
464:
465: case DIR:
466: if (expr != null && expr.isLiteralText()) {
467: _dir = Util.evalString(expr);
468: return;
469: } else
470: _dirExpr = expr;
471: break;
472:
473: case HEIGHT:
474: if (expr != null && expr.isLiteralText()) {
475: _height = Util.evalString(expr);
476: return;
477: } else
478: _heightExpr = expr;
479: break;
480:
481: case ISMAP:
482: if (expr != null && expr.isLiteralText()) {
483: _ismap = Util.evalBoolean(expr);
484: return;
485: } else
486: _ismapExpr = expr;
487: break;
488:
489: case LANG:
490: if (expr != null && expr.isLiteralText()) {
491: _lang = Util.evalString(expr);
492: return;
493: } else
494: _langExpr = expr;
495: break;
496:
497: case LONGDESC:
498: if (expr != null && expr.isLiteralText()) {
499: _longdesc = Util.evalString(expr);
500: return;
501: } else
502: _longdescExpr = expr;
503: break;
504:
505: case ONCLICK:
506: if (expr != null && expr.isLiteralText()) {
507: _onclick = Util.evalString(expr);
508: return;
509: } else
510: _onclickExpr = expr;
511: break;
512:
513: case ONDBLCLICK:
514: if (expr != null && expr.isLiteralText()) {
515: _ondblclick = Util.evalString(expr);
516: return;
517: } else
518: _ondblclickExpr = expr;
519: break;
520:
521: case ONKEYDOWN:
522: if (expr != null && expr.isLiteralText()) {
523: _onkeydown = Util.evalString(expr);
524: return;
525: } else
526: _onkeydownExpr = expr;
527: break;
528:
529: case ONKEYPRESS:
530: if (expr != null && expr.isLiteralText()) {
531: _onkeypress = Util.evalString(expr);
532: return;
533: } else
534: _onkeypressExpr = expr;
535: break;
536:
537: case ONKEYUP:
538: if (expr != null && expr.isLiteralText()) {
539: _onkeyup = Util.evalString(expr);
540: return;
541: } else
542: _onkeyupExpr = expr;
543: break;
544:
545: case ONMOUSEDOWN:
546: if (expr != null && expr.isLiteralText()) {
547: _onmousedown = Util.evalString(expr);
548: return;
549: } else
550: _onmousedownExpr = expr;
551: break;
552:
553: case ONMOUSEMOVE:
554: if (expr != null && expr.isLiteralText()) {
555: _onmousemove = Util.evalString(expr);
556: return;
557: } else
558: _onmousemoveExpr = expr;
559: break;
560:
561: case ONMOUSEOUT:
562: if (expr != null && expr.isLiteralText()) {
563: _onmouseout = Util.evalString(expr);
564: return;
565: } else
566: _onmouseoutExpr = expr;
567: break;
568:
569: case ONMOUSEOVER:
570: if (expr != null && expr.isLiteralText()) {
571: _onmouseover = Util.evalString(expr);
572: return;
573: } else
574: _onmouseoverExpr = expr;
575: break;
576:
577: case ONMOUSEUP:
578: if (expr != null && expr.isLiteralText()) {
579: _onmouseup = Util.evalString(expr);
580: return;
581: } else
582: _onmouseupExpr = expr;
583: break;
584:
585: case STYLE:
586: if (expr != null && expr.isLiteralText()) {
587: _style = Util.evalString(expr);
588: return;
589: } else
590: _styleExpr = expr;
591: break;
592:
593: case STYLE_CLASS:
594: if (expr != null && expr.isLiteralText()) {
595: _styleClass = Util.evalString(expr);
596: return;
597: } else
598: _styleClassExpr = expr;
599: break;
600:
601: case TITLE:
602: if (expr != null && expr.isLiteralText()) {
603: _title = Util.evalString(expr);
604: return;
605: } else
606: _titleExpr = expr;
607: break;
608:
609: case USEMAP:
610: if (expr != null && expr.isLiteralText()) {
611: _usemap = Util.evalString(expr);
612: return;
613: } else
614: _usemapExpr = expr;
615: break;
616:
617: case WIDTH:
618: if (expr != null && expr.isLiteralText()) {
619: _width = Util.evalString(expr);
620: return;
621: } else
622: _widthExpr = expr;
623: break;
624: }
625: }
626:
627: super .setValueExpression(name, expr);
628: }
629:
630: //
631: // state
632: //
633:
634: public Object saveState(FacesContext context) {
635: Object parent = super .saveState(context);
636:
637: return new Object[] { parent, _alt, _dir, _height, _ismap,
638: _lang, _longdesc,
639:
640: _onclick, _ondblclick, _onkeydown, _onkeypress,
641: _onkeyup,
642:
643: _onmousedown, _onmousemove, _onmouseout, _onmouseover,
644: _onmouseup,
645:
646: _style, _styleClass, _title, _usemap, _width, };
647: }
648:
649: public void restoreState(FacesContext context, Object value) {
650: Object[] state = (Object[]) value;
651:
652: int i = 0;
653:
654: if (state != null)
655: super .restoreState(context, state[i++]);
656:
657: _alt = (String) state[i++];
658: _dir = (String) state[i++];
659: _height = (String) state[i++];
660: _ismap = (Boolean) state[i++];
661: _lang = (String) state[i++];
662: _longdesc = (String) state[i++];
663: _onclick = (String) state[i++];
664: _ondblclick = (String) state[i++];
665: _onkeydown = (String) state[i++];
666: _onkeypress = (String) state[i++];
667: _onkeyup = (String) state[i++];
668: _onmousedown = (String) state[i++];
669: _onmousemove = (String) state[i++];
670: _onmouseout = (String) state[i++];
671: _onmouseover = (String) state[i++];
672: _onmouseup = (String) state[i++];
673: _style = (String) state[i++];
674: _styleClass = (String) state[i++];
675: _title = (String) state[i++];
676: _usemap = (String) state[i++];
677: _width = (String) state[i++];
678: }
679:
680: //
681: // utility
682: //
683:
684: private enum PropEnum {
685: ALT, DIR, HEIGHT, ISMAP, LANG, LONGDESC, ONCLICK, ONDBLCLICK, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEMOVE, ONMOUSEOUT, ONMOUSEOVER, ONMOUSEUP, STYLE, STYLE_CLASS, TITLE, USEMAP, WIDTH,
686: }
687:
688: static {
689: _propMap.put("alt", PropEnum.ALT);
690: _propMap.put("dir", PropEnum.DIR);
691: _propMap.put("height", PropEnum.HEIGHT);
692: _propMap.put("ismap", PropEnum.ISMAP);
693: _propMap.put("lang", PropEnum.LANG);
694: _propMap.put("longdesc", PropEnum.LONGDESC);
695: _propMap.put("onclick", PropEnum.ONCLICK);
696: _propMap.put("ondblclick", PropEnum.ONDBLCLICK);
697: _propMap.put("onkeydown", PropEnum.ONKEYDOWN);
698: _propMap.put("onkeypress", PropEnum.ONKEYPRESS);
699: _propMap.put("onkeyup", PropEnum.ONKEYUP);
700: _propMap.put("onmousedown", PropEnum.ONMOUSEDOWN);
701: _propMap.put("onmousemove", PropEnum.ONMOUSEMOVE);
702: _propMap.put("onmouseover", PropEnum.ONMOUSEOVER);
703: _propMap.put("onmouseout", PropEnum.ONMOUSEOUT);
704: _propMap.put("onmouseup", PropEnum.ONMOUSEUP);
705: _propMap.put("style", PropEnum.STYLE);
706: _propMap.put("styleClass", PropEnum.STYLE_CLASS);
707: _propMap.put("title", PropEnum.TITLE);
708: _propMap.put("usemap", PropEnum.USEMAP);
709: _propMap.put("width", PropEnum.WIDTH);
710: }
711: }
|