1 61 62 package org.jaxen.pattern; 63 64 import org.jaxen.Context; 65 import org.jaxen.Navigator; 66 67 72 public class NameTest extends NodeTest { 73 74 75 private String name; 76 77 78 private short nodeType; 79 80 public NameTest(String name, short nodeType) 81 { 82 this.name = name; 83 this.nodeType = nodeType; 84 } 85 86 88 public boolean matches( Object node, Context context ) 89 { 90 Navigator navigator = context.getNavigator(); 91 if ( nodeType == Pattern.ELEMENT_NODE ) 92 { 93 return navigator.isElement( node ) 94 && name.equals( navigator.getElementName( node ) ); 95 } 96 else if ( nodeType == Pattern.ATTRIBUTE_NODE ) 97 { 98 return navigator.isAttribute( node ) 99 && name.equals( navigator.getAttributeName( node ) ); 100 } 101 else 102 { 103 if ( navigator.isElement( node ) ) 104 { 105 return name.equals( navigator.getElementName( node ) ); 106 } 107 else 108 if ( navigator.isAttribute( node ) ) 109 { 110 return name.equals( navigator.getAttributeName( node ) ); 111 } 112 } 113 return false; 114 } 115 116 public double getPriority() 117 { 118 return 0.0; 119 } 120 121 122 public short getMatchType() 123 { 124 return nodeType; 125 } 126 127 public String getText() 128 { 129 if ( nodeType == Pattern.ATTRIBUTE_NODE ) 130 { 131 return "@" + name; 132 } 133 else 134 { 135 return name; 136 } 137 } 138 139 public String toString() 140 { 141 return super.toString() + "[ name: " + name + " type: " + nodeType + " ]"; 142 } 143 } 144 | Popular Tags |