X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FRes.java;h=d35be0975b8d7649d1bb894fdfbeaa0001a812f3;hb=a03f96763f672e067b1cc08dcf17261a12e9e2e2;hp=df0813f8e6f01c3b73e256093f6c37d0445588ef;hpb=a76646eb76b01b5f1b5f0507b1c4bcd4202f1f11;p=org.ibex.core.git diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index df0813f..d35be09 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -12,19 +12,6 @@ import org.bouncycastle.util.encoders.Base64; /** Base class for XWT resources */ public abstract class Res extends JS { - - // Public Static ////////////////////////////////////////////////////////////////////// - - // FIXME: move to XWT.load()? - public static Res fromString(String url) { - if (url.startsWith("http://")) return new HTTP(url); - else if (url.startsWith("https://")) return new HTTP(url); - else if (url.startsWith("data:")) return new ByteArray(Base64.decode(url.substring(5)), null); - else if (url.startsWith("utf8:")) return new ByteArray(url.substring(5).getBytes(), null); - throw new JS.Exn("invalid resource specifier " + url); - } - - // Base Class ////////////////////////////////////////////////////////////////////// public String typeName() { return "resource"; } @@ -113,7 +100,7 @@ public abstract class Res extends JS { ByteArray(byte[] bytes, String cacheKey) { this.bytes = bytes; this.cacheKey = cacheKey; } public String getCacheKey() throws NotCacheableException { return cacheKey; } public InputStream getInputStream(String path) throws IOException { - if (!"".equals(path)) throw new JS.Exn("can't get subresources of a byte[] resource"); + if (!"".equals(path)) throw new JSExn("can't get subresources of a byte[] resource"); return new ByteArrayInputStream(bytes); } } @@ -141,7 +128,7 @@ public abstract class Res extends JS { ZipInputStream zis = new ZipInputStream(pis); ZipEntry ze = zis.getNextEntry(); while(ze != null && !ze.getName().equals(path)) ze = zis.getNextEntry(); - if (ze == null) throw new JS.Exn("requested file (" + path + ") not found in archive"); + if (ze == null) throw new JSExn("requested file (" + path + ") not found in archive"); return new KnownLength.KnownLengthInputStream(zis, (int)ze.getSize()); } } @@ -171,6 +158,7 @@ public abstract class Res extends JS { public static class Ref extends Res { Res parent; Object key; + public String toString() { return parent.toString() + "/" + key; } Ref(Res parent, Object key) { this.parent = parent; this.key = key; } public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "/" + key; } public Res addExtension(String extension) { @@ -197,10 +185,8 @@ public abstract class Res extends JS { int ret = super.read(b, off, len); if (ret != 1) bytesDownloaded += ret; Scheduler.add(new Scheduler.Task() { public void perform() { - JSArray args = new JSArray(); - args.addElement(new Integer(bytesDownloaded)); - args.addElement(new Integer(is instanceof KnownLength ? ((KnownLength)is).getLength() : 0)); - callback.call(args); + callback.call(N(bytesDownloaded), + N(is instanceof KnownLength ? ((KnownLength)is).getLength() : 0), null, null, 2); } }); return ret; }