예제 #1
0
 /**
  * Returns get response for the {@code GetFolders*} commands. This is simply a helper method.
  *
  * @param command the current command, should be only GetFolders or GetFoldersAndFiles
  * @param the current resource type
  * @param currentFolder the current folder
  * @param constructedUrl the final URL
  * @return the get response instance associated with this request
  * @throws InvalidCurrentFolderException if the current folder name is invalid or does not exist
  *     within the underlying backend
  * @throws ReadException if the file attributes and/or folder names could not be read due to some
  *     reason
  */
 private GetResponse getFoldersAndOrFiles(
     final Command command,
     final ResourceType type,
     final String currentFolder,
     final String constructedUrl)
     throws InvalidCurrentFolderException, ReadException {
   final GetResponse getResponse = new GetResponse(command, type, currentFolder, constructedUrl);
   getResponse.setFolders(this.connector.getFolders(type, currentFolder));
   if (command.equals(Command.GET_FOLDERS_AND_FILES)) {
     getResponse.setFiles(this.connector.getFiles(type, currentFolder));
   }
   return getResponse;
 }
예제 #2
0
  /**
   * Called by the connector servlet to handle a {@code GET} request. In particular, it handles the
   * {@link Command#GET_FOLDERS GetFolders}, {@link Command#GET_FOLDERS_AND_FILES
   * GetFoldersAndFiles} and {@link Command#CREATE_FOLDER CreateFolder} commands.
   *
   * @param request the current request instance
   * @return the get response instance associated with this request
   */
  GetResponse doGet(final HttpServletRequest request) {
    Dispatcher.logger.debug("Entering Dispatcher#doGet");

    final Context context = ThreadLocalData.getContext();
    context.logBaseParameters();

    GetResponse getResponse = null;
    // check parameters
    if (!Command.isValidForGet(context.getCommandStr())) {
      getResponse = GetResponse.getInvalidCommandError();
    } else if (!ResourceType.isValidType(context.getTypeStr())) {
      getResponse = GetResponse.getInvalidResourceTypeError();
    } else if (!UtilsFile.isValidPath(context.getCurrentFolderStr())) {
      getResponse = GetResponse.getInvalidCurrentFolderError();
    } else {

      // in contrast to doPost the referrer has to send an explicit type
      final ResourceType type = context.getResourceType();
      final Command command = context.getCommand();

      // check permissions for user action
      if ((command.equals(Command.GET_FOLDERS) || command.equals(Command.GET_FOLDERS_AND_FILES))
          && !RequestCycleHandler.isGetResourcesEnabled(request)) {
        getResponse = GetResponse.getGetResourcesDisabledError();
      } else if (command.equals(Command.CREATE_FOLDER)
          && !RequestCycleHandler.isCreateFolderEnabled(request)) {
        getResponse = GetResponse.getCreateFolderDisabledError();
      } else {
        // make the connector calls, catch its exceptions and generate
        // the proper response object
        try {
          if (command.equals(Command.CREATE_FOLDER)) {
            final String newFolderNameStr = request.getParameter("NewFolderName");
            Dispatcher.logger.debug("Parameter NewFolderName: {}", newFolderNameStr);
            final String sanitizedNewFolderNameStr = UtilsFile.sanitizeFolderName(newFolderNameStr);
            if (Utils.isEmpty(sanitizedNewFolderNameStr)) {
              getResponse = GetResponse.getInvalidNewFolderNameError();
            } else {
              Dispatcher.logger.debug(
                  "Parameter NewFolderName (sanitized): {}", sanitizedNewFolderNameStr);
              this.connector.createFolder(
                  type, context.getCurrentFolderStr(), sanitizedNewFolderNameStr);
              getResponse = GetResponse.getOK();
            }
          } else if (command.equals(Command.GET_FOLDERS)
              || command.equals(Command.GET_FOLDERS_AND_FILES)) {
            final String url =
                UtilsResponse.getUrl(
                    RequestCycleHandler.getUserFilesPath(request),
                    type,
                    context.getCurrentFolderStr());
            getResponse =
                this.getFoldersAndOrFiles(command, type, context.getCurrentFolderStr(), url);
          }
        } catch (final InvalidCurrentFolderException e) {
          getResponse = GetResponse.getInvalidCurrentFolderError();
        } catch (final InvalidNewFolderNameException e) {
          getResponse = GetResponse.getInvalidNewFolderNameError();
        } catch (final FolderAlreadyExistsException e) {
          getResponse = GetResponse.getFolderAlreadyExistsError();
        } catch (final WriteException e) {
          getResponse = GetResponse.getCreateFolderWriteError();
        } catch (final ReadException e) {
          getResponse = GetResponse.getGetResourcesReadError();
        }
      }
    }

    Dispatcher.logger.debug("Exiting Dispatcher#doGet");
    return getResponse;
  }