Coverage Report - org.jtheque.films.services.impl.utils.file.jt.FileFilterFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
FileFilterFactory
0 %
0/24
0 %
0/4
1.5
FileFilterFactory$1
N/A
N/A
1.5
FileFilterFactory$FiltersUpdater
0 %
0/3
N/A
1.5
 
 1  
 package org.jtheque.films.services.impl.utils.file.jt;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.language.ILanguageManager;
 21  
 import org.jtheque.core.managers.language.Internationalizable;
 22  
 import org.jtheque.films.utils.Constants.Files.FileType;
 23  
 import org.jtheque.utils.io.SimpleFilter;
 24  
 
 25  
 /**
 26  
  * A factory to obtain file filter for a specific type of file.
 27  
  *
 28  
  * @author Baptiste Wicht
 29  
  */
 30  0
 public final class FileFilterFactory {
 31  
     private static final JTFileFilter[] FILTERS;
 32  
 
 33  
     static {
 34  0
         FILTERS = new JTFileFilter[9];
 35  
 
 36  0
         createFilters();
 37  
 
 38  0
         Managers.getManager(ILanguageManager.class).addInternationalizable(new FiltersUpdater());
 39  0
     }
 40  
 
 41  
     /**
 42  
      * Construct a new FileFilterFactory.
 43  
      */
 44  
     private FileFilterFactory() {
 45  0
         super();
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Create the filters.
 50  
      */
 51  
     private static void createFilters() {
 52  0
         ILanguageManager resources = Managers.getManager(ILanguageManager.class);
 53  
 
 54  0
         FILTERS[0] = new JTFileFilter(resources.getMessage("utils.filters.html"), ".html", FileType.HTML);
 55  0
         FILTERS[1] = new JTFileFilter(resources.getMessage("utils.filters.xml"), ".xml", FileType.XML);
 56  0
         FILTERS[2] = new JTFileFilter(resources.getMessage("utils.filters.xls"), ".xls", FileType.XLS);
 57  0
         FILTERS[3] = new JTFileFilter(resources.getMessage("utils.filters.txt"), ".txt", FileType.TXT);
 58  0
         FILTERS[4] = new JTFileFilter(resources.getMessage("utils.filters.pdf"), ".pdf", FileType.PDF);
 59  0
         FILTERS[5] = new JTFileFilter(resources.getMessage("utils.filters.jtf"), ".jtf", FileType.JTF);
 60  0
         FILTERS[6] = new JTFileFilter(resources.getMessage("utils.filters.rtf"), ".rtf", FileType.RTF);
 61  0
         FILTERS[7] = new JTFileFilter(resources.getMessage("utils.filters.csv"), ".csv", FileType.CSV);
 62  0
         FILTERS[8] = new JTFileFilter(resources.getMessage("utils.filters.jtfe"), ".jtfe", FileType.JTFE);
 63  0
     }
 64  
 
 65  
     /**
 66  
      * Return the file filter for this type of file.
 67  
      *
 68  
      * @param fileType The file type.
 69  
      * @return The good filter or <code>null</code> if we doesn't filter an appropriate filter.
 70  
      */
 71  
     public static SimpleFilter getFileFilter(FileType fileType) {
 72  0
         JTFileFilter filter = null;
 73  
 
 74  0
         for (JTFileFilter f : FILTERS) {
 75  0
             if (f.canFilter(fileType)) {
 76  0
                 filter = f;
 77  0
                 break;
 78  
             }
 79  
         }
 80  
 
 81  0
         return filter;
 82  
     }
 83  
 
 84  
     /**
 85  
      * A filters updater.
 86  
      *
 87  
      * @author Baptiste Wicht
 88  
      */
 89  0
     private static final class FiltersUpdater implements Internationalizable {
 90  
         @Override
 91  
         public void refreshText() {
 92  0
             createFilters();
 93  0
         }
 94  
     }
 95  
 }