3 import java.io.IOException;
4 import java.io.InputStream;
6 import java.net.URLConnection;
8 import javajs.api.JmolObjectInterface;
12 * A method to allow a JavaScript Ajax
15 public class AjaxURLConnection extends URLConnection {
17 protected AjaxURLConnection(URL url) {
26 * doAjax() is where the synchronous call to AJAX is to happen. or at least
27 * where we wait for the asynchronous call to return. This method should fill
28 * the dataIn field with either a string or byte array, or null if you want to
31 * url, bytesOut, and postOut are all available for use
33 * the method is "private", but in JavaScript that can still be overloaded.
34 * Just set something to org.jmol.awtjs.JmolURLConnection.prototype.doAjax
36 * @return file data as a javajs.util.SB or byte[] depending upon the file
41 @SuppressWarnings("null")
42 private Object doAjax() {
43 JmolObjectInterface jmol = null;
52 return jmol._doAjax(url, postOut, bytesOut);
56 public void connect() throws IOException {
57 // not expected to be used.
60 public void outputBytes(byte[] bytes) {
61 // type = "application/octet-stream;";
65 public void outputString(String post) {
67 // type = "application/x-www-form-urlencoded";
71 public InputStream getInputStream() {
72 InputStream is = null;
75 is = Rdr.getBIS((byte[]) o);
76 else if (o instanceof SB)
77 is = Rdr.getBIS(Rdr.getBytesFromSB((SB)o));
78 else if (o instanceof String)
79 is = Rdr.getBIS(((String) o).getBytes());
83 * @return javajs.util.SB or byte[], depending upon the file type
85 public Object getContents() {