X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FResources.java;h=c0240ca7d5e8c3ca710bbd9ceddc9e371416228a;hb=e58686eae8a823ed64ed0ec92c2274c41d90ec93;hp=d525ad094c6038c609b4d7a7ccaa4354d2216bbe;hpb=ad7d057ea80d61610f4b8729919384a979f389a2;p=org.ibex.core.git diff --git a/src/org/xwt/Resources.java b/src/org/xwt/Resources.java index d525ad0..c0240ca 100644 --- a/src/org/xwt/Resources.java +++ b/src/org/xwt/Resources.java @@ -4,10 +4,10 @@ package org.xwt; import java.io.*; import java.net.*; import java.util.*; -import jazz.*; +import java.util.zip.*; import java.lang.*; import java.applet.*; -import org.mozilla.javascript.*; +import org.xwt.js.*; import org.xwt.util.*; /** @@ -39,9 +39,8 @@ public class Resources { char c = name.charAt(i); if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || - c == '_' || - (c >= '0' && c <= '9') || - (c == '.' && i == name.length() - 4))) return false; + c == '_' || c == '.' || + (c >= '0' && c <= '9'))) return false; } return true; } @@ -61,7 +60,6 @@ public class Resources { if (name.endsWith(".xwt")) { String name2 = name.substring(0, name.length() - 4); Static.createStatic(name2.replace(File.separatorChar, '.'), false); - usedPackages.put(JSObject.nodeNameToPackageName(name2.replace('/', '.')), new Object()); } bytes.put(name.replace(File.separatorChar, '.'), file); } @@ -70,7 +68,7 @@ public class Resources { /** Load an archive from an inputstream. */ public static synchronized void loadArchive(InputStream is) throws IOException { loadArchive(is, 0, null); } - public static synchronized void loadArchive(InputStream is, final int length, final Function callback) throws IOException { + public static synchronized void loadArchive(InputStream is, final int length, final JS.Function callback) throws IOException { // random placeholder Object thisArchive = new Object(); @@ -84,13 +82,15 @@ public class Resources { } public int read(byte[] b, int off, int len) throws IOException { int ret = super.read(b, off, len); - if (ret != -1) bytesDownloaded += ret; if (clear && callback != null) { clear = false; - ThreadMessage.newthread(new JSObject.JSFunction() { - public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { + ThreadMessage.newthread(new JS.Function() { + public Object _call(JS.Array args_) throws JS.Exn { try { - callback.call(cx, null, null, new Object[] { new Double(bytesDownloaded), new Double(length) }); + JS.Array args = new JS.Array(); + args.addElement(new Double(bytesDownloaded)); + args.addElement(new Double(length)); + callback.call(args); } finally { clear = true; } @@ -98,10 +98,13 @@ public class Resources { } }); } + bytesDownloaded += ret; return ret; } }); + Template.TemplateHelper t = new Template.TemplateHelper(); + for(ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry()) { String name = ze.getName(); if (!validResourceName(name.substring(name.lastIndexOf('/') + 1))) { @@ -113,16 +116,8 @@ public class Resources { // placeholder so resolveResource() works properly bytes.put(name.replace('/', '.'), new byte[] { }); name = name.substring(0, name.length() - 4); - - String packageName = JSObject.nodeNameToPackageName(name.replace('/', '.')); - Object user = usedPackages.get(packageName); - if (user != null && user != thisArchive) { - if (Log.on) Log.log(Resources.class, "templates have already been loaded into " + packageName + "; refusing to load " + name); - } else { - usedPackages.put(packageName, thisArchive); - Static.createStatic(name.replace('/', '.'), false); - Template.buildTemplate(zis, name.replace('/', '.')); - } + Static.createStatic(name.replace('/', '.'), false); + Template.buildTemplate(zis, name.replace('/', '.'), t); } else { bytes.put(name.replace('/', '.'), isToByteArray(zis));