1 package com.icl.saxon.pattern; 2 import com.icl.saxon.Context; 3 import com.icl.saxon.om.NodeInfo; 4 import com.icl.saxon.om.DocumentInfo; 5 import com.icl.saxon.expr.XPathException; 6 7 import java.util.StringTokenizer ; 8 9 12 13 public final class IDPattern extends Pattern { 14 15 private String id; private boolean containsSpaces; 17 18 public IDPattern(String idvalue) { 19 id = idvalue; 20 containsSpaces = 21 (id.indexOf(' ') >= 0 || 22 id.indexOf(0x09) >= 0 || 23 id.indexOf(0x0a) >= 0 || 24 id.indexOf(0x0c) >= 0); 25 } 26 27 32 33 public boolean matches(NodeInfo e, Context c) throws XPathException { 34 if (e.getNodeType() != NodeInfo.ELEMENT) return false; 35 DocumentInfo doc = e.getDocumentRoot(); 36 if (!containsSpaces) { 37 NodeInfo element = doc.selectID(id); 38 if (element==null) return false; 39 return (element.isSameNode(e)); 40 } else { 41 StringTokenizer tokenizer = new StringTokenizer (id); 42 while (tokenizer.hasMoreElements()) { 43 String idv = (String )tokenizer.nextElement(); 44 NodeInfo element = doc.selectID(idv); 45 if (element != null && e.isSameNode(element)) { 46 return true; 47 } 48 } 49 return false; 50 } 51 } 52 53 57 58 public short getNodeType() { 59 return NodeInfo.ELEMENT; 60 } 61 62 } 63 64 | Popular Tags |