Example #1
0
 public void setFileInput(IFileInput input) {
   if (fileInput != null) {
     fileInput.asWidget().removeFromParent();
   }
   fileInput = input;
   fileInput.addChangeHandler(onFileInputChanged);
   fileInput.setText(
       fileInput instanceof IDragAndDropFileInput
           ? i18nStrs.uploaderDrop()
           : i18nStrs.uploaderBrowse());
   fileInput.setEnabled(enabled);
   setFileInputSize(DEFAULT_FILEINPUT_SIZE);
   assignNewNameToFileInput();
   uploadForm.add(fileInput.asWidget());
 }
Example #2
0
 /** Change the fileInput name, because the server uses it as an uniq identifier. */
 protected void assignNewNameToFileInput() {
   String fileInputName = (fileInputPrefix + "-" + Math.random()).replaceAll("\\.", "");
   if (multiple) {
     fileInputName += MULTI_SUFFIX;
   }
   fileInput.setName(fileInputName);
 }
Example #3
0
  /* (non-Javadoc)
   * @see gwtupload.client.IUploader#setValidExtensions(java.lang.String[])
   */
  public void setValidExtensions(String... extensions) {
    this.validExtensions = new ArrayList<String>();
    validExtensionsMsg = "";
    if (extensions == null || extensions.length == 0) {
      return;
    }
    List<String> v = new ArrayList<String>();
    String accept = "";
    for (String ext : extensions) {
      if (ext == null) {
        continue;
      }
      if (ext.contains("/")) {
        accept += (accept.isEmpty() ? "" : ",") + ext;
        continue;
      }
      if (!ext.startsWith(".")) ext = "." + ext;
      accept += (accept.isEmpty() ? "" : ",") + ext;

      validExtensionsMsg += (validExtensionsMsg.isEmpty() ? "" : ",") + ext;
      ext = ext.replaceAll("\\.", "\\\\.");
      ext = ".+" + ext;
      validExtensions.add(ext);
    }
    fileInput.setAccept(accept);
  }
Example #4
0
 /* (non-Javadoc)
  * @see gwtupload.client.IUploader#setI18Constants(gwtupload.client.I18nUploadConstants)
  */
 public void setI18Constants(UploaderConstants strs) {
   this.i18nStrs = strs;
   fileInput.setText(
       fileInput instanceof IDragAndDropFileInput
           ? i18nStrs.uploaderDrop()
           : i18nStrs.uploaderBrowse());
   statusWidget.setI18Constants(strs);
 }
Example #5
0
 public boolean anyFileIsRepeated(boolean checkOnlyUploadedFiles) {
   if (!multiple && avoidRepeatedFiles) {
     for (String s : fileInput.getFilenames()) {
       if (fileDone.contains(s) || (!checkOnlyUploadedFiles && fileUploading.contains(s)))
         return true;
     }
   }
   return false;
 }
Example #6
0
        public void onResponseReceived(Request request, Response response) {
          String text = response.getText();
          String url = null;
          Document document = null;

          String bpath = "<" + TAG_BLOBSTORE_PATH + ">";
          String sbpath = "</" + TAG_BLOBSTORE_PATH + ">";
          if (text.contains(bpath)) {
            try {
              document = XMLParser.parse(text);
              url = Utils.getXmlNodeValue(document, TAG_BLOBSTORE_PATH);
            } catch (Exception e) {
              cancelUpload(
                  i18nStrs.uploaderBlobstoreError() + "\n>>>\n" + e.getMessage() + "\n>>>>\n" + e);
              return;
            }
            if (url == null) {
              url =
                  text.replaceAll("[\r\n]+", "")
                      .replaceAll("^.*" + bpath + "\\s*", "")
                      .replaceAll("\\s*" + sbpath + ".*$", "");
            }
          }
          if (url != null && url.length() > 0 && !"null".equalsIgnoreCase(url)) {
            if (session.getServletPath().startsWith("http")) {
              url = session.getServletPath().replaceFirst("(https?://[^/]+).*", "$1") + url;
            }
            uploadForm.setAction(url);
          } else {
            uploadForm.setAction(session.getServletPath());
          }
          removeHiddens();
          if (document != null) {
            String name = Utils.getXmlNodeValue(document, TAG_BLOBSTORE_NAME);
            if (name != null) {
              fileInput.setName(name);
            }
            NodeList list = document.getElementsByTagName(TAG_BLOBSTORE_PARAM);
            for (int i = 0; i < list.getLength(); i++) {
              Node node = list.item(i);
              String value = Utils.getXmlNodeValue(node);
              if (value != null) {
                Node attribute = node.getAttributes().getNamedItem(ATTR_BLOBSTORE_PARAM_NAME);
                if (attribute != null) {
                  String paramName = attribute.getNodeValue();
                  if (paramName != null) {
                    addHidden(paramName, value);
                  }
                }
              }
            }
          }
          receivedBlobPath = true;
          uploadForm.submit();
        }
