1 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 ; 38 39 import javax.servlet.jsp.JspException ; 40 import javax.servlet.jsp.JspWriter ; 41 import javax.servlet.jsp.tagext.TagSupport ; 42 import java.io.IOException ; 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 46 public class XmlOutTag extends TagSupport { 47 private static final Logger log = Log.open(XmlOutTag.class); 48 private com.caucho.xpath.Expr _select; 49 private com.caucho.el.Expr _escapeXml; 50 51 54 public void setSelect(com.caucho.xpath.Expr select) 55 { 56 _select = select; 57 } 58 59 62 public void setEscapeXml(com.caucho.el.Expr escapeXml) 63 { 64 _escapeXml = escapeXml; 65 } 66 67 70 public int doStartTag() 71 throws JspException 72 { 73 try { 74 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 75 76 JspWriter out = pageContext.getOut(); 77 78 boolean doEscape = (_escapeXml == null || 79 _escapeXml.evalBoolean(pageContext.getELContext())); 80 81 toStream(out, pageContext, _select, doEscape); 82 } catch (Exception e) { 83 log.log(Level.FINE, e.toString(), e); 84 } 85 86 return SKIP_BODY; 87 } 88 89 92 public static void toStream(JspWriter out, PageContextImpl pageContext, 93 com.caucho.xpath.Expr select, 94 boolean doEscape) 95 throws JspException , XPathException, IOException 96 { 97 Env env = XPath.createEnv(); 98 env.setVarEnv(pageContext.getVarEnv()); 99 100 Node node = pageContext.getNodeEnv(); 101 102 String 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 |