Package er.ajax

Examples of er.ajax.AjaxUploadProgress$Delegate


    return uploadUrl;
  }

  public String bytesReadSize() {
    String bytesReadSize = null;
    AjaxUploadProgress progress = uploadProgress();
    if (progress != null) {
      NumberFormat formatter = new ERXUnitAwareDecimalFormat(ERXUnitAwareDecimalFormat.BYTE);
      formatter.setMaximumFractionDigits(2);
      bytesReadSize = formatter.format(progress.value());
    }
    return bytesReadSize;
  }
View Full Code Here


    return bytesReadSize;
  }

  public String streamLengthSize() {
    String streamLengthSize = null;
    AjaxUploadProgress progress = uploadProgress();
    if (progress != null) {
      NumberFormat formatter = new ERXUnitAwareDecimalFormat(ERXUnitAwareDecimalFormat.BYTE);
      formatter.setMaximumFractionDigits(2);
      streamLengthSize = formatter.format(progress.maximum());
    }
    return streamLengthSize;
  }
View Full Code Here

    boolean uploadStarted;
    if (hasBinding("uploadStarted")) {
      uploadStarted = ERXComponentUtilities.booleanValueForBinding(this, "uploadStarted");
    }
    else {
      AjaxUploadProgress progress = uploadProgress();
      if (progress != null && progress.shouldReset()) {
        _uploadStarted = false;
        setValueForBinding(Boolean.FALSE, "uploadStarted");
      }
      uploadStarted = _uploadStarted;
    }
View Full Code Here

    WOActionResults results = (WOActionResults) valueForBinding("canceledAction");
    return results;
  }

  public WOActionResults uploadSucceeded() {
    AjaxUploadProgress progress = uploadProgress();
    try {
      boolean deleteFile = true;
      if (hasBinding("filePath")) {
        setValueForBinding(progress.fileName(), "filePath");
      }

      if (hasBinding("data")) {
        NSData data = new NSData(progress.tempFile().toURI().toURL());
        setValueForBinding(data, "data");
      }
     
      if (hasBinding("mimeType")) {
        String contentType = progress.contentType();
        if (contentType != null) {
          setValueForBinding(contentType, "mimeType");
        }
      }

      if (hasBinding("inputStream")) {
        setValueForBinding(new FileInputStream(progress.tempFile()), "inputStream");
        deleteFile = false;
      }

      if (hasBinding("outputStream")) {
        OutputStream outputStream = (OutputStream) valueForBinding("outputStream");
        if (outputStream != null) {
          ERXFileUtilities.writeInputStreamToOutputStream(new FileInputStream(progress.tempFile()), true, outputStream, true);
        }
      }

      String finalFilePath = progress.tempFile().getAbsolutePath();
      if (hasBinding("streamToFilePath")) {
        File streamToFile = new File((String) valueForBinding("streamToFilePath"));
        boolean renamedFile;
        boolean renameFile;
        if (streamToFile.exists()) {
          boolean overwrite = ERXComponentUtilities.booleanValueForBinding(this, "overwrite");
          if (streamToFile.isDirectory()) {
            File parentDir = streamToFile;
            String fileName = ERXFileUtilities.fileNameFromBrowserSubmittedPath(progress.fileName());
            streamToFile = ERXFileUtilities.reserveUniqueFile(new File(parentDir, fileName), overwrite);
            renameFile = true;
          }
          else {
            renameFile = overwrite;
          }
        }
        else {
          renameFile = true;
        }

        if (renameFile && !streamToFile.isDirectory()) {
          ERXFileUtilities.renameTo(progress.tempFile(), streamToFile);
          renamedFile = true;
        }
        else {
          renamedFile = false;
          progress.setFailure(new Exception ("Could not rename file."));
          return uploadFailed();
        }
       
        if (renamedFile) {
          finalFilePath = streamToFile.getAbsolutePath();
        }
       
        deleteFile = false;
      }
      else if (hasBinding("keepTempFile") && deleteFile) {
        deleteFile = !ERXComponentUtilities.booleanValueForBinding(this, "keepTempFile");
      }

      if (deleteFile) {
        progress.dispose();
      }
      else if (hasBinding("finalFilePath")) {
        setValueForBinding(finalFilePath, "finalFilePath");
      }

    }
    catch (Throwable t) {
      t.printStackTrace();
      progress.setFailure(t);
      return uploadFailed();
    }
    finally {
      uploadFinished();
    }
View Full Code Here

TOP

Related Classes of er.ajax.AjaxUploadProgress$Delegate

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.