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.fatturapa.v1_1.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 boolean isFattura(byte [] doc){
  33.         try{
  34.             org.openspcoop2.message.xml.MessageXMLUtils xmlUtils = org.openspcoop2.message.xml.MessageXMLUtils.DEFAULT;
  35.             Document docXML = xmlUtils.newDocument(doc);
  36.             Element elemXML = docXML.getDocumentElement();
  37.             return XMLUtils.isFattura_engine(elemXML);
  38.         }catch(Exception e){
  39.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  40.             return false;
  41.         }
  42.     }
  43.     public static boolean isFattura(Document docXML){
  44.         try{
  45.             Element elemXML = docXML.getDocumentElement();
  46.             return XMLUtils.isFattura_engine(elemXML);
  47.         }catch(Exception e){
  48.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  49.             return false;
  50.         }
  51.     }
  52.     public static boolean isFattura(Element elemXML){
  53.         return isFattura_engine(elemXML);
  54.     }
  55.     public static boolean isFattura(Node nodeXml){
  56.         return isFattura_engine(nodeXml);
  57.     }
  58.     private static boolean isFattura_engine(Node nodeXml){
  59.         try{
  60.             ProjectInfo info = new ProjectInfo();
  61.             if("FatturaElettronica".equals(nodeXml.getLocalName()) &&
  62.                     info.getProjectNamespace().equals(nodeXml.getNamespaceURI() )
  63.                 ){
  64.                 return true;
  65.             }
  66.             else{
  67.                 return false;
  68.             }
  69.         }catch(Exception e){
  70.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  71.             return false;
  72.         }
  73.     }
  74.    
  75. }