Coverage Report - org.mule.module.xml.transformer.XmlToDomDocument
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlToDomDocument
0%
0/22
0%
0/8
0
 
 1  
 /*
 2  
  * $Id: XmlToDomDocument.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.module.xml.transformer;
 12  
 
 13  
 import org.mule.api.MuleMessage;
 14  
 import org.mule.api.transformer.DiscoverableTransformer;
 15  
 import org.mule.api.transformer.TransformerException;
 16  
 import org.mule.module.xml.util.XMLUtils;
 17  
 
 18  
 import javax.xml.stream.XMLStreamReader;
 19  
 import javax.xml.transform.OutputKeys;
 20  
 import javax.xml.transform.Source;
 21  
 import javax.xml.transform.Transformer;
 22  
 
 23  
 import org.w3c.dom.Document;
 24  
 
 25  
 /**
 26  
  * <code>XmlToDomDocument</code> transforms a XML String to org.w3c.dom.Document.
 27  
  */
 28  0
 public class XmlToDomDocument extends AbstractXmlTransformer implements DiscoverableTransformer
 29  
 {
 30  0
     private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING;
 31  
 
 32  
     @Override
 33  
     public Object transformMessage(MuleMessage message, String encoding) throws TransformerException
 34  
     {
 35  0
         Object src = message.getPayload();
 36  
         try
 37  
         {
 38  0
             Source sourceDoc = XMLUtils.toXmlSource(getXMLInputFactory(), isUseStaxSource(), src);
 39  0
             if (sourceDoc == null)
 40  
             {
 41  0
                 return null;
 42  
             }
 43  
 
 44  0
             if (XMLStreamReader.class.equals(returnType))
 45  
             {
 46  0
                 return getXMLInputFactory().createXMLStreamReader(sourceDoc);
 47  
             }
 48  0
             else if (returnType.getType().isAssignableFrom(sourceDoc.getClass()))
 49  
             {
 50  0
                 return sourceDoc;
 51  
             }
 52  
 
 53  
             // If returnClass is not set, assume W3C DOM
 54  
             // This is the original behaviour
 55  0
             ResultHolder holder = getResultHolder(returnType.getType());
 56  0
             if (holder == null)
 57  
             {
 58  0
                 holder = getResultHolder(Document.class);
 59  
             }
 60  
 
 61  0
             Transformer idTransformer = XMLUtils.getTransformer();
 62  0
             idTransformer.setOutputProperty(OutputKeys.ENCODING, encoding);
 63  0
             idTransformer.transform(sourceDoc, holder.getResult());
 64  
 
 65  0
             return holder.getResultObject();
 66  
         }
 67  0
         catch (Exception e)
 68  
         {
 69  0
             throw new TransformerException(this, e);
 70  
         }
 71  
     }
 72  
 
 73  
     public int getPriorityWeighting()
 74  
     {
 75  0
         return priorityWeighting;
 76  
     }
 77  
 
 78  
     public void setPriorityWeighting(int priorityWeighting)
 79  
     {
 80  0
         this.priorityWeighting = priorityWeighting;
 81  0
     }
 82  
 }