1 package com.quadcap.http.servlets.jsp; 2 3 40 41 import java.io.PrintWriter ; 42 43 import org.xml.sax.AttributeList ; 44 45 50 public abstract class TagJsp implements TagHandler, TagInstance { 51 TagContext context = null; 52 String tagName = null; 53 54 public TagJsp() {} 55 56 public TagJsp(TagContext context) { 57 this.context = context; 58 } 59 60 public abstract TagInstance makeInstance(TagContext context); 61 62 public String getTagName() { return tagName; } 63 64 public void doStartTag(String tagName, AttributeList attributes) 65 throws JspException 66 { 67 this.tagName = tagName; 68 } 69 70 public void doEndTag() throws JspException {} 71 72 public void doCharacters(char[] ch, int off, int cnt) 73 throws JspException 74 { 75 } 76 77 public void doTemplateCharacters(char[] ch, int off, int cnt) { 78 PrintWriter w = context.getPrintWriter(); 79 80 w.print("out.print(\""); 81 for (int i = 0; i < cnt; i++) { 82 char c = ch[off + i]; 83 switch (c) { 84 case '\n': 85 w.print("\\n"); 86 break; 87 case '\r': 88 w.print("\\r"); 89 break; 90 case '\t': 91 w.print("\\t"); 92 break; 93 case '\'': 94 w.print("\\'"); 95 break; 96 case '\"': 97 w.print("\\\""); 98 break; 99 case '\\': 100 w.print("\\\\"); 101 break; 102 default: 103 if (c > 0xfff) { 104 w.print("\\u"); 105 w.print(Integer.toHexString(c)); 106 } else if (c > 0xff) { 107 w.print("\\u0"); 108 w.print(Integer.toHexString(c)); 109 } else if (c <= 0x1f || c >= 0xf7f) { 110 w.print("\\u00"); 111 w.print(Integer.toHexString(c)); 112 } else { 113 w.print((char)c); 114 } 115 } 116 } 117 w.println("\");"); 118 } 119 120 public static String toString(AttributeList attributes) { 121 StringBuffer sb = new StringBuffer (); 122 for (int i = 0; i < attributes.getLength(); i++) { 123 sb.append(' '); 124 sb.append("[" + String.valueOf(i) + "]"); 125 sb.append(attributes.getName(i)); 126 sb.append("=\""); 127 sb.append(attributes.getValue(i)); 128 sb.append("\""); 129 } 130 return sb.toString(); 131 } 132 } 133 134 | Popular Tags |