1 29 30 package com.caucho.jsp.java; 31 32 import com.caucho.util.CharBuffer; 33 import com.caucho.vfs.WriteStream; 34 import com.caucho.xml.QName; 35 import com.caucho.xml.XmlChar; 36 37 import java.io.IOException ; 38 39 42 public class StaticText extends JspNode { 43 private static final QName TEXT = new QName("jsp", "text", JSP_NS); 44 45 private String _text; 46 47 public StaticText(JavaJspGenerator gen, String text, JspNode parent) 48 { 49 if (gen == null) 50 throw new NullPointerException (); 51 52 setGenerator(gen); 53 setQName(TEXT); 54 setParent(parent); 55 56 _text = text; 57 } 58 59 62 public String getText() 63 { 64 return _text; 65 } 66 67 70 public void setText(String text) 71 { 72 _text = text; 73 } 74 75 78 public boolean isStatic() 79 { 80 return true; 81 } 82 83 86 public void getStaticText(CharBuffer cb) 87 { 88 cb.append(_text); 89 } 90 91 94 public boolean isWhitespace() 95 { 96 String text = _text; 97 98 for (int i = text.length() - 1; i >= 0; i--) { 99 if (! XmlChar.isWhitespace(text.charAt(i))) 100 return false ; 101 } 102 103 return true; 104 } 105 106 111 public void printXml(WriteStream os) 112 throws IOException 113 { 114 os.print("<jsp:text"); 115 printJspId(os); 116 os.print(">"); 117 118 printXmlText(os, _text); 119 os.print("</jsp:text>"); 120 } 121 122 125 public void generateStartLocation(JspJavaWriter out) 126 throws IOException 127 { 128 out.setLocation(_filename, _startLine); 129 } 130 131 134 public void generateEndLocation(JspJavaWriter out) 135 throws IOException 136 { 137 out.setLocation(_filename, _endLine); 138 } 139 140 145 public void generate(JspJavaWriter out) 146 throws Exception 147 { 148 out.addText(_text); 149 } 150 151 156 public void generateStatic(JspJavaWriter out) 157 throws Exception 158 { 159 out.print(_text); 160 } 161 162 170 private void generateText(JspJavaWriter out, String text, 171 int offset, int length) 172 throws IOException 173 { 174 175 if (length > 32000) { 176 generateText(out, text, offset, 16 * 1024); 177 generateText(out, text, offset + 16 * 1024, length - 16 * 1024); 178 return; 179 } 180 181 text = text.substring(offset, offset + length); 182 183 if (length == 1) { 184 int ch = text.charAt(0); 185 186 out.print("out.write('"); 187 switch (ch) { 188 case '\\': 189 out.print("\\\\"); 190 break; 191 case '\'': 192 out.print("\\'"); 193 break; 194 case '\n': 195 out.print("\\n"); 196 break; 197 case '\r': 198 out.print("\\r"); 199 break; 200 default: 201 out.print((char) ch); 202 break; 203 } 204 205 out.println("');"); 206 } 207 else { 208 int index = _gen.addString(text); 209 210 out.print("out.write(_jsp_string" + index + ", 0, "); 211 out.println("_jsp_string" + index + ".length);"); 212 } 213 } 214 } 215 | Popular Tags |