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.http.HttpServletRequest ; 43 import javax.servlet.http.HttpUtils ; 44 import javax.servlet.jsp.JspException ; 45 46 47 55 public abstract class SearchResultSupport extends StyleSupport 56 { 57 60 protected GoogleSearchBean bean = null; 61 62 68 public int doEndTag() 69 throws JspException 70 { 71 try 72 { 73 if ((bean != null) && (bean.isValidResult())) 75 { 76 pageContext.getOut().write(getResultProperty()); 78 } 79 } 80 catch (Exception e) 81 { 82 throw TagUtility.outputError(getTagName(), e); 83 } 84 85 reset(); 87 88 return EVAL_PAGE; 89 } 90 91 97 public int doStartTag() 98 throws JspException 99 { 100 bean = TagUtility.getGoogleSearchBean(pageContext); 102 103 if ((bean != null) && (bean.isValidResult())) 105 { 106 return EVAL_BODY_TAG; 107 } 108 109 return SKIP_BODY; 110 } 111 112 115 public void release() 116 { 117 super.release(); 118 119 bean = null; 121 122 reset(); 124 } 125 126 136 protected abstract String getPropertyName(); 137 138 143 protected String getResultProperty() 144 { 145 String name = getPropertyName(); 146 String value = bean.getResultProperty(name); 147 148 if ((TagUtility.isValidString(value)) 149 && (name.equals(GoogleSearchBean.NEXT_KEYWORD) 150 || name.equals(GoogleSearchBean.PREVIOUS_KEYWORD))) 151 { 152 HttpServletRequest request = 153 (HttpServletRequest )pageContext.getRequest(); 154 155 String url = 156 HttpUtils.getRequestURL(request).toString() + '?' 157 + TagUtility.START_PARAM + '=' + value + '&' 158 + TagUtility.requestParamsToUrl(request, TagUtility.START_PARAM); 159 160 return (TagUtility.buildRefLink(url, 161 TagUtility.getTagBody(bodyContent), 162 target, style, css)); 163 } 164 else 165 { 166 return value; 167 } 168 } 169 170 179 protected abstract String getTagName(); 180 181 184 protected void reset() 185 { 186 super.reset(); 187 } 188 } 189 | Popular Tags |