| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ExporterFactory |
|
| 2.0;2 |
| 1 | package org.jtheque.films.services.impl.utils.file.exports; | |
| 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.films.persistence.od.able.Film; | |
| 20 | import org.jtheque.films.utils.Constants.Files.FileType; | |
| 21 | ||
| 22 | import java.util.Arrays; | |
| 23 | import java.util.Collection; | |
| 24 | ||
| 25 | /** | |
| 26 | * An Exporter factory. | |
| 27 | * | |
| 28 | * @author Baptiste Wicht | |
| 29 | */ | |
| 30 | public final class ExporterFactory { | |
| 31 | 0 | private static final Collection<AbstractExporter<Film>> EXPORTERS = Arrays.asList( |
| 32 | new TextExporter(), | |
| 33 | new XMLExporter(), | |
| 34 | new HTMLExporter(), | |
| 35 | new JTFExporter(), | |
| 36 | new JTFEExporter(), | |
| 37 | new XLSExporter(), | |
| 38 | new PDFExporter(), | |
| 39 | new CSVExporter(), | |
| 40 | new RTFExporter()); | |
| 41 | ||
| 42 | /** | |
| 43 | * Construct a new ExporterFactory. This class isn't instanciable. | |
| 44 | */ | |
| 45 | private ExporterFactory() { | |
| 46 | 0 | super(); |
| 47 | 0 | } |
| 48 | ||
| 49 | /** | |
| 50 | * Return the exporter for the spécific file type. | |
| 51 | * | |
| 52 | * @param fileType The file type. | |
| 53 | * @return The exporter or <code>null</code> if we don't find the exporter of the file type | |
| 54 | */ | |
| 55 | public static Exporter<Film> getExporter(FileType fileType) { | |
| 56 | 0 | Exporter<Film> exporter = null; |
| 57 | ||
| 58 | 0 | for (Exporter<Film> e : EXPORTERS) { |
| 59 | 0 | if (e.canExportTo(fileType)) { |
| 60 | 0 | exporter = e; |
| 61 | 0 | break; |
| 62 | } | |
| 63 | } | |
| 64 | ||
| 65 | 0 | return exporter; |
| 66 | } | |
| 67 | } |