KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > taglib > UIComponentBodyTagBase


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.taglib;
17
18 import org.apache.myfaces.renderkit.JSFAttr;
19 import org.apache.myfaces.renderkit.RendererUtils;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.webapp.UIComponentBodyTag;
26 import javax.servlet.jsp.JspException JavaDoc;
27 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.Reader JavaDoc;
30
31 /**
32  * @author Manfred Geiler (latest modification by $Author: mmarinschek $)
33  * @version $Revision: 1.15 $ $Date: 2005/03/05 10:29:56 $
34  * $Log: UIComponentBodyTagBase.java,v $
35  * Revision 1.15 2005/03/05 10:29:56 mmarinschek
36  * better error handling
37  *
38  * Revision 1.14 2005/01/30 15:24:10 matzew
39  * thanks to sean schofield for removing *legacy* attributes of MyFaces
40  *
41  * Revision 1.13 2005/01/28 17:19:09 matzew
42  * Patch for MYFACES-91 form Sean Schofield
43  *
44  * Revision 1.12 2005/01/25 22:15:53 matzew
45  * JavaDoc patch form Sean Schofield
46  *
47  * Revision 1.11 2005/01/10 08:08:12 matzew
48  * added patch form sean schofield. forceId for reuse of "legacy JavaScript" (MyFaces-70)
49  *
50  * Revision 1.10 2004/10/13 11:51:01 matze
51  * renamed packages to org.apache
52  *
53  * Revision 1.9 2004/07/01 22:01:21 mwessendorf
54  * ASF switch
55  *
56  * Revision 1.8 2004/04/16 15:13:33 manolito
57  * validator attribute support and MethodBinding invoke exception handling fixed
58  *
59  * Revision 1.7 2004/04/05 11:04:56 manolito
60  * setter for renderer type removed, no more default renderer type needed
61  *
62  * Revision 1.6 2004/04/01 13:18:39 manolito
63  * warning message
64  *
65  * Revision 1.5 2004/04/01 12:57:44 manolito
66  * additional extended component classes for user role support
67  *
68  * Revision 1.4 2004/04/01 09:33:43 manolito
69  * user role support removed
70  *
71  * Revision 1.3 2004/03/31 11:14:28 royalts
72  * no message
73  *
74  * Revision 1.2 2004/03/30 12:16:08 manolito
75  * header comments
76  *
77  */

