1 16 17 package org.apache.taglibs.scrape; 18 19 import java.util.*; 20 import java.io.*; 21 import java.net.*; 22 import javax.servlet.jsp.*; 23 import javax.servlet.jsp.tagext.*; 24 import org.apache.taglibs.scrape.*; 25 26 93 public class PageTag extends TagSupport { 94 95 private String url; 98 private long time = 600000; 100 private PageData pagedata; 103 private int pport = -1; 105 private String pserver = null; 107 private String pname = null; 109 private String ppass = null; 111 private boolean ssl = false; 114 private String sslpass = null; 116 private String charset = null; 118 119 120 131 public final int doStartTag() throws JspException { 132 if (url != null) 135 getPage(); 136 return EVAL_BODY_INCLUDE; } 138 139 150 public final int doEndTag() throws JspException { 151 pagedata.scrapePage(url, time, pageContext, charset); 153 putScrapes(); 155 return EVAL_PAGE; 156 } 157 158 163 public final void getPage() { 164 pagedata = PageData.getPage(url, pport, pserver, pname, ppass); 166 } 167 168 176 public final void setTime(String wait) throws JspException { 177 long temp; try { 179 Long num = new Long (wait); 180 temp = num.longValue(); 181 if (temp > 10) { 182 time = temp * 60000; 183 } 184 } catch(NumberFormatException nfe) { 185 throw new JspException("Scrape: Page tag: the time attribute needs" 187 + " to be an integer"); 188 } 189 } 190 191 198 public final void setUrl(String url) throws JspException { 199 this.url = url.trim(); 200 if (url.startsWith("https")) 201 ssl = true; 202 } 203 204 210 public final void setuseProxy(String value) throws JspException { 211 if (value.equalsIgnoreCase("true")) { 212 pserver = System.getProperty("http.proxyHost"); 213 pport = Integer.getInteger("http.proxyPort").intValue(); 214 } 215 } 216 217 223 public final void setProxyPort(String value) throws JspException { 224 try { 225 pport = new Integer (value).intValue(); 226 } catch(NumberFormatException nfe) { 227 throw new JspException("Scrape: Page tag: the proxyPort attribute needs" 229 + " to be an integer"); 230 } 231 } 232 233 239 public final void setProxyServer(String value) { 240 pserver = value; 241 } 242 243 249 public final void setProxyPass(String value) { 250 ppass = value; 251 } 252 253 259 public final void setProxyName(String value) { 260 pname = value; 261 } 262 263 269 public final void setClientPass(String value) { 270 sslpass = value; 271 } 272 273 279 public final void setHeader(String name, String value) { 280 pagedata.setHeader(name, value); 281 } 282 283 289 public final void setCharset(String value) { 290 charset = value; 291 } 292 306 public final void setScrape(String id, String begin, String end, 307 String anchors, String strip) throws JspException { 308 309 pagedata.setScrape(id, begin, end, anchors, strip); 311 } 312 313 318 private final void putScrapes() { 319 Set scrapedatakeys = pagedata.getKeySet(); 321 Iterator scrapesit1 = scrapedatakeys.iterator(); 324 Iterator scrapesit2 = scrapedatakeys.iterator(); 325 326 while(scrapesit1.hasNext()) { 329 330 pageContext.setAttribute((String )scrapesit2.next(), 332 pagedata.getScrape((String )scrapesit1.next()).getResult()); 333 } 334 } 335 } 336 | Popular Tags |