Package net.fckeditor.requestcycle

Examples of net.fckeditor.requestcycle.Context


   * @return the get response instance associated with this request
   */
  GetResponse doGet(final HttpServletRequest request) {
    logger.debug("Entering Dispatcher#doGet");
   
    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
      ResourceType type = context.getResourceType();
      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)) {
            String newFolderNameStr = request
                .getParameter("NewFolderName");
            logger.debug("Parameter NewFolderName: {}",
                newFolderNameStr);       
            String sanitizedNewFolderNameStr = UtilsFile
                .sanitizeFolderName(newFolderNameStr);
            if (Utils.isEmpty(sanitizedNewFolderNameStr))
              getResponse = GetResponse
                  .getInvalidNewFolderNameError();
            else {
              logger.debug(
                  "Parameter NewFolderName (sanitized): {}",
                  sanitizedNewFolderNameStr);
              connector.createFolder(type, context
                  .getCurrentFolderStr(),
                  sanitizedNewFolderNameStr);
              getResponse = GetResponse.getOK();
            }
          } else if (command.equals(Command.GET_FOLDERS)
              || command
                  .equals(Command.GET_FOLDERS_AND_FILES)) {
            String url = UtilsResponse.getUrl(RequestCycleHandler
                .getUserFilesPath(request), type, context
                .getCurrentFolderStr());
            getResponse = getFoldersAndOrFiles(command, type, context
                .getCurrentFolderStr(), url);
          }
        } catch (InvalidCurrentFolderException e) {
          getResponse = GetResponse.getInvalidCurrentFolderError();
        } catch (InvalidNewFolderNameException e) {
View Full Code Here


   * @return the upload response instance associated with this request
   */
  UploadResponse doPost(final HttpServletRequest request) {
    logger.debug("Entering Dispatcher#doPost");
   
    Context context = ThreadLocalData.getContext();
    context.logBaseParameters();
   
    UploadResponse uploadResponse = null;
    // check permissions for user actions
    if (!RequestCycleHandler.isFileUploadEnabled(request))
      uploadResponse = UploadResponse.getFileUploadDisabledError();
    // check parameters 
    else if (!Command.isValidForPost(context.getCommandStr()))
      uploadResponse = UploadResponse.getInvalidCommandError();
    else if (!ResourceType.isValidType(context.getTypeStr()))
      uploadResponse = UploadResponse.getInvalidResourceTypeError();
    else if (!UtilsFile.isValidPath(context.getCurrentFolderStr()))
      uploadResponse = UploadResponse.getInvalidCurrentFolderError();
    else {

      // call the Connector#fileUpload
      ResourceType type = context.getDefaultResourceType();
      FileItemFactory factory = new DiskFileItemFactory();
      ServletFileUpload upload = new ServletFileUpload(factory);
      try {
        List<FileItem> items = upload.parseRequest(request);
        // We upload just one file at the same time
        FileItem uplFile = items.get(0);
        // Some browsers transfer the entire source path not just the
        // filename
        String fileName = FilenameUtils.getName(uplFile.getName());
        logger.debug("Parameter NewFile: {}", fileName);
        // check the extension
        if (type.isDeniedExtension(FilenameUtils.getExtension(fileName)))
          uploadResponse = UploadResponse.getInvalidFileTypeError();
        // Secure image check (can't be done if QuickUpload)
        else if (type.equals(ResourceType.IMAGE)
            && PropertiesLoader.isSecureImageUploads()
            && !UtilsFile.isImage(uplFile.getInputStream())) {
          uploadResponse = UploadResponse.getInvalidFileTypeError();
        } else {
          String sanitizedFileName = UtilsFile
              .sanitizeFileName(fileName);
          logger.debug("Parameter NewFile (sanitized): {}",
              sanitizedFileName);
          String newFileName = connector.fileUpload(type, context
              .getCurrentFolderStr(), sanitizedFileName, uplFile
              .getInputStream());
          String fileUrl = UtilsResponse.fileUrl(RequestCycleHandler
              .getUserFilesPath(request), type, context
              .getCurrentFolderStr(), newFileName);

          if (sanitizedFileName.equals(newFileName))
            uploadResponse = UploadResponse.getOK(fileUrl);
          else {
View Full Code Here

TOP

Related Classes of net.fckeditor.requestcycle.Context

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.