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 FromNextSibling extends Axis { 41 public FromNextSibling(AbstractPattern parent) 42 { 43 super(parent); 44 45 if (parent == null) 46 throw new RuntimeException (); 47 } 48 49 57 public boolean match(Node node, ExprEnvironment env) 58 throws XPathException 59 { 60 if (node == null) 61 return false; 62 63 for (node = node.getPreviousSibling(); 64 node != null; 65 node = node.getPreviousSibling()) { 66 if (_parent.match(node, env)) 67 return true; 68 } 69 70 return false; 71 } 72 73 79 public int position(Node node, Env env, AbstractPattern pattern) 80 throws XPathException 81 { 82 int index = env.getPositionIndex(); 83 84 int count = 1; 85 while ((node = node.getPreviousSibling()) != null) { 86 if (_parent.match(node, env)) { 87 if (--index <= 0) { 88 for (node = node.getPreviousSibling(); 90 node != null; 91 node = node.getPreviousSibling()) { 92 if (_parent.match(node, env)) { 93 env.setMorePositions(true); 94 break; 95 } 96 } 97 return count; 98 } 99 } 100 101 if (pattern.match(node, env)) 102 count++; 103 } 104 105 return count; 106 } 107 108 111 public boolean isStrictlyAscending() 112 { 113 if (_parent == null) 114 return true; 115 else 116 return _parent.isSingleSelect(); 117 } 118 119 126 public Node firstNode(Node node, ExprEnvironment env) 127 { 128 return node.getNextSibling(); 129 } 130 131 139 public Node nextNode(Node node, Node lastNode) 140 { 141 return node.getNextSibling(); 142 } 143 144 public String toString() 145 { 146 return getPrefix() + "following-sibling::"; 147 } 148 } 149 | Popular Tags |