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