KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > el > CoreOutTag


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jstl.el;
30
31 import com.caucho.el.Expr;
32 import com.caucho.jsp.BodyContentImpl;
33 import com.caucho.jsp.PageContextImpl;
34 import com.caucho.log.Log;
35
36 import javax.el.ELContext;
37 import javax.servlet.jsp.JspException JavaDoc;
38 import javax.servlet.jsp.JspWriter JavaDoc;
39 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
40 import java.util.logging.Level JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 public class CoreOutTag extends BodyTagSupport JavaDoc {
44   private static final Logger JavaDoc log = Log.open(CoreOutTag.class);
45   
46   private Expr _value;
47   private Expr _escapeXml;
48   private Expr _defaultValue;
49
50   /**
51    * Sets the JSP-EL expression value.
52    */

53   public void setValue(Expr value)
54   {
55     _value = value;
56   }
57
58   /**
59    * Sets true if XML should be escaped.
60    */

61   public void setEscapeXml(Expr value)
62   {
63     _escapeXml = value;
64   }
65
66   /**
67    * Sets the default value.
68    */

69   public void setDefault(Expr value)
70   {
71     _defaultValue = value;
72   }
73
74   /**
75    * Process the tag.
76    */

77   public int doStartTag()
78     throws JspException JavaDoc
79   {
80     try {
81       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
82       ELContext env = pageContext.getELContext();
83       
84       JspWriter JavaDoc out = pageContext.getOut();
85
86       boolean doEscape = (_escapeXml == null || _escapeXml.evalBoolean(env));
87       
88       if (! _value.print(out, env, doEscape)) {
89       }
90       else if (_defaultValue != null)
91         _defaultValue.print(out, env, doEscape);
92       else
93         return EVAL_BODY_BUFFERED;
94     } catch (Exception JavaDoc e) {
95       log.log(Level.WARNING, e.toString(), e);
96     }
97
98     return SKIP_BODY;
99   }
100
101   public int doEndTag() throws JspException JavaDoc
102   {
103     try {
104       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
105       ELContext env = pageContext.getELContext();
106       
107       JspWriter JavaDoc out = pageContext.getOut();
108       
109       BodyContentImpl body = (BodyContentImpl) getBodyContent();
110
111       if (body != null) {
112         boolean doEscape = (_escapeXml == null || _escapeXml.evalBoolean(env));
113
114         String JavaDoc s = body.getString().trim();
115
116         if (doEscape)
117           Expr.toStreamEscaped(out, s);
118         else
119           out.print(s);
120       }
121     } catch (Exception JavaDoc e) {
122     }
123
124     return EVAL_PAGE;
125   }
126 }
127
Popular Tags