1 5 package net.sourceforge.jwebunit; 6 7 import org.w3c.dom.Element ; 8 import org.w3c.dom.NodeList ; 9 import com.meterware.httpunit.WebLink; 10 import com.meterware.httpunit.HTMLElementPredicate; 11 12 17 public class LinkImagePredicate implements HTMLElementPredicate 18 { 19 20 public 21 boolean matchesCriteria(Object webLink, Object criteria) 22 { 23 Element a = (Element ) ((WebLink) webLink).getDOMSubtree(); 24 NodeList imgs = getChildImageElement(a); 25 26 if (imgs == null) 27 { 28 return false; 29 } 30 31 for(int i=0; i< imgs.getLength(); i++) 32 { 33 Element img = (Element ) imgs.item(i); 34 String source = img.getAttribute("src"); 35 36 if(source.endsWith((String ) criteria)) 37 return true; 38 } 39 return false; 40 } 41 42 private 43 NodeList getChildImageElement(Element htmlElement) 44 { 45 NodeList nodes = htmlElement.getElementsByTagName("img"); 46 return nodes.getLength() == 0 ? null : nodes; 47 } 48 } 49 | Popular Tags |