Example #7
0
 /* (non-Javadoc)
  * @see gwtupload.client.IUpdateable#update()
  */
 public void update() {
   if (waitingForResponse) {
     return;
   }
   waitingForResponse = true;
   session.sendRequest(
       "get_status",
       onStatusReceivedCallback,
       "filename=" + fileInput.getName().replace(MULTI_SUFFIX, ""),
       "c=" + requestsCounter++);
 }
Example #8
0
 /**
  * Sends a request to the server in order to get the blobstore path. When the response with the
  * session comes, it submits the form.
  */
 private void sendAjaxRequestToGetBlobstorePath() throws RequestException {
   session.sendRequest(
       "blobstore",
       onBlobstoreReceivedCallback,
       PARAM_BLOBSTORE
           + "=true&"
           + PARAM_NAME
           + "="
           + getInputName()
           + "&"
           + PARAM_FILENAME
           + "="
           + fileInput.getFilename());
 }
Example #9
0
  /**
   * Called when the uploader detects that the upload process has finished: - in the case of submit
   * complete. - in the case of error talking with the server.
   */
  private void uploadFinished() {
    removeFromQueue();
    finished = true;
    uploading = false;
    updateStatusTimer.cancel();
    statusWidget.setVisible(false);

    if (successful) {
      if (avoidRepeatedFiles) {
        fileDone.addAll(fileInput.getFilenames());
        statusWidget.setStatus(IUploadStatus.Status.SUCCESS);
      } else {
        statusWidget.setStatus(IUploadStatus.Status.SUCCESS);
      }
    } else if (canceled) {
      statusWidget.setStatus(IUploadStatus.Status.CANCELED);
    } else {
      statusWidget.setStatus(IUploadStatus.Status.ERROR);
    }
    onFinishUpload();
    reatachIframe(uploadForm.getElement().getAttribute("target"));
  }
Example #10
0
 /* (non-Javadoc)
  * @see gwtupload.client.IUploader#setFileInputSize(int)
  */
 public void setFileInputSize(int length) {
   fileInput.setLength(length);
 }
Example #11
0
 /* (non-Javadoc)
  * @see gwtupload.client.IUploader#setEnabled(boolean)
  */
 public void setEnabled(boolean b) {
   enabled = b;
   if (fileInput != null) {
     fileInput.setEnabled(b);
   }
 }
Example #12
0
 public String getInputName() {
   return fileInput.getName().replace(MULTI_SUFFIX, "");
 }
Example #13
0
 /* (non-Javadoc)
  * @see gwtupload.client.IUploader#getFileNames()
  */
 public List<String> getFileNames() {
   return fileInput.getFilenames();
 }
Example #14
0
 /* (non-Javadoc)
  * @see gwtupload.client.IUploader#getFileName()
  */
 public String getFileName() {
   return fileInput.getFilename();
 }
Example #15
0
 /** Remove all widget from the form. */
 public void clear() {
   uploadForm.clear();
   uploadForm.add(fileInput.asWidget());
 }
Example #16
0
 public void setMultipleSelection(boolean b) {
   multiple = b;
   fileInput.enableMultiple(b);
 }