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