1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.axis.message.addressing.util;
19
20 import javax.xml.soap.SOAPElement;
21
22 import javax.xml.namespace.QName;
23
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26 import org.w3c.dom.Node;
27 import org.w3c.dom.NodeList;
28 import org.w3c.dom.Text;
29
30 /***
31 * Class TextExtractor
32 *
33 * @author Davanum Srinivas (dims@yahoo.com)
34 */
35 public class TextExtractor {
36
37 public static QName getQName(String value, SOAPElement elem) {
38 int p = value.indexOf(':');
39 String prefix = (p == -1) ? "" : value.substring(0, p);
40 String ns = elem.getNamespaceURI(prefix);
41 return new QName(ns, value.substring(p+1));
42 }
43
44 public static String getText(Node node) {
45 if (node == null) {
46 return "";
47 }
48
49 if (node instanceof Text) {
50 return node.getNodeValue().trim();
51 }
52
53 StringBuffer result = new StringBuffer();
54 NodeList list = node.getChildNodes();
55 for (int i=0;i<list.getLength();i++) {
56 Node child = list.item(i);
57 if (child instanceof Text) {
58 result.append(child.getNodeValue());
59 } else {
60
61 break;
62 }
63 }
64 return result.toString().trim();
65 }
66
67 public static String getText(SOAPElement element) {
68 String value = element.getValue();
69 return (value == null) ? "" : value.trim();
70 }
71
72 }