From 1f550a4fce54040aa41f6351b0ba1fe1c404652d Mon Sep 17 00:00:00 2001
From: ulrich <undisclosed>
Date: Sat, 18 Mar 2017 16:26:15 +0000
Subject: [PATCH] WebBox-Basis und -Daten-Ordner fuer wbxAdmin in Dateimanager aufgenommen

---
 src/java/de/uhilger/filecms/api/FileMgr.java |   66 ++++++++++++++++++++++++++++----
 1 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/src/java/de/uhilger/filecms/api/FileMgr.java b/src/java/de/uhilger/filecms/api/FileMgr.java
index b4ece2e..8fb1ea3 100644
--- a/src/java/de/uhilger/filecms/api/FileMgr.java
+++ b/src/java/de/uhilger/filecms/api/FileMgr.java
@@ -46,13 +46,16 @@
 public class FileMgr extends Api {
   private static final Logger logger = Logger.getLogger(FileMgr.class.getName());
   
+  public static final String WBX_DATA_PATH = "daten/";
   public static final String PUB_DIR_PATH = "www/";
   public static final String HOME_DIR_PATH = "home/";
   public static final String PUB_DIR_NAME = "Oeffentlich";
   //public static final String HOME_DIR_NAME = "Persoenlicher Ordner";
   public static final String HOME_DIR_NAME = "Persoenlich";
+  public static final String WBX_ADMIN_ROLE = "wbxAdmin";
   
-  public static final String CATALINA_BASE_FOLDER = "base";
+  public static final String WBX_BASE = "$basis";
+  public static final String WBX_DATA = "$daten";
   
   public static final int OP_COPY = 1;
   public static final int OP_MOVE = 2;
@@ -61,6 +64,16 @@
     return "Hallo Welt!";
   }
   
+  /**
+   * Inhalte der WebBox listen. Hier wird nur der relative Pfad 
+   * ausgehend von www oder home ausgegeben sowie zudem ausgehend 
+   * von $daten und $basis, sofern der Benutzer die Rolle wbxAdmin hat.
+   * 
+   * Andere Inhalte werden nicht ausgegeben.
+   * 
+   * @param relPath
+   * @return 
+   */
   public List<FileRef> list(String relPath) {
     Bild bild = new Bild();
     List<FileRef> files = new ArrayList();
@@ -69,11 +82,15 @@
       logger.finer(namedPublicFolder.getAbsolutePath());
       FileRef namedHomeFolder = new FileRef(HOME_DIR_NAME, true);
       logger.finer(namedHomeFolder.getAbsolutePath());
-      FileRef namedBaseFolder = new FileRef(CATALINA_BASE_FOLDER, true);
       files = new ArrayList();
       files.add(namedHomeFolder);
-      files.add(namedPublicFolder);
-      files.add(namedBaseFolder);
+      files.add(namedPublicFolder);      
+      if(getRequest().isUserInRole(WBX_ADMIN_ROLE)) {
+        FileRef namedBaseFolder = new FileRef(WBX_BASE, true);
+        FileRef namedDataFolder = new FileRef(WBX_DATA, true);
+        files.add(namedBaseFolder);
+        files.add(namedDataFolder);
+      }      
     } else {
       String path = getTargetDir(relPath).getAbsolutePath();
       logger.fine("listing path: " + path);
@@ -355,6 +372,20 @@
 
   /* ---- Hilfsfunktionen ---- */
   
+  /**
+   * Einen relativen Pfad in einen absoluten Pfad der WebBox 
+   * aufloesen.
+   * 
+   * Nur die absoluten Pfade zu PUB_DIR_NAME, HOME_DIR_NAME 
+   * sowie WBX_BASE und WBX_DATA werden ausgegeben. Letztere 
+   * beiden nur fuer Nutzer mit der Rolle WBX_ADMIN_ROLE.
+   * 
+   * D.h., es werden nur Pfade aufgeloest, die sich innerhalb 
+   * des Ordners der WeBox befinden.
+   * 
+   * @param relPath
+   * @return 
+   */
   private File getTargetDir(String relPath) {
     logger.fine(relPath);
     File targetDir;
@@ -365,17 +396,28 @@
     } else if(relPath.startsWith(HOME_DIR_NAME)) {
       targetPath = HOME_DIR_PATH + getUserName() + relPath.substring(HOME_DIR_NAME.length());
       targetDir = new File(getBase().getAbsolutePath(), targetPath);
-    } else if(relPath.startsWith(CATALINA_BASE_FOLDER)) {
-      targetPath = getCatalinaBase();
-      targetDir = new File(targetPath, relPath.substring(CATALINA_BASE_FOLDER.length()));
+    } else if(getRequest().isUserInRole(WBX_ADMIN_ROLE)) {
+      if(relPath.startsWith(WBX_BASE)) {
+        targetPath = getCatalinaBase();
+        targetDir = new File(targetPath, relPath.substring(WBX_BASE.length()));
+      } else if(relPath.startsWith(WBX_DATA)) {
+        targetPath = getWbxDataDir();
+        targetDir = new File(targetPath, relPath.substring(WBX_BASE.length()));
+      } else {
+        targetDir = getDefaultDir(relPath);
+      }
     } else {
       // kann eigentlich nicht sein..
-      targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length());
-      targetDir = new File(getBase().getAbsolutePath(), targetPath);
+      targetDir = getDefaultDir(relPath);
     }
     logger.fine(targetPath);
     //File targetDir = new File(getBase().getAbsolutePath(), targetPath);
     return targetDir;
+  }
+  
+  private File getDefaultDir(String relPath) {
+    String targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length());
+    return new File(getBase().getAbsolutePath(), targetPath);
   }
   
   private FileRef getBase() {
@@ -406,4 +448,10 @@
     file = file.getParentFile().getParentFile();
     return file.getAbsolutePath();
   }
+  
+  private String getWbxDataDir() {
+    String wbxBase = getBase().getAbsolutePath();
+    File file = new File(wbxBase);
+    return file.getAbsolutePath();
+  }
 }
\ No newline at end of file

--
Gitblit v1.9.3