1 8 package org.apache.avalon.excalibur.xml.xpath; 9 10 import org.apache.avalon.framework.thread.ThreadSafe; 11 import org.apache.avalon.framework.component.Component; 12 import org.apache.avalon.framework.logger.AbstractLoggable; 13 import org.w3c.dom.Node ; 14 import org.w3c.dom.NodeList ; 15 import org.jaxen.dom.XPath; 16 17 18 import java.util.List ; 19 20 35 public class JaxenProcessorImpl 36 extends AbstractLoggable 37 implements XPathProcessor, ThreadSafe 38 { 39 48 public Node selectSingleNode(Node contextNode, String str) 49 { 50 try { 51 XPath path = new XPath(str); 52 return (Node )path.selectSingleNode((Object )contextNode); 53 } catch (Exception e){ 54 } 56 return null; 57 } 58 59 67 public NodeList selectNodeList(Node contextNode, String str) 68 { 69 try { 70 XPath path = new XPath(str); 71 List list = path.selectNodes((Object )contextNode); 72 return new NodeListEx(list); 73 } catch (Exception e){ 74 } 76 return new NodeListEx(); 77 } 78 79 class NodeListEx implements NodeList { 80 List list = null; 81 NodeListEx(){ 82 } 83 NodeListEx(List l){ 84 list = l; 85 } 86 public Node item(int index) { 87 if(list==null) 88 return null; 89 return (Node )list.get(index); 90 } 91 public int getLength(){ 92 if(list==null) 93 return 0; 94 return list.size(); 95 } 96 } 97 } 98 | Popular Tags |