Coverage Report - net.sf.jabref.OpenFileFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
OpenFileFilter
66%
28/42
50%
11/22
3
 
 1  
 package net.sf.jabref;
 2  
 
 3  
 import java.io.File;
 4  
 import java.io.FilenameFilter;
 5  
 import java.util.HashSet;
 6  
 
 7  
 public class OpenFileFilter extends javax.swing.filechooser.FileFilter implements FilenameFilter {
 8  
 
 9  239471258
   HashSet<String> extSet = new HashSet<String>();
 10  
   String desc;
 11  
 
 12  239471258
   public OpenFileFilter(String[] extensions) {
 13  239471258
     StringBuffer buf = new StringBuffer();
 14  239471258
     int numExt = extensions.length;
 15  
 
 16  239471258
     if (numExt>0) {
 17  239471258
       buf.append('*');
 18  239471258
       buf.append(extensions[0]);
 19  
 
 20  239471258
       extSet.add(extensions[0]);
 21  
     }
 22  
 
 23  524523002
     for(int curExt = 1; curExt<numExt; curExt++) {
 24  285051744
       buf.append(", *");
 25  285051744
       buf.append(extensions[curExt]);
 26  
 
 27  285051744
       extSet.add(extensions[curExt]);
 28  
     }
 29  
 
 30  239471258
     desc = buf.toString();
 31  239471258
   }
 32  
 
 33  
   public OpenFileFilter() {
 34  37909474
     this( new String[] {
 35  
       ".bib",
 36  
       ".dat",  // silverplatter ending
 37  
       ".txt",  // windows puts ".txt" extentions and for scifinder
 38  
       ".ris",
 39  
       ".ref",  // refer/endnote format
 40  
       ".fcgi", // default for pubmed
 41  
       ".bibx", // default for BibTeXML
 42  
       ".xml"
 43  
     });
 44  37909474
   }
 45  
 
 46  
   public OpenFileFilter(String s) {
 47  183056883
     this(s.split("[, ]+",0));
 48  183056883
   }
 49  
 
 50  
   public boolean accept(File file){
 51  4663172688
     if (file.isDirectory())
 52  3997518298
       return true;
 53  
 
 54  665654390
     return accept(file.getName());
 55  
   }
 56  
 
 57  
   public boolean accept(String filenm){
 58  
 
 59  665654390
     filenm = filenm.toLowerCase();
 60  665654390
     int dotPos = filenm.lastIndexOf(".");
 61  
 
 62  665654390
     if (dotPos==-1)
 63  447133170
       return false;
 64  
 
 65  218521220
     int dotDotPos = filenm.lastIndexOf(".", dotPos-1); // for dot.dot extensions
 66  
 
 67  218521220
     return extSet.contains(filenm.substring(dotPos)) ||
 68  
       (dotDotPos>=0 && extSet.contains(filenm.substring(dotDotPos)));
 69  
   }
 70  
 
 71  
   public String getSuffix(String filenm) {
 72  
 
 73  
     int dotPos;
 74  
     String suffix;
 75  
     
 76  0
     dotPos = filenm.lastIndexOf(".");
 77  0
     if (dotPos==-1)
 78  0
       return null;
 79  
 
 80  0
     suffix = filenm.substring(dotPos);
 81  0
     if (extSet.contains(suffix))
 82  0
       return suffix;
 83  
 
 84  0
     dotPos = filenm.lastIndexOf(".", dotPos-1); // for dot.dot extensions
 85  0
     if (dotPos==-1)
 86  0
       return null;
 87  
 
 88  0
     suffix = filenm.substring(dotPos);
 89  0
     if (extSet.contains(suffix))
 90  0
       return suffix;
 91  
 
 92  0
     return null;
 93  
   }
 94  
 
 95  
   public String getDescription(){
 96  866514912
     return desc;
 97  
   }
 98  
 
 99  
   public boolean accept(File dir, String name) {
 100  0
     return accept(new File(dir.getPath()+name));
 101  
   }
 102  
 }
 103