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.taglib.core;
20  
21  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspAttribute;
22  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspTag;
23  import org.apache.myfaces.shared.renderkit.JSFAttr;
24  import org.apache.myfaces.shared.taglib.UIComponentELTagBase;
25  
26  import javax.el.ValueExpression;
27  import javax.faces.component.UIComponent;
28  import javax.faces.component.UIOutput;
29  import javax.servlet.jsp.JspException;
30  import javax.servlet.jsp.tagext.BodyContent;
31  
32  /**
33   * @author Manfred Geiler (latest modification by $Author$)
34   * @version $Revision$ $Date$
35   */
36  @JSFJspTag(name = "f:verbatim", bodyContent = "JSP")
37  public class VerbatimTag extends UIComponentELTagBase
38  {
39      // private static final Log log = LogFactory.getLog(VerbatimTag.class);
40  
41      @Override
42      public String getComponentType()
43      {
44          return "javax.faces.Output";
45      }
46  
47      @Override
48      public String getRendererType()
49      {
50          return "javax.faces.Text";
51      }
52  
53      // HtmlOutputText attributes
54      private ValueExpression _escape;
55      private ValueExpression _rendered;
56  
57      @Override
58      protected void setProperties(UIComponent component)
59      {
60          super.setProperties(component);
61  
62          setBooleanProperty(component, JSFAttr.ESCAPE_ATTR, _escape, Boolean.FALSE);
63          setBooleanProperty(component, JSFAttr.RENDERED, _rendered, Boolean.TRUE);
64  
65          // No need to save component state
66          component.setTransient(true);
67      }
68  
69      /**
70       * If true, generated markup is escaped. Default: false.
71       */
72      @JSFJspAttribute(className="javax.el.ValueExpression",
73              deferredValueType="java.lang.Boolean")
74      public void setEscape(ValueExpression escape)
75      {
76          _escape = escape;
77      }
78  
79      /**
80       * Flag indicating whether or not this component should be rendered (during Render Response Phase), or processed on
81       * any subsequent form submit. The default value for this property is true.
82       */
83      @Override
84      @JSFJspAttribute(className="javax.el.ValueExpression",
85              deferredValueType="java.lang.Boolean")
86      public void setRendered(ValueExpression rendered)
87      {
88          _rendered = rendered;
89      }
90  
91      @Override
92      public int doAfterBody() throws JspException
93      {
94          BodyContent bodyContent = getBodyContent();
95          if (bodyContent != null)
96          {
97              UIOutput component = (UIOutput)getComponentInstance();
98              component.setValue(bodyContent.getString());
99              bodyContent.clearBody();
100         }
101         return super.getDoAfterBodyValue();
102     }
103 }