1 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 ; 36 import javax.servlet.jsp.JspWriter ; 37 import javax.servlet.jsp.tagext.BodyTagSupport ; 38 import java.io.IOException ; 39 40 public class OutTag extends BodyTagSupport { 41 private Object _value; 42 private boolean _escapeXml = true; 43 private String _defaultValue; 44 45 48 public void setValue(Object value) 49 { 50 _value = value; 51 } 52 53 56 public void setEscapeXml(boolean value) 57 { 58 _escapeXml = value; 59 } 60 61 64 public void setDefault(String value) 65 { 66 _defaultValue = value; 67 } 68 69 72 public int doStartTag() 73 throws JspException 74 { 75 try { 76 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 77 78 JspWriter 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 e) { 95 } 96 97 return SKIP_BODY; 98 } 99 100 public int doEndTag() throws JspException 101 { 102 try { 103 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 104 105 JspWriter out = pageContext.getOut(); 106 107 BodyContentImpl body = (BodyContentImpl) getBodyContent(); 108 109 if (body != null) { 110 String s = body.getString().trim(); 111 112 if (_escapeXml) 113 Expr.toStreamEscaped(out, s); 114 else 115 out.print(s); 116 } 117 } catch (Exception e) { 118 } 119 120 return EVAL_PAGE; 121 } 122 } 123 | Popular Tags |