KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > el > 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.el;
30
31 import com.caucho.jsp.PageContextImpl;
32 import com.caucho.log.Log;
33 import com.caucho.xpath.Env;
34 import com.caucho.xpath.XPath;
35 import com.caucho.xpath.XPathException;
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.io.IOException JavaDoc;
43 import java.util.logging.Level JavaDoc;
44 import java.util.logging.Logger JavaDoc;
45
46 public class XmlOutTag extends TagSupport JavaDoc {
47   private static final Logger JavaDoc log = Log.open(XmlOutTag.class);
48   private com.caucho.xpath.Expr _select;
49   private com.caucho.el.Expr _escapeXml;
50
51   /**
52    * Sets the JSP-EL expression value.
53    */

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

62   public void setEscapeXml(com.caucho.el.Expr escapeXml)
63   {
64     _escapeXml = escapeXml;
65   }
66
67   /**
68    * Process the tag.
69    */

70   public int doStartTag()
71     throws JspException JavaDoc
72   {
73     try {
74       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
75       
76       JspWriter JavaDoc out = pageContext.getOut();
77
78       boolean doEscape = (_escapeXml == null ||
79                           _escapeXml.evalBoolean(pageContext.getELContext()));
80
81       toStream(out, pageContext, _select, doEscape);
82     } catch (Exception JavaDoc e) {
83       log.log(Level.FINE, e.toString(), e);
84     }
85
86     return SKIP_BODY;
87   }
88
89   /**
90    * Process the tag.
91    */

92   public static void toStream(JspWriter JavaDoc out, PageContextImpl pageContext,
93                   com.caucho.xpath.Expr select,
94                   boolean doEscape)
95     throws JspException JavaDoc, XPathException, IOException JavaDoc
96   {
97     Env env = XPath.createEnv();
98     env.setVarEnv(pageContext.getVarEnv());
99       
100     Node JavaDoc node = pageContext.getNodeEnv();
101
102     String JavaDoc value = select.evalString(node, env);
103
104     env.free();
105
106     if (doEscape)
107       com.caucho.el.Expr.toStreamEscaped(out, value);
108     else
109       out.print(value);
110   }
111 }
112
Popular Tags