/sitev/
/.classpath
*.class
+/site1/
+/site2/
package javajs.api.js;
/**
- * methods in JSmol JavaScript accessed in Jmol
+ * methods in JSmol JavaScript accessed in Jmol
*/
public interface J2SObjectInterface {
- Object _doAjax(Object url, String postOut, Object bytesOrStringOut, boolean isBinary);
+ Object doAjax(String url, String postOut, Object bytesOrStringOut, boolean isBinary);
- void _apply(Object func, Object data);
+ void applyFunc(Object func, Object data);
}
*
*/
{
+ n -= i0;
+ int[] t = new int[n];
+ System.arraycopy(array, i0, t, 0, n);
+ return t;
}
- n -= i0;
- int[] t = new int[n];
- System.arraycopy(array, i0, t, 0, n);
- return t;
}
public static int[] arrayCopyRangeRevI(int[] array, int i0, int n) {
* return Clazz.array(-1, array, i0, n).reverse();
*/
{
+ int[] t = arrayCopyRangeI(array, i0, n);
+ if (n < 0)
+ n = array.length;
+ for (int i = n / 2; --i >= 0;)
+ swapInt(t, i, n - 1 - i);
+ return t;
}
- int[] t = arrayCopyRangeI(array, i0, n);
- if (n < 0)
- n = array.length;
- for (int i = n / 2; --i >= 0;)
- swapInt(t, i, n - 1 - i);
- return t;
}
public static short[] arrayCopyShort(short[] array, int newLength) {
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
* A method to allow a JavaScript Ajax
*
*/
-public class AjaxURLConnection extends URLConnection {
+public class AjaxURLConnection extends HttpURLConnection {
protected AjaxURLConnection(URL url) {
super(url);
*/
@SuppressWarnings("null")
private Object doAjax(boolean isBinary) {
- J2SObjectInterface j2s = null;
- /**
- * @j2sNative
- *
- * j2s = J2S;
- *
- */
- {
- }
- return j2s._doAjax(url, postOut, bytesOut, isBinary);
+ J2SObjectInterface J2S = /** @j2sNative self.J2S || */ null;
+ return J2S.doAjax(url.toString(), postOut, bytesOut, isBinary);
}
@Override
* data = url._streamData;
* if (andDelete) url._streamData = null;
*/
- {
- }
return (data == null ? null : Rdr.toBIS(data));
}
return doAjax(false);
}
+ @Override
+ public int getResponseCode() throws IOException {
+ /*
+ * We're got the response code already
+ */
+ if (responseCode != -1) {
+ return responseCode;
+ }
+
+ /*
+ * Ensure that we have connected to the server. Record
+ * exception as we need to re-throw it if there isn't
+ * a status line.
+ */
+ Exception exc = null;
+ try {
+ BufferedInputStream is = (BufferedInputStream) getInputStream();
+ if (is.available() > 40)
+ return responseCode = HTTP_OK;
+ is.mark(15);
+ byte[] bytes = new byte[13];
+ is.read(bytes);
+ is.reset();
+ String s = new String(bytes);
+ if (s.startsWith("Network Error"))
+ return responseCode = HTTP_NOT_FOUND;
+ } catch (Exception e) {
+ exc = e;
+ }
+ return responseCode = HTTP_INTERNAL_ERROR;
+ }
+@Override
+public void disconnect() {
+ // TODO Auto-generated method stub
+
+}
+
+@Override
+public boolean usingProxy() {
+ // TODO Auto-generated method stub
+ return false;
+}
+
}
| (bytes[j + 1] & 0xff) << 16 | (bytes[j] & 0xff) << 24
: (bytes[j++] & 0xff) | (bytes[j++] & 0xff) << 8
| (bytes[j++] & 0xff) << 16 | (bytes[j++] & 0xff) << 24);
- /**
- * @j2sNative
- *
- * return (n > 0x7FFFFFFF ? n - 0x100000000 : n);
- *
- */
- {
- return n;
- }
+
+ return (/** @j2sNative (n|0) || */ n);
+// /**
+// * xxxxxxj2sNative
+// *
+// * return (n > 0x7FFFFFFF ? n - 0x100000000 : n);
+// *
+// */
+// {
+// return n;
+// }
}
public static int intToSignedInt(int n) {
- /**
- * @j2sNative
- *
- * return (n > 0x7FFFFFFF ? n - 0x100000000 : n);
- *
- */
- {
- return n;
- }
+
+ return (/** @j2sNative n || */ n);
+
+// /**
+// * xxxxxxj2sNative
+// *
+// * return (n > 0x7FFFFFFF ? n - 0x100000000 : n);
+// *
+// */
+// {
+// return n;
+// }
}
public static float intToFloat(int x) throws Exception {
- /**
- * see http://en.wikipedia.org/wiki/Binary32
- *
- * [sign] [8 bits power] [23 bits fraction]
- * 0x80000000 0x7F800000 0x7FFFFF
- *
- * (untested)
- *
- * @j2sNative
- *
- * if (x == 0) return 0;
- * var o = javajs.util.BC;
- * if (o.fracIEEE == null)
- * o.setFracIEEE();
- * var m = ((x & 0x7F800000) >> 23);
- * return ((x & 0x80000000) == 0 ? 1 : -1) * o.shiftIEEE$D$I((x & 0x7FFFFF) | 0x800000, m - 149);
- *
- */
- {
+
+// // see http://en.wikipedia.org/wiki/Binary32
+// //
+// // [sign] [8 bits power] [23 bits fraction]
+// // 0x80000000 0x7F800000 0x7FFFFF
+// //
+// // (untested)
+// if (x == 0)
+// return 0;
+// boolean isJS = /** xxxxxxj2sNative true | */false;
+//
+//
+// if (isJS) {
+// if (fracIEEE == null)
+// setFracIEEE();
+// int m = ((x & 0x7F800000) >> 23);
+// * return ((x & 0x80000000) == 0 ? 1 : -1) * o.shiftIEEE$D$I((x & 0x7FFFFF) | 0x800000, m - 149);
+//
+// }
+// /**
+// *
+// * xxxxxxj2sNative
+// *
+// * if (x == 0) return 0;
+// * var o = javajs.util.BC;
+// * if (o.fracIEEE$ == null)
+// * o.setFracIEEE$();
+// * var m = ((x & 0x7F800000) >> 23);
+// * return ((x & 0x80000000) == 0 ? 1 : -1) * o.shiftIEEE$D$I((x & 0x7FFFFF) | 0x800000, m - 149);
+// *
+// */
+// {
return Float.intBitsToFloat(x);
- }
+ // }
}
/**
public class DebugJS {
- /**
- * Insert a JavaScript debug statement
- *
- */
- public static void _(String msg) {
- /**
- * @j2sNative
- *
- * if (Clazz._debugging) {
- *
- * debugger;
- *
- * }
- *
- */
- {}
- }
+// /**
+// * Insert a JavaScript debug statement
+// *
+// */
+// public static void _(String msg) {
+// /**
+// * xxxxj2sNative
+// *
+// * if (Clazz._debugging) {
+// *
+// * debugger;
+// *
+// * }
+// *
+// */
+// {}
+// }
}
*
*/
//@J2SRequireImport(swingjs.JSToolkit.class)
-public abstract class JSThread extends Thread implements JSFunction {
+public abstract class JSThread extends Thread {
public static final int INIT = 0;
public static final int LOOP = 1;
public static int threadCount = 0;
- protected boolean isJS;
+ protected boolean isJS = /** @j2sNative true || */false;
public JSThread() {
this(null, "JSThread-" + (++threadCount));
public JSThread(ThreadGroup group, String name) {
super(group, name);
- /**
- * @j2sNative
- *
- * this.isJS = true;
- */
- {}
- }
+ }
@Override
public void run() {
*
* setTimeout(
* function() {
- * java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent$java_awt_AWTEvent(
+ * java.awt.Toolkit.getDefaultToolkit$().getSystemEventQueue$().postEvent$java_awt_AWTEvent(
* Clazz.new_(java.awt.event.InvocationEvent.c$$O$Runnable,[me, r]))},
* delay);
*
private byte[] bytes; // preset bytes; output only
public boolean bigEndian = true;
+
+ private boolean isTemp;
+
+ /**
+ * Setting isTemp=true informs OC that this is a temporary file
+ * and not to send it to the user as a "download". Instead, the calling
+ * class can use .toByteArray() to retrieve the byte[] result.
+ *
+ * @param tf
+ */
+ public void setTemp(boolean tf) {
+ isTemp = tf;
+ }
+
+
@Override
public boolean isBigEndian() {
bigEndian = TF;
}
+ /**
+ * Set up an output channel. String or byte data can be added without problem.
+ *
+ * @param bytePoster a byte poster can take the output byte[] when closing and
+ * do something with them
+ * @param fileName TODO: It is possible that JavaScript will call this with a
+ * function name for fileName
+ * @param asWriter string-based
+ * @param os the desired target OutputStream - not the calling stream!
+ * @return
+ */
public OC setParams(BytePoster bytePoster, String fileName,
boolean asWriter, OutputStream os) {
this.bytePoster = bytePoster;
return (sb == null ? null : sb.toString());
}
closed = true;
- J2SObjectInterface jmol = null;
+ J2SObjectInterface J2S = null;
Object _function = null;
/**
* @j2sNative
*
- * jmol = self.J2S || Jmol; _function = (typeof this.fileName == "function" ?
+ * J2S = self.J2S || self.Jmol; _function = (typeof this.fileName == "function" ?
* this.fileName : null);
*
*/
return ret;
}
}
- if (jmol != null) {
+ if (J2S != null && !isTemp) {
+
+ // action here generally will be for the browser to display a download message
+ // temp files will not be sent this way.
Object data = (sb == null ? toByteArray() : sb.toString());
if (_function == null)
- jmol._doAjax(fileName, null, data, sb == null);
+ J2S.doAjax(fileName, null, data, sb == null);
else
- jmol._apply(_function, data);
+ J2S.applyFunc(_function, data);
}
return null;
}
}
public byte[] toByteArray() {
- return (bytes != null ? bytes : os instanceof ByteArrayOutputStream ? ((ByteArrayOutputStream)os).toByteArray() : null);
+ return (bytes != null ? bytes : (bytes = os instanceof ByteArrayOutputStream ? ((ByteArrayOutputStream)os).toByteArray() :
+ sb == null ? null : sb.toBytes(0, sb.length())));
}
@Override
return byteCount + " bytes";
}
+ /**
+ * We have constructed some sort of byte[] that needs to be posted to a remote site.
+ * We don't do that posting here -- we let the bytePoster do it.
+ *
+ * @return
+ */
private String postByteArray() {
- byte[] bytes = (sb == null ? toByteArray() : sb.toString().getBytes());
- return bytePoster.postByteArray(fileName, bytes);
+ return bytePoster == null ? null : bytePoster.postByteArray(fileName, toByteArray());
}
public final static String[] urlPrefixes = { "http:", "https:", "sftp:", "ftp:",
}
public static int parseIntRadix(String s, int i) throws NumberFormatException {
- /**
- *
- * JavaScript uses parseIntRadix
- *
- * @j2sNative
- *
- * return Integer.parseIntRadix(s, i);
- *
- */
- {
+// /**
+// *
+// * JavaScript uses parseIntRadix
+// *
+// * @j2sNative
+// *
+// * return Integer.parseIntRadix(s, i);
+// *
+// */
+// {
return Integer.parseInt(s, i);
- }
+// }
}
public static String[] getTokens(String line) {
*/
public static String escF(float f) {
String sf = "" + f;
+ // NaN, Infinity
/**
* @j2sNative
*
- * if (sf.indexOf(".") < 0 && sf.indexOf("e") < 0)
+ * if (sf.indexOf(".") < 0 && sf.indexOf("e") < 0 && sf.indexOf("N") < 0 && sf.indexOf("n") < 0)
* sf += ".0";
*/
{
private static Encoding getUTFEncodingForStream(BufferedInputStream is) throws IOException {
-// /**
-// * @j2sNative
-// *
-// * is.resetStream();
-// *
-// */
-// {
-// }
byte[] abMagic = new byte[4];
abMagic[3] = 1;
try{
public static byte[] getMagic(InputStream is, int n) {
byte[] abMagic = new byte[n];
-// /**
-// * @j2sNative
-// *
-// * is.resetStream();
-// *
-// */
-// {
-// }
try {
is.mark(n + 1);
is.read(abMagic, 0, n);
}
public static BufferedWriter getBufferedWriter(OutputStream os, String charSetName) {
- OutputStreamWriter osw = (OutputStreamWriter) Interface.getInstanceWithParams("java.io.OutputStreamWriter",
- new Class<?>[] { java.io.OutputStream.class, String.class },
- new Object[] { os, charSetName == null ? "UTF-8" : charSetName }
- );
- /**
- * @j2sNative
- * return osw.getBufferedWriter();
- *
- */
- {
- return new BufferedWriter(osw);
- }
+ OutputStreamWriter osw = (OutputStreamWriter) Interface.getInstanceWithParams("java.io.OutputStreamWriter",
+ new Class<?>[] { java.io.OutputStream.class, String.class },
+ new Object[] { os, charSetName == null ? "UTF-8" : charSetName });
+
+ return new BufferedWriter(osw);
}
@Override
public Object getZipOutputStream(Object bos) {
// /**
-// * @j2sNative
+// * xxxxj2sNative
// *
// * return javajs.api.Interface.getInterface(
// * "java.util.zip.ZipOutputStream").setZOS(bos);
-20180827222513
+20180917232142
-20180827222513
+20180917232142