View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    * 
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   */
19  package org.apache.myfaces.shared.taglib;
20  
21  import org.apache.myfaces.shared.renderkit.JSFAttr;
22  import org.apache.myfaces.shared.taglib.html.HtmlCommandLinkELTagBase;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  import javax.faces.component.UIComponent;
28  import javax.faces.webapp.UIComponentBodyTag;
29  import javax.servlet.jsp.JspException;
30  import javax.servlet.jsp.tagext.BodyContent;
31  import java.io.IOException;
32  import java.io.Reader;
33  
34  /***
35   * @author Manfred Geiler (latest modification by $Author: cagatay $)
36   * @version $Revision: 606793 $ $Date: 2007-12-25 10:20:46 -0500 (Tue, 25 Dec 2007) $
37   * @deprecated use {@link UIComponentBodyELTagBase} instead
38   */
39  public abstract class UIComponentBodyTagBase
40          extends UIComponentBodyTag
41  {
42      private static final Log log = LogFactory.getLog(UIComponentBodyTagBase.class);
43  
44      public int doEndTag() throws JspException
45      {
46          if (log.isWarnEnabled())
47          {
48              UIComponent component = getComponentInstance();
49              if (component != null &&
50                  component.getRendersChildren() &&
51                  !isBodyContentEmpty())
52              {
53                  log.warn("Component with id '" + component.getClientId(getFacesContext()) +
54                           "' (" + getClass().getName() +
55                           " tag) and path : "+org.apache.myfaces.shared.renderkit.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." +
56                           "\n BodyContent:\n" + getBodyContent().getString().trim());
57              }
58          }
59          return super.doEndTag();
60      }
61  
62      /***
63       * TODO: Ignore <!-- --> comments
64       */
65      private boolean isBodyContentEmpty()
66      {
67          BodyContent bodyContent = getBodyContent();
68          if (bodyContent == null)
69          {
70              return true;
71          }
72          try
73          {
74              Reader reader = bodyContent.getReader();
75              int c;
76              while ((c = reader.read()) != -1)
77              {
78                  if (!Character.isWhitespace((char)c))
79                  {
80                      return false;
81                  }
82              }
83              return true;
84          }
85          catch (IOException e)
86          {
87              log.error("Error inspecting BodyContent", e);
88              return false;
89          }
90      }
91  
92      //-------- rest is identical to UIComponentTagBase ------------------
93  
94      //UIComponent attributes
95      private String _forceId;
96      private String _forceIdIndex = "true";
97  
98      //Special UIComponent attributes (ValueHolder, ConvertibleValueHolder)
99      private String _value;
100     private String _converter;
101     //attributes id, rendered and binding are handled by UIComponentTag
102 
103     protected void setProperties(UIComponent component)
104     {
105         super.setProperties(component);
106 
107         setBooleanProperty(component, JSFAttr.FORCE_ID_ATTR, _forceId);
108         setBooleanProperty(component, org.apache.myfaces.shared.renderkit.JSFAttr.FORCE_ID_INDEX_ATTR, _forceIdIndex);
109 
110         //rendererType already handled by UIComponentTag
111 
112         setValueProperty(component, _value);
113         setConverterProperty(component, _converter);
114     }
115 
116     /***
117      * Sets the forceId attribute of the tag.  NOTE: Not every tag that extends this class will
118      * actually make use of this attribute.  Check the TLD to see which components actually
119      * implement it.
120      *
121      * @param aForceId The value of the forceId attribute.
122      */
123     public void setForceId(String aForceId)
124     {
125         _forceId = aForceId;
126     }
127 
128     /***
129      * Sets the forceIdIndex attribute of the tag.  NOTE: Not every tag that extends this class will
130      * actually make use of this attribute.  Check the TLD to see which components actually implement it.
131      *
132      * @param aForceIdIndex The value of the forceIdIndex attribute.
133      */
134     public void setForceIdIndex(String aForceIdIndex)
135     {
136         _forceIdIndex = aForceIdIndex;
137     }
138 
139     public void setValue(String value)
140     {
141         _value = value;
142     }
143 
144     public void setConverter(String converter)
145     {
146         _converter = converter;
147     }
148 
149 
150 
151     // sub class helpers
152 
153     protected void setIntegerProperty(UIComponent component, String propName, String value)
154     {
155         UIComponentTagUtils.setIntegerProperty(getFacesContext(), component, propName, value);
156     }
157 
158     protected void setStringProperty(UIComponent component, String propName, String value)
159     {
160         UIComponentTagUtils.setStringProperty(getFacesContext(), component, propName, value);
161     }
162 
163     protected void setBooleanProperty(UIComponent component, String propName, String value)
164     {
165         UIComponentTagUtils.setBooleanProperty(getFacesContext(), component, propName, value);
166     }
167 
168     protected void setValueProperty(UIComponent component, String value)
169     {
170         UIComponentTagUtils.setValueProperty(getFacesContext(), component, value);
171     }
172 
173     private void setConverterProperty(UIComponent component, String value)
174     {
175         UIComponentTagUtils.setConverterProperty(getFacesContext(), component, value);
176     }
177 
178     protected void setValidatorProperty(UIComponent component, String value)
179     {
180         UIComponentTagUtils.setValidatorProperty(getFacesContext(), component, value);
181     }
182 
183     protected void setActionProperty(UIComponent component, String action)
184     {
185         UIComponentTagUtils.setActionProperty(getFacesContext(), component, action);
186     }
187 
188     protected void setActionListenerProperty(UIComponent component, String actionListener)
189     {
190         UIComponentTagUtils.setActionListenerProperty(getFacesContext(), component, actionListener);
191     }
192 
193     protected void setValueChangedListenerProperty(UIComponent component, String valueChangedListener)
194     {
195         UIComponentTagUtils.setValueChangedListenerProperty(getFacesContext(), component, valueChangedListener);
196     }
197 
198     protected void setValueBinding(UIComponent component,
199                                    String propName,
200                                    String value)
201     {
202         UIComponentTagUtils.setValueBinding(getFacesContext(), component, propName, value);
203     }
204 
205 }