Dateiverwaltung für die WebBox
ulrich
2017-02-21 5efd94fed0b470d715b9aa4d2e6b0e300ca2ec06
FileMgr aufgeraeumt
1 files modified
71 ■■■■ changed files
src/java/de/uhilger/filecms/api/FileMgr.java 71 ●●●● patch | view | raw | blame | history
src/java/de/uhilger/filecms/api/FileMgr.java
@@ -57,9 +57,9 @@
      files.add(namedHomeFolder);
      files.add(namedPublicFolder);
    } else {
      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]);
@@ -83,39 +83,6 @@
    File targetDir = new File(getBase().getAbsolutePath(), targetPath);
    targetDir.mkdirs();
    return new FileRef(targetDir.getAbsolutePath(), true);
  }
  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;
  }
  
  public FileRef saveTextFile(String relPath, String fileName, String contents) {
@@ -154,12 +121,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())));
  }
  */
    
}