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 HtmlOutputLink extends UIOutput {
039: public static final String COMPONENT_TYPE = "javax.faces.HtmlOutputLink";
040:
041: private static final HashMap<String, PropEnum> _propMap = new HashMap<String, PropEnum>();
042:
043: private String _accesskey;
044: private ValueExpression _accesskeyExpr;
045:
046: private String _charset;
047: private ValueExpression _charsetExpr;
048:
049: private String _coords;
050: private ValueExpression _coordsExpr;
051:
052: private String _dir;
053: private ValueExpression _dirExpr;
054:
055: private Boolean _disabled;
056: private ValueExpression _disabledExpr;
057:
058: private String _hreflang;
059: private ValueExpression _hreflangExpr;
060:
061: private String _lang;
062: private ValueExpression _langExpr;
063:
064: private String _onblur;
065: private ValueExpression _onblurExpr;
066:
067: private String _onclick;
068: private ValueExpression _onclickExpr;
069:
070: private String _ondblclick;
071: private ValueExpression _ondblclickExpr;
072:
073: private String _onfocus;
074: private ValueExpression _onfocusExpr;
075:
076: private String _onkeydown;
077: private ValueExpression _onkeydownExpr;
078:
079: private String _onkeypress;
080: private ValueExpression _onkeypressExpr;
081:
082: private String _onkeyup;
083: private ValueExpression _onkeyupExpr;
084:
085: private String _onmousedown;
086: private ValueExpression _onmousedownExpr;
087:
088: private String _onmousemove;
089: private ValueExpression _onmousemoveExpr;
090:
091: private String _onmouseout;
092: private ValueExpression _onmouseoutExpr;
093:
094: private String _onmouseover;
095: private ValueExpression _onmouseoverExpr;
096:
097: private String _onmouseup;
098: private ValueExpression _onmouseupExpr;
099:
100: private String _rel;
101: private ValueExpression _relExpr;
102:
103: private String _rev;
104: private ValueExpression _revExpr;
105:
106: private String _shape;
107: private ValueExpression _shapeExpr;
108:
109: private String _style;
110: private ValueExpression _styleExpr;
111:
112: private String _styleClass;
113: private ValueExpression _styleClassExpr;
114:
115: private String _tabindex;
116: private ValueExpression _tabindexExpr;
117:
118: private String _target;
119: private ValueExpression _targetExpr;
120:
121: private String _title;
122: private ValueExpression _titleExpr;
123:
124: private String _type;
125: private ValueExpression _typeExpr;
126:
127: public HtmlOutputLink() {
128: setRendererType("javax.faces.Link");
129: }
130:
131: //
132: // properties
133: //
134:
135: public String getAccesskey() {
136: if (_accesskey != null)
137: return _accesskey;
138: else if (_accesskeyExpr != null)
139: return Util.evalString(_accesskeyExpr);
140: else
141: return null;
142: }
143:
144: public void setAccesskey(String value) {
145: _accesskey = value;
146: }
147:
148: public String getCharset() {
149: if (_charset != null)
150: return _charset;
151: else if (_charsetExpr != null)
152: return Util.evalString(_charsetExpr);
153: else
154: return null;
155: }
156:
157: public void setCharset(String value) {
158: _charset = value;
159: }
160:
161: public String getDir() {
162: if (_dir != null)
163: return _dir;
164: else if (_dirExpr != null)
165: return Util.evalString(_dirExpr);
166: else
167: return null;
168: }
169:
170: public void setDir(String value) {
171: _dir = value;
172: }
173:
174: public boolean isDisabled() {
175: if (_disabled != null)
176: return _disabled;
177: else if (_disabledExpr != null)
178: return Util.evalBoolean(_disabledExpr);
179: else
180: return false;
181: }
182:
183: public void setDisabled(boolean value) {
184: _disabled = value;
185: }
186:
187: public String getCoords() {
188: if (_coords != null)
189: return _coords;
190: else if (_coordsExpr != null)
191: return Util.evalString(_coordsExpr);
192: else
193: return null;
194: }
195:
196: public void setCoords(String value) {
197: _coords = value;
198: }
199:
200: public String getHreflang() {
201: if (_hreflang != null)
202: return _hreflang;
203: else if (_hreflangExpr != null)
204: return Util.evalString(_hreflangExpr);
205: else
206: return null;
207: }
208:
209: public void setHreflang(String value) {
210: _hreflang = value;
211: }
212:
213: public String getLang() {
214: if (_lang != null)
215: return _lang;
216: else if (_langExpr != null)
217: return Util.evalString(_langExpr);
218: else
219: return null;
220: }
221:
222: public void setLang(String value) {
223: _lang = value;
224: }
225:
226: public String getOnblur() {
227: if (_onblur != null)
228: return _onblur;
229: else if (_onblurExpr != null)
230: return Util.evalString(_onblurExpr);
231: else
232: return null;
233: }
234:
235: public void setOnblur(String value) {
236: _onblur = value;
237: }
238:
239: public String getOnclick() {
240: if (_onclick != null)
241: return _onclick;
242: else if (_onclickExpr != null)
243: return Util.evalString(_onclickExpr);
244: else
245: return null;
246: }
247:
248: public void setOnclick(String value) {
249: _onclick = value;
250: }
251:
252: public String getOndblclick() {
253: if (_ondblclick != null)
254: return _ondblclick;
255: else if (_ondblclickExpr != null)
256: return Util.evalString(_ondblclickExpr);
257: else
258: return null;
259: }
260:
261: public void setOndblclick(String value) {
262: _ondblclick = value;
263: }
264:
265: public String getOnfocus() {
266: if (_onfocus != null)
267: return _onfocus;
268: else if (_onfocusExpr != null)
269: return Util.evalString(_onfocusExpr);
270: else
271: return null;
272: }
273:
274: public void setOnfocus(String value) {
275: _onfocus = value;
276: }
277:
278: public String getOnkeydown() {
279: if (_onkeydown != null)
280: return _onkeydown;
281: else if (_onkeydownExpr != null)
282: return Util.evalString(_onkeydownExpr);
283: else
284: return null;
285: }
286:
287: public void setOnkeydown(String value) {
288: _onkeydown = value;
289: }
290:
291: public String getOnkeypress() {
292: if (_onkeypress != null)
293: return _onkeypress;
294: else if (_onkeypressExpr != null)
295: return Util.evalString(_onkeypressExpr);
296: else
297: return null;
298: }
299:
300: public void setOnkeypress(String value) {
301: _onkeypress = value;
302: }
303:
304: public String getOnkeyup() {
305: if (_onkeyup != null)
306: return _onkeyup;
307: else if (_onkeyupExpr != null)
308: return Util.evalString(_onkeyupExpr);
309: else
310: return null;
311: }
312:
313: public void setOnkeyup(String value) {
314: _onkeyup = value;
315: }
316:
317: public String getOnmousedown() {
318: if (_onmousedown != null)
319: return _onmousedown;
320: else if (_onmousedownExpr != null)
321: return Util.evalString(_onmousedownExpr);
322: else
323: return null;
324: }
325:
326: public void setOnmousedown(String value) {
327: _onmousedown = value;
328: }
329:
330: public String getOnmousemove() {
331: if (_onmousemove != null)
332: return _onmousemove;
333: else if (_onmousemoveExpr != null)
334: return Util.evalString(_onmousemoveExpr);
335: else
336: return null;
337: }
338:
339: public void setOnmousemove(String value) {
340: _onmousemove = value;
341: }
342:
343: public String getOnmouseout() {
344: if (_onmouseout != null)
345: return _onmouseout;
346: else if (_onmouseoutExpr != null)
347: return Util.evalString(_onmouseoutExpr);
348: else
349: return null;
350: }
351:
352: public void setOnmouseout(String value) {
353: _onmouseout = value;
354: }
355:
356: public String getOnmouseover() {
357: if (_onmouseover != null)
358: return _onmouseover;
359: else if (_onmouseoverExpr != null)
360: return Util.evalString(_onmouseoverExpr);
361: else
362: return null;
363: }
364:
365: public void setOnmouseover(String value) {
366: _onmouseover = value;
367: }
368:
369: public String getOnmouseup() {
370: if (_onmouseup != null)
371: return _onmouseup;
372: else if (_onmouseupExpr != null)
373: return Util.evalString(_onmouseupExpr);
374: else
375: return null;
376: }
377:
378: public void setOnmouseup(String value) {
379: _onmouseup = value;
380: }
381:
382: public String getRel() {
383: if (_rel != null)
384: return _rel;
385: else if (_relExpr != null)
386: return Util.evalString(_relExpr);
387: else
388: return null;
389: }
390:
391: public void setRel(String value) {
392: _rel = value;
393: }
394:
395: public String getRev() {
396: if (_rev != null)
397: return _rev;
398: else if (_revExpr != null)
399: return Util.evalString(_revExpr);
400: else
401: return null;
402: }
403:
404: public void setRev(String value) {
405: _rev = value;
406: }
407:
408: public String getShape() {
409: if (_shape != null)
410: return _shape;
411: else if (_shapeExpr != null)
412: return Util.evalString(_shapeExpr);
413: else
414: return null;
415: }
416:
417: public void setShape(String value) {
418: _shape = value;
419: }
420:
421: public String getStyle() {
422: if (_style != null)
423: return _style;
424: else if (_styleExpr != null)
425: return Util.evalString(_styleExpr);
426: else
427: return null;
428: }
429:
430: public void setStyle(String value) {
431: _style = value;
432: }
433:
434: public String getStyleClass() {
435: if (_styleClass != null)
436: return _styleClass;
437: else if (_styleClassExpr != null)
438: return Util.evalString(_styleClassExpr);
439: else
440: return null;
441: }
442:
443: public void setStyleClass(String value) {
444: _styleClass = value;
445: }
446:
447: public String getTabindex() {
448: if (_tabindex != null)
449: return _tabindex;
450: else if (_tabindexExpr != null)
451: return Util.evalString(_tabindexExpr);
452: else
453: return null;
454: }
455:
456: public void setTabindex(String value) {
457: _tabindex = value;
458: }
459:
460: public String getTarget() {
461: if (_target != null)
462: return _target;
463: else if (_targetExpr != null)
464: return Util.evalString(_targetExpr);
465: else
466: return null;
467: }
468:
469: public void setTarget(String value) {
470: _target = value;
471: }
472:
473: public String getTitle() {
474: if (_title != null)
475: return _title;
476: else if (_titleExpr != null)
477: return Util.evalString(_titleExpr);
478: else
479: return null;
480: }
481:
482: public void setTitle(String value) {
483: _title = value;
484: }
485:
486: public String getType() {
487: if (_type != null)
488: return _type;
489: else if (_typeExpr != null)
490: return Util.evalString(_typeExpr);
491: else
492: return null;
493: }
494:
495: public void setType(String value) {
496: _type = value;
497: }
498:
499: //
500: // value expression override
501: //
502:
503: /**
504: * Returns the value expression with the given name.
505: */
506: @Override
507: public ValueExpression getValueExpression(String name) {
508: PropEnum prop = _propMap.get(name);
509:
510: if (prop != null) {
511: switch (prop) {
512: case ACCESSKEY:
513: return _accesskeyExpr;
514: case CHARSET:
515: return _charsetExpr;
516: case COORDS:
517: return _coordsExpr;
518: case DIR:
519: return _dirExpr;
520: case DISABLED:
521: return _disabledExpr;
522: case HREFLANG:
523: return _hreflangExpr;
524: case LANG:
525: return _langExpr;
526: case ONBLUR:
527: return _onblurExpr;
528: case ONCLICK:
529: return _onclickExpr;
530: case ONDBLCLICK:
531: return _ondblclickExpr;
532: case ONFOCUS:
533: return _onfocusExpr;
534: case ONKEYDOWN:
535: return _onkeydownExpr;
536: case ONKEYPRESS:
537: return _onkeypressExpr;
538: case ONKEYUP:
539: return _onkeyupExpr;
540: case ONMOUSEDOWN:
541: return _onmousedownExpr;
542: case ONMOUSEMOVE:
543: return _onmousemoveExpr;
544: case ONMOUSEOUT:
545: return _onmouseoutExpr;
546: case ONMOUSEOVER:
547: return _onmouseoverExpr;
548: case ONMOUSEUP:
549: return _onmouseupExpr;
550: case REL:
551: return _relExpr;
552: case REV:
553: return _revExpr;
554: case SHAPE:
555: return _shapeExpr;
556: case STYLE:
557: return _styleExpr;
558: case STYLE_CLASS:
559: return _styleClassExpr;
560: case TABINDEX:
561: return _tabindexExpr;
562: case TARGET:
563: return _targetExpr;
564: case TITLE:
565: return _titleExpr;
566: case TYPE:
567: return _typeExpr;
568: }
569: }
570:
571: return super .getValueExpression(name);
572: }
573:
574: /**
575: * Sets the value expression with the given name.
576: */
577: @Override
578: public void setValueExpression(String name, ValueExpression expr) {
579: PropEnum prop = _propMap.get(name);
580:
581: if (prop != null) {
582: switch (prop) {
583: case ACCESSKEY:
584: if (expr != null && expr.isLiteralText()) {
585: _accesskey = Util.evalString(expr);
586: return;
587: } else
588: _accesskeyExpr = expr;
589: break;
590:
591: case CHARSET:
592: if (expr != null && expr.isLiteralText()) {
593: _charset = Util.evalString(expr);
594: return;
595: } else
596: _charsetExpr = expr;
597: break;
598:
599: case COORDS:
600: if (expr != null && expr.isLiteralText()) {
601: _coords = Util.evalString(expr);
602: return;
603: } else
604: _coordsExpr = expr;
605: break;
606:
607: case DIR:
608: if (expr != null && expr.isLiteralText()) {
609: _dir = Util.evalString(expr);
610: return;
611: } else
612: _dirExpr = expr;
613: break;
614:
615: case DISABLED:
616: if (expr != null && expr.isLiteralText()) {
617: _disabled = Util.evalBoolean(expr);
618: return;
619: } else
620: _disabledExpr = expr;
621: break;
622:
623: case HREFLANG:
624: if (expr != null && expr.isLiteralText()) {
625: _hreflang = Util.evalString(expr);
626: return;
627: } else
628: _hreflangExpr = expr;
629: break;
630:
631: case LANG:
632: if (expr != null && expr.isLiteralText()) {
633: _lang = Util.evalString(expr);
634: return;
635: } else
636: _langExpr = expr;
637: break;
638:
639: case ONBLUR:
640: if (expr != null && expr.isLiteralText()) {
641: _onblur = Util.evalString(expr);
642: return;
643: } else
644: _onblurExpr = expr;
645: break;
646:
647: case ONCLICK:
648: if (expr != null && expr.isLiteralText()) {
649: _onclick = Util.evalString(expr);
650: return;
651: } else
652: _onclickExpr = expr;
653: break;
654:
655: case ONDBLCLICK:
656: if (expr != null && expr.isLiteralText()) {
657: _ondblclick = Util.evalString(expr);
658: return;
659: } else
660: _ondblclickExpr = expr;
661: break;
662:
663: case ONFOCUS:
664: if (expr != null && expr.isLiteralText()) {
665: _onfocus = Util.evalString(expr);
666: return;
667: } else
668: _onfocusExpr = expr;
669: break;
670:
671: case ONKEYDOWN:
672: if (expr != null && expr.isLiteralText()) {
673: _onkeydown = Util.evalString(expr);
674: return;
675: } else
676: _onkeydownExpr = expr;
677: break;
678:
679: case ONKEYPRESS:
680: if (expr != null && expr.isLiteralText()) {
681: _onkeypress = Util.evalString(expr);
682: return;
683: } else
684: _onkeypressExpr = expr;
685: break;
686:
687: case ONKEYUP:
688: if (expr != null && expr.isLiteralText()) {
689: _onkeyup = Util.evalString(expr);
690: return;
691: } else
692: _onkeyupExpr = expr;
693: break;
694:
695: case ONMOUSEDOWN:
696: if (expr != null && expr.isLiteralText()) {
697: _onmousedown = Util.evalString(expr);
698: return;
699: } else
700: _onmousedownExpr = expr;
701: break;
702:
703: case ONMOUSEMOVE:
704: if (expr != null && expr.isLiteralText()) {
705: _onmousemove = Util.evalString(expr);
706: return;
707: } else
708: _onmousemoveExpr = expr;
709: break;
710:
711: case ONMOUSEOUT:
712: if (expr != null && expr.isLiteralText()) {
713: _onmouseout = Util.evalString(expr);
714: return;
715: } else
716: _onmouseoutExpr = expr;
717: break;
718:
719: case ONMOUSEOVER:
720: if (expr != null && expr.isLiteralText()) {
721: _onmouseover = Util.evalString(expr);
722: return;
723: } else
724: _onmouseoverExpr = expr;
725: break;
726:
727: case ONMOUSEUP:
728: if (expr != null && expr.isLiteralText()) {
729: _onmouseup = Util.evalString(expr);
730: return;
731: } else
732: _onmouseupExpr = expr;
733: break;
734:
735: case REL:
736: if (expr != null && expr.isLiteralText()) {
737: _rel = Util.evalString(expr);
738: return;
739: } else
740: _relExpr = expr;
741: break;
742:
743: case REV:
744: if (expr != null && expr.isLiteralText()) {
745: _rev = Util.evalString(expr);
746: return;
747: } else
748: _revExpr = expr;
749: break;
750:
751: case SHAPE:
752: if (expr != null && expr.isLiteralText()) {
753: _shape = Util.evalString(expr);
754: return;
755: } else
756: _shapeExpr = expr;
757: break;
758:
759: case STYLE:
760: if (expr != null && expr.isLiteralText()) {
761: _style = Util.evalString(expr);
762: return;
763: } else
764: _styleExpr = expr;
765: break;
766:
767: case STYLE_CLASS:
768: if (expr != null && expr.isLiteralText()) {
769: _styleClass = Util.evalString(expr);
770: return;
771: } else
772: _styleClassExpr = expr;
773: break;
774:
775: case TABINDEX:
776: if (expr != null && expr.isLiteralText()) {
777: _tabindex = Util.evalString(expr);
778: return;
779: } else
780: _tabindexExpr = expr;
781: break;
782:
783: case TARGET:
784: if (expr != null && expr.isLiteralText()) {
785: _target = Util.evalString(expr);
786: return;
787: } else
788: _targetExpr = expr;
789: break;
790:
791: case TITLE:
792: if (expr != null && expr.isLiteralText()) {
793: _title = Util.evalString(expr);
794: return;
795: } else
796: _titleExpr = expr;
797: break;
798:
799: case TYPE:
800: if (expr != null && expr.isLiteralText()) {
801: _type = Util.evalString(expr);
802: return;
803: } else
804: _typeExpr = expr;
805: break;
806: }
807: }
808:
809: super .setValueExpression(name, expr);
810: }
811:
812: //
813: // state
814: //
815:
816: public Object saveState(FacesContext context) {
817: Object parent = super .saveState(context);
818:
819: return new Object[] { parent,
820:
821: _accesskey, _charset, _coords, _dir, _disabled, _hreflang,
822: _lang,
823:
824: _onblur, _onclick, _ondblclick, _onfocus,
825:
826: _onkeydown, _onkeypress, _onkeyup,
827:
828: _onmousedown, _onmousemove, _onmouseout, _onmouseover,
829: _onmouseup,
830:
831: _rel, _rev, _shape, _style, _styleClass, _tabindex,
832: _target, _title, _type, };
833: }
834:
835: public void restoreState(FacesContext context, Object value) {
836: Object[] state = (Object[]) value;
837:
838: int i = 0;
839:
840: if (state != null)
841: super .restoreState(context, state[i++]);
842:
843: _accesskey = (String) state[i++];
844: _charset = (String) state[i++];
845: _coords = (String) state[i++];
846: _dir = (String) state[i++];
847: _disabled = (Boolean) state[i++];
848: _hreflang = (String) state[i++];
849: _lang = (String) state[i++];
850: _onblur = (String) state[i++];
851: _onclick = (String) state[i++];
852: _ondblclick = (String) state[i++];
853: _onfocus = (String) state[i++];
854: _onkeydown = (String) state[i++];
855: _onkeypress = (String) state[i++];
856: _onkeyup = (String) state[i++];
857: _onmousedown = (String) state[i++];
858: _onmousemove = (String) state[i++];
859: _onmouseout = (String) state[i++];
860: _onmouseover = (String) state[i++];
861: _onmouseup = (String) state[i++];
862: _rel = (String) state[i++];
863: _rev = (String) state[i++];
864: _shape = (String) state[i++];
865: _style = (String) state[i++];
866: _styleClass = (String) state[i++];
867: _tabindex = (String) state[i++];
868: _target = (String) state[i++];
869: _title = (String) state[i++];
870: _type = (String) state[i++];
871: }
872:
873: //
874: // utility
875: //
876:
877: private enum PropEnum {
878: ACCESSKEY, CHARSET, COORDS, DIR, DISABLED, HREFLANG, LANG, ONBLUR, ONCLICK, ONDBLCLICK, ONFOCUS, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEMOVE, ONMOUSEOUT, ONMOUSEOVER, ONMOUSEUP, REL, REV, SHAPE, STYLE, STYLE_CLASS, TABINDEX, TARGET, TITLE, TYPE,
879: }
880:
881: static {
882: _propMap.put("accesskey", PropEnum.ACCESSKEY);
883: _propMap.put("charset", PropEnum.CHARSET);
884: _propMap.put("coords", PropEnum.COORDS);
885: _propMap.put("dir", PropEnum.DIR);
886: _propMap.put("disabled", PropEnum.DISABLED);
887: _propMap.put("hreflang", PropEnum.HREFLANG);
888: _propMap.put("lang", PropEnum.LANG);
889: _propMap.put("onblur", PropEnum.ONBLUR);
890: _propMap.put("onclick", PropEnum.ONCLICK);
891: _propMap.put("ondblclick", PropEnum.ONDBLCLICK);
892: _propMap.put("onfocus", PropEnum.ONFOCUS);
893: _propMap.put("onkeydown", PropEnum.ONKEYDOWN);
894: _propMap.put("onkeypress", PropEnum.ONKEYPRESS);
895: _propMap.put("onkeyup", PropEnum.ONKEYUP);
896: _propMap.put("onmousedown", PropEnum.ONMOUSEDOWN);
897: _propMap.put("onmousemove", PropEnum.ONMOUSEMOVE);
898: _propMap.put("onmouseover", PropEnum.ONMOUSEOVER);
899: _propMap.put("onmouseout", PropEnum.ONMOUSEOUT);
900: _propMap.put("onmouseup", PropEnum.ONMOUSEUP);
901: _propMap.put("rel", PropEnum.REL);
902: _propMap.put("rev", PropEnum.REV);
903: _propMap.put("shape", PropEnum.SHAPE);
904: _propMap.put("style", PropEnum.STYLE);
905: _propMap.put("styleClass", PropEnum.STYLE_CLASS);
906: _propMap.put("tabindex", PropEnum.TABINDEX);
907: _propMap.put("target", PropEnum.TARGET);
908: _propMap.put("title", PropEnum.TITLE);
909: _propMap.put("type", PropEnum.TYPE);
910: }
911: }
|