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.context.*;
036: import javax.faces.component.*;
037:
038: public class HtmlOutputText extends UIOutput {
039: public static final String COMPONENT_TYPE = "javax.faces.HtmlOutputText";
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 _lang;
047: private ValueExpression _langExpr;
048:
049: private String _style;
050: private ValueExpression _styleExpr;
051:
052: private String _styleClass;
053: private ValueExpression _styleClassExpr;
054:
055: private String _title;
056: private ValueExpression _titleExpr;
057:
058: private Boolean _escape;
059: private ValueExpression _escapeExpr;
060:
061: public HtmlOutputText() {
062: setRendererType("javax.faces.Text");
063: }
064:
065: //
066: // properties
067: //
068:
069: public String getDir() {
070: if (_dir != null)
071: return _dir;
072: else if (_dirExpr != null)
073: return Util.evalString(_dirExpr);
074: else
075: return null;
076: }
077:
078: public void setDir(String dir) {
079: _dir = dir;
080: }
081:
082: public boolean isEscape() {
083: if (_escape != null)
084: return _escape;
085: else if (_escapeExpr != null)
086: return Util.evalBoolean(_escapeExpr);
087: else
088: return true;
089: }
090:
091: public void setEscape(boolean isEscape) {
092: _escape = isEscape;
093: }
094:
095: public String getLang() {
096: if (_lang != null)
097: return _lang;
098: else if (_langExpr != null)
099: return Util.evalString(_langExpr);
100: else
101: return null;
102: }
103:
104: public void setLang(String lang) {
105: _lang = lang;
106: }
107:
108: public String getStyle() {
109: if (_style != null)
110: return _style;
111: else if (_styleExpr != null)
112: return Util.evalString(_styleExpr);
113: else
114: return null;
115: }
116:
117: public void setStyle(String style) {
118: _style = style;
119: }
120:
121: public String getStyleClass() {
122: if (_styleClass != null)
123: return _styleClass;
124: else if (_styleClassExpr != null)
125: return Util.evalString(_styleClassExpr);
126: else
127: return null;
128: }
129:
130: public void setStyleClass(String styleClass) {
131: _styleClass = styleClass;
132: }
133:
134: public String getTitle() {
135: if (_title != null)
136: return _title;
137: else if (_titleExpr != null)
138: return Util.evalString(_titleExpr);
139: else
140: return null;
141: }
142:
143: public void setTitle(String title) {
144: _title = title;
145: }
146:
147: //
148: // value expression override
149: //
150:
151: /**
152: * Returns the value expression with the given name.
153: */
154: @Override
155: public ValueExpression getValueExpression(String name) {
156: PropEnum prop = _propMap.get(name);
157:
158: if (prop != null) {
159: switch (prop) {
160: case DIR:
161: return _dirExpr;
162: case ESCAPE:
163: return _escapeExpr;
164: case LANG:
165: return _langExpr;
166: case STYLE:
167: return _styleExpr;
168: case STYLE_CLASS:
169: return _styleClassExpr;
170: case TITLE:
171: return _titleExpr;
172: }
173: }
174:
175: return super .getValueExpression(name);
176: }
177:
178: /**
179: * Sets the value expression with the given name.
180: */
181: @Override
182: public void setValueExpression(String name, ValueExpression expr) {
183: PropEnum prop = _propMap.get(name);
184:
185: if (prop != null) {
186: switch (prop) {
187: case DIR:
188: if (expr != null && expr.isLiteralText()) {
189: _dir = Util.evalString(expr);
190: return;
191: } else
192: _dirExpr = expr;
193: break;
194:
195: case ESCAPE:
196: if (expr != null && expr.isLiteralText()) {
197: _escape = Util.evalBoolean(expr);
198: return;
199: } else
200: _escapeExpr = expr;
201: break;
202:
203: case LANG:
204: if (expr != null && expr.isLiteralText()) {
205: _lang = Util.evalString(expr);
206: return;
207: } else
208: _langExpr = expr;
209: break;
210:
211: case STYLE:
212: if (expr != null && expr.isLiteralText()) {
213: _style = Util.evalString(expr);
214: return;
215: } else
216: _styleExpr = expr;
217: break;
218:
219: case STYLE_CLASS:
220: if (expr != null && expr.isLiteralText()) {
221: _styleClass = Util.evalString(expr);
222: return;
223: } else
224: _styleClassExpr = expr;
225: break;
226:
227: case TITLE:
228: if (expr != null && expr.isLiteralText()) {
229: _title = Util.evalString(expr);
230: return;
231: } else
232: _titleExpr = expr;
233: break;
234: }
235: }
236:
237: super .setValueExpression(name, expr);
238: }
239:
240: //
241: // state
242: //
243:
244: public Object saveState(FacesContext context) {
245: Object parent = super .saveState(context);
246:
247: return new Object[] { parent, _dir, _escape, _lang, _style,
248: _styleClass, _title, };
249: }
250:
251: public void restoreState(FacesContext context, Object value) {
252: Object[] state = (Object[]) value;
253:
254: if (state != null)
255: super .restoreState(context, state[0]);
256:
257: _dir = (String) state[1];
258: _escape = (Boolean) state[2];
259: _lang = (String) state[3];
260: _style = (String) state[4];
261: _styleClass = (String) state[5];
262: _title = (String) state[6];
263: }
264:
265: //
266: // private impl
267: //
268:
269: private enum PropEnum {
270: DIR, ESCAPE, LANG, STYLE, STYLE_CLASS, TITLE,
271: }
272:
273: static {
274: _propMap.put("dir", PropEnum.DIR);
275: _propMap.put("escape", PropEnum.ESCAPE);
276: _propMap.put("lang", PropEnum.LANG);
277: _propMap.put("style", PropEnum.STYLE);
278: _propMap.put("styleClass", PropEnum.STYLE_CLASS);
279: _propMap.put("title", PropEnum.TITLE);
280: }
281: }
|