Dateiverwaltung für die WebBox
ulrich
2017-07-07 fafe1b3b2b35a3c032a367d5ed76b243f6d654a9
commit | author | age
fafe1b 1 /*
U 2     Dateiverwaltung - File management in your browser
3     Copyright (C) 2017 Ulrich Hilger, http://uhilger.de
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 <http://www.gnu.org/licenses/>.
17 */
18
19 package de.uhilger.filecms.pub;
20
21 import de.uhilger.filecms.api.Api;
22 import de.uhilger.filecms.data.Bild;
23 import de.uhilger.filecms.data.FileRef;
24 import java.io.File;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.logging.Logger;
28
29 /**
30  * Methoden zur Arbeit mit Inhalten in der oeffentlichen 
31  * Ablage einer WebBox
32  */
33 public class Catalog extends Api {
34
35   private static final Logger logger = Logger.getLogger(Catalog.class.getName());
36   
37   /**
38    * Inhalte der WebBox listen. Hier wird nur ausgegeben was mit 
39    * einer relativen Pfadangabe ausgehend von www, der oeffentlichen 
40    * Ablage einer WeBox, erreichbar ist. 
41    * 
42    * Andere Inhalte werden nicht ausgegeben.
43    * 
44    * @param relPath der relative Pfad, der von www aus gelistet werden soll, ohne www
45    * @return Liste der Dateien und Ordner am Ort relPath
46    */
47   public List<FileRef> list(String relPath) {
48     Bild bild = new Bild();
49     List<FileRef> files = new ArrayList();
50     StringBuffer path = new StringBuffer(PUB_DIR_PATH); // www/
51     path.append(relPath);
52     File dir = new File(getBase().getAbsolutePath(), path.toString());
53     if(dir.exists()) {
54       File[] fileArray = dir.listFiles();
55       for(int i = 0; i < fileArray.length; i++) {
56         logger.fine(fileArray[i].toURI().toString());
57         String fname = fileArray[i].toURI().toString().replace("file:/", "");
58         if(fileArray[i].isDirectory()) {
59           fname = fname.substring(0, fname.length() - 1);
60         }
61         logger.fine(fname);
62         FileRef ref = new FileRef(fname, fileArray[i].isDirectory());
63         ref.setMimetype(bild.getMimeType(fileArray[i]));
64         files.add(ref);
65       }
66     }
67     return files;
68   }
69   
70 }