1 28 29 package com.caucho.jsp.java; 30 31 import com.caucho.jsp.JspParseException; 32 import com.caucho.jsp.TagInstance; 33 import com.caucho.vfs.WriteStream; 34 35 import javax.servlet.jsp.tagext.VariableInfo ; 36 import java.io.IOException ; 37 38 41 public class JspBody extends JspFragmentNode { 42 private TagInstance _tag; 43 44 47 public JspNode addText(String text) 48 throws JspParseException 49 { 50 JspNode node = new StaticText(_gen, text, this); 51 52 addChild(node); 53 54 return node; 55 } 56 57 60 public String getCustomTagName() 61 { 62 if (isJspFragment()) 63 return "_jsp_parent_tag"; 64 else 65 return getParent().getCustomTagName(); 66 } 67 68 71 public boolean isStatic() 72 { 73 if (_children == null) 74 return true; 75 76 for (int i = 0; i < _children.size(); i++) { 77 if (! _children.get(i).isStatic()) 78 return false; 79 } 80 81 return true; 82 } 83 84 87 public TagInstance getTag() 88 { 89 JspNode parent = getParent(); 90 91 if (parent == null) 92 return _gen.getRootTag(); 93 else if (parent instanceof CustomSimpleTag || 94 parent instanceof TagFileTag) { 95 if (_tag == null) 96 _tag = new TagInstance(_gen.getTagManager()); 97 98 return _tag; 99 } 100 else 101 return parent.getTag(); 102 } 103 104 107 public void endAttributes() 108 throws JspParseException 109 { 110 super.endAttributes(); 111 112 JspNode parent = getParent(); 113 114 if (parent == null || 115 parent instanceof JspTop) { 117 throw error(L.l("jsp:body must be contained in a valid tag.")); 118 } 119 else if (parent instanceof JspBody || 120 parent instanceof JspAttribute) { 121 throw error(L.l("jsp:body is not allowed in <{0}>", 122 parent.getTagName())); 123 } 124 } 125 126 131 public void printXml(WriteStream os) 132 throws IOException 133 { 134 os.print("<jsp:body"); 135 os.print(" jsp:id=\"" + _gen.generateJspId() + "\">"); 136 printXmlChildren(os); 137 os.print("</jsp:body>"); 138 } 139 140 143 public void generatePrologue(JspJavaWriter out) 144 throws Exception 145 { 146 JspNode parent = getParent(); 147 148 if (! isJspFragment()) { 149 generatePrologueChildren(out); 150 return; 151 } 152 153 super.generatePrologue(out); 154 155 TagInstance parentTag = getParent().getTag(); 156 boolean isSimple = false; 157 158 if (parentTag == null || parentTag.isTop()) { 159 } 160 else if (! getTag().isTop()) { 161 } 162 else if (parentTag.isSimpleTag()) { 163 getTag().setId(TagInstance.FRAGMENT_WITH_SIMPLE_PARENT); 164 } 165 else 166 getTag().setId(TagInstance.FRAGMENT_WITH_TAG_PARENT); 167 } 168 169 173 public void generatePrologueChildren(JspJavaWriter out) 174 throws Exception 175 { 176 super.generatePrologueChildren(out); 177 178 JspNode parent = getParent(); 179 180 if (parent instanceof GenericTag) { 181 GenericTag tag = (GenericTag) parent; 182 183 tag.printVarDeclaration(out, VariableInfo.AT_BEGIN); 184 tag.printVarDeclaration(out, VariableInfo.NESTED); 185 } 186 } 187 188 191 198 } 199 | Popular Tags |