1 16 19 package org.apache.xalan.transformer; 20 21 import java.util.Vector ; 22 23 import org.apache.xalan.res.XSLMessages; 24 import org.apache.xalan.res.XSLTErrorResources; 25 import org.apache.xalan.templates.KeyDeclaration; 26 import org.apache.xml.dtm.DTM; 27 import org.apache.xml.dtm.DTMIterator; 28 import org.apache.xml.utils.QName; 29 import org.apache.xml.utils.XMLString; 30 import org.apache.xpath.objects.XNodeSet; 31 import org.apache.xpath.objects.XObject; 32 33 38 public class KeyRefIterator extends org.apache.xpath.axes.ChildTestIterator 39 { 40 47 public KeyRefIterator(QName name, XMLString ref, Vector keyDecls, DTMIterator ki) 48 { 49 super(null); 50 m_name = name; 51 m_ref = ref; 52 m_keyDeclarations = keyDecls; 53 m_keysNodes = ki; 54 setWhatToShow(org.apache.xml.dtm.DTMFilter.SHOW_ALL); 55 } 56 57 DTMIterator m_keysNodes; 58 59 63 protected int getNextNode() 64 { 65 int next; 66 while(DTM.NULL != (next = m_keysNodes.nextNode())) 67 { 68 if(DTMIterator.FILTER_ACCEPT == filterNode(next)) 69 break; 70 } 71 m_lastFetched = next; 72 73 return next; 74 } 75 76 77 88 public short filterNode(int testNode) 89 { 90 boolean foundKey = false; 91 Vector keys = m_keyDeclarations; 92 93 QName name = m_name; 94 KeyIterator ki = (KeyIterator)(((XNodeSet)m_keysNodes).getContainedIter()); 95 org.apache.xpath.XPathContext xctxt = ki.getXPathContext(); 96 97 if(null == xctxt) 98 assertion(false, "xctxt can not be null here!"); 99 100 try 101 { 102 XMLString lookupKey = m_ref; 103 104 int nDeclarations = keys.size(); 106 107 for (int i = 0; i < nDeclarations; i++) 109 { 110 KeyDeclaration kd = (KeyDeclaration) keys.elementAt(i); 111 112 if (!kd.getName().equals(name)) 115 continue; 116 117 foundKey = true; 118 120 XObject xuse = kd.getUse().execute(xctxt, testNode, ki.getPrefixResolver()); 123 124 if (xuse.getType() != xuse.CLASS_NODESET) 125 { 126 XMLString exprResult = xuse.xstr(); 127 128 if (lookupKey.equals(exprResult)) 129 return DTMIterator.FILTER_ACCEPT; 130 } 131 else 132 { 133 DTMIterator nl = ((XNodeSet)xuse).iterRaw(); 134 int useNode; 135 136 while (DTM.NULL != (useNode = nl.nextNode())) 137 { 138 DTM dtm = getDTM(useNode); 139 XMLString exprResult = dtm.getStringValue(useNode); 140 if ((null != exprResult) && lookupKey.equals(exprResult)) 141 return DTMIterator.FILTER_ACCEPT; 142 } 143 } 144 145 } } 147 catch (javax.xml.transform.TransformerException te) 148 { 149 throw new org.apache.xml.utils.WrappedRuntimeException(te); 150 } 151 152 if (!foundKey) 153 throw new RuntimeException ( 154 XSLMessages.createMessage( 155 XSLTErrorResources.ER_NO_XSLKEY_DECLARATION, 156 new Object [] { name.getLocalName()})); 157 return DTMIterator.FILTER_REJECT; 158 } 159 160 protected XMLString m_ref; 161 protected QName m_name; 162 163 165 protected Vector m_keyDeclarations; 166 167 } 168 | Popular Tags |