1 37 package org.webharvest.runtime.processors; 38 39 import org.webharvest.definition.TryDef; 40 import org.webharvest.definition.BaseElementDef; 41 import org.webharvest.exception.BaseException; 42 import org.webharvest.runtime.Scraper; 43 import org.webharvest.runtime.ScraperContext; 44 import org.webharvest.runtime.variables.IVariable; 45 46 49 public class TryProcessor extends BaseProcessor { 50 51 private TryDef tryDef; 52 53 public TryProcessor(TryDef tryDef) { 54 super(tryDef); 55 this.tryDef = tryDef; 56 } 57 58 public IVariable execute(Scraper scraper, ScraperContext context) { 59 try { 60 BaseElementDef tryBodyDef = tryDef.getTryBodyDef(); 61 IVariable result = getBodyListContent(tryBodyDef, scraper, context); 62 debug(tryBodyDef, scraper, result); 63 64 return result; 65 } catch(BaseException e) { 66 log.info("Exception caught with try processor: " + e.getMessage()); 67 BaseElementDef catchValueDef = tryDef.getCatchValueDef(); 68 IVariable result = getBodyListContent(catchValueDef, scraper, context); 69 debug(catchValueDef, scraper, result); 70 71 return result; 72 } 73 } 74 75 } | Popular Tags |