Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FileUtils |
|
| 1.0;1 |
1 | package org.jtheque.films.utils; | |
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 | ||
22 | import java.io.File; | |
23 | import java.net.URL; | |
24 | import java.util.regex.Pattern; | |
25 | ||
26 | /** | |
27 | * This class provide utilities function to file. | |
28 | * | |
29 | * @author Baptiste Wicht | |
30 | */ | |
31 | public final class FileUtils { | |
32 | 0 | private static final Pattern SPECIAL_CHARACTERS = Pattern.compile("[ :\\?|<>']"); |
33 | ||
34 | /** | |
35 | * Construct a new FileUtils. This class isn't instanciable. | |
36 | */ | |
37 | private FileUtils() { | |
38 | 0 | super(); |
39 | 0 | } |
40 | ||
41 | /** | |
42 | * Prepare a string to be a file. It seems deleting special characters with normal characters. | |
43 | * | |
44 | * @param destinationPath The string path to prepare. | |
45 | * @return The prepared path. | |
46 | */ | |
47 | public static String prepareFilePath(String destinationPath) { | |
48 | 0 | String filePath = destinationPath.substring(destinationPath.lastIndexOf(File.separator)); |
49 | ||
50 | 0 | String prepared = SPECIAL_CHARACTERS.matcher(filePath).replaceAll("_"); |
51 | ||
52 | 0 | return destinationPath.replace(filePath, prepared); |
53 | } | |
54 | ||
55 | /** | |
56 | * Return the HTML page's link for the id in the good language. | |
57 | * | |
58 | * @param id The id of the localised page | |
59 | * @return The HTML page's link | |
60 | */ | |
61 | public static URL getLocalisedPage(String id) { | |
62 | 0 | return FileUtils.class.getClassLoader(). |
63 | getResource("org/jtheque/films/i18n/pages/" + | |
64 | id + '_' + Managers.getManager(ILanguageManager.class). | |
65 | getCurrentLocale().getLanguage() + ".html"); | |
66 | } | |
67 | } |