1 28 29 package com.caucho.xpath.pattern; 30 31 import com.caucho.xpath.Env; 32 import com.caucho.xpath.ExprEnvironment; 33 import com.caucho.xpath.XPathException; 34 35 import org.w3c.dom.Node ; 36 37 40 public class FromChildren extends Axis { 41 public FromChildren(AbstractPattern parent) 42 { 43 super(parent); 44 } 45 46 55 public boolean match(Node node, ExprEnvironment env) 56 throws XPathException 57 { 58 if (node == null) 59 return false; 60 61 return _parent == null || _parent.match(node.getParentNode(), env); 62 } 63 64 74 public int position(Node node, Env env, AbstractPattern pattern) 75 throws XPathException 76 { 77 int count = 1; 78 79 for (node = node.getPreviousSibling(); 80 node != null; 81 node = node.getPreviousSibling()) { 82 if (pattern == null || pattern.match(node, env)) 83 count++; 84 } 85 86 return count; 87 } 88 89 98 public int count(Node node, Env env, AbstractPattern pattern) 99 throws XPathException 100 { 101 int count = 0; 102 103 for (node = node.getParentNode().getFirstChild(); 104 node != null; 105 node = node.getNextSibling()) { 106 if (pattern.match(node, env)) 107 count++; 108 } 109 110 return count; 111 } 112 113 120 public Node firstNode(Node node, ExprEnvironment env) 121 { 122 return node.getFirstChild(); 123 } 124 125 133 public Node nextNode(Node node, Node lastNode) 134 { 135 return node.getNextSibling(); 136 } 137 138 141 boolean isSingleLevel() 142 { 143 return _parent == null || _parent.isSingleLevel(); 144 } 145 146 149 public boolean isStrictlyAscending() 150 { 151 if (_parent == null) 152 return true; 153 else { 154 return _parent.isStrictlyAscending(); 155 } 156 } 157 158 161 public boolean equals(Object b) 162 { 163 if (! (b instanceof FromChildren)) 164 return false; 165 166 FromChildren bPattern = (FromChildren) b; 167 168 return (_parent == bPattern._parent || 169 (_parent != null && _parent.equals(bPattern._parent))); 170 } 171 172 public String toString() 173 { 174 return getPrefix() + "child::"; 175 } 176 } 177 | Popular Tags |