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 import java.util.ArrayList ; 37 38 41 public class JspForward extends JspNode { 42 private static final QName PAGE = new QName("page"); 43 44 private String _page; 45 46 private ArrayList <JspParam> _params; 47 48 51 public void addAttribute(QName name, String value) 52 throws JspParseException 53 { 54 if (PAGE.equals(name)) 55 _page = value; 56 else 57 throw error(L.l("`{0}' is an invalid attribute in <jsp:forward>", 58 name.getName())); 59 } 60 61 64 public void addChild(JspNode node) 65 throws JspParseException 66 { 67 if (node instanceof JspParam) { 68 JspParam param = (JspParam) node; 69 70 if (_params == null) 71 _params = new ArrayList <JspParam>(); 72 73 _params.add(param); 74 } 75 else { 76 super.addChild(node); 77 } 78 } 79 80 85 public void printXml(WriteStream os) 86 throws IOException 87 { 88 os.print("<jsp:forward page=\"" + _page + "\">"); 89 90 os.print("</jsp:forward>"); 91 } 92 93 98 public void generate(JspJavaWriter out) 99 throws Exception 100 { 101 boolean hasQuery = false; 102 103 if (_page == null) 104 throw error(L.l("<jsp:forward> expects a `page' attribute. `page' specifies the path to forward.")); 105 106 if (hasRuntimeAttribute(_page)) { 107 out.print("pageContext.forward("); 108 out.print(getRuntimeAttribute(_page)); 109 } 110 else { 111 out.print("pageContext.forward(\""); 112 out.print(_page); 113 out.print("\""); 114 } 115 116 if (_params != null) { 117 out.print(", "); 118 generateIncludeParams(out, _params); 119 } 120 121 out.println(");"); 122 if (_gen.isTag() || isInFragment()) 123 out.println("if (true) throw new SkipPageException();"); 124 else 125 out.println("if (true) return;"); 126 } 127 } 128 | Popular Tags |