1 28 29 package com.caucho.jsp.java; 30 31 import com.caucho.jsp.JspParseException; 32 import com.caucho.vfs.WriteStream; 33 import com.caucho.xml.QName; 34 35 import java.io.IOException ; 36 37 public class JstlCoreRemove extends JstlNode { 38 private static final QName VAR = new QName("var"); 39 private static final QName SCOPE = new QName("scope"); 40 41 private String _var; 42 private String _scope; 43 44 47 public void addAttribute(QName name, String value) 48 throws JspParseException 49 { 50 if (VAR.equals(name)) 51 _var = value; 52 else if (SCOPE.equals(name)) 53 _scope = value; 54 else 55 throw error(L.l("`{0}' is an unknown attribute for <{1}>.", 56 name.getName(), getTagName())); 57 } 58 63 public void printXml(WriteStream os) 64 throws IOException 65 { 66 os.print("<c:remove var=\"" + xmlText(_var) + "\""); 67 68 if (_scope != null) 69 os.print(" scope=\"" + xmlText(_scope) + "\""); 70 71 os.print("/>"); 72 } 73 74 77 public void generate(JspJavaWriter out) 78 throws Exception 79 { 80 if (_var == null) 81 throw error(L.l("required attribute `var' missing from `{0}'", 82 getTagName())); 83 84 if (_scope == null || _scope.equals("page")) { 85 out.println("pageContext.removeAttribute(\"" + _var + "\");"); 86 } 87 else if (_scope.equals("request")) { 88 out.println("pageContext.getRequest().removeAttribute(\"" + _var + "\");"); 89 } 90 else if (_scope.equals("session")) { 91 out.println("pageContext.getSession().removeAttribute(\"" + _var + "\");"); 92 } 93 else if (_scope.equals("application")) { 94 out.println("pageContext.getServletContext().removeAttribute(\"" + _var + "\");"); 95 } 96 else 97 throw error(L.l("invalid scope `{0}'", _scope)); 98 } 99 } 100 | Popular Tags |