ZIPUtils.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.basic.archive;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.utils.Utilities;


  24. /**
  25.  * Classe utilizzata per lavorare sui package
  26.  *
  27.  *
  28.  * @author Poli Andrea (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */

  32. public class ZIPUtils  {

  33.     public static final String ID_CORRELAZIONE_DEFAULT = "@PackageOpenSPCoop@";
  34.    
  35.    
  36.    
  37.    
  38.     public static String oldMethod_convertCharNonPermessiQualsiasiSistemaOperativo(String nome){
  39.         return oldMethod_convertCharNonPermessiQualsiasiSistemaOperativo(nome, true, null);
  40.     }
  41.     public static String oldMethod_convertCharNonPermessiQualsiasiSistemaOperativo(String nome,boolean permitUnderscore){
  42.         return oldMethod_convertCharNonPermessiQualsiasiSistemaOperativo(nome, permitUnderscore, null);
  43.     }
  44.     public static String oldMethod_convertCharNonPermessiQualsiasiSistemaOperativo(String nome,boolean permitUnderscore,List<Character> permit){
  45.         StringBuilder bf = new StringBuilder();
  46.         for (int i = 0; i < nome.length(); i++) {
  47.             if(Character.isLetterOrDigit(nome.charAt(i))){
  48.                 bf.append(nome.charAt(i));
  49.             }
  50.             else {
  51.                 if(permit!=null){
  52.                     // check che sia nella lista dei caratteri permessi
  53.                     boolean found = false;
  54.                     for (char charPermit : permit) {
  55.                         if(charPermit == nome.charAt(i)){
  56.                             found = true;
  57.                             break;
  58.                         }
  59.                     }
  60.                     if(found){
  61.                         bf.append(nome.charAt(i));
  62.                         continue;
  63.                     }
  64.                 }
  65.                
  66.                 // Se non e' nella lista dei caratteri permessi, se e' abilitato l'underscore mappo qualsiasi carattere in un '_',
  67.                 // altrimenti lo "brucio"
  68.                 if(permitUnderscore){
  69.                     // sostituisco tutto con _
  70.                     bf.append("_");
  71.                 }
  72.             }
  73.         }
  74.         return bf.toString();
  75.     }
  76.    
  77.    
  78.     public static String convertNameToSistemaOperativoCompatible(String nome){
  79.         List<Character> permit = new ArrayList<Character>();
  80.         // Non permetto nessun carattere poiche' alcune versioni del S.O. ad esempio non accettano un dato carattere se e' all'inizio o alla fine...
  81.         // quindi li maschero con il carattere jolly e sono tranquillo
  82. //      permit.add('.');
  83. //      permit.add('_');
  84. //      permit.add('-');
  85.        
  86.         Character cJolly = 'X'; // uso un carattere come jolly almeno non ho problemi
  87.        
  88.         return Utilities.convertNameToSistemaOperativoCompatible(nome,true,cJolly,permit,true);
  89.     }

  90.    
  91.    
  92. }