KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > util > properties > Dom4jPropertyExtractor


1 /*
2  * $Id: Dom4jPropertyExtractor.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.util.properties;
12
13 import org.dom4j.Node;
14 import org.mule.umo.UMOMessage;
15
16 /**
17  * Will select the text of a single node based on the property name
18  */

19 public class Dom4jPropertyExtractor implements PropertyExtractor
20 {
21     public Object JavaDoc getProperty(String JavaDoc name, Object JavaDoc message)
22     {
23         Object JavaDoc payload = message;
24         if (message instanceof UMOMessage)
25         {
26             payload = ((UMOMessage)message).getPayload();
27         }
28         if (payload instanceof org.dom4j.Document)
29         {
30             org.dom4j.Document dom4jDoc = (org.dom4j.Document)payload;
31             try
32             {
33                 Node node = dom4jDoc.selectSingleNode(name);
34                 if (node != null)
35                 {
36                     return node.getText();
37                 }
38             }
39             catch (Exception JavaDoc ignored)
40             {
41                 // ignore
42
}
43         }
44         else if (payload instanceof org.dom4j.Node)
45         {
46             org.dom4j.Node dom4jNode = (org.dom4j.Node)payload;
47             try
48             {
49                 Node node = dom4jNode.selectSingleNode(name);
50                 if (node != null)
51                 {
52                     return node.getText();
53                 }
54             }
55             catch (Exception JavaDoc ignored)
56             {
57                 // ignore
58
}
59         }
60         return null;
61     }
62 }
63
Popular Tags