1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.subscription.dte;
|
---|
6 |
|
---|
7 | import javax.xml.transform.dom.DOMResult;
|
---|
8 | import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
---|
9 | import org.w3c.dom.*;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | *
|
---|
13 | * @author rayj
|
---|
14 | */
|
---|
15 | public class XmlHelper {
|
---|
16 |
|
---|
17 | private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(XmlHelper.class);
|
---|
18 |
|
---|
19 | public static String getNodeValue(Node node) {
|
---|
20 | String nodeValue = "";
|
---|
21 | if (node != null) {
|
---|
22 | nodeValue = node.getTextContent();
|
---|
23 | if (nodeValue != null) {
|
---|
24 | nodeValue = nodeValue.trim();
|
---|
25 | }
|
---|
26 | }
|
---|
27 | return nodeValue;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public static String getNodeValue(Document document, String elementName) {
|
---|
31 | return getNodeValue(getSingleNode(document, elementName));
|
---|
32 | }
|
---|
33 |
|
---|
34 | public static NodeList getNodeList(Document document, String elementName) {
|
---|
35 | NodeList nodeList = null;
|
---|
36 | if (document != null) {
|
---|
37 | nodeList = document.getElementsByTagName(elementName);
|
---|
38 | }
|
---|
39 | return nodeList;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public static Node getSingleNode(Document document, String elementName) {
|
---|
43 | Node node = null;
|
---|
44 | NodeList nodeList = getNodeList(document, elementName);
|
---|
45 | if ((nodeList != null) && (nodeList.getLength() > 0)) {
|
---|
46 | node = nodeList.item(0);
|
---|
47 | }
|
---|
48 | return node;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public static NodeList getSingleNodeChildren(Document document, String elementName) {
|
---|
52 | NodeList childrenNodeList = null;
|
---|
53 | Node parentNode = null;
|
---|
54 | NodeList parentNodeList = getNodeList(document, elementName);
|
---|
55 | if ((parentNodeList != null) && (parentNodeList.getLength() > 0)) {
|
---|
56 | parentNode = parentNodeList.item(0);
|
---|
57 | }
|
---|
58 | if (parentNode != null) {
|
---|
59 | childrenNodeList = parentNode.getChildNodes();
|
---|
60 | }
|
---|
61 | return childrenNodeList;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public static Document transformEndpointReferenceToDocument(W3CEndpointReference endpointRef) {
|
---|
65 | DOMResult domresult = new DOMResult();
|
---|
66 | endpointRef.writeTo(domresult);
|
---|
67 | Node endpointNode = domresult.getNode();
|
---|
68 |
|
---|
69 | Document endpointNodeDoc = (Document) endpointNode;
|
---|
70 | return endpointNodeDoc;
|
---|
71 | }
|
---|
72 | }
|
---|