Skip to content

Commit d92f54f

Browse files
committed
JSUtilI interface for AjaxURLConnection
maybe need to move AjaxURL Connection out of javajs
1 parent aa1d922 commit d92f54f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

sources/net.sf.j2s.java.core/src/javajs/util/AjaxURLConnection.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.function.Function;
1919

2020
import javajs.api.js.J2SObjectInterface;
21-
import swingjs.JSUtil;
21+
import swingjs.api.JSUtilI;
2222

2323
/**
2424
*
@@ -27,6 +27,14 @@
2727
*/
2828
public class AjaxURLConnection extends HttpURLConnection {
2929

30+
static private JSUtilI jsutil = null;
31+
static {
32+
try {
33+
jsutil = (JSUtilI) Class.forName("swingjs.JSUtil").newInstance();
34+
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
35+
e.printStackTrace();
36+
}
37+
}
3038
public static class AjaxHttpsURLConnection extends AjaxURLConnection {
3139

3240
static {
@@ -130,7 +138,7 @@ private Object doAjax(boolean isBinary, Function<Object, Void> whenDone) {
130138
getBytesOut();
131139
J2SObjectInterface J2S = /** @j2sNative self.J2S || */
132140
null;
133-
Object info = null;
141+
Object info = null;
134142
/**
135143
* @j2sNative
136144
*
@@ -188,7 +196,8 @@ private Object doAjax(boolean isBinary, Function<Object, Void> whenDone) {
188196
String myURL = url.toString();
189197
boolean isEmpty = false;
190198
if (myURL.startsWith("file:/TEMP/")) {
191-
result = JSUtil.getCachedFileData(myURL, true);
199+
200+
result = jsutil.getCachedBytes(myURL);
192201
isEmpty = (result == null);
193202
if (whenDone != null) {
194203
whenDone.apply(isEmpty ? null : result);
@@ -197,8 +206,8 @@ private Object doAjax(boolean isBinary, Function<Object, Void> whenDone) {
197206
responseCode = (isEmpty ? HTTP_NOT_FOUND : HTTP_ACCEPTED);
198207
} else {
199208
if (myURL.startsWith("file:")) {
200-
String path = JSUtil.J2S.getResourcePath("", true);
201-
String base = JSUtil.getAppletDocumentPath();
209+
String path = jsutil.getCodeBase().toString();
210+
String base = jsutil.getDocumentBase().toString();
202211
if (myURL.indexOf(path) >= 0)
203212
myURL = path + myURL.split(path)[1];
204213
else if (base != null && myURL.indexOf(base) == 0)

0 commit comments

Comments
 (0)