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 JspInclude extends JspNode { 42 private static final QName PAGE = new QName("page"); 43 private static final QName FLUSH = new QName("flush"); 44 45 private String _page; 46 private boolean _flush = false; 48 private String _text; 49 50 private ArrayList <JspParam> _params; 51 52 55 public void addAttribute(QName name, String value) 56 throws JspParseException 57 { 58 if (PAGE.equals(name)) 59 _page = value; 60 else if (FLUSH.equals(name)) 61 _flush = value.equals("true"); 62 else 63 throw error(L.l("`{0}' is an invalid attribute in <jsp:include>", 64 name.getName())); 65 } 66 67 70 public boolean hasScripting() 71 { 72 if (_params == null) 73 return false; 74 75 for (int i = 0; i < _params.size(); i++) { 76 if (_params.get(i).hasScripting()) 77 return true; 78 } 79 80 return false; 81 } 82 83 86 public JspNode addText(String text) 87 { 88 _text = text; 89 90 return null; 91 } 92 93 96 public void addChild(JspNode node) 97 throws JspParseException 98 { 99 if (node instanceof JspParam) { 100 JspParam param = (JspParam) node; 101 102 if (_params == null) 103 _params = new ArrayList <JspParam>(); 104 105 _params.add(param); 106 } 107 else { 108 super.addChild(node); 109 } 110 } 111 112 117 public void printXml(WriteStream os) 118 throws IOException 119 { 120 os.print("<jsp:include page=\"" + _page + "\">"); 121 122 os.print("</jsp:include>"); 123 } 124 125 130 public void generate(JspJavaWriter out) 131 throws Exception 132 { 133 boolean hasQuery = false; 134 135 if (_page == null) 136 throw error(L.l("<jsp:include> expects a `page' attribute. `page' specifies the path to include.")); 137 138 if (hasRuntimeAttribute(_page)) { 139 out.print("pageContext.include("); 140 out.print(getRuntimeAttribute(_page)); 141 } 142 else { 143 String page = _page; 144 145 out.print("pageContext.include("); 146 out.print(generateParameterValue(String .class, _page)); 147 } 148 149 if (_params != null) { 150 out.print(", "); 151 generateIncludeParams(out, _params); 152 } 153 154 out.print(", " + _flush); 155 156 out.println(");"); 157 } 158 } 159 | Popular Tags |