WebBox Klassenbibliothek
ulrich
2017-03-07 8953e9119b88a98cf411ca43a3712d2f364467fd
commit | author | age
a01889 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.wbx;
20
21 import java.io.File;
22 import java.util.logging.Logger;
23 import javax.servlet.ServletContext;
24
25 /**
26  *
27  */
28 public class WbxUtils {
29   
30   private static final Logger logger = Logger.getLogger(WbxUtils.class.getName());
31   
32   /**
33    * Bei der WebBox ist das Datenverzeichnis relativ zum Verzeichnis 
34    * $CATALINA_BASE/webapps untergebracht. 
35    * Die Abfrage ServletContext.getRealPath 
36    * liefert das Verzeichnis des Context dieser Webanwendung, also 
37    * $CATALINA_BASE/webapps/file-cms
38    * oder
39    * $WBX/sys/base/webapps/file-cms
40    * 
41    * Unter Windows z.B.
42    * C:\Users\fred\Documents\srv\wbx\sys\base\webapps\file-cms
43    * Unter Linux oder Mac OS z.B.
44    * /home/fred/srv/wbx/sys/base/webapps/file-cms
45    * 
46    * Das Datenverzeichis liegt dann auf 
47    * $WBX/daten
48    * 
49    * Mit dem Verzeichnis des Context dieser Webanwendung ist das 
50    * Datenverzeichnis der WebBox hart kodierbar mit dieser Methode
51    * 
52    * @return Verzeichnis 'daten' der WebBox
53    */
54   public static File getWbxDataDir(ServletContext ctx) {
55     String path = ctx.getRealPath("/");
56     logger.fine("getRealPath: " + path); // file-cms in webapps
57     File file = new File(path);
58     file = file.getParentFile().getParentFile().getParentFile().getParentFile();    
59     file = new File(file, "daten/");
60     logger.fine("Basis: " + file.getAbsolutePath());
61     return file;
62   }
63
64 }