1 16 19 20 package org.apache.xalan.transformer; 21 22 import javax.xml.transform.Transformer ; 23 24 import org.apache.xalan.templates.ElemTemplate; 25 import org.apache.xalan.templates.ElemTemplateElement; 26 import org.apache.xml.dtm.DTM; 27 import org.apache.xml.dtm.DTMIterator; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.traversal.NodeIterator; 30 31 35 public class XalanTransformState 36 implements TransformState { 37 38 Node m_node = null; 39 ElemTemplateElement m_currentElement = null; 40 ElemTemplate m_currentTemplate = null; 41 ElemTemplate m_matchedTemplate = null; 42 int m_currentNodeHandle = DTM.NULL; 43 Node m_currentNode = null; 44 int m_matchedNode = DTM.NULL; 45 DTMIterator m_contextNodeList = null; 46 boolean m_elemPending = false; 47 TransformerImpl m_transformer = null; 48 49 52 public void setCurrentNode(Node n) { 53 m_node = n; 54 } 55 56 59 public void resetState(Transformer transformer) { 60 if ((transformer != null) && (transformer instanceof TransformerImpl)) { 61 m_transformer = (TransformerImpl)transformer; 62 m_currentElement = m_transformer.getCurrentElement(); 63 m_currentTemplate = m_transformer.getCurrentTemplate(); 64 m_matchedTemplate = m_transformer.getMatchedTemplate(); 65 int currentNodeHandle = m_transformer.getCurrentNode(); 66 DTM dtm = m_transformer.getXPathContext().getDTM(currentNodeHandle); 67 m_currentNode = dtm.getNode(currentNodeHandle); 68 m_matchedNode = m_transformer.getMatchedNode(); 69 m_contextNodeList = m_transformer.getContextNodeList(); 70 } 71 } 72 73 76 public ElemTemplateElement getCurrentElement() { 77 if (m_elemPending) 78 return m_currentElement; 79 else 80 return m_transformer.getCurrentElement(); 81 } 82 83 86 public Node getCurrentNode() { 87 if (m_currentNode != null) { 88 return m_currentNode; 89 } else { 90 DTM dtm = m_transformer.getXPathContext().getDTM(m_transformer.getCurrentNode()); 91 return dtm.getNode(m_transformer.getCurrentNode()); 92 } 93 } 94 95 98 public ElemTemplate getCurrentTemplate() { 99 if (m_elemPending) 100 return m_currentTemplate; 101 else 102 return m_transformer.getCurrentTemplate(); 103 } 104 105 108 public ElemTemplate getMatchedTemplate() { 109 if (m_elemPending) 110 return m_matchedTemplate; 111 else 112 return m_transformer.getMatchedTemplate(); 113 } 114 115 118 public Node getMatchedNode() { 119 120 if (m_elemPending) { 121 DTM dtm = m_transformer.getXPathContext().getDTM(m_matchedNode); 122 return dtm.getNode(m_matchedNode); 123 } else { 124 DTM dtm = m_transformer.getXPathContext().getDTM(m_transformer.getMatchedNode()); 125 return dtm.getNode(m_transformer.getMatchedNode()); 126 } 127 } 128 129 132 public NodeIterator getContextNodeList() { 133 if (m_elemPending) { 134 return new org.apache.xml.dtm.ref.DTMNodeIterator(m_contextNodeList); 135 } else { 136 return new org.apache.xml.dtm.ref.DTMNodeIterator(m_transformer.getContextNodeList()); 137 } 138 } 139 142 public Transformer getTransformer() { 143 return m_transformer; 144 } 145 146 } 147 | Popular Tags |