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 org.openspcoop2.core.registry.utils;

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


  24. /**
  25.  * Classe utilizzata per la generazione del registro dei servizi
  26.  *
  27.  *
  28.  * @author Poli Andrea (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */

  32. public class XMLUtils  {

  33.    
  34.     public static boolean isRegistroServizi(byte [] doc){
  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.isRegistroServizi_engine(elemXML);
  40.         }catch(Exception e){
  41.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  42.             return false;
  43.         }
  44.     }
  45.     public static boolean isRegistroServizi(Document docXML){
  46.         try{
  47.             Element elemXML = docXML.getDocumentElement();
  48.             return XMLUtils.isRegistroServizi_engine(elemXML);
  49.         }catch(Exception e){
  50.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  51.             return false;
  52.         }
  53.     }
  54.     public static boolean isRegistroServizi(Element elemXML){
  55.         return isRegistroServizi_engine(elemXML);
  56.     }
  57.     public static boolean isRegistroServizi(Node nodeXml){
  58.         return isRegistroServizi_engine(nodeXml);
  59.     }
  60.     private static boolean isRegistroServizi_engine(Node nodeXml){
  61.         try{
  62.             ProjectInfo pInfo = new ProjectInfo();
  63.            
  64.             //System.out.println("LOCAL["+Costanti.ROOT_LOCAL_NAME_DETTAGLIO_ECCEZIONE+"]vs["+elemXML.getLocalName()+"]  NAMESPACE["+Costanti.TARGET_NAMESPACE+"]vs["+elemXML.getNamespaceURI()+"]");
  65.             if("registro-servizi".equals(nodeXml.getLocalName()) &&
  66.                     pInfo.getProjectNamespace().equals(nodeXml.getNamespaceURI() )
  67.                 ){
  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. }