WebBox Klassenbibliothek
ulrich
2017-04-08 c91307f4d70a89a66465272968b262914e3c32ef
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   
eab7bb 32   //public static final String FILE_BASE = "filebase";
U 33   //public static final String DATENABLAGE = "datenAblage";  
34   
a01889 35   /**
U 36    * Bei der WebBox ist das Datenverzeichnis relativ zum Verzeichnis 
37    * $CATALINA_BASE/webapps untergebracht. 
38    * Die Abfrage ServletContext.getRealPath 
39    * liefert das Verzeichnis des Context dieser Webanwendung, also 
40    * $CATALINA_BASE/webapps/file-cms
41    * oder
42    * $WBX/sys/base/webapps/file-cms
43    * 
44    * Unter Windows z.B.
45    * C:\Users\fred\Documents\srv\wbx\sys\base\webapps\file-cms
46    * Unter Linux oder Mac OS z.B.
47    * /home/fred/srv/wbx/sys/base/webapps/file-cms
48    * 
49    * Das Datenverzeichis liegt dann auf 
50    * $WBX/daten
51    * 
52    * Mit dem Verzeichnis des Context dieser Webanwendung ist das 
53    * Datenverzeichnis der WebBox hart kodierbar mit dieser Methode
54    * 
55    * @return Verzeichnis 'daten' der WebBox
56    */
eab7bb 57   /*
a01889 58   public static File getWbxDataDir(ServletContext ctx) {
6c2165 59     File file = getWbxDir(ctx);    
U 60     file = new File(file, "daten/");
61     logger.fine("WebBox Datenbasis: " + file.getAbsolutePath());
62     return file;
63   }
64   
65   public static File getWbxDir(ServletContext ctx) {
a01889 66     String path = ctx.getRealPath("/");
U 67     logger.fine("getRealPath: " + path); // file-cms in webapps
68     File file = new File(path);
69     file = file.getParentFile().getParentFile().getParentFile().getParentFile();    
6c2165 70     logger.fine("WebBox: " + file.getAbsolutePath());
a01889 71     return file;
U 72   }
eab7bb 73   */
U 74   
75   /**
76    * Die Dateiablage wird entweder auf einen absoluten Pfad gesetzt, 
77    * der im Deployment Descriptor hinterlegt werden kann oder, wenn 
78    * dort nichts eingetragen ist, auf den hart kodierten Pfad 
79    * der WebBox.
80    * 
81    * @param ctx der ServletContext, in den die Angabe eingetragen wird. Dort 
82    * ist anschliessend die Angabe unter Initialiser.FILE_BASE abrufbar
83    */
84   /*
85   public static void ablageErmitteln(ServletContext ctx) {
86     Object o = ctx.getInitParameter(DATENABLAGE);
87     try {
88       if(o instanceof String) {
89         String pfad = o.toString();
90         if(pfad.trim().length() > 0) {
91           ctx.setAttribute(FILE_BASE, pfad);
92           logger.fine("Basis: " + pfad);
93         } else {
94           ctx.setAttribute(FILE_BASE, WbxUtils.getWbxDataDir(ctx).getAbsolutePath());  
95         }
96       } else {
97         ctx.setAttribute(FILE_BASE, WbxUtils.getWbxDataDir(ctx).getAbsolutePath());      
98       }    
99     } catch(Exception ex) {
100       ctx.setAttribute(FILE_BASE, WbxUtils.getWbxDataDir(ctx).getAbsolutePath());
101     }
102   } 
103   */
a01889 104
U 105 }