1 37 package net.thauvin.google.taglibs; 38 39 import net.thauvin.google.GoogleSearchBean; 40 import net.thauvin.google.TagUtility; 41 42 import javax.servlet.jsp.*; 43 import javax.servlet.jsp.tagext.*; 44 45 46 54 public class SearchResult extends BodyTagSupport 55 { 56 private GoogleSearchBean bean = null; 57 private StringBuffer output = null; 58 private int loopCount = 0; 59 60 66 public int doAfterBody() 67 throws JspTagException 68 { 69 final String body = bodyContent.getString(); 71 72 output.append(body); 74 75 try 76 { 77 bodyContent.clear(); 79 } 80 catch (java.io.IOException e) 81 { 82 throw TagUtility.nestedException("An error occurred while clearing the content of the 'searchResult' tag.", 83 e); 84 } 85 86 if (++loopCount < bean.getResultElementsCount()) 88 { 89 return EVAL_BODY_TAG; 90 } 91 92 return SKIP_BODY; 93 } 94 95 101 public int doEndTag() 102 throws JspTagException 103 { 104 if (output.length() > 0) 106 { 107 try 108 { 109 bodyContent.getEnclosingWriter().write(output.toString()); 111 } 112 catch (java.io.IOException e) 113 { 114 throw TagUtility.outputError("searchResult", e); 115 } 116 } 117 118 reset(); 120 121 return EVAL_PAGE; 122 } 123 124 130 public int doStartTag() 131 throws JspException 132 { 133 output = new StringBuffer (); 134 135 loopCount = 0; 137 138 bean = TagUtility.getGoogleSearchBean(pageContext); 140 141 if ((bean != null) && (bean.getResultElementsCount() > 0)) 143 { 144 return EVAL_BODY_TAG; 145 } 146 147 return SKIP_BODY; 148 } 149 150 153 public void release() 154 { 155 super.release(); 156 157 bean = null; 159 160 output = null; 162 163 reset(); 165 } 166 167 173 protected String getElementProperty(String name) 174 { 175 if (bean != null) 176 { 177 return bean.getResultElementProperty(loopCount, name); 178 } 179 180 return ""; 181 } 182 183 186 protected void reset() 187 { 188 loopCount = 0; 190 } 191 } 192 | Popular Tags |