1 16 19 package org.apache.xalan.transformer; 20 21 import java.util.Vector ; 22 23 import javax.xml.transform.TransformerException ; 24 25 import org.apache.xalan.res.XSLMessages; 26 import org.apache.xalan.res.XSLTErrorResources; 27 import org.apache.xalan.templates.KeyDeclaration; 28 import org.apache.xml.dtm.Axis; 29 import org.apache.xml.dtm.DTMIterator; 30 import org.apache.xml.utils.QName; 31 import org.apache.xpath.XPath; 32 import org.apache.xpath.axes.OneStepIteratorForward; 33 34 40 public class KeyIterator extends OneStepIteratorForward 41 { 42 43 45 private QName m_name; 46 47 53 public QName getName() 54 { 55 return m_name; 56 } 57 58 60 private Vector m_keyDeclarations; 61 62 68 public Vector getKeyDeclarations() 69 { 70 return m_keyDeclarations; 71 } 72 73 82 KeyIterator(QName name, Vector keyDeclarations) 83 { 84 super(Axis.ALL); 85 m_keyDeclarations = keyDeclarations; 86 m_name = name; 88 } 89 90 101 public short acceptNode(int testNode) 102 { 103 boolean foundKey = false; 104 KeyIterator ki = (KeyIterator) m_lpi; 105 org.apache.xpath.XPathContext xctxt = ki.getXPathContext(); 106 Vector keys = ki.getKeyDeclarations(); 107 108 QName name = ki.getName(); 109 try 110 { 111 int nDeclarations = keys.size(); 113 114 for (int i = 0; i < nDeclarations; i++) 116 { 117 KeyDeclaration kd = (KeyDeclaration) keys.elementAt(i); 118 119 if (!kd.getName().equals(name)) 122 continue; 123 124 foundKey = true; 125 127 XPath matchExpr = kd.getMatch(); 130 double score = matchExpr.getMatchScore(xctxt, testNode); 131 132 if (score == kd.getMatch().MATCH_SCORE_NONE) 133 continue; 134 135 return DTMIterator.FILTER_ACCEPT; 136 137 } } 139 catch (TransformerException se) 140 { 141 142 } 144 145 if (!foundKey) 146 throw new RuntimeException ( 147 XSLMessages.createMessage( 148 XSLTErrorResources.ER_NO_XSLKEY_DECLARATION, 149 new Object [] { name.getLocalName()})); 150 151 return DTMIterator.FILTER_REJECT; 152 } 153 154 } 155 | Popular Tags |