Esempio n. 1
0
  public int addTitaniumFileAsPostData(String name, Object value) {
    try {
      if (value instanceof TiBaseFile) {
        TiBaseFile baseFile = (TiBaseFile) value;
        FileBody body =
            new FileBody(
                baseFile.getNativeFile(), TiMimeTypeHelper.getMimeType(baseFile.nativePath()));
        parts.put(name, body);
        return (int) baseFile.getNativeFile().length();
      } else if (value instanceof TiBlob) {
        TiBlob blob = (TiBlob) value;
        String mimeType = blob.getMimeType();
        File tmpFile =
            File.createTempFile(
                "tixhr", TiMimeTypeHelper.getFileExtensionFromMimeType(mimeType, ".txt"));
        FileOutputStream fos = new FileOutputStream(tmpFile);
        fos.write(blob.getBytes());
        fos.close();

        FileBody body = new FileBody(tmpFile, mimeType);
        parts.put(name, body);
        return blob.getLength();
      } else {
        if (value != null) {
          Log.e(LCAT, name + " is a " + value.getClass().getSimpleName());
        } else {
          Log.e(LCAT, name + " is null");
        }
      }
    } catch (IOException e) {
      Log.e(LCAT, "Error adding post data (" + name + "): " + e.getMessage());
    }
    return 0;
  }
  public void setData(TiBlob blob) {
    reloadMethod = reloadTypes.DATA;
    reloadData = blob;
    String mimeType = "text/html";

    // iOS parity: for whatever reason, in setData, the iOS implementation
    // explicitly sets the native webview's setScalesPageToFit to YES if the
    // Ti scalesPageToFit property has _not_ been set.
    if (!proxy.hasProperty(TiC.PROPERTY_SCALES_PAGE_TO_FIT)) {
      getWebView().getSettings().setLoadWithOverviewMode(true);
    }

    if (blob.getType() == TiBlob.TYPE_FILE) {
      String fullPath = blob.getNativePath();
      if (fullPath != null) {
        setUrl(fullPath);
        return;
      }
    }

    if (blob.getMimeType() != null) {
      mimeType = blob.getMimeType();
    }
    if (TiMimeTypeHelper.isBinaryMimeType(mimeType)) {
      getWebView().loadData(blob.toBase64(), mimeType, "base64");
    } else {
      getWebView().loadData(escapeContent(new String(blob.getBytes())), mimeType, "utf-8");
    }
  }
 private boolean mightBeHtml(String url) {
   String mime = TiMimeTypeHelper.getMimeType(url);
   if (mime.equals("text/html")) {
     return true;
   } else if (mime.equals("application/xhtml+xml")) {
     return true;
   } else {
     return false;
   }
 }
Esempio n. 4
0
  public DocumentProxy getResponseXML() {
    // avoid eating up tons of memory if we have a large binary data blob
    if (TiMimeTypeHelper.isBinaryMimeType(contentType)) {
      return null;
    }
    if (responseXml == null && (responseData != null || responseText != null)) {
      try {
        responseXml = XMLModule.parse(proxy.getTiContext(), getResponseText());
      } catch (Exception e) {
        Log.e(LCAT, "Error parsing XML", e);
      }
    }

    return responseXml;
  }
Esempio n. 5
0
  @Override
  public TiBlob read() throws IOException {
    ByteArrayOutputStream baos = null;
    InputStream in = null;
    try {
      baos = new ByteArrayOutputStream();
      in = getInputStream();
      byte buffer[] = new byte[4096];
      while (true) {
        int count = in.read(buffer);
        if (count < 0) {
          break;
        }
        baos.write(buffer, 0, count);
      }
    } finally {
      if (in != null) {
        in.close();
      }
    }

    return TiBlob.blobFromData(
        getTiContext(), baos.toByteArray(), TiMimeTypeHelper.getMimeType(toURL()));
  }