1 16 19 package org.apache.xalan.templates; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.xalan.transformer.ClonerToResultTree; 24 import org.apache.xalan.transformer.TransformerImpl; 25 import org.apache.xml.dtm.DTM; 26 import org.apache.xalan.serialize.SerializerUtils; 27 import org.apache.xml.serializer.SerializationHandler; 28 import org.apache.xpath.XPathContext; 29 30 42 public class ElemCopy extends ElemUse 43 { 44 45 51 public int getXSLToken() 52 { 53 return Constants.ELEMNAME_COPY; 54 } 55 56 61 public String getNodeName() 62 { 63 return Constants.ELEMNAME_COPY_STRING; 64 } 65 66 87 public void execute( 88 TransformerImpl transformer) 89 throws TransformerException 90 { 91 XPathContext xctxt = transformer.getXPathContext(); 92 93 try 94 { 95 int sourceNode = xctxt.getCurrentNode(); 96 xctxt.pushCurrentNode(sourceNode); 97 DTM dtm = xctxt.getDTM(sourceNode); 98 short nodeType = dtm.getNodeType(sourceNode); 99 100 if ((DTM.DOCUMENT_NODE != nodeType) && (DTM.DOCUMENT_FRAGMENT_NODE != nodeType)) 101 { 102 SerializationHandler rthandler = transformer.getSerializationHandler(); 103 104 if (TransformerImpl.S_DEBUG) 105 transformer.getTraceManager().fireTraceEvent(this); 106 107 ClonerToResultTree.cloneToResultTree(sourceNode, nodeType, dtm, 109 rthandler, false); 110 111 if (DTM.ELEMENT_NODE == nodeType) 112 { 113 super.execute(transformer); 114 SerializerUtils.processNSDecls(rthandler, sourceNode, nodeType, dtm); 115 transformer.executeChildTemplates(this, true); 116 117 String ns = dtm.getNamespaceURI(sourceNode); 118 String localName = dtm.getLocalName(sourceNode); 119 transformer.getResultTreeHandler().endElement(ns, localName, 120 dtm.getNodeName(sourceNode)); 121 } 122 if (TransformerImpl.S_DEBUG) 123 transformer.getTraceManager().fireTraceEndEvent(this); 124 } 125 else 126 { 127 if (TransformerImpl.S_DEBUG) 128 transformer.getTraceManager().fireTraceEvent(this); 129 130 super.execute(transformer); 131 transformer.executeChildTemplates(this, true); 132 133 if (TransformerImpl.S_DEBUG) 134 transformer.getTraceManager().fireTraceEndEvent(this); 135 } 136 } 137 catch(org.xml.sax.SAXException se) 138 { 139 throw new TransformerException (se); 140 } 141 finally 142 { 143 xctxt.popCurrentNode(); 144 } 145 } 146 } 147 | Popular Tags |