From 0c1d5b5d2d3b026d1f358eae35726c6a25748115 Mon Sep 17 00:00:00 2001 From: Ulrich <undisclosed> Date: Mon, 27 Feb 2017 15:26:54 +0000 Subject: [PATCH] Verzeichnisse fuer TinyMCE berichtigt, Resize fuer TinyMCE berichtigt --- src/java/de/uhilger/filecms/api/FileMgr.java | 198 +++++++++++++++++++++++++++--------------------- 1 files changed, 111 insertions(+), 87 deletions(-) diff --git a/src/java/de/uhilger/filecms/api/FileMgr.java b/src/java/de/uhilger/filecms/api/FileMgr.java index 20277a1..78ac92d 100644 --- a/src/java/de/uhilger/filecms/api/FileMgr.java +++ b/src/java/de/uhilger/filecms/api/FileMgr.java @@ -20,8 +20,11 @@ import de.uhilger.filecms.web.Initialiser; import de.uhilger.filesystem.FileRef; +import de.uhilger.filesystem.FileSystem; import de.uhilger.filesystem.LocalFileSystem; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.security.Principal; @@ -42,26 +45,13 @@ public static final String PUB_DIR_NAME = "Oeffentlich"; public static final String HOME_DIR_NAME = "Persoenlicher Ordner"; - //private FileRef homeFolder; - //private FileRef publicFolder; - //private FileRef namedHomeFolder; - //private FileRef namedPublicFolder; - - public String hallo() { return "Hallo Welt!"; } public List<FileRef> list(String relPath) { List<FileRef> files = new ArrayList(); - if(relPath.length() == 0) { - /* - publicFolder = new FileRef(getUserPubDir().getAbsolutePath(), true); - logger.info(publicFolder.getAbsolutePath()); - homeFolder = new FileRef(getUserHomeDir().getAbsolutePath(), true); - logger.info(homeFolder.getAbsolutePath()); - */ FileRef namedPublicFolder = new FileRef(PUB_DIR_NAME, true); logger.finer(namedPublicFolder.getAbsolutePath()); FileRef namedHomeFolder = new FileRef(HOME_DIR_NAME, true); @@ -70,102 +60,100 @@ files.add(namedHomeFolder); files.add(namedPublicFolder); } else { - /* - logger.finer(relPath); - String targetPath = null; - if(relPath.startsWith(PUB_DIR_NAME)) { - targetPath = PUB_DIR_PATH + getUserName() + "/" + relPath.substring(PUB_DIR_NAME.length()); - } else if(relPath.startsWith(HOME_DIR_NAME)) { - targetPath = HOME_DIR_PATH + getUserName() + "/" + relPath.substring(HOME_DIR_NAME.length()); - } else { - // kann eigentlich nicht sein.. - } - logger.finer(targetPath); - File targetDir = new File(getBase().getAbsolutePath(), targetPath); - */ - - LocalFileSystem fs = new LocalFileSystem(); String path = getTargetDir(relPath).getAbsolutePath(); logger.fine(path); + LocalFileSystem fs = new LocalFileSystem(); FileRef[] fileRefs = fs.list(new FileRef(getTargetDir(relPath).getAbsolutePath(), true)); for(int i = 0; i < fileRefs.length; i++) { files.add(fileRefs[i]); logger.finer("added " + fileRefs[i].getAbsolutePath()); } - //files = Arrays.asList(fileRefs); - } - + } return files; } - private File getTargetDir(String relPath) { - logger.finer(relPath); - String targetPath = null; - if(relPath.startsWith(PUB_DIR_NAME)) { - targetPath = PUB_DIR_PATH + getUserName() + "/" + relPath.substring(PUB_DIR_NAME.length()); - } else if(relPath.startsWith(HOME_DIR_NAME)) { - targetPath = HOME_DIR_PATH + getUserName() + "/" + relPath.substring(HOME_DIR_NAME.length()); - } else { - // kann eigentlich nicht sein.. + public FileRef newFolder(String relPath, String folderName) { + logger.finer(relPath); + String targetPath = null; + if(relPath.startsWith(PUB_DIR_NAME)) { + targetPath = PUB_DIR_PATH + getUserName() + "/" + relPath.substring(PUB_DIR_NAME.length()) + "/" + folderName; + } else if(relPath.startsWith(HOME_DIR_NAME)) { + targetPath = HOME_DIR_PATH + getUserName() + "/" + relPath.substring(HOME_DIR_NAME.length()) + "/" + folderName; + } else { + // kann eigentlich nicht sein.. + } + logger.finer(targetPath); + File targetDir = new File(getBase().getAbsolutePath(), targetPath); + targetDir.mkdirs(); + return new FileRef(targetDir.getAbsolutePath(), true); + } + + public String getCode(String relPath, String fileName) { + String code = null; + + Object p = getRequest().getUserPrincipal(); + if(p instanceof Principal) { + FileReader reader = null; + try { + File targetFile = new File(getTargetDir(relPath), fileName); + reader = new FileReader(targetFile); + StringBuffer buf = new StringBuffer(); + char[] readBuffer = new char[1024]; + int charsRead = reader.read(readBuffer); + while(charsRead > -1) { + buf.append(readBuffer, 0, charsRead); + charsRead = reader.read(readBuffer); + } + code = buf.toString(); + } catch (FileNotFoundException ex) { + Logger.getLogger(FileMgr.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(FileMgr.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + reader.close(); + } catch (IOException ex) { + Logger.getLogger(FileMgr.class.getName()).log(Level.SEVERE, null, ex); + } } - logger.finer(targetPath); - File targetDir = new File(getBase().getAbsolutePath(), targetPath); - return targetDir; + + } + + return code; } - private FileRef getBase() { - FileRef base = null; - Object o = getServletContext().getAttribute(Initialiser.FILE_BASE); - if(o instanceof FileRef) { - base = (FileRef) o; + public String deleteFiles(String relPath, List fileNames) { + String result = null; + try { + FileRef[] delRefs = new FileRef[fileNames.size()]; + logger.fine(fileNames.toString()); + File targetDir = getTargetDir(relPath); + for(int i=0; i < fileNames.size(); i++) { + Object o = fileNames.get(i); + if(o instanceof ArrayList) { + ArrayList al = (ArrayList) o; + logger.fine(al.get(0).toString()); + File targetFile = new File(targetDir, al.get(0).toString()); + logger.fine(targetFile.getAbsolutePath()); + delRefs[i] = new FileRef(targetFile.getAbsolutePath(), targetFile.isDirectory()); + } + } + FileSystem fs = new LocalFileSystem(); + fs.delete(delRefs); + result = "deleted"; + } catch (Throwable ex) { + logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex); } - return base; + return result; } - - /* - private File getUserPubDir() { - File userDir = null; - File daten = new File(getBase().getAbsolutePath()); - Object p = getRequest().getUserPrincipal(); - if(p instanceof Principal) { - userDir = new File(daten, PUB_DIR_PATH + ((Principal) p).getName()); - } - return userDir; - } - */ - - private String getUserName() { - String userName = null; - Object p = getRequest().getUserPrincipal(); - if(p instanceof Principal) { - userName = ((Principal) p).getName(); - } - return userName; - } - - /* - private File getUserHomeDir() { - File userDir = null; - File daten = new File(getBase().getAbsolutePath()); - Object p = getRequest().getUserPrincipal(); - if(p instanceof Principal) { - userDir = new File(daten, HOME_DIR_PATH + ((Principal) p).getName()); - } - return userDir; - } - */ public FileRef saveTextFile(String relPath, String fileName, String contents) { FileRef savedFile = null; try { FileRef datenRef = getBase(); - File daten = new File(datenRef.getAbsolutePath()); + //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(getTargetDir(relPath), fileName); if(targetFile.exists()) { /* @@ -195,12 +183,48 @@ } return savedFile; } + + /* ---- Hilfsfunktionen ---- */ + private File getTargetDir(String relPath) { + logger.finer(relPath); + String targetPath = null; + if(relPath.startsWith(PUB_DIR_NAME)) { + targetPath = PUB_DIR_PATH + getUserName() + "/" + relPath.substring(PUB_DIR_NAME.length()); + } else if(relPath.startsWith(HOME_DIR_NAME)) { + targetPath = HOME_DIR_PATH + getUserName() + "/" + relPath.substring(HOME_DIR_NAME.length()); + } else { + // kann eigentlich nicht sein.. + } + logger.finer(targetPath); + File targetDir = new File(getBase().getAbsolutePath(), targetPath); + return targetDir; + } + private FileRef getBase() { + FileRef base = null; + Object o = getServletContext().getAttribute(Initialiser.FILE_BASE); + if(o instanceof FileRef) { + base = (FileRef) o; + } + return base; + } + + private String getUserName() { + String userName = null; + Object p = getRequest().getUserPrincipal(); + if(p instanceof Principal) { + userName = ((Principal) p).getName(); + } + return userName; + } + + /* private File getWebappsDir() { File cfile = new File(this.getClass().getResource( this.getClass().getSimpleName() + ".class").getFile()); String path = cfile.getAbsolutePath(); return new File(path.substring(0, path.indexOf(getRequest().getContextPath()))); } + */ } -- Gitblit v1.9.3