ArchiveVersion.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.protocol.sdk.constants;

  21. import java.io.BufferedReader;
  22. import java.io.StringReader;


  23. /**
  24.  *  ArchiveVersion
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public enum ArchiveVersion {

  31.     V_UNDEFINED, // indica una versione precedente a qualsiasi sistema di versionamento
  32.     V_1,
  33.     V_OTHER; // indica la prima versione in cui sono stati introdotti i sistemi di versionamento

  34.     public static final ArchiveVersion OPENSPCOOP2_ARCHIVE_ACTUAL_VERSION = ArchiveVersion.V_1;
  35.    
  36.     public static ArchiveVersion toArchiveVersion(byte [] content){
  37.         return toArchiveVersion(new String(content));
  38.     }
  39.     public static ArchiveVersion toArchiveVersion(String content){
  40.         if(content == null){
  41.             return V_UNDEFINED;
  42.         }
  43.        
  44.         StringReader sr = new StringReader(content);
  45.         BufferedReader br = new BufferedReader(sr);
  46.         try{
  47.             String v = br.readLine();
  48.            
  49.             if(V_1.name().equals(v)){
  50.                 return V_1;
  51.             }
  52.             else{
  53.                 return V_OTHER; // se non comprendo la versione
  54.             }
  55.         }catch(Exception e){
  56.             return V_UNDEFINED;
  57.         }
  58.     }
  59.     public static String toProductVersion(byte[] content){
  60.         return toProductVersion(new String(content));
  61.     }
  62.     public static String toProductVersion(String content){
  63.         if(content == null){
  64.             return null;
  65.         }
  66.        
  67.         StringReader sr = new StringReader(content);
  68.         BufferedReader br = new BufferedReader(sr);
  69.         try{
  70.             String v = br.readLine();
  71.             StringBuilder bf = new StringBuilder();
  72.             while((v=br.readLine())!=null){
  73.                 if(bf.length()>0){
  74.                     bf.append("\n");
  75.                 }
  76.                 bf.append(v);
  77.             }
  78.             return bf.toString();
  79.            
  80.         }catch(Exception e){
  81.             return null;
  82.         }
  83.     }
  84.    
  85.     public static String getContentFileVersion(String pddVersion){
  86.         return OPENSPCOOP2_ARCHIVE_ACTUAL_VERSION.name()+"\n"+pddVersion;
  87.     }
  88. }