| 1 package com.quadcap.http.servlets.jsp; 2 3 40 41 import java.io.PrintWriter ; 42 43 import java.util.Hashtable ; 44 45 import org.xml.sax.AttributeList ; 46 47 import com.quadcap.util.Debug; 48 49 55 public class TagJspSetProperty extends TagJsp { 56 public TagJspSetProperty() {} 57 58 public TagJspSetProperty(TagContext context) { 59 super(context); 60 } 61 62 public TagInstance makeInstance(TagContext context) { 63 return new TagJspSetProperty(context); 64 } 65 66 public void doStartTag(String tagName, AttributeList attributes) 67 throws JspException 68 { 69 super.doStartTag(tagName, attributes); 70 context.addPageDirective("import", 71 "com.quadcap.http.servlets.jsp.PropertyUtils"); 72 73 PrintWriter w = context.getPrintWriter(); 74 String name = attributes.getValue("name"); 75 String prop = attributes.getValue("property"); 76 if (prop.equals("*")) { 77 w.print(" PropertyUtils."); 78 w.print("setPropertiesFromRequest("); 79 w.print(name); 80 w.println(", request);"); 81 return; 82 } 83 84 String param = attributes.getValue("param"); 85 if (param != null) { 86 w.print(" PropertyUtils."); 87 w.print("setPropertyFromRequestParameter("); 88 w.print(name); 89 w.print(", request, \""); 90 w.print(param); 91 w.println("\");"); 92 return; 93 } 94 95 String value = attributes.getValue("value").trim(); 96 if (value != null) { 97 if (value.startsWith("<%=") && value.endsWith("%>")) { 98 value = value.substring(3); 99 value = value.substring(value.length() - 2).trim(); 100 } else { 101 value = "\"" + value + "\""; 102 } 103 w.print(" PropertyUtils."); 104 w.print("setPropertyFromValue("); 105 w.print(name); 106 w.print(", String.valueOf("); 107 w.print(value); 108 w.println("));"); 109 return; 110 } 111 112 throw new JspException("Bad jsp:setProperty tag"); 113 } 114 } 115 116 | Popular Tags |