later version of client-side WSDL2Java generated simple Alignment
[jalview.git] / src / ext / jemboss / soap / MakeFileSafe.java
1 /****************************************************************
2 *
3 *  This program is free software; you can redistribute it and/or
4 *  modify it under the terms of the GNU General Public License
5 *  as published by the Free Software Foundation; either version 2
6 *  of the License, or (at your option) any later version.
7 *
8 *  This program is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with this program; if not, write to the Free Software
15 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 *
17 *  Based on EmbreoMakeFileSafe
18 *
19 *  @author: Copyright (C) Tim Carver
20 *
21 ***************************************************************/
22
23 package ext.jemboss.soap;
24
25 import java.io.*;
26
27 /**
28 *
29 * Create a sanitised filename. All undesirable characters in the
30 * filename are replaced by underscores.
31 *
32 */
33 public class MakeFileSafe
34 {
35
36   private String safeFileName;
37
38   /**
39   *
40   * @param unSafeFileName unsanitised name of the file
41   *
42   */
43   public MakeFileSafe(String unSafeFileName)
44   {
45     char c;
46     int len = unSafeFileName.length();
47     StringBuffer dest = new StringBuffer(len);
48
49     for(int i=0 ; i<len; i++)
50     {
51       c = unSafeFileName.charAt(i);
52       if(c == ':')
53         dest.append('_');
54       else if(c == '/')
55         dest.append('_');
56       else if(c == ' ')
57         dest.append('_');
58       else if(c == '>')
59         dest.append('_');
60       else if(c == '<')
61         dest.append('_');
62       else if(c == ';')
63         dest.append('_');
64       else if(c == '\\')
65         dest.append('_');
66       else
67         dest.append(c);
68
69     }
70     safeFileName = dest.toString();
71   }
72
73   /**
74   *
75   * Get the safe/sanitised file name
76   * @return     sanitised file name
77   *
78   */
79   public String getSafeFileName()
80   {
81     return safeFileName;
82   }
83 }