1 10 11 package org.mule.util.properties; 12 13 import org.apache.commons.jxpath.JXPathContext; 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 import org.dom4j.Document; 17 import org.dom4j.DocumentException; 18 import org.dom4j.DocumentHelper; 19 import org.mule.util.properties.PropertyExtractor; 20 import org.mule.umo.UMOMessage; 21 22 25 public class JXPathPropertyExtractor implements PropertyExtractor 26 { 27 28 31 protected transient Log logger = LogFactory.getLog(getClass()); 32 33 public Object getProperty(String name, Object message) 34 { 35 36 Object result = null; 37 Object payload = message; 38 if (message instanceof UMOMessage) 39 { 40 payload = ((UMOMessage)message).getPayload(); 41 } 42 43 if (payload instanceof String ) 44 { 45 Document doc; 46 try 47 { 48 doc = DocumentHelper.parseText((String )payload); 49 } 50 catch (DocumentException e) 51 { 52 logger.error(e); 53 return null; 54 } 55 result = doc.valueOf(name); 56 } 57 else 58 { 59 JXPathContext context = JXPathContext.newContext(payload); 60 try 61 { 62 result = context.getValue(name); 63 } 64 catch (Exception e) 65 { 66 } 68 } 69 return result; 70 } 71 } 72 | Popular Tags |