1 16 19 package org.apache.xalan.transformer; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.xalan.serialize.SerializerUtils; 24 import org.apache.xml.dtm.DTM; 25 import org.apache.xml.serializer.SerializationHandler; 26 import org.apache.xml.utils.XMLString; 27 28 33 public class ClonerToResultTree 34 { 35 36 119 130 public static void cloneToResultTree(int node, int nodeType, DTM dtm, 131 SerializationHandler rth, 132 boolean shouldCloneAttributes) 133 throws TransformerException 134 { 135 136 try 137 { 138 switch (nodeType) 139 { 140 case DTM.TEXT_NODE : 141 dtm.dispatchCharactersEvents(node, rth, false); 142 break; 143 case DTM.DOCUMENT_FRAGMENT_NODE : 144 case DTM.DOCUMENT_NODE : 145 break; 148 case DTM.ELEMENT_NODE : 149 { 150 String ns = dtm.getNamespaceURI(node); 153 if (ns==null) ns=""; 154 String localName = dtm.getLocalName(node); 155 rth.startElement(ns, localName, dtm.getNodeNameX(node)); 159 160 if (shouldCloneAttributes) 164 { 165 SerializerUtils.addAttributes(rth, node); 166 SerializerUtils.processNSDecls(rth, node, nodeType, dtm); 167 } 168 } 169 break; 170 case DTM.CDATA_SECTION_NODE : 171 rth.startCDATA(); 172 dtm.dispatchCharactersEvents(node, rth, false); 173 rth.endCDATA(); 174 break; 175 case DTM.ATTRIBUTE_NODE : 176 SerializerUtils.addAttribute(rth, node); 177 break; 178 case DTM.NAMESPACE_NODE: 179 SerializerUtils.processNSDecls(rth,node,DTM.NAMESPACE_NODE,dtm); 184 break; 185 case DTM.COMMENT_NODE : 186 XMLString xstr = dtm.getStringValue (node); 187 xstr.dispatchAsComment(rth); 188 break; 189 case DTM.ENTITY_REFERENCE_NODE : 190 rth.entityReference(dtm.getNodeNameX(node)); 191 break; 192 case DTM.PROCESSING_INSTRUCTION_NODE : 193 { 194 rth.processingInstruction(dtm.getNodeNameX(node), 196 dtm.getNodeValue(node)); 197 } 198 break; 199 default : 200 throw new TransformerException ( 202 "Can't clone node: "+dtm.getNodeName(node)); 203 } 204 } 205 catch(org.xml.sax.SAXException se) 206 { 207 throw new TransformerException (se); 208 } 209 } } 211 | Popular Tags |