From fab80c872af697d61f200fd410a7ecc64ca0a537 Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Mon, 06 Mar 2017 22:59:47 +0000 Subject: [PATCH] dekodieren fuer Codemirror --- src/java/de/uhilger/filecms/api/UploadServlet.java | 52 ++++++++++++++++++++++++++++++++++------------------ 1 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/java/de/uhilger/filecms/api/UploadServlet.java b/src/java/de/uhilger/filecms/api/UploadServlet.java index 1a07401..ff788ff 100644 --- a/src/java/de/uhilger/filecms/api/UploadServlet.java +++ b/src/java/de/uhilger/filecms/api/UploadServlet.java @@ -22,8 +22,8 @@ import static de.uhilger.filecms.api.FileMgr.HOME_DIR_PATH; import static de.uhilger.filecms.api.FileMgr.PUB_DIR_NAME; import static de.uhilger.filecms.api.FileMgr.PUB_DIR_PATH; +import de.uhilger.filecms.data.FileRef; import de.uhilger.filecms.web.Initialiser; -import de.uhilger.filesystem.FileRef; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -56,6 +56,8 @@ public static final String DESC = "file-cms uploader"; private static final Logger logger = Logger.getLogger(UploadServlet.class.getName()); + + private String targetDirStr; /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> @@ -68,6 +70,7 @@ */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //logger.log(Level.INFO, "start"); boolean isMultipart = ServletFileUpload.isMultipartContent(request); @@ -91,6 +94,7 @@ // Process the uploaded items Iterator<FileItem> iter = items.iterator(); + FileItem fileItem = null; while (iter.hasNext()) { FileItem item = iter.next(); @@ -100,10 +104,13 @@ //File base = repository.getParentFile().getParentFile().getParentFile().getParentFile(); //File webapps = new File(base, "webapps"); //logger.info(webapps.getAbsolutePath()); - File targetDir = getTargetDir(request, PUB_DIR_NAME); - logger.log(Level.FINE, "rufe processUploadedFile"); - processUploadedFile(targetDir, item, true); + fileItem = item; } + } + File targetDir = getTargetDir(request, targetDirStr); + if(targetDir != null && fileItem != null) { + logger.log(Level.FINER, "targetDir before upload: " + targetDir.getAbsolutePath()); + processUploadedFile(targetDir, fileItem, true); } } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); @@ -129,17 +136,20 @@ } private File getTargetDir(HttpServletRequest request, String relPath) { - logger.finer(relPath); - String targetPath = null; - if(relPath.startsWith(PUB_DIR_NAME)) { - targetPath = PUB_DIR_PATH + getUserName(request) + "/" + relPath.substring(PUB_DIR_NAME.length()); - } else if(relPath.startsWith(HOME_DIR_NAME)) { - targetPath = HOME_DIR_PATH + getUserName(request) + "/" + relPath.substring(HOME_DIR_NAME.length()); - } else { - // kann eigentlich nicht sein.. + File targetDir = null; + if(relPath != null) { + logger.finer(relPath); + String targetPath = null; + if(relPath.startsWith(PUB_DIR_NAME)) { + targetPath = PUB_DIR_PATH + getUserName(request) + relPath.substring(PUB_DIR_NAME.length()); + } else if(relPath.startsWith(HOME_DIR_NAME)) { + targetPath = HOME_DIR_PATH + getUserName(request) + relPath.substring(HOME_DIR_NAME.length()); + } else { + // kann eigentlich nicht sein.. + } + logger.finer(targetPath); + targetDir = new File(getBase().getAbsolutePath(), targetPath); } - logger.finer(targetPath); - File targetDir = new File(getBase().getAbsolutePath(), targetPath); return targetDir; } @@ -155,8 +165,11 @@ private FileRef getBase() { FileRef base = null; Object o = getServletContext().getAttribute(Initialiser.FILE_BASE); - if (o instanceof FileRef) { - base = (FileRef) o; + if(o instanceof String) { + String baseStr = (String) o; + logger.fine(baseStr); + File file = new File(baseStr); + base = new FileRef(file.getAbsolutePath(), file.isDirectory()); } return base; } @@ -172,8 +185,8 @@ long sizeInBytes = item.getSize(); // Process a file upload if (writeToFile) { - //logger.log(Level.INFO, "writeToFile " + fileName); File uploadedFile = new File(targetDir, fileName); + logger.log(Level.FINER, "writeToFile " + uploadedFile.getAbsolutePath()); item.write(uploadedFile); } else { InputStream uploadedStream = item.getInputStream(); @@ -189,8 +202,11 @@ if (item.isFormField()) { String name = item.getFieldName(); String value = item.getString(); - //logger.log(Level.INFO, "field name: " + name + ", value: " + value); + logger.log(Level.FINER, "field name: " + name + ", value: " + value); //... + if(name.equals("pfad")) { + targetDirStr = value; + } } } -- Gitblit v1.9.3