commit | author | age
|
e369b9
|
1 |
/* |
U |
2 |
neon-fm - File management extensions to Neon |
|
3 |
Copyright (C) 2024 Ulrich Hilger |
|
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 com.google.gson.Gson; |
|
21 |
import java.io.File; |
|
22 |
import java.io.IOException; |
|
23 |
import java.util.ArrayList; |
|
24 |
import java.util.Arrays; |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* Eine Klasse zur Bildung einer Liste mit den Dateien eines Verzeichnisses. |
|
29 |
* |
|
30 |
* Varianten von Bilddateien werden ausgeblendet. Enthaelt ein Ordner die Dateien |
|
31 |
* mein-bild.jpg |
|
32 |
* mein-bild_tn.jpg |
|
33 |
* mein-bild_kl.jpg |
|
34 |
* erscheint nur die Datei mein-bild.jpg in der Liste. |
|
35 |
* |
|
36 |
* |
|
37 |
* @author Ulrich Hilger |
|
38 |
* @version 0.1, 05.11.2024 |
|
39 |
*/ |
|
40 |
public class Lister { |
|
41 |
|
|
42 |
public static final String STR_DOT = "."; |
|
43 |
|
|
44 |
public String liste(String fName, String ctxPath, String base/*, String path*/) throws IOException { |
|
45 |
File[] files = new File(base, fName).listFiles(new ImageFileFilter()); |
|
46 |
if (files != null && files.length > 0) { |
|
47 |
Arrays.sort(files); |
|
48 |
ArrayList liste = new ArrayList(); |
|
49 |
for (File file : files) { |
|
50 |
Datei datei = new Datei(); |
|
51 |
String dateiName = file.getName(); |
|
52 |
datei.setName(dateiName); |
|
53 |
if (file.isDirectory()) { |
|
54 |
datei.setTyp(Datei.TYP_ORDNER); |
|
55 |
} else { |
|
56 |
datei.setTyp(Datei.TYP_DATEI); |
|
57 |
} |
|
58 |
String lowerName = dateiName.toLowerCase(); |
|
59 |
if (lowerName.endsWith(Const.JPEG) |
|
60 |
|| lowerName.endsWith(Const.JPG) |
|
61 |
|| lowerName.endsWith(Const.PNG)) { |
|
62 |
datei.setBild(true); |
|
63 |
String ext = dateiName.substring(dateiName.lastIndexOf(STR_DOT)); |
|
64 |
String ohneExt = dateiName.substring(0, dateiName.lastIndexOf(STR_DOT)); |
|
65 |
datei.setMiniurl(ctxPath + /*"/" + */ fName + ohneExt + Const.TN + ext); |
|
66 |
//buildImgSrc(file, datei, ohneExt, ext); |
|
67 |
} |
|
68 |
liste.add(datei); |
|
69 |
} |
|
70 |
//while(threadCount > 0) { |
|
71 |
// try { |
|
72 |
// Thread.sleep(50); |
|
73 |
// } catch (InterruptedException ex) { |
|
74 |
// Logger.getLogger(FileManager.class.getName()).log(Level.SEVERE, null, ex); |
|
75 |
// } |
|
76 |
//} |
|
77 |
if (!liste.isEmpty()) { |
|
78 |
DirList list = new DirList(); |
|
79 |
list.setPfad(ctxPath + fName); |
|
80 |
list.setDateien(liste); |
|
81 |
Gson gson = new Gson(); |
|
82 |
String json = gson.toJson(list); |
|
83 |
return json; |
|
84 |
} else { |
|
85 |
return null; |
|
86 |
} |
|
87 |
} else { |
|
88 |
return null; |
|
89 |
} |
|
90 |
//} else { |
|
91 |
//} |
|
92 |
} |
|
93 |
|
|
94 |
} |