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