KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > rt > OutTag


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.rt;
30
31 import com.caucho.el.Expr;
32 import com.caucho.jsp.BodyContentImpl;
33 import com.caucho.jsp.PageContextImpl;
34
35 import javax.servlet.jsp.JspException JavaDoc;
36 import javax.servlet.jsp.JspWriter JavaDoc;
37 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
38 import java.io.IOException JavaDoc;
39
40 public class OutTag extends BodyTagSupport JavaDoc {
41   private Object JavaDoc _value;
42   private boolean _escapeXml = true;
43   private String JavaDoc _defaultValue;
44
45   /**
46    * Sets the value.
47    */

48   public void setValue(Object JavaDoc value)
49   {
50     _value = value;
51   }
52
53   /**
54    * Sets true if XML should be escaped.
55    */

56   public void setEscapeXml(boolean value)
57   {
58     _escapeXml = value;
59   }
60
61   /**
62    * Sets the default value.
63    */

64   public void setDefault(String JavaDoc value)
65   {
66     _defaultValue = value;
67   }
68
69   /**
70    * Process the tag.
71    */

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