From 8eb306139956fa840a8422d3ad679dfa033ebe99 Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Wed, 29 Mar 2017 08:58:13 +0000 Subject: [PATCH] FileRef nach lib verschoben --- src/java/de/uhilger/filecms/api/Api.java | 136 ++++++++++++++++++++++++++++++--------------- 1 files changed, 91 insertions(+), 45 deletions(-) diff --git a/src/java/de/uhilger/filecms/api/Api.java b/src/java/de/uhilger/filecms/api/Api.java index 625e070..bd52f22 100644 --- a/src/java/de/uhilger/filecms/api/Api.java +++ b/src/java/de/uhilger/filecms/api/Api.java @@ -1,61 +1,107 @@ /* - * Nutzerverwaltung - User and role management in your browser - * Copyright (C) 2011-2017 Ulrich Hilger, http://uhilger.de - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/ - */ + + Dateiverwaltung - File management in your browser + Copyright (C) 2017 Ulrich Hilger, http://uhilger.de + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +*/ package de.uhilger.filecms.api; -import de.uhilger.transit.web.RequestKontext; -import de.uhilger.transit.web.WebKontext; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; +import de.uhilger.wbx.api.ApiBase; +import de.uhilger.wbx.data.FileRef; +import java.io.File; +import java.util.logging.Logger; /** * */ -public abstract class Api implements WebKontext, RequestKontext { +public abstract class Api extends ApiBase { - /** Zeiger zum Servlet-Kontext dieser Anwendung */ - private ServletContext ctx; - - private HttpServletRequest request; - - - /* ------------- Implementierung WebKontext ------------- */ + private static final Logger logger = Logger.getLogger(Api.class.getName()); - @Override - public ServletContext getServletContext() { - return ctx; - } - - @Override - public void setServletContext(ServletContext servletContext) { - this.ctx = servletContext; + 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 WBX_BASE = "$basis"; + public static final String WBX_DATA = "$daten"; + + /** + * 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 + */ + protected File getTargetDir(String relPath) { + logger.fine(relPath); + File targetDir; + String targetPath = null; + if(relPath.startsWith(PUB_DIR_NAME)) { + targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length()); + targetDir = new File(getBase().getAbsolutePath(), targetPath); + } 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(getRequest().isUserInRole(WBX_ADMIN_ROLE)) { + logger.fine("in admin role"); + if(relPath.startsWith(WBX_BASE)) { + logger.fine("is base"); + targetPath = getCatalinaBase(); + targetDir = new File(targetPath, relPath.substring(WBX_BASE.length())); + } else if(relPath.startsWith(WBX_DATA)) { + targetPath = getWbxDataDir(); + logger.fine("is data, combine " + targetPath + ' ' + relPath.substring(WBX_DATA.length())); + targetDir = new File(targetPath, relPath.substring(WBX_DATA.length())); + } else { + targetDir = getDefaultDir(relPath); + } + } else { + // kann eigentlich nicht sein.. + targetDir = getDefaultDir(relPath); + } + logger.fine("returning targetDir " + targetDir.getAbsolutePath()); + //File targetDir = new File(getBase().getAbsolutePath(), targetPath); + return targetDir; } - /* ------------- Implementierung RequestKontext ------------- */ - - @Override - public HttpServletRequest getRequest() { - return request; + protected File getDefaultDir(String relPath) { + String targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length()); + return new File(getBase().getAbsolutePath(), targetPath); } - - @Override - public void setRequest(HttpServletRequest r) { - this.request = r; + + protected FileRef getBase() { + FileRef base = null; + Object o = getFileBase(); + if(o instanceof File) { + File file = (File) o; + base = new FileRef(file.getAbsolutePath(), file.isDirectory()); + } + return base; } } -- Gitblit v1.9.3