KickJava   Java API By Example, From Geeks To Geeks.

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


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.jsp.PageContextImpl;
32 import com.caucho.log.Log;
33 import com.caucho.xpath.Env;
34 import com.caucho.xpath.Expr;
35 import com.caucho.xpath.XPath;
36
37 import org.w3c.dom.Node JavaDoc;
38
39 import javax.servlet.jsp.JspException JavaDoc;
40 import javax.servlet.jsp.JspWriter JavaDoc;
41 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
42 import java.util.logging.Level JavaDoc;
43 import java.util.logging.Logger JavaDoc;
44
45 public class XmlOutTag extends TagSupport JavaDoc {
46   private static final Logger JavaDoc log = Log.open(XmlOutTag.class);
47   private Expr _select;
48   private boolean _escapeXml = true;
49
50   /**
51    * Sets the JSP-EL expression value.
52    */

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

61   public void setEscapeXml(boolean escapeXml)
62   {
63     _escapeXml = escapeXml;
64   }
65
66   /**
67    * Process the tag.
68    */

69   public int doStartTag()
70     throws JspException JavaDoc
71   {
72     try {
73       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
74       
75       JspWriter JavaDoc out = pageContext.getOut();
76
77       Env env = XPath.createEnv();
78       env.setVarEnv(pageContext.getVarEnv());
79
80       Node JavaDoc node = pageContext.getNodeEnv();
81
82       String JavaDoc value = _select.evalString(node, env);
83
84       env.free();
85
86       if (_escapeXml)
87         com.caucho.el.Expr.toStreamEscaped(out, value);
88       else
89         out.print(value);
90     } catch (Exception JavaDoc e) {
91       log.log(Level.FINE, e.toString(), e);
92     }
93
94     return SKIP_BODY;
95   }
96 }
97
Popular Tags