From 9159275f8efe97da69e138ef3378931181447370 Mon Sep 17 00:00:00 2001 From: ulrich <not disclosed> Date: Sat, 18 Feb 2017 16:04:10 +0000 Subject: [PATCH] Textdatei speichern implementiert --- src/java/de/uhilger/filecms/api/FileMgr.java | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/src/java/de/uhilger/filecms/api/FileMgr.java b/src/java/de/uhilger/filecms/api/FileMgr.java index b8151d8..d39ab79 100644 --- a/src/java/de/uhilger/filecms/api/FileMgr.java +++ b/src/java/de/uhilger/filecms/api/FileMgr.java @@ -4,6 +4,10 @@ import de.uhilger.transit.web.RequestKontext; import de.uhilger.transit.web.WebKontext; import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.security.Principal; +import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -89,6 +93,27 @@ public FileRef saveTextFile(String relPath, String fileName, String contents) { FileRef savedFile = null; + try { + FileRef datenRef = getBase(); + File daten = new File(datenRef.getAbsolutePath()); + Object p = getRequest().getUserPrincipal(); + if(p instanceof Principal) { + File userDir = new File(daten, "www/" + ((Principal) p).getName()); + File saveDir = new File(userDir, relPath); + File targetFile = new File(saveDir, fileName); + if(!targetFile.exists()) { + targetFile.getParentFile().mkdirs(); + targetFile.createNewFile(); + FileWriter w = new FileWriter(targetFile); + w.write(contents); + w.flush(); + w.close(); + savedFile = new FileRef(targetFile.getAbsolutePath(), targetFile.isDirectory(), targetFile.isHidden(), targetFile.lastModified(), targetFile.length()); + } + } + } catch (IOException ex) { + logger.log(Level.SEVERE, null, ex); + } return savedFile; } -- Gitblit v1.9.3