XMLUtils.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 it.gov.fatturapa.sdi.messaggi.v1_0.utils;

  21. import org.w3c.dom.Document;
  22. import org.w3c.dom.Element;
  23. import org.w3c.dom.Node;


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

  32.     public static final String NAMESPACE_SENZA_GOV = new ProjectInfo().getProjectNamespace().replace("www.fatturapa.gov.it", "www.fatturapa.it");
  33.        
  34.     public static boolean isNotificaPA(byte [] doc, boolean compatibilitaNamespaceSenzaGov){
  35.         try{
  36.             org.openspcoop2.message.xml.MessageXMLUtils xmlUtils = org.openspcoop2.message.xml.MessageXMLUtils.DEFAULT;
  37.             Document docXML = xmlUtils.newDocument(doc);
  38.             Element elemXML = docXML.getDocumentElement();
  39.             return XMLUtils.isNotificaPA_engine(elemXML, compatibilitaNamespaceSenzaGov);
  40.         }catch(Exception e){
  41.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  42.             return false;
  43.         }
  44.     }
  45.     public static boolean isNotificaPA(Document docXML, boolean compatibilitaNamespaceSenzaGov){
  46.         try{
  47.             Element elemXML = docXML.getDocumentElement();
  48.             return XMLUtils.isNotificaPA_engine(elemXML,compatibilitaNamespaceSenzaGov);
  49.         }catch(Exception e){
  50.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  51.             return false;
  52.         }
  53.     }
  54.     public static boolean isNotificaPA(Element elemXML, boolean compatibilitaNamespaceSenzaGov){
  55.         return isNotificaPA_engine(elemXML,compatibilitaNamespaceSenzaGov);
  56.     }
  57.     public static boolean isNotificaPA(Node nodeXml, boolean compatibilitaNamespaceSenzaGov){
  58.         return isNotificaPA_engine(nodeXml, compatibilitaNamespaceSenzaGov);
  59.     }
  60.     private static boolean isNotificaPA_engine(Node nodeXml, boolean compatibilitaNamespaceSenzaGov){
  61.         try{
  62.             ProjectInfo info = new ProjectInfo();
  63.             if(info.getProjectNamespace().equals(nodeXml.getNamespaceURI() )
  64.                 ){
  65.                 return true;
  66.             }
  67.             else if(compatibilitaNamespaceSenzaGov && NAMESPACE_SENZA_GOV.equals(nodeXml.getNamespaceURI())) {
  68.                 return true;
  69.             }
  70.             else {
  71.                 return false;
  72.             }
  73.         }catch(Exception e){
  74.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  75.             return false;
  76.         }
  77.     }
  78.    
  79.    
  80.    
  81. }