1 28 29 package com.caucho.xpath.pattern; 30 31 import com.caucho.xpath.ExprEnvironment; 32 import com.caucho.xpath.XPathException; 33 34 import org.w3c.dom.Node ; 35 36 public class NamespacePattern extends AbstractPattern { 37 private String _prefix; 38 private int _nodeType; 39 40 public NamespacePattern(AbstractPattern parent, String prefix, int nodeType) 41 { 42 super(parent); 43 44 _prefix = prefix.intern(); 45 _nodeType = nodeType; 46 47 if (parent == null) 48 throw new RuntimeException (); 49 } 50 51 54 public double getPriority() 55 { 56 return -0.25; 57 } 58 59 67 public boolean match(Node node, ExprEnvironment env) 68 throws XPathException 69 { 70 if (node == null) 71 return false; 72 73 if (node.getNodeType() != _nodeType) 74 return false; 75 76 String prefix = node.getPrefix(); 77 78 if (prefix != _prefix) 79 return false; 80 81 return _parent.match(node, env); 82 } 83 84 public String toString() 85 { 86 switch (_nodeType) { 87 case Node.ATTRIBUTE_NODE: 88 return _parent.toString() + "@" + _prefix + ":*"; 89 case Node.ELEMENT_NODE: 90 return _parent.toString() + _prefix + ":*"; 91 92 default: 93 return super.toString(); 94 } 95 } 96 } 97 | Popular Tags |