Coverage Report - org.mule.module.xml.expression.XPathExpressionEvaluator
 
Classes in this File Line Coverage Branch Coverage Complexity
XPathExpressionEvaluator
0%
0/19
0%
0/20
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.xml.expression;
 8  
 
 9  
 import org.mule.module.xml.i18n.XmlMessages;
 10  
 
 11  
 import org.dom4j.Node;
 12  
 import org.jaxen.JaxenException;
 13  
 import org.jaxen.XPath;
 14  
 import org.jaxen.dom.DOMXPath;
 15  
 import org.jaxen.dom4j.Dom4jXPath;
 16  
 
 17  
 /**
 18  
  * Will select the text of a single node based on the property name
 19  
  */
 20  0
 public class XPathExpressionEvaluator extends AbstractXPathExpressionEvaluator
 21  
 {
 22  
     public static final String NAME = "xpath";
 23  
 
 24  
     @Override
 25  
     protected XPath createXPath(String expression, Object object) throws JaxenException
 26  
     {
 27  0
         if(createDOMXPath(object))
 28  
         {
 29  0
             return new DOMXPath(expression);
 30  
         }
 31  0
         else if (createDom4jXPath(object))
 32  
         {
 33  0
             return new Dom4jXPath(expression);
 34  
         }
 35  
         else
 36  
         {
 37  0
             throw new IllegalArgumentException(XmlMessages.domTypeNotSupported(object.getClass()).getMessage());
 38  
         }
 39  
     }
 40  
 
 41  
     @Override
 42  
     protected String getXPathClassName(Object object)
 43  
     {
 44  0
         if(createDOMXPath(object))
 45  
         {
 46  0
             return DOMXPath.class.getName();
 47  
         }
 48  0
         if(createDom4jXPath(object))
 49  
         {
 50  0
             return Dom4jXPath.class.getName();
 51  
         }
 52  0
         return super.getXPathClassName(object);
 53  
     }
 54  
 
 55  
     private boolean createDOMXPath(Object object)
 56  
     {
 57  0
         return object instanceof org.w3c.dom.Document || object instanceof org.w3c.dom.Element;
 58  
     }
 59  
 
 60  
     private boolean createDom4jXPath(Object object)
 61  
     {
 62  0
         return object instanceof org.dom4j.Document || object instanceof org.dom4j.Element;
 63  
     }
 64  
 
 65  
     protected Object extractResultFromNode(Object result)
 66  
     {
 67  0
         if(result instanceof Node)
 68  
         {
 69  0
             return ((Node)result).getText();
 70  
         }
 71  0
         else if(result instanceof org.w3c.dom.Node)
 72  
         {
 73  0
             return ((org.w3c.dom.Node)result).getFirstChild().getNodeValue();
 74  
         }
 75  
         else
 76  
         {
 77  0
             return result;
 78  
         }
 79  
     }
 80  
 
 81  
     /** {@inheritDoc} */
 82  
     public String getName()
 83  
     {
 84  0
         return NAME;
 85  
     }
 86  
 }