/** * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /******************************************************************************\ * * This product was developed by * * SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), * * a government company established under Brazilian law (5.615/70), * at Department of Development of Porto Alegre. * \******************************************************************************/ package serpro.mailarchiver.util; import javax.xml.soap.Detail; import javax.xml.soap.DetailEntry; import javax.xml.soap.Node; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPBodyElement; import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPFault; import javax.xml.soap.SOAPFaultElement; import javax.xml.soap.SOAPHeader; import javax.xml.soap.SOAPHeaderElement; import javax.xml.soap.Text; import org.w3c.dom.Attr; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NodeList; public class SoapUtils { public static String dump(Node node) { StringBuilder sb = new StringBuilder(); dumpNode(node, sb, ""); return sb.toString(); } private static void dumpNode(Node node, StringBuilder sb, String ident) { if(node instanceof SOAPElement) { dumpSOAPElement((SOAPElement)node, sb, ident); } else if(node instanceof Text) { dumpText((Text)node, sb, ident); } else { sb.append(ident).append("--Node--------").append("\n"); } String nodeName = node.getNodeName(); sb.append(ident).append("nodeName: ").append(nodeName).append("\n"); String baseURI = node.getBaseURI(); sb.append(ident).append("baseURI: ").append(baseURI).append("\n"); String namespaceURI = node.getNamespaceURI(); sb.append(ident).append("namespaceURI: ").append(namespaceURI).append("\n"); String localName = node.getLocalName(); sb.append(ident).append("localName: ").append(localName).append("\n"); String nodeValue = node.getNodeValue(); sb.append(ident).append("nodeValue: ").append(nodeValue).append("\n"); short nodeType = node.getNodeType(); sb.append(ident).append("nodeType: ").append(nodeType).append("\n"); String prefix = node.getPrefix(); sb.append(ident).append("prefix: ").append(prefix).append("\n"); String textContent = node.getTextContent(); sb.append(ident).append("textContent: ").append(textContent).append("\n"); boolean hasAttributes = node.hasAttributes(); if(hasAttributes) { sb.append(ident).append("attributes: {"); NamedNodeMap attributes = node.getAttributes(); for(int i = 0; i < attributes.getLength(); i++) { if(i > 0) { sb.append(", "); } Attr attr = (Attr)attributes.item(i); sb.append(attr.getName()).append("=").append(attr.getValue()); } sb.append("}\n"); } boolean hasChildNodes = node.hasChildNodes(); if(hasChildNodes) { NodeList nodeList = node.getChildNodes(); for(int i = 0; i < nodeList.getLength(); i++) { dumpNode((Node)nodeList.item(i), sb, ident + " "); } } } private static void dumpSOAPElement(SOAPElement soapElement, StringBuilder sb, String ident) { if(soapElement instanceof DetailEntry) { dumpDetailEntry((DetailEntry)soapElement, sb, ident); } else if(soapElement instanceof SOAPBody) { dumpSOAPBody((SOAPBody)soapElement, sb, ident); } else if(soapElement instanceof SOAPBodyElement) { dumpSOAPBodyElement((SOAPBodyElement)soapElement, sb, ident); } else if(soapElement instanceof SOAPEnvelope) { dumpSOAPEnvelope((SOAPEnvelope)soapElement, sb, ident); } else if(soapElement instanceof SOAPFaultElement) { dumpSOAPFaultElement((SOAPFaultElement)soapElement, sb, ident); } else if(soapElement instanceof SOAPHeader) { dumpSOAPHeader((SOAPHeader)soapElement, sb, ident); } else if(soapElement instanceof SOAPHeaderElement) { dumpSOAPHeaderElement((SOAPHeaderElement)soapElement, sb, ident); } else { sb.append(ident).append("--SOAPElement--------").append("\n"); } //TODO } private static void dumpDetailEntry(DetailEntry detailEntry, StringBuilder sb, String ident) { sb.append(ident).append("--DetailEntry--------").append("\n"); //TODO } private static void dumpSOAPBody(SOAPBody soapBody, StringBuilder sb, String ident) { sb.append(ident).append("--SOAPBody--------").append("\n"); //TODO } private static void dumpSOAPBodyElement(SOAPBodyElement soapBodyElement, StringBuilder sb, String ident) { if(soapBodyElement instanceof SOAPFault) { dumpSOAPFault((SOAPFault)soapBodyElement, sb, ident); } else { sb.append(ident).append("--SOAPBodyElement--------").append("\n"); } //TODO } private static void dumpSOAPFault(SOAPFault soapFault, StringBuilder sb, String ident) { sb.append(ident).append("--SOAPFault--------").append("\n"); //TODO } private static void dumpSOAPEnvelope(SOAPEnvelope soapEnvelope, StringBuilder sb, String ident) { sb.append(ident).append("--SOAPEnvelope--------").append("\n"); //TODO } private static void dumpSOAPFaultElement(SOAPFaultElement soapFaultElement, StringBuilder sb, String ident) { if(soapFaultElement instanceof Detail) { dumpDetail((Detail)soapFaultElement, sb, ident); } else { sb.append(ident).append("--SOAPFaultElement--------").append("\n"); } //TODO } private static void dumpDetail(Detail detail, StringBuilder sb, String ident) { sb.append(ident).append("--Detail--------").append("\n"); //TODO } private static void dumpSOAPHeader(SOAPHeader soapHeader, StringBuilder sb, String ident) { sb.append(ident).append("--SOAPHeader--------").append("\n"); //TODO } private static void dumpSOAPHeaderElement(SOAPHeaderElement soapHeaderElement, StringBuilder sb, String ident) { sb.append(ident).append("--SOAPHeaderElement--------").append("\n"); //TODO } private static void dumpText(Text text, StringBuilder sb, String ident) { sb.append(ident).append("--Text--------").append("\n"); //TODO } }