TransferLengthModes.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.constants;

  21. /**
  22.  * Contiene i tipi di transfer length utilizzati dai servizi PD e PA
  23.  *
  24.  * @author apoli@link.it
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */

  28. public enum TransferLengthModes {

  29.     TRANSFER_ENCODING_CHUNKED ("transfer-encoding-chunked"),
  30.     CONTENT_LENGTH ("content-length"),
  31.     WEBSERVER_DEFAULT ("webserver-default");
  32.    
  33.    
  34.     private final String nome;

  35.     TransferLengthModes(String nome)
  36.     {
  37.         this.nome = nome;
  38.     }

  39.     public String getNome()
  40.     {
  41.         return this.nome;
  42.     }
  43.    
  44.     public static TransferLengthModes getTransferLengthModes(String value) throws Exception{
  45.         if(TRANSFER_ENCODING_CHUNKED.toString().equals(value)){
  46.             return TRANSFER_ENCODING_CHUNKED;
  47.         }
  48.         else if(CONTENT_LENGTH.toString().equals(value)){
  49.             return CONTENT_LENGTH;
  50.         }
  51.         else if(WEBSERVER_DEFAULT.toString().equals(value)){
  52.             return WEBSERVER_DEFAULT;
  53.         }
  54.         else{
  55.             throw new Exception("Tipo transfer-length non supportato (valori supportati "+TransferLengthModes.stringValues()+"): "+value);
  56.         }
  57.     }
  58.    
  59.     public static String stringValues(){
  60.         StringBuilder res = new StringBuilder();
  61.         int i=0;
  62.         for (TransferLengthModes tmp : TransferLengthModes.values()) {
  63.             if(i>0)
  64.                 res.append(",");
  65.             res.append(tmp.getNome());
  66.             i++;
  67.         }
  68.         return res.toString();
  69.     }
  70.    
  71.     public static String[] toStringArray(){
  72.         String[] res = new String[TransferLengthModes.values().length];
  73.         int i=0;
  74.         for (TransferLengthModes tmp : TransferLengthModes.values()) {
  75.             res[i]=tmp.getNome();
  76.             i++;
  77.         }
  78.         return res;
  79.     }
  80.    
  81.     @Override
  82.     public String toString() {
  83.         return this.nome;
  84.     }
  85.    
  86.     public boolean equals(String tlm){
  87.         if(tlm==null) {
  88.             return false;
  89.         }
  90.         return this.toString().equals(tlm);
  91.     }
  92. }