1 | /** |
---|
2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
4 | * |
---|
5 | * This program is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU Affero General Public License as |
---|
7 | * published by the Free Software Foundation, either version 3 of the |
---|
8 | * License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU Affero General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Affero General Public License |
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | */ |
---|
18 | |
---|
19 | /******************************************************************************\ |
---|
20 | * |
---|
21 | * This product was developed by |
---|
22 | * |
---|
23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
24 | * |
---|
25 | * a government company established under Brazilian law (5.615/70), |
---|
26 | * at Department of Development of Porto Alegre. |
---|
27 | * |
---|
28 | \******************************************************************************/ |
---|
29 | |
---|
30 | package serpro.mailarchiver.util; |
---|
31 | |
---|
32 | import javax.xml.soap.Detail; |
---|
33 | import javax.xml.soap.DetailEntry; |
---|
34 | import javax.xml.soap.Node; |
---|
35 | import javax.xml.soap.SOAPBody; |
---|
36 | import javax.xml.soap.SOAPBodyElement; |
---|
37 | import javax.xml.soap.SOAPElement; |
---|
38 | import javax.xml.soap.SOAPEnvelope; |
---|
39 | import javax.xml.soap.SOAPFault; |
---|
40 | import javax.xml.soap.SOAPFaultElement; |
---|
41 | import javax.xml.soap.SOAPHeader; |
---|
42 | import javax.xml.soap.SOAPHeaderElement; |
---|
43 | import javax.xml.soap.Text; |
---|
44 | |
---|
45 | import org.w3c.dom.Attr; |
---|
46 | import org.w3c.dom.NamedNodeMap; |
---|
47 | import org.w3c.dom.NodeList; |
---|
48 | |
---|
49 | public class SoapUtils { |
---|
50 | |
---|
51 | public static String dump(Node node) { |
---|
52 | StringBuilder sb = new StringBuilder(); |
---|
53 | dumpNode(node, sb, ""); |
---|
54 | return sb.toString(); |
---|
55 | } |
---|
56 | |
---|
57 | private static void dumpNode(Node node, StringBuilder sb, String ident) { |
---|
58 | if(node instanceof SOAPElement) { |
---|
59 | dumpSOAPElement((SOAPElement)node, sb, ident); |
---|
60 | } |
---|
61 | else if(node instanceof Text) { |
---|
62 | dumpText((Text)node, sb, ident); |
---|
63 | } |
---|
64 | else { |
---|
65 | sb.append(ident).append("--Node--------").append("\n"); |
---|
66 | } |
---|
67 | |
---|
68 | String nodeName = node.getNodeName(); |
---|
69 | sb.append(ident).append("nodeName: ").append(nodeName).append("\n"); |
---|
70 | |
---|
71 | String baseURI = node.getBaseURI(); |
---|
72 | sb.append(ident).append("baseURI: ").append(baseURI).append("\n"); |
---|
73 | |
---|
74 | String namespaceURI = node.getNamespaceURI(); |
---|
75 | sb.append(ident).append("namespaceURI: ").append(namespaceURI).append("\n"); |
---|
76 | |
---|
77 | String localName = node.getLocalName(); |
---|
78 | sb.append(ident).append("localName: ").append(localName).append("\n"); |
---|
79 | |
---|
80 | String nodeValue = node.getNodeValue(); |
---|
81 | sb.append(ident).append("nodeValue: ").append(nodeValue).append("\n"); |
---|
82 | |
---|
83 | short nodeType = node.getNodeType(); |
---|
84 | sb.append(ident).append("nodeType: ").append(nodeType).append("\n"); |
---|
85 | |
---|
86 | String prefix = node.getPrefix(); |
---|
87 | sb.append(ident).append("prefix: ").append(prefix).append("\n"); |
---|
88 | |
---|
89 | String textContent = node.getTextContent(); |
---|
90 | sb.append(ident).append("textContent: ").append(textContent).append("\n"); |
---|
91 | |
---|
92 | boolean hasAttributes = node.hasAttributes(); |
---|
93 | if(hasAttributes) { |
---|
94 | sb.append(ident).append("attributes: {"); |
---|
95 | NamedNodeMap attributes = node.getAttributes(); |
---|
96 | for(int i = 0; i < attributes.getLength(); i++) { |
---|
97 | if(i > 0) { |
---|
98 | sb.append(", "); |
---|
99 | } |
---|
100 | Attr attr = (Attr)attributes.item(i); |
---|
101 | sb.append(attr.getName()).append("=").append(attr.getValue()); |
---|
102 | } |
---|
103 | sb.append("}\n"); |
---|
104 | } |
---|
105 | |
---|
106 | boolean hasChildNodes = node.hasChildNodes(); |
---|
107 | if(hasChildNodes) { |
---|
108 | NodeList nodeList = node.getChildNodes(); |
---|
109 | for(int i = 0; i < nodeList.getLength(); i++) { |
---|
110 | dumpNode((Node)nodeList.item(i), sb, ident + " "); |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | private static void dumpSOAPElement(SOAPElement soapElement, StringBuilder sb, String ident) { |
---|
116 | if(soapElement instanceof DetailEntry) { |
---|
117 | dumpDetailEntry((DetailEntry)soapElement, sb, ident); |
---|
118 | } |
---|
119 | else if(soapElement instanceof SOAPBody) { |
---|
120 | dumpSOAPBody((SOAPBody)soapElement, sb, ident); |
---|
121 | } |
---|
122 | else if(soapElement instanceof SOAPBodyElement) { |
---|
123 | dumpSOAPBodyElement((SOAPBodyElement)soapElement, sb, ident); |
---|
124 | } |
---|
125 | else if(soapElement instanceof SOAPEnvelope) { |
---|
126 | dumpSOAPEnvelope((SOAPEnvelope)soapElement, sb, ident); |
---|
127 | } |
---|
128 | else if(soapElement instanceof SOAPFaultElement) { |
---|
129 | dumpSOAPFaultElement((SOAPFaultElement)soapElement, sb, ident); |
---|
130 | } |
---|
131 | else if(soapElement instanceof SOAPHeader) { |
---|
132 | dumpSOAPHeader((SOAPHeader)soapElement, sb, ident); |
---|
133 | } |
---|
134 | else if(soapElement instanceof SOAPHeaderElement) { |
---|
135 | dumpSOAPHeaderElement((SOAPHeaderElement)soapElement, sb, ident); |
---|
136 | } |
---|
137 | else { |
---|
138 | sb.append(ident).append("--SOAPElement--------").append("\n"); |
---|
139 | } |
---|
140 | //TODO |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | private static void dumpDetailEntry(DetailEntry detailEntry, StringBuilder sb, String ident) { |
---|
145 | sb.append(ident).append("--DetailEntry--------").append("\n"); |
---|
146 | //TODO |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | private static void dumpSOAPBody(SOAPBody soapBody, StringBuilder sb, String ident) { |
---|
151 | sb.append(ident).append("--SOAPBody--------").append("\n"); |
---|
152 | //TODO |
---|
153 | |
---|
154 | } |
---|
155 | |
---|
156 | private static void dumpSOAPBodyElement(SOAPBodyElement soapBodyElement, StringBuilder sb, String ident) { |
---|
157 | if(soapBodyElement instanceof SOAPFault) { |
---|
158 | dumpSOAPFault((SOAPFault)soapBodyElement, sb, ident); |
---|
159 | } |
---|
160 | else { |
---|
161 | sb.append(ident).append("--SOAPBodyElement--------").append("\n"); |
---|
162 | } |
---|
163 | //TODO |
---|
164 | |
---|
165 | } |
---|
166 | |
---|
167 | private static void dumpSOAPFault(SOAPFault soapFault, StringBuilder sb, String ident) { |
---|
168 | sb.append(ident).append("--SOAPFault--------").append("\n"); |
---|
169 | //TODO |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | private static void dumpSOAPEnvelope(SOAPEnvelope soapEnvelope, StringBuilder sb, String ident) { |
---|
174 | sb.append(ident).append("--SOAPEnvelope--------").append("\n"); |
---|
175 | //TODO |
---|
176 | |
---|
177 | } |
---|
178 | |
---|
179 | private static void dumpSOAPFaultElement(SOAPFaultElement soapFaultElement, StringBuilder sb, String ident) { |
---|
180 | if(soapFaultElement instanceof Detail) { |
---|
181 | dumpDetail((Detail)soapFaultElement, sb, ident); |
---|
182 | } |
---|
183 | else { |
---|
184 | sb.append(ident).append("--SOAPFaultElement--------").append("\n"); |
---|
185 | } |
---|
186 | //TODO |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | private static void dumpDetail(Detail detail, StringBuilder sb, String ident) { |
---|
191 | sb.append(ident).append("--Detail--------").append("\n"); |
---|
192 | //TODO |
---|
193 | |
---|
194 | } |
---|
195 | |
---|
196 | private static void dumpSOAPHeader(SOAPHeader soapHeader, StringBuilder sb, String ident) { |
---|
197 | sb.append(ident).append("--SOAPHeader--------").append("\n"); |
---|
198 | //TODO |
---|
199 | |
---|
200 | } |
---|
201 | |
---|
202 | private static void dumpSOAPHeaderElement(SOAPHeaderElement soapHeaderElement, StringBuilder sb, String ident) { |
---|
203 | sb.append(ident).append("--SOAPHeaderElement--------").append("\n"); |
---|
204 | //TODO |
---|
205 | |
---|
206 | } |
---|
207 | |
---|
208 | private static void dumpText(Text text, StringBuilder sb, String ident) { |
---|
209 | sb.append(ident).append("--Text--------").append("\n"); |
---|
210 | //TODO |
---|
211 | } |
---|
212 | |
---|
213 | } |
---|