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;
030:
031: import java.util.*;
032:
033: import javax.el.*;
034: import javax.faces.context.*;
035:
036: public class UIGraphic extends UIComponentBase {
037: public static final String COMPONENT_FAMILY = "javax.faces.Graphic";
038: public static final String COMPONENT_TYPE = "javax.faces.Graphic";
039:
040: private static final HashMap<String, PropEnum> _propMap = new HashMap<String, PropEnum>();
041:
042: private String _url;
043: private ValueExpression _urlExpr;
044:
045: private boolean _isSubmitted;
046:
047: public UIGraphic() {
048: setRendererType("javax.faces.Image");
049: }
050:
051: /**
052: * Returns the component family, used to select the renderer.
053: */
054: public String getFamily() {
055: return COMPONENT_FAMILY;
056: }
057:
058: //
059: // properties
060: //
061:
062: public String getUrl() {
063: if (_url != null)
064: return _url;
065: else if (_urlExpr != null)
066: return Util.evalString(_urlExpr, getFacesContext());
067: else
068: return null;
069: }
070:
071: public void setUrl(String url) {
072: _url = url;
073: }
074:
075: public Object getValue() {
076: if (_url != null)
077: return _url;
078: else if (_urlExpr != null)
079: return Util.eval(_urlExpr, getFacesContext());
080: else
081: return null;
082: }
083:
084: public void setValue(Object url) {
085: _url = (String) url;
086: }
087:
088: /**
089: * Returns the value expression with the given name.
090: */
091: @Override
092: public ValueExpression getValueExpression(String name) {
093: PropEnum prop = _propMap.get(name);
094:
095: if (prop != null) {
096: switch (_propMap.get(name)) {
097: case URL:
098: case VALUE:
099: return _urlExpr;
100: }
101: }
102:
103: return super .getValueExpression(name);
104: }
105:
106: /**
107: * Sets the value expression with the given name.
108: */
109: @Override
110: public void setValueExpression(String name, ValueExpression expr) {
111: PropEnum prop = _propMap.get(name);
112:
113: if (prop != null) {
114: switch (prop) {
115: case URL:
116: case VALUE:
117: if (expr != null && expr.isLiteralText()) {
118: _url = (String) expr.getValue(null);
119: return;
120: } else
121: _urlExpr = expr;
122: break;
123: }
124: }
125:
126: super .setValueExpression(name, expr);
127: }
128:
129: //
130: // state
131: //
132:
133: @Override
134: public Object saveState(FacesContext context) {
135: return new Object[] { super .saveState(context), _url, };
136: }
137:
138: @Override
139: public void restoreState(FacesContext context, Object value) {
140: Object[] state = (Object[]) value;
141:
142: super .restoreState(context, state[0]);
143:
144: _url = (String) state[1];
145: }
146:
147: //
148: // private helpers
149: //
150:
151: private static enum PropEnum {
152: URL, VALUE,
153: }
154:
155: static {
156: _propMap.put("url", PropEnum.URL);
157: _propMap.put("value", PropEnum.VALUE);
158: }
159: }
|