Dateiverwaltung für die WebBox
ulrich
2018-03-03 eb2a2d78152c7ca689e3aac116c107229a896a66
src/java/de/uhilger/filecms/api/FileMgr.java
@@ -141,6 +141,7 @@
  
  
  public FileRef newFolder(String relPath, String folderName) {
    if (!relPath.startsWith(".")) {
    logger.finer(relPath);
    String targetPath = null;
    if(relPath.startsWith(PUB_DIR_NAME)) {
@@ -154,11 +155,14 @@
    File targetDir = new File(getBase().getAbsolutePath(), targetPath);
    targetDir.mkdirs();
    return new FileRef(targetDir.getAbsolutePath(), true);
    } else {
      return null;
    }
  }
  
  public String getCode(String relPath, String fileName) {
    String code = null;
    if (!relPath.startsWith(".")) {
    Object p = getRequest().getUserPrincipal();
    if(p instanceof Principal) {
      Reader reader = null;
@@ -166,7 +170,6 @@
        File targetFile = new File(getTargetDir(relPath), fileName);
        
        //reader = new InputStreamReader(new FileInputStream(targetFile), "UTF8");
        reader = new FileReader(targetFile);
        StringBuffer buf = new StringBuffer();
        char[] readBuffer = new char[1024];
@@ -189,21 +192,26 @@
      }
      
    }    
    }
    return code;
  }
  
  public String renameFile(String relPath, String fname, String newName) {
    if (!relPath.startsWith(".")) {
    File targetDir = getTargetDir(relPath);
    File file = new File(targetDir, fname);
    file.renameTo(new File(targetDir, newName));
    return fname + " umbenannt zu " + newName;
    } else {
      return "Pfad nicht erlaubt.";
    }
  }
  
  public String deleteFiles(String relPath, List fileNames) {
    String result = null;
    try {
      logger.fine(fileNames.toString());
      if (!relPath.startsWith(".")) {
      File targetDir = getTargetDir(relPath);
      for(int i=0; i < fileNames.size(); i++) {
        Object o = fileNames.get(i);
@@ -220,6 +228,7 @@
        }
      }
      result = "deleted";
      }
    } catch (Throwable ex) {
      logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
@@ -237,6 +246,7 @@
  private String copyOrMoveFiles(String fromPath, String toPath, List fileNames, int operation) {
    String result = null;
    try {
      if (!fromPath.startsWith(".")) {
      File srcDir = getTargetDir(fromPath);
      File targetDir = getTargetDir(toPath);
      Iterator i = fileNames.iterator();
@@ -260,6 +270,7 @@
          }
        }
      }
      }
    } catch (IOException ex) {
      logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
@@ -269,6 +280,7 @@
  public FileRef saveTextFileAs(String relPath, String fileName, String contents) {
    FileRef savedFile = null;
    logger.fine(relPath + " " + fileName);
    if (!relPath.startsWith(".")) {
    //FileRef datenRef = getBase();
    Object p = getRequest().getUserPrincipal();
    if(p instanceof Principal) {
@@ -279,6 +291,7 @@
        targetFile.getParentFile().mkdirs();
      }
      saveToFile(targetFile, contents);
      }
    }
    return savedFile;
  }
@@ -334,6 +347,7 @@
  public FileRef saveTextFile(String relPath, String fileName, String contents) {
    FileRef savedFile = null;
    logger.fine(relPath + " " + fileName);
    if (!relPath.startsWith(".")) {
    //FileRef datenRef = getBase();
    Object p = getRequest().getUserPrincipal();
    if(p instanceof Principal) {
@@ -351,17 +365,18 @@
      }
      saveToFile(targetFile, contents);
    }
    }
    return savedFile;
  }
  
  public String bildVerkleinern(String relPath, String bildName) {
    if (!relPath.startsWith(".")) {
    File dir = getTargetDir(relPath);
    File original = new File(dir, bildName);
    Bild bild = new Bild();
    //for (int i = 0; i < Bild.GR.length; i++) {
    
      //int gr = bild.getVariantenGroesse(i);
      String ext = "";
      String nurname = bildName;
      int dotpos = bildName.indexOf(".");
@@ -393,12 +408,15 @@
      } catch(IOException | InterruptedException ex) {
        logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
      }
    return "ok";
    } else {
      return "Pfad micht erlaubt.";
    }
  }
  
  public String extractZipfile(String relPath, String filename) {
    String result;
    String result = null;
    if (!relPath.startsWith(".")) {
    try {
      File targetDir = getTargetDir(relPath);
      File archive = new File(targetDir, filename);
@@ -411,6 +429,7 @@
      result = ex.getLocalizedMessage();
      logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    }
    return result;
  }