2003/07/05 22:11:55
[org.ibex.core.git] / src / org / xwt / Resources.java
index 26d4f68..615ef97 100644 (file)
@@ -6,8 +6,7 @@ import java.net.*;
 import java.util.*;
 import java.util.zip.*;
 import java.lang.*;
-import java.applet.*;
-import org.mozilla.javascript.*;
+import org.xwt.js.*;
 import org.xwt.util.*;
 
 /**
@@ -48,7 +47,9 @@ public class Resources {
     /** Load a directory as if it were an archive */
     public static synchronized void loadDirectory(File dir) throws IOException { loadDirectory(dir, ""); }
     private static synchronized void loadDirectory(File dir, String prefix) throws IOException {
-        new Static(prefix.replace(File.separatorChar, '.'));
+        String n = prefix.replace(File.separatorChar, '.');
+        if (n.endsWith(".")) n = n.substring(0, n.length() - 1);
+        new Static(n);
         String[] subfiles = dir.list();
         for(int i=0; i<subfiles.length; i++) {
             if (subfiles[i].equals("CVS") || !validResourceName(subfiles[i])) continue;
@@ -60,7 +61,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);
             }
@@ -69,7 +69,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.Callable callback) throws IOException {
 
         // random placeholder
         Object thisArchive = new Object();
@@ -85,10 +85,13 @@ public class Resources {
                     int ret = super.read(b, off, len);
                     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.Callable() {
+                                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;
                                     }
@@ -114,16 +117,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('/', '.'), t);
-                }
+                Static.createStatic(name.replace('/', '.'), false);
+                Template.buildTemplate(zis, name.replace('/', '.'), t);
 
             } else {
                 bytes.put(name.replace('/', '.'), isToByteArray(zis));