예제 #1
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);
 }
예제 #2
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();
        }