78 public abstract class UIComponentBodyTagBase
79         extends UIComponentBodyTag
80 {
81     private static final Log log = LogFactory.getLog(UIComponentBodyTagBase.class);
82
83     public int doEndTag() throws JspException JavaDoc
84     {
85         if (log.isWarnEnabled())
86         {
87             UIComponent component = getComponentInstance();
88             if (component != null &&
89                 component.getRendersChildren() &&
90                 !isBodyContentEmpty())
91             {
92                 log.warn("Component with id '" + component.getClientId(getFacesContext()) +
93                          "' (" + getClass().getName() +
94                          " tag) and path : "+RendererUtils.getPathToComponent(component)+"renders it's children, but has embedded JSP or HTML code. Use the <f:verbatim> tag for nested HTML. For comments use <%/* */%> style JSP comments instead of <!-- --> style HTML comments." +
95                          "\n BodyContent:\n" + getBodyContent().getString().trim());
96             }
97         }
98         return super.doEndTag();
99     }
100
101     /**
102      * TODO: Ignore <!-- --> comments
103      */

104     private boolean isBodyContentEmpty()
105     {
106         BodyContent JavaDoc bodyContent = getBodyContent();
107         if (bodyContent == null)
108         {
109             return true;
110         }
111         try
112         {
113             Reader JavaDoc reader = bodyContent.getReader();
114             int c;
115             while ((c = reader.read()) != -1)
116             {
117                 if (!Character.isWhitespace((char)c))
118                 {
119                     return false;
120                 }
121             }
122             return true;
123         }
124         catch (IOException JavaDoc e)
125         {
126             log.error("Error inspecting BodyContent", e);
127             return false;
128         }
129     }
130
131     //-------- rest is identical to UIComponentTagBase ------------------
132

133     //UIComponent attributes
134
private String JavaDoc _forceId;
135     private String JavaDoc _forceIdIndex = "true";
136
137     //Special UIComponent attributes (ValueHolder, ConvertibleValueHolder)
138
private String JavaDoc _value;
139     private String JavaDoc _converter;
140     //attributes id, rendered and binding are handled by UIComponentTag
141

142     protected void setProperties(UIComponent component)
143     {
144         super.setProperties(component);
145
146         setBooleanProperty(component, JSFAttr.FORCE_ID_ATTR, _forceId);
147         setBooleanProperty(component, JSFAttr.FORCE_ID_INDEX_ATTR, _forceIdIndex);
148
149         //rendererType already handled by UIComponentTag
150

151         setValueProperty(component, _value);
152         setConverterProperty(component, _converter);
153     }
154
155     /**
156      * Sets the forceId attribute of the tag. NOTE: Not every tag that extends this class will
157      * actually make use of this attribute. Check the TLD to see which components actually
158      * implement it.
159      *
160      * @param aForceId The value of the forceId attribute.
161      */

162     public void setForceId(String JavaDoc aForceId)
163     {
164         _forceId = aForceId;
165     }
166
167     /**
168      * Sets the forceIdIndex attribute of the tag. NOTE: Not every tag that extends this class will
169      * actually make use of this attribute. Check the TLD to see which components actually implement it.
170      *
171      * @param aForceIdIndex The value of the forceIdIndex attribute.
172      */

173     public void setForceIdIndex(String JavaDoc aForceIdIndex)
174     {
175         _forceIdIndex = aForceIdIndex;
176     }
177
178     public void setValue(String JavaDoc value)
179     {
180         _value = value;
181     }
182
183     public void setConverter(String JavaDoc converter)
184     {
185         _converter = converter;
186     }
187
188
189
190     // sub class helpers
191

192     protected void setIntegerProperty(UIComponent component, String JavaDoc propName, String JavaDoc value)
193     {
194         UIComponentTagUtils.setIntegerProperty(getFacesContext(), component, propName, value);
195     }
196
197     protected void setStringProperty(UIComponent component, String JavaDoc propName, String JavaDoc value)
198     {
199         UIComponentTagUtils.setStringProperty(getFacesContext(), component, propName, value);
200     }
201
202     protected void setBooleanProperty(UIComponent component, String JavaDoc propName, String JavaDoc value)
203     {
204         UIComponentTagUtils.setBooleanProperty(getFacesContext(), component, propName, value);
205     }
206
207     protected void setValueProperty(UIComponent component, String JavaDoc value)
208     {
209         UIComponentTagUtils.setValueProperty(getFacesContext(), component, value);
210     }
211
212     private void setConverterProperty(UIComponent component, String JavaDoc value)
213     {
214         UIComponentTagUtils.setConverterProperty(getFacesContext(), component, value);
215     }
216
217     protected void setValidatorProperty(UIComponent component, String JavaDoc value)
218     {
219         UIComponentTagUtils.setValidatorProperty(getFacesContext(), component, value);
220     }
221     
222     protected void setActionProperty(UIComponent component, String JavaDoc action)
223     {
224         UIComponentTagUtils.setActionProperty(getFacesContext(), component, action);
225     }
226
227     protected void setActionListenerProperty(UIComponent component, String JavaDoc actionListener)
228     {
229         UIComponentTagUtils.setActionListenerProperty(getFacesContext(), component, actionListener);
230     }
231
232     protected void setValueChangedListenerProperty(UIComponent component, String JavaDoc valueChangedListener)
233     {
234         UIComponentTagUtils.setValueChangedListenerProperty(getFacesContext(), component, valueChangedListener);
235     }
236
237     protected void setValueBinding(UIComponent component,
238                                    String JavaDoc propName,
239                                    String JavaDoc value)
240     {
241         UIComponentTagUtils.setValueBinding(getFacesContext(), component, propName, value);
242     }
243
244 }
245
Popular Tags