View Javadoc

1   /*
2    * FileUtil.java
3    *
4    * Created on 10 January 2007, 22:38
5    *
6    * To change this template, choose Tools | Template Manager
7    * and open the template in the editor.
8    */
9   
10  package org.wiztools.jenkryptor.util;
11  
12  import java.io.File;
13  import java.io.IOException;
14  import javax.swing.JOptionPane;
15  import org.wiztools.jenkryptor.Globals;
16  import org.wiztools.jenkryptor.validation.ValidatorException;
17  
18  /***
19   *
20   * @author subhash
21   */
22  public class FileUtil {
23      
24      /*** Creates a new instance of FileUtil */
25      private FileUtil() {
26      }
27      
28      public static String getFileNamesCSV(File[] files) throws ValidatorException, IOException{
29          StringBuffer sb = new StringBuffer();
30          
31          int filesEndingWithWiz = 0;
32          for(int i=0; i<files.length; i++){
33              String path = files[i].getCanonicalPath();
34              if(path.endsWith(".wiz")){
35                  filesEndingWithWiz += 1;
36              }
37              path = path.replaceAll("\"", "//\"");
38              sb.append('"').append(path).append('"').append(',');
39          }
40          sb.deleteCharAt(sb.length()-1);
41  
42          Globals.mode = Globals.MODE_ENCRYPT;
43          if(files.length == filesEndingWithWiz){
44              Globals.mode = Globals.MODE_DECRYPT;
45              Globals.msgDisplayer.setStatus("Decrypt mode set");
46          }
47          else if(filesEndingWithWiz != 0 && files.length > filesEndingWithWiz){
48              throw new ValidatorException("Please select one type of file!");
49          }
50          else{
51              Globals.msgDisplayer.setStatus("Encrypt mode set");
52          }
53  
54          Globals.files = files;
55          
56          return sb.toString();
57      }
58      
59  }