Package org.elfinder.servlets

Examples of org.elfinder.servlets.ConnectorException


      File targetFile = getExistingFile(getParam("target"), dirCurrent, FileActionEnum.DELETE);
      File futureFile = getNewFile(getParam("name"), dirCurrent, FileActionEnum.WRITE);
      try {
        getFs().renameFileOrDirectory(targetFile, futureFile);
      } catch (FsException e) {
        throw new ConnectorException("Unable to rename file", e);
      }

      putResponse("select", _hash(targetFile));
      _content(dirCurrent, true);
    }
View Full Code Here


        int i = 0;
        for (FileItemStream uplFile : getListFiles()) {
          String fileName = getUploadedFileName(uplFile);
          ByteArrayOutputStream os = getListFileStreams().get(i);
          if (os == null) {
            throw new ConnectorException("Unable to save uploaded file");
          }

          checkUploadFile(fileName, os);

          File newFile = getNewFile(fileName, dirCurrent, FileActionEnum.WRITE);
          getFs().createFile(newFile, os);

          listeResponseSelect.add(_hash(newFile));
          i++;
        }

      } catch (ConnectorException e) {
        throw e;
      } catch (Exception e) {
        logger.error("", e);
        throw new ConnectorException("Unable to save uploaded file");
      }

      putResponse("select", listeResponseSelect);

      _content(dirCurrent, true);
View Full Code Here

    return uplFile.getName();
  }

  protected void checkUploadFile(String fileName, ByteArrayOutputStream os) throws ConnectorException {
    if (!_checkName(fileName)) {
      throw new ConnectorException("Invalid name");
    }
    if (!_isUploadAllow(fileName)) {
      throw new ConnectorException("Not allowed file type");
    }

    // check uploaded size
    int uploadSizeOctets = os.size();
    checkUploadSizes(uploadSizeOctets);
View Full Code Here

  }

  protected void checkUploadSizes(int uploadSizeOctets) throws ConnectorException {
    // check uploaded file size
    if (uploadSizeOctets > (getConfig().getUploadMaxSize() * 1024 * 1024)) {
      throw new ConnectorException("File exceeds the maximum allowed filesize");
    }

    // check total size
    long totalSizeOctets = getFs().getDirSize(getRootFile());
    if ((totalSizeOctets + uploadSizeOctets) > (getConfig().getUploadMaxSizeTotal() * 1024 * 1024)) {
      throw new ConnectorException("File exceeds the maximum allowed filesize");
    }
  }
View Full Code Here

      try {
        // write with empty data
        getFs().createFile(newFile, null);
      } catch (Exception e) {
        logger.error("", e);
        throw new ConnectorException("Unable to create folder");
      }
      if (out != null) {
        try {
          out.close();
        } catch (Exception e) {
View Full Code Here

    File dir = null;
    if (dirHash != null && !"".equals(dirHash)) {
      dir = _findDir(dirHash, null);

      if (dir == null) {
        throw new ConnectorException("Invalid parameters");
      }

      if (!getConfig()._isAllowedExistingDir(dir, actionCheck)) {
        throw new ConnectorException("Access denied");
      }
    }
    return dir;
  }
View Full Code Here

  }

  protected File getExistingFile(String fileHash, File existingDir, FileActionEnum actionCheck) throws ConnectorException {
    File existingFile = _find(fileHash, existingDir);
    if (existingFile == null) {
      throw new ConnectorException("File not found");
    }

    if (!getConfig()._isAllowedExistingFile(existingFile, actionCheck)) {
      throw new ConnectorException("Access denied");
    }
    return existingFile;
  }
View Full Code Here

    return existingFile;
  }

  protected File getNewFile(String fileName, File existingDir, FileActionEnum actionCheck) throws ConnectorException {
    if (!_checkName(fileName)) {
      throw new ConnectorException("Invalid name");
    }

    File newFile = new File(existingDir, fileName);
    if (newFile.exists()) {
      throw new ConnectorException("File or folder with the same name already exists");
    }

    if (!config._isAllowedNewFile(newFile, actionCheck)) {
      throw new ConnectorException("Access denied");
    }
    return newFile;
  }
View Full Code Here

    return newFile;
  }

  protected File getNewDirectory(String dirName, File existingDir, FileActionEnum actionCheck) throws ConnectorException {
    if (!_checkName(dirName)) {
      throw new ConnectorException("Invalid name");
    }

    File newFile = new File(existingDir, dirName);
    if (newFile.exists()) {
      throw new ConnectorException("File or folder with the same name already exists");
    }

    if (!config._isAllowedNewDir(newFile, actionCheck)) {
      throw new ConnectorException("Access denied");
    }
    return newFile;
  }
View Full Code Here

        File dirDst = getExistingDir(getParam("dst"), FileActionEnum.READ);
        if (dirDst != null) {

          List<String> targets = (List<String>) getParamObject("targets[]");
          if (targets == null || targets.isEmpty()) {
            throw new ConnectorException("Invalid parameters");
          }

          boolean cut = "1".equals(getParam("cut"));

          for (String targetHash : targets) {
            File fileTarget = getExistingFile(targetHash, dirSrc, FileActionEnum.READ);
            if (fileTarget == null) {
              _content(dirCurrent, true);
              throw new ConnectorException("File not found");
            }

            if (dirSrc.getAbsolutePath().equals(dirDst.getAbsolutePath())) {
              _content(dirCurrent, true);
              throw new ConnectorException("Unable to copy into itself");
            }

            File futureFile = getNewFile(basename(fileTarget), dirDst, FileActionEnum.WRITE);

            if (cut) {
              // moving file...
              if (!getConfig()._isAllowedExistingFile(fileTarget, FileActionEnum.DELETE)) {
                throw new ConnectorException("Access denied");
              }

              try {
                getFs().renameFileOrDirectory(fileTarget, futureFile);
                // TODO
                //                if (!is_dir($f)) {
                //                  $this->_rmTmb($f);
                //                }
              } catch (FsException e) {
                _content(dirCurrent, true);
                throw new ConnectorException("Unable to move files");
              }
            } else {
              // copying file...
              try {
                getFs().copyFileOrDirectory(fileTarget, futureFile);
              } catch (FsException e) {
                _content(dirCurrent, true);
                throw new ConnectorException("Unable to copy files");
              }
            }
          }
        }
      }
View Full Code Here

TOP

Related Classes of org.elfinder.servlets.ConnectorException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.