DumpUtility.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.logger;

  21. import org.openspcoop2.message.OpenSPCoop2Message;
  22. import org.openspcoop2.utils.xml.PrettyPrintXMLUtils;
  23. import org.openspcoop2.utils.xml.XMLUtils;
  24. import org.slf4j.Logger;
  25. import org.w3c.dom.Document;
  26. import org.w3c.dom.Element;

  27. /**    
  28.  * DumpUtility
  29.  *
  30.  * @author Poli Andrea (poli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */
  34. public class DumpUtility {

  35.     public static String toString(Element element,Logger log,OpenSPCoop2Message msg){
  36.         // Faccio una pretty-print
  37.         String xml = null;
  38.         try{
  39.             xml = PrettyPrintXMLUtils.prettyPrintWithTrAX(element);
  40.         }catch(Throwable e){
  41.             if(log!=null) {
  42.                 log.error("(DumpUtility) PrettyPrintWithTrAX non riuscita",e);
  43.             }
  44.             try{
  45.                 xml = msg.getAsString(element, false);
  46.             }catch(Throwable e2){
  47.                 if(log!=null) {
  48.                     log.error("(DumpUtility) msg.getAsString(soap,false) non riuscita",e2);
  49.                 }
  50.                 try{
  51.                     xml = XMLUtils.getInstance().toString(element, false);
  52.                 }catch(Throwable e3){
  53.                     if(log!=null)
  54.                         log.error("(DumpUtility) XMLUtils.toString non riuscita",e3);
  55.                 }
  56.             }
  57.         }
  58.         return xml;
  59.     }
  60.    
  61.     public static String toString(Document d,Logger log,OpenSPCoop2Message msg){
  62.         // Faccio una pretty-print
  63.         String xml = null;
  64.         try {
  65.             xml = PrettyPrintXMLUtils.prettyPrintWithTrAX(d);
  66.         }catch(Throwable e){
  67.             if(log!=null) {
  68.                 log.error("(DumpUtility) PrettyPrintWithTrAX non riuscita",e);
  69.             }
  70.             try{
  71.                 xml = msg.getAsString(d, false);
  72.             }catch(Throwable e2){
  73.                 if(log!=null)
  74.                     log.error("(DumpUtility) msg.getAsString(soap,false) non riuscita",e2);
  75.                 try{
  76.                     xml = XMLUtils.getInstance().toString(d, false);
  77.                 }catch(Throwable e3){
  78.                     if(log!=null)
  79.                         log.error("(DumpUtility) XMLUtils.toString non riuscita",e3);
  80.                 }
  81.             }
  82.         }
  83.         return xml;
  84.     }
  85.    
  86. }