View Javadoc

1   /*
2   Copyright (c) 2010, Chin Huang
3   All rights reserved.
4   
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions are met:
7   
8    * Redistributions of source code must retain the above copyright notice,
9      this list of conditions and the following disclaimer.
10   * Redistributions in binary form must reproduce the above copyright notice,
11     this list of conditions and the following disclaimer in the documentation
12     and/or other materials provided with the distribution.
13  
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25  
26  package org.appfuse.webapp.taglib;
27  
28  import javax.servlet.jsp.tagext.TagSupport;
29  import org.appfuse.webapp.jsp.EscapeXmlELResolver;
30  
31  /**
32   * Tag surrounds JSP code in which EL expressions should not be XML-escaped.
33   */
34  public class OutTag extends TagSupport {
35      private static final long serialVersionUID = 1L;
36  
37      private static final boolean ESCAPE_XML_DEFAULT = true;
38      private boolean escapeXml;
39      
40      public OutTag() {
41          release();
42      }
43      
44      public void setEscapeXml(boolean escapeXml) {
45          this.escapeXml = escapeXml;
46      }
47      
48      @Override
49      public int doStartTag() {
50          pageContext.setAttribute(
51                  EscapeXmlELResolver.ESCAPE_XML_ATTRIBUTE, escapeXml);
52          return EVAL_BODY_INCLUDE;
53      }
54      
55      @Override
56      public int doEndTag() {
57          pageContext.setAttribute(
58                  EscapeXmlELResolver.ESCAPE_XML_ATTRIBUTE, ESCAPE_XML_DEFAULT);
59          return EVAL_PAGE;
60      }
61      
62      @Override
63      public void release() {
64          escapeXml = ESCAPE_XML_DEFAULT;
65      }
66  }