1 10 11 package org.mule.transformers.xml; 12 13 import org.mule.umo.transformer.TransformerException; 14 import org.w3c.dom.Document ; 15 16 import javax.xml.transform.OutputKeys ; 17 import javax.xml.transform.Source ; 18 import javax.xml.transform.Transformer ; 19 import javax.xml.transform.TransformerFactory ; 20 21 24 public class XmlToDomDocument extends AbstractXmlTransformer 25 { 26 29 private static final long serialVersionUID = 5056464684549099908L; 30 31 public XmlToDomDocument() 32 { 33 registerSourceType(String .class); 34 registerSourceType(byte[].class); 35 } 36 37 public Object doTransform(Object src, String encoding) throws TransformerException 38 { 39 try 40 { 41 Source sourceDoc = getXmlSource(src); 42 if (sourceDoc == null) return null; 43 44 ResultHolder holder = getResultHolder(returnClass); 47 if (holder == null) holder = getResultHolder(Document .class); 48 49 Transformer idTransformer = TransformerFactory.newInstance().newTransformer(); 50 idTransformer.setOutputProperty(OutputKeys.ENCODING, encoding); 51 idTransformer.transform(sourceDoc, holder.getResult()); 52 53 return holder.getResultObject(); 54 } 55 catch (Exception e) 56 { 57 throw new TransformerException(this, e); 58 } 59 } 60 } 61 | Popular Tags |