commit | author | age
|
e369b9
|
1 |
/* |
c45b52
|
2 |
fm - File management class library |
e369b9
|
3 |
Copyright (C) 2024 Ulrich Hilger |
U |
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program 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 Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.fm; |
|
19 |
|
|
20 |
import java.io.File; |
|
21 |
import java.io.FileFilter; |
|
22 |
|
|
23 |
/** |
|
24 |
* Ein Filter zum Auslassen kleiner Versionen einer Original-Bilddatei |
6ea8d4
|
25 |
* |
e369b9
|
26 |
* @author Ulrich Hilger |
U |
27 |
* @version 1, 12. Mai 2021 |
|
28 |
*/ |
|
29 |
public class ImageFileFilter implements FileFilter { |
|
30 |
|
6ea8d4
|
31 |
/** Endung fuer JPEG-Bilddateien */ |
U |
32 |
public static final String JPG = ".jpg"; |
|
33 |
/** Endung fuer JPEG-Bilddateien */ |
|
34 |
public static final String JPEG = ".jpeg"; |
|
35 |
/** Endung fuer PNG-Bilddateien */ |
|
36 |
public static final String PNG = ".png"; |
|
37 |
|
|
38 |
/** Namenszusatz fuer Base64-kodierte Dateien */ |
|
39 |
public static final String B64 = "_b64"; // Base64-Encoded |
|
40 |
|
|
41 |
/** Namenszusatz fuer Bilddateien der Groesse 120 */ |
|
42 |
public static final String TN = "_tn"; // 120 |
|
43 |
/** Namenszusatz fuer Bilddateien der Groesse 240 */ |
|
44 |
public static final String KL = "_kl"; // 240 |
|
45 |
/** Namenszusatz fuer Bilddateien der Groesse 500 */ |
|
46 |
public static final String SM = "_sm"; // 500 |
|
47 |
/** Namenszusatz fuer Bilddateien der Groesse 700 */ |
|
48 |
public static final String MT = "_mt"; // 700 |
|
49 |
/** Namenszusatz fuer Bilddateien der Groesse 1200 */ |
|
50 |
public static final String GR = "_gr"; // 1200 |
|
51 |
|
|
52 |
/** |
|
53 |
* Bilddateien mit den Namenszusaetzen _tn, _kl, _sm, _mt, _gr und _b64 werden mit |
|
54 |
* diesem FileFilter weggelassen. |
|
55 |
* |
|
56 |
* @param pathname Name und Pfad einer zu filternden Datei |
|
57 |
* @return false (weglassen), wenn pathname den Namenszusatz |
|
58 |
* _tn, _kl, _sm, _mt, _gr und _b64 enthaelt, sonst true |
|
59 |
*/ |
|
60 |
@Override |
|
61 |
public boolean accept(File pathname) { |
|
62 |
boolean pass = true; |
|
63 |
String fname = pathname.getName().toLowerCase(); |
|
64 |
if (fname.endsWith(JPEG) |
|
65 |
|| fname.endsWith(JPG) || fname.endsWith(PNG)) { |
|
66 |
if (fname.contains(GR) || fname.contains(KL) |
|
67 |
|| fname.contains(MT) || fname.contains(SM) |
|
68 |
|| fname.contains(TN) || fname.contains(B64)) { |
|
69 |
pass = false; |
|
70 |
} |
|
71 |
} |
|
72 |
return pass; |
|
73 |
} |
|
74 |
} |