Quadcap Embeddable Server

com/quadcap/http/servlets/jsp/TagJsp.java

Go to the documentation of this file.
00001 package com.quadcap.http.servlets.jsp; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.PrintWriter; 00042 00043 import org.xml.sax.AttributeList; 00044 00045 /** 00046 * Useful base class for all JSP tag handlers. 00047 * 00048 * @author Stan Bailes 00049 */ 00050 public abstract class TagJsp implements TagHandler, TagInstance { 00051 TagContext context = null; 00052 String tagName = null; 00053 00054 public TagJsp() {} 00055 00056 public TagJsp(TagContext context) { 00057 this.context = context; 00058 } 00059 00060 public abstract TagInstance makeInstance(TagContext context); 00061 00062 public String getTagName() { return tagName; } 00063 00065 throws JspException 00066 { 00067 this.tagName = tagName; 00068 } 00069 00070 public void doEndTag() throws JspException {} 00071 00072 public void doCharacters(char[] ch, int off, int cnt) 00073 throws JspException 00074 { 00075 } 00076 00077 public void doTemplateCharacters(char[] ch, int off, int cnt) { 00078 PrintWriter w = context.getPrintWriter(); 00079 00080 w.print("out.print(\""); 00081 for (int i = 0; i < cnt; i++) { 00082 char c = ch[off + i]; 00083 switch (c) { 00084 case '\n': 00085 w.print("\\n"); 00086 break; 00087 case '\r': 00088 w.print("\\r"); 00089 break; 00090 case '\t': 00091 w.print("\\t"); 00092 break; 00093 case '\'': 00094 w.print("\\'"); 00095 break; 00096 case '\"': 00097 w.print("\\\""); 00098 break; 00099 case '\\': 00100 w.print("\\\\"); 00101 break; 00102 default: 00103 if (c > 0xfff) { 00104 w.print("\\u"); 00105 w.print(Integer.toHexString(c)); 00106 } else if (c > 0xff) { 00107 w.print("\\u0"); 00108 w.print(Integer.toHexString(c)); 00109 } else if (c <= 0x1f || c >= 0xf7f) { 00110 w.print("\\u00"); 00111 w.print(Integer.toHexString(c)); 00112 } else { 00113 w.print((char)c); 00114 } 00115 } 00116 } 00117 w.println("\");"); 00118 } 00119 00121 StringBuffer sb = new StringBuffer(); 00123 sb.append(' '); 00124 sb.append("[" + String.valueOf(i) + "]"); 00126 sb.append("=\""); 00128 sb.append("\""); 00129 } 00130 return sb.toString(); 00131 } 00132 } 00133