SDICompatibilitaNamespaceErrati.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.protocol.sdi.utils;

  21. import org.slf4j.Logger;

  22. /**
  23.  * SDICompatibilitaNamespaceErrati
  24.  *
  25.  * @author Andrea Poli (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class SDICompatibilitaNamespaceErrati {

  30.     private static it.gov.fatturapa.sdi.messaggi.v1_0.utils.ProjectInfo pInfo = new it.gov.fatturapa.sdi.messaggi.v1_0.utils.ProjectInfo();
  31.    
  32.     private static final String NAMESPACE_SENZA_GOV = it.gov.fatturapa.sdi.messaggi.v1_0.utils.XMLUtils.NAMESPACE_SENZA_GOV;
  33.    
  34.     public static byte[] convertiXmlNamespaceSenzaGov(Logger log, byte[] xml){
  35.         try{
  36.            
  37.             String xmlAsAstring = new String(xml);
  38.             if(xmlAsAstring.contains(NAMESPACE_SENZA_GOV)){
  39.                 int count = 0;
  40.                 while(xmlAsAstring.contains(NAMESPACE_SENZA_GOV) && count<1000){
  41.                     count++; // per evitare un loop infinito
  42.                     xmlAsAstring = xmlAsAstring.replace(NAMESPACE_SENZA_GOV, pInfo.getProjectNamespace());
  43.                 }
  44.                
  45.                 //System.out.println("RITORNO MODIFICATO ["+xmlAsAstring+"]");
  46.                 return xmlAsAstring.getBytes();
  47.             }
  48.            
  49.         }catch(Exception e){
  50.             log.debug("Compatibilita' Namespace senza Gov abilitata, la modifica al namespace non e' riuscita (Puo' darsi che fosse sbagliato gia' il documento originale, prendere questo messaggio come informazione di debug): "+e.getMessage(),e);
  51.         }
  52.         //System.out.println("RITORNO ORIGINALE");
  53.         return xml;
  54.     }
  55.    
  56.     public static byte[] produciXmlNamespaceSenzaGov(Logger log, byte[] xml){
  57.         try{
  58.            
  59.             String xmlAsAstring = new String(xml);
  60.             if(xmlAsAstring.contains(pInfo.getProjectNamespace())){
  61.                 int count = 0;
  62.                 while(xmlAsAstring.contains(pInfo.getProjectNamespace()) && count<1000){
  63.                     count++; // per evitare un loop infinito
  64.                     xmlAsAstring = xmlAsAstring.replace(pInfo.getProjectNamespace(), NAMESPACE_SENZA_GOV);
  65.                 }
  66.                
  67.                 //System.out.println("RITORNO MODIFICATO ["+xmlAsAstring+"]");
  68.                 return xmlAsAstring.getBytes();
  69.             }
  70.            
  71.         }catch(Exception e){
  72.             log.debug("Generazione Namespace senza Gov abilitata, la modifica al namespace non e' riuscita (Puo' darsi che fosse sbagliato gia' il documento originale, prendere questo messaggio come informazione di debug): "+e.getMessage(),e);
  73.         }
  74.         //System.out.println("RITORNO ORIGINALE");
  75.         return xml;
  76.     }
  77.    
  78. }