ConfigurazionePdDUtils.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.config.utils;

  21. import org.openspcoop2.core.config.Configurazione;
  22. import org.openspcoop2.core.config.ConfigurazioneUrlInvocazioneRegola;
  23. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  24. import org.w3c.dom.Document;
  25. import org.w3c.dom.Element;
  26. import org.w3c.dom.Node;

  27. /**
  28.  *  ConfigurazionePdDUtils
  29.  *
  30.  * @author Poli Andrea (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */
  34. public class ConfigurazionePdDUtils {

  35.     public static boolean isConfigurazionePdD(byte [] doc){
  36.         return ConfigurazionePdDUtils.isConfigurazionePdD(doc,CostantiConfigurazione.ROOT_LOCAL_NAME_CONFIG);
  37.     }
  38.     public static boolean isConfigurazionePdD(byte [] doc,String localName){
  39.         try{
  40.             org.openspcoop2.message.xml.MessageXMLUtils xmlUtils = org.openspcoop2.message.xml.MessageXMLUtils.DEFAULT;
  41.             Document docXML = xmlUtils.newDocument(doc);
  42.             Element elemXML = docXML.getDocumentElement();
  43.             return ConfigurazionePdDUtils.isConfigurazionePdD_engine(elemXML,localName);
  44.         }catch(Exception e){
  45.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  46.             return false;
  47.         }
  48.     }
  49.     public static boolean isConfigurazionePdD(Document docXML){
  50.         return ConfigurazionePdDUtils.isConfigurazionePdD(docXML,CostantiConfigurazione.ROOT_LOCAL_NAME_CONFIG);
  51.     }
  52.     public static boolean isConfigurazionePdD(Document docXML,String localName){
  53.         try{
  54.             Element elemXML = docXML.getDocumentElement();
  55.             return ConfigurazionePdDUtils.isConfigurazionePdD_engine(elemXML,localName);
  56.         }catch(Exception e){
  57.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  58.             return false;
  59.         }
  60.     }
  61.     public static boolean isConfigurazionePdD(Element elemXML,String localName){
  62.         return isConfigurazionePdD_engine(elemXML,localName);
  63.     }
  64.     public static boolean isConfigurazionePdD(Node nodeXml,String localName){
  65.         return isConfigurazionePdD_engine(nodeXml,localName);
  66.     }
  67.     private static boolean isConfigurazionePdD_engine(Node nodeXml,String localName){
  68.         try{
  69.             //System.out.println("LOCAL["+Costanti.ROOT_LOCAL_NAME_DETTAGLIO_ECCEZIONE+"]vs["+elemXML.getLocalName()+"]  NAMESPACE["+Costanti.TARGET_NAMESPACE+"]vs["+elemXML.getNamespaceURI()+"]");
  70.             if(localName.equals(nodeXml.getLocalName()) &&
  71.                     CostantiConfigurazione.TARGET_NAMESPACE.equals(nodeXml.getNamespaceURI() )
  72.                 ){
  73.                 return true;
  74.             }
  75.             else{
  76.                 return false;
  77.             }
  78.         }catch(Exception e){
  79.             //System.out.println("NON e' un DOCUMENTO VALIDO: "+e.getMessage());
  80.             return false;
  81.         }
  82.     }

  83.    
  84.     public static int getProssimaPosizioneUrlInvocazioneRegola(Configurazione config) {
  85.         // calcolo prossima posizione
  86.         int posizione = 1;
  87.         if(config!=null) {
  88.             for (ConfigurazioneUrlInvocazioneRegola check : config.getUrlInvocazione().getRegolaList()) {
  89.                 if(check.getPosizione()>=posizione) {
  90.                     posizione = check.getPosizione()+1;
  91.                 }
  92.             }
  93.         }
  94.         return posizione;
  95.     }
  96. }