1 37 package org.webharvest.runtime.processors; 38 39 import org.webharvest.definition.HttpParamDef; 40 import org.webharvest.exception.HttpException; 41 import org.webharvest.runtime.Scraper; 42 import org.webharvest.runtime.ScraperContext; 43 import org.webharvest.runtime.templaters.BaseTemplater; 44 import org.webharvest.runtime.variables.IVariable; 45 46 49 public class HttpParamProcessor extends BaseProcessor { 50 51 private HttpParamDef httpParamDef; 52 53 public HttpParamProcessor(HttpParamDef httpParamDef) { 54 super(httpParamDef); 55 this.httpParamDef = httpParamDef; 56 } 57 58 public IVariable execute(Scraper scraper, ScraperContext context) { 59 String name = BaseTemplater.execute( httpParamDef.getName(), scraper.getScriptEngine() ); 60 IVariable value = getBodyTextContent(httpParamDef, scraper, context); 61 62 HttpProcessor httpProcessor = scraper.getRunningHttpProcessor(); 63 if (httpProcessor != null) { 64 httpProcessor.addHttpParam(name, value.toString()); 65 } else { 66 throw new HttpException("Usage of http-param processor is not allowed outside of http processor!"); 67 } 68 69 return value; 70 } 71 72 } 73 | Popular Tags |