View Javadoc

1   package org.rcfaces.core.internal.taglib;
2   
3   import javax.faces.component.UIComponent;
4   import org.rcfaces.core.internal.component.Properties;
5   import org.rcfaces.core.component.TextComponent;
6   import javax.servlet.jsp.JspException;
7   import org.apache.commons.logging.LogFactory;
8   import javax.servlet.jsp.tagext.Tag;
9   import org.rcfaces.core.internal.tools.ListenersTools;
10  import javax.faces.context.FacesContext;
11  import javax.faces.application.Application;
12  import javax.el.ValueExpression;
13  import org.apache.commons.logging.Log;
14  import javax.faces.component.UIViewRoot;
15  import org.rcfaces.core.internal.tools.ListenersTools1_2;
16  import org.rcfaces.core.component.capability.ITextCapability;
17  
18  public class TextTag extends AbstractOutputTag implements Tag {
19  
20  
21  	private static final Log LOG=LogFactory.getLog(TextTag.class);
22  
23  	private ValueExpression text;
24  	private ValueExpression textDirection;
25  	private ValueExpression fontBold;
26  	private ValueExpression fontItalic;
27  	private ValueExpression fontName;
28  	private ValueExpression fontSize;
29  	private ValueExpression fontUnderline;
30  	private ValueExpression textAlignment;
31  	private ValueExpression accessKey;
32  	private ValueExpression forValue;
33  	private ValueExpression type;
34  	public String getComponentType() {
35  		return TextComponent.COMPONENT_TYPE;
36  	}
37  
38  	public final void setText(ValueExpression text) {
39  		this.text = text;
40  	}
41  
42  	public final void setTextDirection(ValueExpression textDirection) {
43  		this.textDirection = textDirection;
44  	}
45  
46  	public final void setFontBold(ValueExpression fontBold) {
47  		this.fontBold = fontBold;
48  	}
49  
50  	public final void setFontItalic(ValueExpression fontItalic) {
51  		this.fontItalic = fontItalic;
52  	}
53  
54  	public final void setFontName(ValueExpression fontName) {
55  		this.fontName = fontName;
56  	}
57  
58  	public final void setFontSize(ValueExpression fontSize) {
59  		this.fontSize = fontSize;
60  	}
61  
62  	public final void setFontUnderline(ValueExpression fontUnderline) {
63  		this.fontUnderline = fontUnderline;
64  	}
65  
66  	public final void setTextAlignment(ValueExpression textAlignment) {
67  		this.textAlignment = textAlignment;
68  	}
69  
70  	public final void setAccessKey(ValueExpression accessKey) {
71  		this.accessKey = accessKey;
72  	}
73  
74  	public final void setFor(ValueExpression forValue) {
75  		this.forValue = forValue;
76  	}
77  
78  	public final void setType(ValueExpression type) {
79  		this.type = type;
80  	}
81  
82  	protected void setProperties(UIComponent uiComponent) {
83  		if (LOG.isDebugEnabled()) {
84  			if (TextComponent.COMPONENT_TYPE==getComponentType()) {
85  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
86  			}
87  			LOG.debug("  text='"+text+"'");
88  			LOG.debug("  textDirection='"+textDirection+"'");
89  			LOG.debug("  fontBold='"+fontBold+"'");
90  			LOG.debug("  fontItalic='"+fontItalic+"'");
91  			LOG.debug("  fontName='"+fontName+"'");
92  			LOG.debug("  fontSize='"+fontSize+"'");
93  			LOG.debug("  fontUnderline='"+fontUnderline+"'");
94  			LOG.debug("  textAlignment='"+textAlignment+"'");
95  			LOG.debug("  accessKey='"+accessKey+"'");
96  			LOG.debug("  forValue='"+forValue+"'");
97  			LOG.debug("  type='"+type+"'");
98  		}
99  		if ((uiComponent instanceof TextComponent)==false) {
100 			if (uiComponent instanceof UIViewRoot) {
101 				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
102 			}
103 			throw new IllegalStateException("Component specified by tag is not instanceof of 'TextComponent'.");
104 		}
105 
106 		super.setProperties(uiComponent);
107 
108 		TextComponent component = (TextComponent) uiComponent;
109 		FacesContext facesContext = getFacesContext();
110 
111 		if (text != null) {
112 			if (text.isLiteralText()==false) {
113 				component.setValueExpression(Properties.TEXT, text);
114 
115 			} else {
116 				component.setText(text.getExpressionString());
117 			}
118 		}
119 
120 		if (textDirection != null) {
121 			if (textDirection.isLiteralText()==false) {
122 				component.setValueExpression(Properties.TEXT_DIRECTION, textDirection);
123 
124 			} else {
125 				component.setTextDirection(getInt(textDirection.getExpressionString()));
126 			}
127 		}
128 
129 		if (fontBold != null) {
130 			if (fontBold.isLiteralText()==false) {
131 				component.setValueExpression(Properties.FONT_BOLD, fontBold);
132 
133 			} else {
134 				component.setFontBold(getBoolean(fontBold.getExpressionString()));
135 			}
136 		}
137 
138 		if (fontItalic != null) {
139 			if (fontItalic.isLiteralText()==false) {
140 				component.setValueExpression(Properties.FONT_ITALIC, fontItalic);
141 
142 			} else {
143 				component.setFontItalic(getBoolean(fontItalic.getExpressionString()));
144 			}
145 		}
146 
147 		if (fontName != null) {
148 			if (fontName.isLiteralText()==false) {
149 				component.setValueExpression(Properties.FONT_NAME, fontName);
150 
151 			} else {
152 				component.setFontName(fontName.getExpressionString());
153 			}
154 		}
155 
156 		if (fontSize != null) {
157 			if (fontSize.isLiteralText()==false) {
158 				component.setValueExpression(Properties.FONT_SIZE, fontSize);
159 
160 			} else {
161 				component.setFontSize(fontSize.getExpressionString());
162 			}
163 		}
164 
165 		if (fontUnderline != null) {
166 			if (fontUnderline.isLiteralText()==false) {
167 				component.setValueExpression(Properties.FONT_UNDERLINE, fontUnderline);
168 
169 			} else {
170 				component.setFontUnderline(getBoolean(fontUnderline.getExpressionString()));
171 			}
172 		}
173 
174 		if (textAlignment != null) {
175 			if (textAlignment.isLiteralText()==false) {
176 				component.setValueExpression(Properties.TEXT_ALIGNMENT, textAlignment);
177 
178 			} else {
179 				component.setTextAlignment(textAlignment.getExpressionString());
180 			}
181 		}
182 
183 		if (accessKey != null) {
184 			if (accessKey.isLiteralText()==false) {
185 				component.setValueExpression(Properties.ACCESS_KEY, accessKey);
186 
187 			} else {
188 				component.setAccessKey(accessKey.getExpressionString());
189 			}
190 		}
191 
192 		if (forValue != null) {
193 			if (forValue.isLiteralText()==false) {
194 				component.setValueExpression(Properties.FOR, forValue);
195 
196 			} else {
197 				component.setFor(forValue.getExpressionString());
198 			}
199 		}
200 
201 		if (type != null) {
202 			if (type.isLiteralText()==false) {
203 				component.setValueExpression(Properties.TYPE, type);
204 
205 			} else {
206 				component.setType(type.getExpressionString());
207 			}
208 		}
209 	}
210 
211 	public void release() {
212 		text = null;
213 		textDirection = null;
214 		fontBold = null;
215 		fontItalic = null;
216 		fontName = null;
217 		fontSize = null;
218 		fontUnderline = null;
219 		textAlignment = null;
220 		accessKey = null;
221 		forValue = null;
222 		type = null;
223 
224 		super.release();
225 	}
226 
227 	protected int getDoStartValue() {
228 		return EVAL_BODY_BUFFERED;
229 	}
230 
231 	public int doEndTag() throws JspException {
232 		if (text == null && getBodyContent() != null) {
233 			String content = getBodyContent().getString();
234 			if (content != null && content.length() > 0) {
235 				content = content.trim();
236 				if (content.length() > 0) {
237 					if (LOG.isDebugEnabled()) {
238 						LOG.debug("  [body of tag] text='"+content+"'");
239 					}
240 					((ITextCapability)getComponentInstance()).setText(content);
241 				}
242 			}
243 		}
244 		return super.doEndTag();
245 	}
246 }