litesoft
@ 947
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.dev.ui.inspection.finders; import java.util.*; import org.litesoft.GWT.client.dev.ui.inspection.*; import com.google.gwt.dom.client.*; public class ElementFinder extends Finder { public ElementFinder(ElementSelectionSpec pSelectionSpec) { super(pSelectionSpec); } @Override protected ElementSelectionSpec getSelectionSpec() { return (ElementSelectionSpec) super.getSelectionSpec(); } /** * Traverse the DOM breadth first, looking for an element which matches the * selector's criteria. */ @Override public Element find(Element pRoot) { // TODO: extract traversal logic for reuse? Pull out as an Iterator so compound selectors can pull and pass control around? String elementName = getSelectionSpec().getElementName(); LinkedList<Element> queue = new LinkedList<Element>(); queue.add(pRoot); while (queue.size() > 0) { Element element = queue.remove(0); if (elementName.equals(element.getNodeName())) { return element; } else { Element sibling = element.getFirstChildElement(); while (sibling != null) { queue.add(sibling); sibling = sibling.getNextSiblingElement(); } } } return null; } } |