1 15 package org.josql.contrib; 16 17 import java.util.List ; 18 19 import javax.servlet.jsp.tagext.BodyTagSupport ; 20 import javax.servlet.jsp.tagext.Tag ; 21 22 import javax.servlet.jsp.JspException ; 23 24 import org.josql.Query; 25 import org.josql.QueryResults; 26 27 60 public class JoSQLJSPQueryTag extends BodyTagSupport 61 { 62 63 private Object inputList = null; 64 private String results = null; 65 private Query query = null; 66 67 72 public void setResults (String r) 73 { 74 75 this.results = r; 76 77 } 78 79 89 public void setInputList (Object l) 90 { 91 92 this.inputList = l; 93 94 } 95 96 102 public int doAfterBody () 103 throws JspException 104 { 105 106 this.query = new Query (); 107 108 String st = this.getBodyContent ().getString (); 109 110 try 111 { 112 113 this.query.parse (st); 114 115 } catch (Exception e) { 116 117 throw new JspException ("Unable to parse statement: " + 118 st, 119 e); 120 121 } 122 123 return Tag.SKIP_BODY; 124 125 } 126 127 140 public int doEndTag () 141 throws JspException 142 { 143 144 List l = null; 145 146 if (this.inputList instanceof String ) 147 { 148 149 String ln = (String ) this.inputList; 150 151 Object o = this.pageContext.findAttribute (ln); 153 154 if (o == null) 155 { 156 157 throw new JspException ("No list with name: " + 158 ln + 159 " can be found"); 160 161 } 162 163 if (!(o instanceof List )) 164 { 165 166 throw new JspException ("Attribute: " + 167 ln + 168 " is not an instance of: " + 169 List .class.getName () + 170 ", is: " + 171 o.getClass ().getName ()); 172 173 } 174 175 l = (List ) o; 176 177 } 178 179 if (this.inputList instanceof List ) 180 { 181 182 l = (List ) this.inputList; 183 184 } 185 186 if (l == null) 187 { 188 189 throw new JspException ("No input list specified."); 190 191 } 192 193 try 194 { 195 196 QueryResults qr = this.query.execute (l); 197 198 this.pageContext.setAttribute (this.results, 200 qr); 201 202 } catch (Exception e) { 203 204 throw new JspException ("Unable to execute query with list: " + 205 this.inputList, 206 e); 207 208 } 209 210 return Tag.EVAL_PAGE; 211 212 } 213 214 217 public void release () 218 { 219 220 this.inputList = null; 221 this.results = null; 222 this.query = null; 223 224 super.release (); 225 226 } 227 228 } 229 | Popular Tags |