commit | author | age
|
b7475d
|
1 |
/* |
8931b7
|
2 |
|
U |
3 |
Dateiverwaltung - File management in your browser |
|
4 |
Copyright (C) 2017 Ulrich Hilger, http://uhilger.de |
|
5 |
|
|
6 |
This program is free software: you can redistribute it and/or modify |
|
7 |
it under the terms of the GNU Affero General Public License as |
|
8 |
published by the Free Software Foundation, either version 3 of the |
|
9 |
License, or (at your option) any later version. |
|
10 |
|
|
11 |
This program is distributed in the hope that it will be useful, |
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
GNU Affero General Public License for more details. |
|
15 |
|
|
16 |
You should have received a copy of the GNU Affero General Public License |
|
17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18 |
|
|
19 |
*/ |
b7475d
|
20 |
|
U |
21 |
package de.uhilger.filecms.api; |
|
22 |
|
72e43d
|
23 |
import de.uhilger.filecms.data.FileRef; |
ae9140
|
24 |
import de.uhilger.wbx.api.ApiBase; |
72e43d
|
25 |
import java.io.File; |
U |
26 |
import java.util.logging.Logger; |
b7475d
|
27 |
|
U |
28 |
/** |
|
29 |
* |
|
30 |
*/ |
ae9140
|
31 |
public abstract class Api extends ApiBase { |
b7475d
|
32 |
|
72e43d
|
33 |
private static final Logger logger = Logger.getLogger(Api.class.getName()); |
U |
34 |
|
|
35 |
public static final String WBX_DATA_PATH = "daten/"; |
|
36 |
public static final String PUB_DIR_PATH = "www/"; |
|
37 |
public static final String HOME_DIR_PATH = "home/"; |
|
38 |
public static final String PUB_DIR_NAME = "Oeffentlich"; |
|
39 |
//public static final String HOME_DIR_NAME = "Persoenlicher Ordner"; |
|
40 |
public static final String HOME_DIR_NAME = "Persoenlich"; |
|
41 |
public static final String WBX_ADMIN_ROLE = "wbxAdmin"; |
|
42 |
|
|
43 |
public static final String WBX_BASE = "$basis"; |
|
44 |
public static final String WBX_DATA = "$daten"; |
ae9140
|
45 |
|
72e43d
|
46 |
/** |
U |
47 |
* Einen relativen Pfad in einen absoluten Pfad der WebBox |
|
48 |
* aufloesen. |
|
49 |
* |
|
50 |
* Nur die absoluten Pfade zu PUB_DIR_NAME, HOME_DIR_NAME |
|
51 |
* sowie WBX_BASE und WBX_DATA werden ausgegeben. Letztere |
|
52 |
* beiden nur fuer Nutzer mit der Rolle WBX_ADMIN_ROLE. |
|
53 |
* |
|
54 |
* D.h., es werden nur Pfade aufgeloest, die sich innerhalb |
|
55 |
* des Ordners der WeBox befinden. |
|
56 |
* |
|
57 |
* @param relPath |
|
58 |
* @return |
|
59 |
*/ |
|
60 |
protected File getTargetDir(String relPath) { |
|
61 |
logger.fine(relPath); |
|
62 |
File targetDir; |
|
63 |
String targetPath = null; |
|
64 |
if(relPath.startsWith(PUB_DIR_NAME)) { |
|
65 |
targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length()); |
|
66 |
targetDir = new File(getBase().getAbsolutePath(), targetPath); |
|
67 |
} else if(relPath.startsWith(HOME_DIR_NAME)) { |
|
68 |
targetPath = HOME_DIR_PATH + getUserName() + relPath.substring(HOME_DIR_NAME.length()); |
|
69 |
targetDir = new File(getBase().getAbsolutePath(), targetPath); |
|
70 |
} else if(getRequest().isUserInRole(WBX_ADMIN_ROLE)) { |
|
71 |
logger.fine("in admin role"); |
|
72 |
if(relPath.startsWith(WBX_BASE)) { |
|
73 |
logger.fine("is base"); |
|
74 |
targetPath = getCatalinaBase(); |
|
75 |
targetDir = new File(targetPath, relPath.substring(WBX_BASE.length())); |
|
76 |
} else if(relPath.startsWith(WBX_DATA)) { |
|
77 |
targetPath = getWbxDataDir(); |
|
78 |
logger.fine("is data, combine " + targetPath + ' ' + relPath.substring(WBX_DATA.length())); |
|
79 |
targetDir = new File(targetPath, relPath.substring(WBX_DATA.length())); |
|
80 |
} else { |
|
81 |
targetDir = getDefaultDir(relPath); |
|
82 |
} |
|
83 |
} else { |
|
84 |
// kann eigentlich nicht sein.. |
|
85 |
targetDir = getDefaultDir(relPath); |
|
86 |
} |
|
87 |
logger.fine("returning targetDir " + targetDir.getAbsolutePath()); |
|
88 |
//File targetDir = new File(getBase().getAbsolutePath(), targetPath); |
|
89 |
return targetDir; |
|
90 |
} |
|
91 |
|
|
92 |
protected File getDefaultDir(String relPath) { |
|
93 |
String targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length()); |
|
94 |
return new File(getBase().getAbsolutePath(), targetPath); |
|
95 |
} |
|
96 |
|
|
97 |
protected FileRef getBase() { |
|
98 |
FileRef base = null; |
ae9140
|
99 |
Object o = getFileBase(); |
U |
100 |
if(o instanceof File) { |
|
101 |
File file = (File) o; |
72e43d
|
102 |
base = new FileRef(file.getAbsolutePath(), file.isDirectory()); |
U |
103 |
} |
|
104 |
return base; |
b7475d
|
105 |
} |
U |
106 |
|
|
107 |
} |